diff --git a/src/modules/gimbal/output_gimbal_manager.cpp b/src/modules/gimbal/output_gimbal_manager.cpp index 1d93622c28c..9ee02f05990 100644 --- a/src/modules/gimbal/output_gimbal_manager.cpp +++ b/src/modules/gimbal/output_gimbal_manager.cpp @@ -85,6 +85,14 @@ void OutputToGimbalManager::update(const ControlData &control_data, bool new_set // This can't take control away from anyone, so it's still up to the // manager to arbitrate between its clients. _send_configure(true); + + } else if (!onboard_intent && _we_are_in_control() + && hrt_elapsed_time(&_last_configure) > CONFIGURE_RETRY_INTERVAL) { + // We don't want control but the manager reports that we have it, e.g. + // because our release got lost, or a retry of an earlier acquire reached + // the manager after the release (COMMAND_ACK can't tell which of the two + // it answers). Release again. This only removes control if we hold it. + _send_configure(false); } _onboard_intent = onboard_intent; @@ -123,6 +131,12 @@ bool OutputToGimbalManager::_nobody_in_control() const return _status.primary_control_sysid == 0 && _status.primary_control_compid == 0; } +bool OutputToGimbalManager::_we_are_in_control() const +{ + return _status.primary_control_sysid == (uint8_t)_parameters.mav_sysid + && _status.primary_control_compid == (uint8_t)_parameters.mav_compid; +} + void OutputToGimbalManager::_send_configure(bool acquire) { _last_configure = hrt_absolute_time(); diff --git a/src/modules/gimbal/output_gimbal_manager.h b/src/modules/gimbal/output_gimbal_manager.h index 3c5495e0365..823d5fdf69a 100644 --- a/src/modules/gimbal/output_gimbal_manager.h +++ b/src/modules/gimbal/output_gimbal_manager.h @@ -53,7 +53,9 @@ namespace gimbal // for control, while it lasts we stream GIMBAL_MANAGER_SET_PITCHYAW, and when // it ends we release control. If another client has taken control, the manager // ignores our setpoints. We only ask again while the manager reports that nobody -// is in control (e.g. after it restarted). +// is in control (e.g. after it restarted), and release again while it reports +// that we are in control without onboard intent (e.g. a lost release, or a +// retried acquire that reached the manager after the release). class OutputToGimbalManager : public OutputBase { public: @@ -68,6 +70,7 @@ private: void _update_manager_status(); void _send_configure(bool acquire); bool _nobody_in_control() const; + bool _we_are_in_control() const; void _publish_set_pitchyaw(); uORB::Subscription _status_sub{ORB_ID(external_gimbal_manager_status)};