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_AttitudeControl/AC_AttitudeControl_Multi.h
Views: 1798
#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, const AP_MultiCopter &aparm, 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 total body frame throttle required to produce the given earth frame throttle63float get_throttle_boosted(float throttle_in);6465// set desired throttle vs attitude mixing (actual mix is slewed towards this value over 1~2 seconds)66// low values favour pilot/autopilot throttle over attitude control, high values favour attitude control over throttle67// 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// are we producing min throttle?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, 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// boost angle_p/pd each cycle on high throttle slew94void update_throttle_gain_boost();9596// update_throttle_rpy_mix - updates thr_low_comp value towards the target97void update_throttle_rpy_mix();9899// get maximum value throttle can be raised to based on throttle vs attitude prioritisation100float get_throttle_avg_max(float throttle_in);101102AP_MotorsMulticopter& _motors_multi;103AC_PID _pid_rate_roll {104AC_PID::Defaults{105.p = AC_ATC_MULTI_RATE_RP_P,106.i = AC_ATC_MULTI_RATE_RP_I,107.d = AC_ATC_MULTI_RATE_RP_D,108.ff = 0.0f,109.imax = AC_ATC_MULTI_RATE_RP_IMAX,110.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,111.filt_E_hz = 0.0f,112.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,113.srmax = 0,114.srtau = 1.0115}116};117AC_PID _pid_rate_pitch{118AC_PID::Defaults{119.p = AC_ATC_MULTI_RATE_RP_P,120.i = AC_ATC_MULTI_RATE_RP_I,121.d = AC_ATC_MULTI_RATE_RP_D,122.ff = 0.0f,123.imax = AC_ATC_MULTI_RATE_RP_IMAX,124.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,125.filt_E_hz = 0.0f,126.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,127.srmax = 0,128.srtau = 1.0129}130};131132AC_PID _pid_rate_yaw{133AC_PID::Defaults{134.p = AC_ATC_MULTI_RATE_YAW_P,135.i = AC_ATC_MULTI_RATE_YAW_I,136.d = AC_ATC_MULTI_RATE_YAW_D,137.ff = 0.0f,138.imax = AC_ATC_MULTI_RATE_YAW_IMAX,139.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,140.filt_E_hz = AC_ATC_MULTI_RATE_YAW_FILT_HZ,141.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,142.srmax = 0,143.srtau = 1.0144}145};146147AP_Float _thr_mix_man; // throttle vs attitude control prioritisation used when using manual throttle (higher values mean we prioritise attitude control over throttle)148AP_Float _thr_mix_min; // throttle vs attitude control prioritisation used when landing (higher values mean we prioritise attitude control over throttle)149AP_Float _thr_mix_max; // throttle vs attitude control prioritisation used during active flight (higher values mean we prioritise attitude control over throttle)150151// angle_p/pd boost multiplier152AP_Float _throttle_gain_boost;153};154155156