Files
ardupilot/ArduCopter/mode_stabilize_heli.cpp
T
Randy MackayandIampete1 17792724fa Copter: simple mode fix
Co-authored-by: Iampete1 <iampete@hotmail.co.uk>

Replaces update_simple_mode with apply_simple_mode function that takes roll and pitch input arguments.  The rotation is now done within the various get-pilot-desired-xxx methods removing the need for each flight mode to call update_simple_mode and also removing the slightly ugly call to overwrite RC_Channels' control inputs from the flight code (e.g. no more calls to set_control_in)
2026-08-11 02:01:53 +01:00

80 lines
3.2 KiB
C++

#include "Copter.h"
#if FRAME_CONFIG == HELI_FRAME
/*
* Init and run calls for stabilize flight mode for trad heli
*/
// stabilize_init - initialise stabilize controller
bool ModeStabilize_Heli::init(bool ignore_checks)
{
// be aware that when adding code to this function that it is *NOT
// RUN* at vehicle startup!
// set stab collective true to use stabilize scaled collective pitch range
copter.input_manager.set_use_stab_col(true);
return true;
}
// stabilize_run - runs the main stabilize controller
// should be called at 100hz or more
void ModeStabilize_Heli::run()
{
float target_roll_rad, target_pitch_rad;
float pilot_throttle_scaled;
// convert pilot input to lean angles
get_pilot_desired_lean_angles_rad(target_roll_rad, target_pitch_rad, attitude_control->lean_angle_max_rad(), attitude_control->lean_angle_max_rad());
// get pilot's desired yaw rate
float target_yaw_rate_rads = get_pilot_desired_yaw_rate_rads();
// get pilot's desired throttle
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(channel_throttle->get_control_in());
// Tradheli should not reset roll, pitch, yaw targets when motors are not runup while flying, because
// we may be in autorotation flight. This is so that the servos move in a realistic fashion while disarmed
// for operational checks. Also, unlike multicopters we do not set throttle (i.e. collective pitch) to zero
// so the swash servos move.
// Request throttle unlimited. The setter enforces safety constraints:
// - Disarmed: held at SHUT_DOWN until armed
// - Armed without interlock: limited to GROUND_IDLE (swash can move, rotor stopped)
// - Armed with interlock: THROTTLE_UNLIMITED granted
motors->set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
switch (motors->get_spool_state()) {
case AP_Motors::SpoolState::SHUT_DOWN:
// Motors Stopped
attitude_control->reset_yaw_target_and_rate(false);
attitude_control->reset_rate_controller_I_terms();
break;
case AP_Motors::SpoolState::GROUND_IDLE:
// If aircraft is landed, set target heading to current and reset the integrator
// Otherwise motors could be at ground idle for practice autorotation
if ((motors->init_targets_on_arming() && motors->using_leaky_integrator()) || (copter.ap.land_complete && !motors->using_leaky_integrator())) {
attitude_control->reset_yaw_target_and_rate(false);
attitude_control->reset_rate_controller_I_terms_smoothly();
}
break;
case AP_Motors::SpoolState::THROTTLE_UNLIMITED:
if (copter.ap.land_complete && !motors->using_leaky_integrator()) {
attitude_control->reset_rate_controller_I_terms_smoothly();
}
break;
case AP_Motors::SpoolState::SPOOLING_UP:
case AP_Motors::SpoolState::SPOOLING_DOWN:
// do nothing
break;
}
// call attitude controller
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw_rad(target_roll_rad, target_pitch_rad, target_yaw_rate_rads);
// output pilot's throttle
attitude_control->set_throttle_out(pilot_throttle_scaled, true, g.throttle_filt);
}
#endif //HELI_FRAME