Skip to content

Commit

Permalink
AP_ExternalControl_Copter: Refactor ready for control
Browse files Browse the repository at this point in the history
* Refactor ready state to a single clearer function
* It can be re-used for all controls API's

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Aug 10, 2023
1 parent 911c236 commit 7f56e7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ArduCopter/AP_ExternalControl_Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
bool AP_ExternalControl_Copter::set_linear_velocity_and_yaw_rate(const Vector3f &linear_velocity, float yaw_rate_rads)
{
if (!copter.flightmode->in_guided_mode() || !copter.motors->armed()) {
if (!ready_for_external_control()) {
return false;
}
const float yaw_rate_cds = isnan(yaw_rate_rads)? 0: degrees(yaw_rate_rads)*100;
Expand All @@ -29,4 +29,9 @@ bool AP_ExternalControl_Copter::set_linear_velocity_and_yaw_rate(const Vector3f
return true;
}

bool AP_ExternalControl_Copter::ready_for_external_control()
{
return copter.flightmode->in_guided_mode() && copter.motors->armed();
}

#endif // AP_EXTERNAL_CONTROL_ENABLED
6 changes: 6 additions & 0 deletions ArduCopter/AP_ExternalControl_Copter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class AP_ExternalControl_Copter : public AP_ExternalControl {
Yaw is in earth frame, NED [rad/s].
*/
bool set_linear_velocity_and_yaw_rate(const Vector3f &linear_velocity, float yaw_rate_rads) override;
private:
/*
Return true if Copter is ready to handle external control data.
Currently checks mode and arm states.
*/
bool ready_for_external_control();
};

#endif // AP_EXTERNAL_CONTROL_ENABLED

0 comments on commit 7f56e7b

Please sign in to comment.