Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_Autorotation/RSC_Autorotation.cpp
Views: 1798
#include "RSC_Autorotation.h"1#include <GCS_MAVLink/GCS.h>2#include <AP_HAL/AP_HAL.h>34#define RSC_AROT_RAMP_TIME_DEFAULT 2 // time in seconds to ramp motors when bailing out of autorotation56extern const AP_HAL::HAL& hal;78// RSC autorotation state specific parameters9const AP_Param::GroupInfo RSC_Autorotation::var_info[] = {1011// @Param: ENBL12// @DisplayName: Enable autorotation handling in RSC13// @Description: Allows you to enable (1) or disable (0) the autorotation functionality within the Rotor Speed Controller.14// @Values: 0:Disabled,1:Enabled15// @User: Standard16AP_GROUPINFO_FLAGS("ENBL", 1, RSC_Autorotation, enable, 0, AP_PARAM_FLAG_ENABLE),1718// @Param: RAMP19// @DisplayName: Time for in-flight power re-engagement when exiting autorotations20// @Description: When exiting an autorotation in a bailout manoeuvre, this is the time in seconds for the throttle output (HeliRSC servo) to ramp from idle (H_RSC_AROT_IDLE) to flight throttle setting when motor interlock is re-enabled. When using an ESC with an autorotation bailout function, this parameter should be set to 0.1 (minimum value).21// @Range: 0.1 1022// @Units: s23// @Increment: 0.124// @User: Standard25AP_GROUPINFO("RAMP", 2, RSC_Autorotation, bailout_throttle_time, RSC_AROT_RAMP_TIME_DEFAULT),2627// @Param: IDLE28// @DisplayName: Idle throttle percentage during autorotation29// @Description: Idle throttle used for during autotoration. For external governors, this would be set to a value that is within the autorotation window of the governer/ESC to enable fast spool-up, when bailing out of an autorotation. Set 0 to disable.30// @Range: 0 4031// @Units: %32// @Increment: 133// @User: Standard34AP_GROUPINFO("IDLE", 3, RSC_Autorotation, idle_output, 0.0),3536// @Param: RUNUP37// @DisplayName: Time allowed for in-flight power re-engagement38// @Description: When exiting an autorotation in a bailout manoeuvre, this is the expected time in seconds for the main rotor to reach full speed after motor interlock is enabled. Must be at least one second longer than the H_RSC_AROT_RAMP time that is set. This timer should be set for at least the amount of time it takes to get your helicopter to full flight power. Failure to heed this warning could result in early entry into autonomously controlled collective modes (e.g. alt hold, loiter, etc), whereby the collective could be raised before the engine has reached full power, with a subsequently dangerous slowing of head speed.39// @Range: 1 1040// @Units: s41// @Increment: 0.142// @User: Standard43AP_GROUPINFO("RUNUP", 4, RSC_Autorotation, bailout_runup_time, RSC_AROT_RAMP_TIME_DEFAULT+1),4445AP_GROUPEND46};4748RSC_Autorotation::RSC_Autorotation(void)49{50AP_Param::setup_object_defaults(this, var_info);51}5253// set the desired autorotation state54// this state machine handles the transition from active to deactivated via the bailout logic55// to force the state to be immediately deactivated, then the force_state bool is used56void RSC_Autorotation::set_active(bool active, bool force_state)57{58if (enable.get() != 1) {59return;60}6162// set the desired state based on the bool. We only set either ACTIVE or DEACTIVATED63// here and let the autorotation state machine and RSC runup code handle the bail out case64RSC_Autorotation::State desired_state = active ? RSC_Autorotation::State::ACTIVE : RSC_Autorotation::State::DEACTIVATED;6566// don't do anything if desired state is already set67if (desired_state == state) {68return;69}7071// Handle the transition from the ACTIVE to DEACTIVATED states via the BAILING_OUT case72// set the bailout case if deactivated has just been requested73if ((state == State::ACTIVE) && (desired_state == State::DEACTIVATED) && !force_state) {74desired_state = State::BAILING_OUT;75bail_out_started_ms = AP_HAL::millis();76}7778// Wait for allocated autorotation run up time before we allow progression of state to deactivated79if ((state == State::BAILING_OUT) &&80(desired_state == State::DEACTIVATED) &&81(bail_out_started_ms > 0) &&82(AP_HAL::millis() - bail_out_started_ms < uint32_t(get_runup_time()*1000)))83{84return;85}8687// handle GCS messages88switch (desired_state)89{90case State::DEACTIVATED:91GCS_SEND_TEXT(MAV_SEVERITY_NOTICE, "RSC: Autorotation Stopped");92break;9394case State::BAILING_OUT:95GCS_SEND_TEXT(MAV_SEVERITY_NOTICE, "RSC: Bailing Out");96break;9798case State::ACTIVE:99GCS_SEND_TEXT(MAV_SEVERITY_NOTICE, "RSC: In Autorotation");100break;101102default:103// do nothing104break;105}106107// Actually set the state108state = desired_state;109}110111bool RSC_Autorotation::get_idle_throttle(float& idle_throttle)112{113if (state != State::ACTIVE) {114// We do not want to use autorotation idle throttle115return false;116}117118if (idle_output.get() <= 0) {119// If autorotation idle is not set, do not modify idle throttle as we just use H_RSC_IDLE120// Heli with an ICE engine is an example of this type of config121return true;122}123124// if we are autorotating and the autorotation idle throttle param is set we want to125// to output this as the idle throttle for ESCs with an autorotation window126idle_throttle = constrain_float(idle_output.get()*0.01, 0.0, 0.4);127128return true;129}130131float RSC_Autorotation::get_bailout_ramp(void) const132{133// Allow ramp times as quick as 0.1 of a second for ESCs with autorotation windows134return MAX(float(bailout_throttle_time.get()), 0.1);135}136137float RSC_Autorotation::get_runup_time(void) const138{139// If we are in the autorotation state we want the rotor speed model to ramp down rapidly to zero, ensuring we get past140// the critical rotor speed, and therefore triggering a proper bailout should we re-engage the interlock at any point141if (state == State::ACTIVE) {142return 0.1;143}144145// Never let the runup timer be less than the throttle ramp time146return (float) MAX(bailout_throttle_time.get() + 1, bailout_runup_time.get());147}148149// sanity check of parameters, should be called only whilst disarmed150bool RSC_Autorotation::arming_checks(size_t buflen, char *buffer) const151{152// throttle runup must be larger than ramp, keep the params up to date to not confuse users153if (bailout_throttle_time.get() + 1 > bailout_runup_time.get()) {154hal.util->snprintf(buffer, buflen, "H_RSC_AROT_RUNUP must be > H_RSC_AROT_RAMP");155return false;156}157return true;158}159160161