Skip to content

Commit

Permalink
AP_Mount: added gimbal rates for SIYI
Browse files Browse the repository at this point in the history
this helps diagnose issues with gyro bias versus control when camera
is spinning
  • Loading branch information
tridge committed Nov 15, 2023
1 parent 6748a07 commit 715d235
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 5 additions & 3 deletions libraries/AP_Mount/AP_Mount_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void AP_Mount_Backend::send_gimbal_device_attitude_status(mavlink_channel_t chan
if (!get_attitude_quaternion(att_quat)) {
return;
}
Vector3f ang_velocity { nanf(""), nanf(""), nanf("") };
IGNORE_RETURN(get_angular_velocity(ang_velocity));

// construct quaternion array
const float quat_array[4] = {att_quat.q1, att_quat.q2, att_quat.q3, att_quat.q4};
Expand All @@ -152,9 +154,9 @@ void AP_Mount_Backend::send_gimbal_device_attitude_status(mavlink_channel_t chan
AP_HAL::millis(), // autopilot system time
get_gimbal_device_flags(),
quat_array, // attitude expressed as quaternion
std::numeric_limits<double>::quiet_NaN(), // roll axis angular velocity (NaN for unknown)
std::numeric_limits<double>::quiet_NaN(), // pitch axis angular velocity (NaN for unknown)
std::numeric_limits<double>::quiet_NaN(), // yaw axis angular velocity (NaN for unknown)
ang_velocity.x, // roll axis angular velocity (NaN for unknown)
ang_velocity.y, // pitch axis angular velocity (NaN for unknown)
ang_velocity.z, // yaw axis angular velocity (NaN for unknown)
0, // failure flags (not supported)
std::numeric_limits<double>::quiet_NaN(), // delta_yaw (NaN for unknonw)
std::numeric_limits<double>::quiet_NaN(), // delta_yaw_velocity (NaN for unknonw)
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Mount/AP_Mount_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class AP_Mount_Backend
// yaw is in body-frame.
virtual bool get_attitude_quaternion(Quaternion& att_quat) = 0;

// get angular velocity of mount. Only available on some backends
virtual bool get_angular_velocity(Vector3f& rates) { return false; }

// get mount's mode
enum MAV_MOUNT_MODE get_mode() const { return _mode; }

Expand Down
8 changes: 4 additions & 4 deletions libraries/AP_Mount/AP_Mount_Siyi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void AP_Mount_Siyi::update()
_last_attitude_send_ms = now_ms;
send_attitude();
}

// run zoom control
update_zoom_control();

Expand Down Expand Up @@ -540,9 +540,9 @@ void AP_Mount_Siyi::process_packet()
_current_angle_rad.z = -radians((int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+1], _msg_buff[_msg_buff_data_start]) * 0.1); // yaw angle
_current_angle_rad.y = radians((int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+3], _msg_buff[_msg_buff_data_start+2]) * 0.1); // pitch angle
_current_angle_rad.x = radians((int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+5], _msg_buff[_msg_buff_data_start+4]) * 0.1); // roll angle
//const float yaw_rate_degs = -(int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+7], _msg_buff[_msg_buff_data_start+6]) * 0.1; // yaw rate
//const float pitch_rate_deg = (int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+9], _msg_buff[_msg_buff_data_start+8]) * 0.1; // pitch rate
//const float roll_rate_deg = (int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+11], _msg_buff[_msg_buff_data_start+10]) * 0.1; // roll rate
_current_rates_rads.z = -radians((int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+7], _msg_buff[_msg_buff_data_start+6]) * 0.1); // yaw rate
_current_rates_rads.y = radians((int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+9], _msg_buff[_msg_buff_data_start+8]) * 0.1); // pitch rate
_current_rates_rads.x = radians((int16_t)UINT16_VALUE(_msg_buff[_msg_buff_data_start+11], _msg_buff[_msg_buff_data_start+10]) * 0.1); // roll rate
break;
}

Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_Mount/AP_Mount_Siyi.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class AP_Mount_Siyi : public AP_Mount_Backend
// get attitude as a quaternion. returns true on success
bool get_attitude_quaternion(Quaternion& att_quat) override;

// get angular velocity of mount. Only available on some backends
bool get_angular_velocity(Vector3f& rates) override {
rates = _current_rates_rads;
return true;
}

private:

// serial protocol command ids
Expand Down Expand Up @@ -309,6 +315,7 @@ class AP_Mount_Siyi : public AP_Mount_Backend

// actual attitude received from gimbal
Vector3f _current_angle_rad; // current angles in radians received from gimbal (x=roll, y=pitch, z=yaw)
Vector3f _current_rates_rads; // current angular rates in rad/s (x=roll, y=pitch, z=yaw)
uint32_t _last_current_angle_rad_ms; // system time _current_angle_rad was updated
uint32_t _last_req_current_angle_rad_ms; // system time that this driver last requested current angle

Expand Down

0 comments on commit 715d235

Please sign in to comment.