Skip to content

Commit

Permalink
provisional commit gimbal manager status support
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidsastresas committed May 8, 2023
1 parent 871797d commit 79510c5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
11 changes: 11 additions & 0 deletions libraries/AP_Mount/AP_Mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,17 @@ void AP_Mount::send_gimbal_manager_information(mavlink_channel_t chan)
}
}

// send a GIMBAL_MANAGER_STATUS message to GCS
void AP_Mount::send_gimbal_manager_status(mavlink_channel_t chan)
{
// call send_gimbal_device_attitude_status for each instance
for (uint8_t instance=0; instance<AP_MOUNT_MAX_INSTANCES; instance++) {
if (_backends[instance] != nullptr) {
_backends[instance]->send_gimbal_manager_status(chan);
}
}
}

// get mount's current attitude in euler angles in degrees. yaw angle is in body-frame
// returns true on success
bool AP_Mount::get_attitude_euler(uint8_t instance, float& roll_deg, float& pitch_deg, float& yaw_bf_deg)
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Mount/AP_Mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class AP_Mount
// send a GIMBAL_MANAGER_INFORMATION message to GCS
void send_gimbal_manager_information(mavlink_channel_t chan);

// send a GIMBAL_MANAGER_STATUS message to GCS
void send_gimbal_manager_status(mavlink_channel_t chan);

// get mount's current attitude in euler angles in degrees. yaw angle is in body-frame
// returns true on success
bool get_attitude_euler(uint8_t instance, float& roll_deg, float& pitch_deg, float& yaw_bf_deg);
Expand Down
13 changes: 13 additions & 0 deletions libraries/AP_Mount/AP_Mount_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ void AP_Mount_Backend::send_gimbal_manager_information(mavlink_channel_t chan)
radians(_params.yaw_angle_max)); // yaw_max in radians
}

// send a GIMBAL_MANAGER_STATUS message to GCS
void AP_Mount_Backend::send_gimbal_manager_status(mavlink_channel_t chan)
{
mavlink_msg_gimbal_manager_status_send(chan,
AP_HAL::millis(), // autopilot system time
get_gimbal_manager_capability_flags(), // bitmap of gimbal manager capability flags
_instance, // gimbal device id
_gimbal_manager_primary_control_sysid, // gimbal manager primary control sysid
_gimbal_manager_primary_control_compid, // gimbal manager primary control compid
0, // gimbal manager secondary control sysid ( unsupported for the moment )
0); // gimbal manager secondary control compid ( unsupported for the moment )
}

// process MOUNT_CONTROL messages received from GCS. deprecated.
void AP_Mount_Backend::handle_mount_control(const mavlink_mount_control_t &packet)
{
Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_Mount/AP_Mount_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class AP_Mount_Backend
// send a GIMBAL_MANAGER_INFORMATION message to GCS
void send_gimbal_manager_information(mavlink_channel_t chan);

// send a GIMBAL_MANAGER_STATUS message to GCS
void send_gimbal_manager_status(mavlink_channel_t chan);

// handle a GIMBAL_REPORT message
virtual void handle_gimbal_report(mavlink_channel_t chan, const mavlink_message_t &msg) {}

Expand Down Expand Up @@ -229,6 +232,10 @@ class AP_Mount_Backend
bool _target_sysid_location_set;// true if _target_sysid has been set

uint32_t _last_warning_ms; // system time of last warning sent to GCS

// Gimbal manager status fields
uint8_t _gimbal_manager_primary_control_sysid = 0;
uint8_t _gimbal_manager_primary_control_compid = 0;
};

#endif // HAL_MOUNT_ENABLED
1 change: 1 addition & 0 deletions libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class GCS_MAVLINK
void send_vibration() const;
void send_gimbal_device_attitude_status() const;
void send_gimbal_manager_information() const;
void send_gimbal_manager_status() const;
void send_named_float(const char *name, float value) const;
void send_home_position() const;
void send_gps_global_origin() const;
Expand Down
22 changes: 20 additions & 2 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,10 @@ ap_message GCS_MAVLINK::mavlink_id_to_ap_message_id(const uint32_t mavlink_id) c
#endif
{ MAVLINK_MSG_ID_CAMERA_FEEDBACK, MSG_CAMERA_FEEDBACK},
#if HAL_MOUNT_ENABLED
{ MAVLINK_MSG_ID_GIMBAL_DEVICE_ATTITUDE_STATUS, MSG_GIMBAL_DEVICE_ATTITUDE_STATUS},
{ MAVLINK_MSG_ID_GIMBAL_DEVICE_ATTITUDE_STATUS, MSG_GIMBAL_DEVICE_ATTITUDE_STATUS},
{ MAVLINK_MSG_ID_AUTOPILOT_STATE_FOR_GIMBAL_DEVICE, MSG_AUTOPILOT_STATE_FOR_GIMBAL_DEVICE},
{ MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, MSG_GIMBAL_MANAGER_INFORMATION},
{ MAVLINK_MSG_ID_GIMBAL_MANAGER_INFORMATION, MSG_GIMBAL_MANAGER_INFORMATION},
{ MAVLINK_MSG_ID_GIMBAL_MANAGER_STATUS, MSG_GIMBAL_MANAGER_STATUS},
#endif
#if AP_OPTICALFLOW_ENABLED
{ MAVLINK_MSG_ID_OPTICAL_FLOW, MSG_OPTICAL_FLOW},
Expand Down Expand Up @@ -5344,6 +5345,17 @@ void GCS_MAVLINK::send_gimbal_manager_information() const
}
#endif

#if HAL_MOUNT_ENABLED
void GCS_MAVLINK::send_gimbal_manager_status() const
{
AP_Mount *mount = AP::mount();
if (mount == nullptr) {
return;
}
mount->send_gimbal_manager_status(chan);
}
#endif

void GCS_MAVLINK::send_set_position_target_global_int(uint8_t target_system, uint8_t target_component, const Location& loc)
{

Expand Down Expand Up @@ -5672,6 +5684,12 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id)
#if HAL_MOUNT_ENABLED
CHECK_PAYLOAD_SIZE(GIMBAL_MANAGER_INFORMATION);
send_gimbal_manager_information();
#endif
break;
case MSG_GIMBAL_MANAGER_STATUS:
#if HAL_MOUNT_ENABLED
CHECK_PAYLOAD_SIZE(GIMBAL_MANAGER_STATUS);
send_gimbal_manager_status();
#endif
break;
case MSG_OPTICAL_FLOW:
Expand Down
1 change: 1 addition & 0 deletions libraries/GCS_MAVLink/ap_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum ap_message : uint8_t {
MSG_CAMERA_FEEDBACK,
MSG_GIMBAL_DEVICE_ATTITUDE_STATUS,
MSG_GIMBAL_MANAGER_INFORMATION,
MSG_GIMBAL_MANAGER_STATUS,
MSG_OPTICAL_FLOW,
MSG_MAG_CAL_PROGRESS,
MSG_MAG_CAL_REPORT,
Expand Down

0 comments on commit 79510c5

Please sign in to comment.