Skip to content

Commit

Permalink
Copter: add flightmode method allows_inverted only allowing inverted …
Browse files Browse the repository at this point in the history
…in supported modes
  • Loading branch information
IamPete1 committed Feb 28, 2024
1 parent 25c9917 commit a170665
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ArduCopter/RC_Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ bool RC_Channel_Copter::do_aux_function(const AUX_FUNC ch_option, const AuxSwitc
#if FRAME_CONFIG == HELI_FRAME
switch (ch_flag) {
case AuxSwitchPos::HIGH:
copter.motors->set_inverted_flight(true);
if (copter.flightmode->allows_inverted()) {
copter.motors->set_inverted_flight(true);
} else {
gcs().send_text(MAV_SEVERITY_WARNING, "Inverted flight not available in %s mode", copter.flightmode->name());
}
break;
case AuxSwitchPos::MIDDLE:
// nothing
Expand Down
5 changes: 5 additions & 0 deletions ArduCopter/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ void Copter::exit_mode(Mode *&old_flightmode,
input_manager.set_stab_col_ramp(0.0);
}
}

// Make sure inverted flight is disabled if not supported in the new mode
if (!new_flightmode->allows_inverted()) {
motors->set_inverted_flight(false);
}
#endif //HELI_FRAME
}

Expand Down
6 changes: 6 additions & 0 deletions ArduCopter/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class Mode {
virtual bool allows_autotune() const { return false; }
virtual bool allows_flip() const { return false; }

#if FRAME_CONFIG == HELI_FRAME
virtual bool allows_inverted() const { return false; };
#endif

// return a string for this flightmode
virtual const char *name() const = 0;
virtual const char *name4() const = 0;
Expand Down Expand Up @@ -1574,6 +1578,8 @@ class ModeStabilize_Heli : public ModeStabilize {
bool init(bool ignore_checks) override;
void run() override;

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

protected:

private:
Expand Down

0 comments on commit a170665

Please sign in to comment.