Path: blob/master/libraries/AC_InputManager/AC_InputManager_Heli.cpp
9347 views
#include "AC_InputManager_Heli.h"1#include <AP_Math/AP_Math.h>2#include <AP_HAL/AP_HAL.h>3#include <GCS_MAVLink/GCS.h>45extern const AP_HAL::HAL& hal;67const AP_Param::GroupInfo AC_InputManager_Heli::var_info[] = {89// parameters from parent vehicle10AP_NESTEDGROUPINFO(AC_InputManager, 0),1112// Indicies 1-4 (STAB_COL_1 thru STAB_COL_4) have been replaced.1314// @Param: ACRO_COL_EXP15// @DisplayName: Acro Mode Collective Expo16// @Description: Used to soften collective pitch inputs near center point in Acro mode.17// @Values: 0:Disabled,0.1:Very Low,0.2:Low,0.3:Medium,0.4:High,0.5:Very High18// @Range: -0.5 0.9519// @User: Advanced20AP_GROUPINFO("ACRO_COL_EXP", 5, AC_InputManager_Heli, _acro_col_expo, 0),2122// @Param: STB_COL_123// @DisplayName: Stabilize Collective Low24// @Description: Helicopter's minimum collective pitch setting at zero collective stick input in Stabilize mode. Set this as a percent of collective range given by H_COL_MAX minus H_COL_MIN.25// @Range: 0 10026// @Units: %27// @Increment: 128// @User: Standard29AP_GROUPINFO("STB_COL_1", 6, AC_InputManager_Heli, _heli_stab_col_min, AC_ATTITUDE_HELI_STAB_COLLECTIVE_MIN_DEFAULT),3031// @Param: STB_COL_232// @DisplayName: Stabilize Collective Mid-Low33// @Description: Helicopter's collective pitch setting at mid-low (40%) collective stick input in Stabilize mode. Set this as a percent of collective range given by H_COL_MAX minus H_COL_MIN.34// @Range: 0 10035// @Units: %36// @Increment: 137// @User: Standard38AP_GROUPINFO("STB_COL_2", 7, AC_InputManager_Heli, _heli_stab_col_low, AC_ATTITUDE_HELI_STAB_COLLECTIVE_LOW_DEFAULT),3940// @Param: STB_COL_341// @DisplayName: Stabilize Collective Mid-High42// @Description: Helicopter's collective pitch setting at mid-high (60%) collective stick input in Stabilize mode. Set this as a percent of collective range given by H_COL_MAX minus H_COL_MIN.43// @Range: 0 10044// @Units: %45// @Increment: 146// @User: Standard47AP_GROUPINFO("STB_COL_3", 8, AC_InputManager_Heli, _heli_stab_col_high, AC_ATTITUDE_HELI_STAB_COLLECTIVE_HIGH_DEFAULT),4849// @Param: STB_COL_450// @DisplayName: Stabilize Collective High51// @Description: Helicopter's maximum collective pitch setting at full collective stick input in Stabilize mode. Set this as a percent of collective range given by H_COL_MAX minus H_COL_MIN.52// @Range: 0 10053// @Units: %54// @Increment: 155// @User: Standard56AP_GROUPINFO("STB_COL_4", 9, AC_InputManager_Heli, _heli_stab_col_max, AC_ATTITUDE_HELI_STAB_COLLECTIVE_MAX_DEFAULT),5758AP_GROUPEND59};6061// get_pilot_desired_collective - rescale's pilot collective pitch input in Stabilize and Acro modes62float AC_InputManager_Heli::get_pilot_desired_collective(int16_t control_in)63{64float slope_low, slope_high, slope_range, slope_run, scalar;65float stab_col_out, acro_col_out;6667// calculate stabilize collective value which scales pilot input to reduced collective range68// code implements a 3-segment curve with knee points at 40% and 60% throttle input69if (control_in < 400){ // control_in ranges from 0 to 100070slope_low = _heli_stab_col_min * 0.01f;71slope_high = _heli_stab_col_low * 0.01f;72slope_range = 0.4f;73slope_run = control_in * 0.001f;74} else if(control_in <600){ // control_in ranges from 0 to 100075slope_low = _heli_stab_col_low * 0.01f;76slope_high = _heli_stab_col_high * 0.01f;77slope_range = 0.2f;78slope_run = (control_in - 400) * 0.001f; // control_in ranges from 0 to 100079} else {80slope_low = _heli_stab_col_high * 0.01f;81slope_high = _heli_stab_col_max * 0.01f;82slope_range = 0.4f;83slope_run = (control_in - 600) * 0.001f; // control_in ranges from 0 to 100084}8586scalar = (slope_high - slope_low)/slope_range;87stab_col_out = slope_low + slope_run * scalar;88stab_col_out = constrain_float(stab_col_out, 0.0f, 1.0f);8990//91// calculate expo-scaled acro collective92// range check expo93if (_acro_col_expo > 1.0f) {94_acro_col_expo.set(1.0f);95}9697if (_acro_col_expo <= 0.0f) {98acro_col_out = control_in * 0.001f; // control_in ranges from 0 to 100099} else {100// expo variables101float col_in, col_in3, col_out;102col_in = (float)(control_in-500)/500.0f; // control_in ranges from 0 to 1000103col_in3 = col_in*col_in*col_in;104col_out = (_acro_col_expo * col_in3) + ((1.0f-_acro_col_expo)*col_in);105acro_col_out = 0.5f + col_out*0.5f;106}107acro_col_out = constrain_float(acro_col_out, 0.0f, 1.0f);108109// ramp function110if (is_positive(_ramp)) {111float dt = 1/(float)_loop_rate;112// factor 2 to transition over a time span of 0.5s113_ramp -= 2*dt;114_ramp = constrain_float(_ramp, 0.0f, 1.0f);115}116117//set Stabilize or Acro collective output118float new_flightmode_col_output;119if (_im_flags_heli.use_stab_col) {120new_flightmode_col_output = stab_col_out;121} else {122new_flightmode_col_output = acro_col_out;123}124125// scale collective output smoothly between previous and current mode output126float collective_out;127collective_out = new_flightmode_col_output * (1.0 - _ramp) + _ramp * _old_flightmode_col_output;128collective_out = constrain_float(collective_out, 0.0f, 1.0f);129130return collective_out;131}132133// parameter_check - check if input manager specific parameters are sensible134bool AC_InputManager_Heli::parameter_check(char* fail_msg, uint8_t fail_msg_len) const135{136137const struct StabCheck {138const char *name;139int16_t value;140} stab_checks[] = {141{"IM_STB_COL_1", _heli_stab_col_min },142{"IM_STB_COL_2", _heli_stab_col_low },143{"IM_STB_COL_3", _heli_stab_col_high },144{"IM_STB_COL_4", _heli_stab_col_max },145};146147// check values are within valid range148for (uint8_t i=0; i<ARRAY_SIZE(stab_checks); i++) {149const StabCheck check = stab_checks[i];150if ((check.value < 0) || (check.value > 100)){151hal.util->snprintf(fail_msg, fail_msg_len, "%s out of range", check.name);152return false;153}154}155// check values are in correct order156for (uint8_t i=1; i<ARRAY_SIZE(stab_checks); i++) {157if ((stab_checks[i-1].value >= stab_checks[i].value)){158hal.util->snprintf(fail_msg, fail_msg_len, "%s must be < %s", stab_checks[i-1].name, stab_checks[i].name);159return false;160}161}162// all other cases parameters are OK163return true;164}165166167168