Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copter: add and use new afs_mode mode method #28132

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions ArduCopter/afs_copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,7 @@ void AP_AdvancedFailsafe_Copter::setup_IO_failsafe(void)
*/
AP_AdvancedFailsafe::control_mode AP_AdvancedFailsafe_Copter::afs_mode(void)
{
switch (copter.flightmode->mode_number()) {
case Mode::Number::AUTO:
case Mode::Number::AUTO_RTL:
case Mode::Number::GUIDED:
case Mode::Number::RTL:
case Mode::Number::LAND:
return AP_AdvancedFailsafe::AFS_AUTO;
default:
break;
}
return AP_AdvancedFailsafe::AFS_STABILIZED;
return copter.flightmode->afs_mode();
}

//to force entering auto mode when datalink loss
Expand Down
29 changes: 29 additions & 0 deletions ArduCopter/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <AP_Math/chirp.h>
#include <AP_ExternalControl/AP_ExternalControl_config.h> // TODO why is this needed if Copter.h includes this

#if ADVANCED_FAILSAFE
#include "afs_copter.h"
#endif

class Parameters;
class ParametersG2;

Expand Down Expand Up @@ -130,6 +134,11 @@ class Mode {
virtual bool allows_flip() const { return false; }
virtual bool crash_check_enabled() const { return true; }

#if ADVANCED_FAILSAFE
// Return the type of this mode for use by advanced failsafe
virtual AP_AdvancedFailsafe_Copter::control_mode afs_mode() const { return AP_AdvancedFailsafe_Copter::control_mode::AFS_STABILIZED; }
#endif

#if FRAME_CONFIG == HELI_FRAME
virtual bool allows_inverted() const { return false; };
#endif
Expand Down Expand Up @@ -509,6 +518,11 @@ class ModeAuto : public Mode {
bool allows_inverted() const override { return true; };
#endif

#if ADVANCED_FAILSAFE
// Return the type of this mode for use by advanced failsafe
AP_AdvancedFailsafe_Copter::control_mode afs_mode() const override { return AP_AdvancedFailsafe_Copter::control_mode::AFS_AUTO; }
#endif

// Auto modes
enum class SubMode : uint8_t {
TAKEOFF,
Expand Down Expand Up @@ -1047,6 +1061,11 @@ class ModeGuided : public Mode {

bool requires_terrain_failsafe() const override { return true; }

#if ADVANCED_FAILSAFE
// Return the type of this mode for use by advanced failsafe
AP_AdvancedFailsafe_Copter::control_mode afs_mode() const override { return AP_AdvancedFailsafe_Copter::control_mode::AFS_AUTO; }
#endif

// Sets guided's angular target submode: Using a rotation quaternion, angular velocity, and climbrate or thrust (depends on user option)
// attitude_quat: IF zero: ang_vel (angular velocity) must be provided even if all zeroes
// IF non-zero: attitude_control is performed using both the attitude quaternion and angular velocity
Expand Down Expand Up @@ -1214,6 +1233,11 @@ class ModeLand : public Mode {

bool is_landing() const override { return true; };

#if ADVANCED_FAILSAFE
// Return the type of this mode for use by advanced failsafe
AP_AdvancedFailsafe_Copter::control_mode afs_mode() const override { return AP_AdvancedFailsafe_Copter::control_mode::AFS_AUTO; }
#endif

void do_not_use_GPS();

// returns true if LAND mode is trying to control X/Y position
Expand Down Expand Up @@ -1391,6 +1415,11 @@ class ModeRTL : public Mode {

bool requires_terrain_failsafe() const override { return true; }

#if ADVANCED_FAILSAFE
// Return the type of this mode for use by advanced failsafe
AP_AdvancedFailsafe_Copter::control_mode afs_mode() const override { return AP_AdvancedFailsafe_Copter::control_mode::AFS_AUTO; }
#endif

// for reporting to GCS
bool get_wp(Location &loc) const override;

Expand Down
Loading