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_InputManager/AC_InputManager_Heli.cpp
Views: 1798
#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// @User: Advanced19AP_GROUPINFO("ACRO_COL_EXP", 5, AC_InputManager_Heli, _acro_col_expo, 0),2021// @Param: STB_COL_122// @DisplayName: Stabilize Collective Low23// @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.24// @Range: 0 10025// @Units: %26// @Increment: 127// @User: Standard28AP_GROUPINFO("STB_COL_1", 6, AC_InputManager_Heli, _heli_stab_col_min, AC_ATTITUDE_HELI_STAB_COLLECTIVE_MIN_DEFAULT),2930// @Param: STB_COL_231// @DisplayName: Stabilize Collective Mid-Low32// @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.33// @Range: 0 10034// @Units: %35// @Increment: 136// @User: Standard37AP_GROUPINFO("STB_COL_2", 7, AC_InputManager_Heli, _heli_stab_col_low, AC_ATTITUDE_HELI_STAB_COLLECTIVE_LOW_DEFAULT),3839// @Param: STB_COL_340// @DisplayName: Stabilize Collective Mid-High41// @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.42// @Range: 0 10043// @Units: %44// @Increment: 145// @User: Standard46AP_GROUPINFO("STB_COL_3", 8, AC_InputManager_Heli, _heli_stab_col_high, AC_ATTITUDE_HELI_STAB_COLLECTIVE_HIGH_DEFAULT),4748// @Param: STB_COL_449// @DisplayName: Stabilize Collective High50// @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.51// @Range: 0 10052// @Units: %53// @Increment: 154// @User: Standard55AP_GROUPINFO("STB_COL_4", 9, AC_InputManager_Heli, _heli_stab_col_max, AC_ATTITUDE_HELI_STAB_COLLECTIVE_MAX_DEFAULT),5657AP_GROUPEND58};5960// get_pilot_desired_collective - rescale's pilot collective pitch input in Stabilize and Acro modes61float AC_InputManager_Heli::get_pilot_desired_collective(int16_t control_in)62{63float slope_low, slope_high, slope_range, slope_run, scalar;64float stab_col_out, acro_col_out;6566// calculate stabilize collective value which scales pilot input to reduced collective range67// code implements a 3-segment curve with knee points at 40% and 60% throttle input68if (control_in < 400){ // control_in ranges from 0 to 100069slope_low = _heli_stab_col_min * 0.01f;70slope_high = _heli_stab_col_low * 0.01f;71slope_range = 0.4f;72slope_run = control_in * 0.001f;73} else if(control_in <600){ // control_in ranges from 0 to 100074slope_low = _heli_stab_col_low * 0.01f;75slope_high = _heli_stab_col_high * 0.01f;76slope_range = 0.2f;77slope_run = (control_in - 400) * 0.001f; // control_in ranges from 0 to 100078} else {79slope_low = _heli_stab_col_high * 0.01f;80slope_high = _heli_stab_col_max * 0.01f;81slope_range = 0.4f;82slope_run = (control_in - 600) * 0.001f; // control_in ranges from 0 to 100083}8485scalar = (slope_high - slope_low)/slope_range;86stab_col_out = slope_low + slope_run * scalar;87stab_col_out = constrain_float(stab_col_out, 0.0f, 1.0f);8889//90// calculate expo-scaled acro collective91// range check expo92if (_acro_col_expo > 1.0f) {93_acro_col_expo.set(1.0f);94}9596if (_acro_col_expo <= 0.0f) {97acro_col_out = control_in * 0.001f; // control_in ranges from 0 to 100098} else {99// expo variables100float col_in, col_in3, col_out;101col_in = (float)(control_in-500)/500.0f; // control_in ranges from 0 to 1000102col_in3 = col_in*col_in*col_in;103col_out = (_acro_col_expo * col_in3) + ((1.0f-_acro_col_expo)*col_in);104acro_col_out = 0.5f + col_out*0.5f;105}106acro_col_out = constrain_float(acro_col_out, 0.0f, 1.0f);107108// ramp to and from stab col over 1/2 second109if (_im_flags_heli.use_stab_col && (_stab_col_ramp < 1.0f)){110_stab_col_ramp += 2.0f/(float)_loop_rate;111} else if(!_im_flags_heli.use_stab_col && (_stab_col_ramp > 0.0f)){112_stab_col_ramp -= 2.0f/(float)_loop_rate;113}114_stab_col_ramp = constrain_float(_stab_col_ramp, 0.0f, 1.0f);115116// scale collective output smoothly between acro and stab col117float collective_out;118collective_out = (float)((1.0f-_stab_col_ramp)*acro_col_out + _stab_col_ramp*stab_col_out);119collective_out = constrain_float(collective_out, 0.0f, 1.0f);120121return collective_out;122}123124// parameter_check - check if input manager specific parameters are sensible125bool AC_InputManager_Heli::parameter_check(char* fail_msg, uint8_t fail_msg_len) const126{127128const struct StabCheck {129const char *name;130int16_t value;131} stab_checks[] = {132{"IM_STB_COL_1", _heli_stab_col_min },133{"IM_STB_COL_2", _heli_stab_col_low },134{"IM_STB_COL_3", _heli_stab_col_high },135{"IM_STB_COL_4", _heli_stab_col_max },136};137138// check values are within valid range139for (uint8_t i=0; i<ARRAY_SIZE(stab_checks); i++) {140const StabCheck check = stab_checks[i];141if ((check.value < 0) || (check.value > 100)){142hal.util->snprintf(fail_msg, fail_msg_len, "%s out of range", check.name);143return false;144}145}146// check values are in correct order147for (uint8_t i=1; i<ARRAY_SIZE(stab_checks); i++) {148if ((stab_checks[i-1].value >= stab_checks[i].value)){149hal.util->snprintf(fail_msg, fail_msg_len, "%s must be < %s", stab_checks[i-1].name, stab_checks[i].name);150return false;151}152}153// all other cases parameters are OK154return true;155}156157158159