Path: blob/master/libraries/AC_AttitudeControl/AC_AttitudeControl_Multi.h
9573 views
#pragma once12/// @file AC_AttitudeControl_Multi.h3/// @brief ArduCopter attitude control library45#include "AC_AttitudeControl.h"6#include <AP_Motors/AP_MotorsMulticopter.h>78// default rate controller PID gains9#ifndef AC_ATC_MULTI_RATE_RP_P10# define AC_ATC_MULTI_RATE_RP_P 0.135f11#endif12#ifndef AC_ATC_MULTI_RATE_RP_I13# define AC_ATC_MULTI_RATE_RP_I 0.135f14#endif15#ifndef AC_ATC_MULTI_RATE_RP_D16# define AC_ATC_MULTI_RATE_RP_D 0.0036f17#endif18#ifndef AC_ATC_MULTI_RATE_RP_IMAX19# define AC_ATC_MULTI_RATE_RP_IMAX 0.5f20#endif21#ifndef AC_ATC_MULTI_RATE_RPY_FILT_HZ22# define AC_ATC_MULTI_RATE_RPY_FILT_HZ 20.0f23#endif24#ifndef AC_ATC_MULTI_RATE_YAW_P25# define AC_ATC_MULTI_RATE_YAW_P 0.180f26#endif27#ifndef AC_ATC_MULTI_RATE_YAW_I28# define AC_ATC_MULTI_RATE_YAW_I 0.018f29#endif30#ifndef AC_ATC_MULTI_RATE_YAW_D31# define AC_ATC_MULTI_RATE_YAW_D 0.0f32#endif33#ifndef AC_ATC_MULTI_RATE_YAW_IMAX34# define AC_ATC_MULTI_RATE_YAW_IMAX 0.5f35#endif36#ifndef AC_ATC_MULTI_RATE_YAW_FILT_HZ37# define AC_ATC_MULTI_RATE_YAW_FILT_HZ 2.5f38#endif394041class AC_AttitudeControl_Multi : public AC_AttitudeControl {42public:43AC_AttitudeControl_Multi(AP_AHRS_View &ahrs, AP_MotorsMulticopter& motors);4445// empty destructor to suppress compiler warning46virtual ~AC_AttitudeControl_Multi() {}4748// pid accessors49AC_PID& get_rate_roll_pid() override { return _pid_rate_roll; }50AC_PID& get_rate_pitch_pid() override { return _pid_rate_pitch; }51AC_PID& get_rate_yaw_pid() override { return _pid_rate_yaw; }52const AC_PID& get_rate_roll_pid() const override { return _pid_rate_roll; }53const AC_PID& get_rate_pitch_pid() const override { return _pid_rate_pitch; }54const AC_PID& get_rate_yaw_pid() const override { return _pid_rate_yaw; }5556// Update Alt_Hold angle maximum57void update_althold_lean_angle_max(float throttle_in) override;5859// Set output throttle60void set_throttle_out(float throttle_in, bool apply_angle_boost, float filt_cutoff) override;6162// Calculate body-frame throttle required to produce the given earth-frame throttle input (accounts for vehicle tilt)63float get_throttle_boosted(float throttle_in);6465// Set desired throttle vs attitude mixing (actual mix is slewed toward this value over 1~2 seconds)66// Low values favor pilot/autopilot throttle over attitude control; high values prioritize attitude control67// Has no effect when throttle is above hover throttle68void set_throttle_mix_min() override { _throttle_rpy_mix_desired = _thr_mix_min; }69void set_throttle_mix_man() override { _throttle_rpy_mix_desired = _thr_mix_man; }70void set_throttle_mix_max(float ratio) override;71void set_throttle_mix_value(float value) override { _throttle_rpy_mix_desired = _throttle_rpy_mix = value; }72float get_throttle_mix(void) const override { return _throttle_rpy_mix; }7374// Returns true if throttle mix is near minimum (i.e., attitude control is deprioritised)75bool is_throttle_mix_min() const override { return (_throttle_rpy_mix < 1.25f * _thr_mix_min); }7677// run lowest level body-frame rate controller and send outputs to the motors78void rate_controller_run_dt(const Vector3f& gyro_rads, float dt) override;79void rate_controller_target_reset() override;80void rate_controller_run() override;8182// sanity check parameters. should be called once before take-off83void parameter_sanity_check() override;8485// set the PID notch sample rates86void set_notch_sample_rate(float sample_rate) override;8788// user settable parameters89static const struct AP_Param::GroupInfo var_info[];9091protected:9293// Boosts angle controller gains during rapid throttle changes to improve responsiveness94// boost angle_p/pd each cycle on high throttle slew95void update_throttle_gain_boost();9697// Slews the current throttle-to-attitude mix ratio toward the target (_throttle_rpy_mix_desired)98void update_throttle_rpy_mix();99100// Get throttle limit based on priority of attitude vs throttle control (used for blending during low thrust)101float get_throttle_avg_max(float throttle_in);102103AP_MotorsMulticopter& _motors_multi;104105// Roll rate PID controller (used for body-frame angular rate control)106AC_PID _pid_rate_roll {107AC_PID::Defaults{108.p = AC_ATC_MULTI_RATE_RP_P,109.i = AC_ATC_MULTI_RATE_RP_I,110.d = AC_ATC_MULTI_RATE_RP_D,111.ff = 0.0f,112.imax = AC_ATC_MULTI_RATE_RP_IMAX,113.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,114.filt_E_hz = 0.0f,115.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,116.srmax = 0,117.srtau = 1.0118}119};120// Pitch rate PID controller (used for body-frame angular rate control)121AC_PID _pid_rate_pitch{122AC_PID::Defaults{123.p = AC_ATC_MULTI_RATE_RP_P,124.i = AC_ATC_MULTI_RATE_RP_I,125.d = AC_ATC_MULTI_RATE_RP_D,126.ff = 0.0f,127.imax = AC_ATC_MULTI_RATE_RP_IMAX,128.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,129.filt_E_hz = 0.0f,130.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,131.srmax = 0,132.srtau = 1.0133}134};135// Yaw rate PID controller (used for body-frame angular rate control)136AC_PID _pid_rate_yaw{137AC_PID::Defaults{138.p = AC_ATC_MULTI_RATE_YAW_P,139.i = AC_ATC_MULTI_RATE_YAW_I,140.d = AC_ATC_MULTI_RATE_YAW_D,141.ff = 0.0f,142.imax = AC_ATC_MULTI_RATE_YAW_IMAX,143.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,144.filt_E_hz = AC_ATC_MULTI_RATE_YAW_FILT_HZ,145.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,146.srmax = 0,147.srtau = 1.0148}149};150151AP_Float _thr_mix_man; // throttle vs attitude control prioritisation used when using manual throttle (higher values mean we prioritise attitude control over throttle)152AP_Float _thr_mix_min; // throttle vs attitude control prioritisation used when landing (higher values mean we prioritise attitude control over throttle)153AP_Float _thr_mix_max; // throttle vs attitude control prioritisation used during active flight (higher values mean we prioritise attitude control over throttle)154155// angle_p/pd boost multiplier156AP_Float _throttle_gain_boost;157};158159160