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_Heli.h
Views: 1798
#pragma once12/// @file AC_AttitudeControl_Heli.h3/// @brief ArduCopter attitude control library for traditional helicopters45#include "AC_AttitudeControl.h"6#include <AP_Motors/AP_MotorsHeli.h>7#include <AC_PID/AC_HELI_PID.h>8#include <Filter/Filter.h>910// default rate controller PID gains11#define AC_ATC_HELI_RATE_RP_P 0.024f12#define AC_ATC_HELI_RATE_RP_I 0.15f13#define AC_ATC_HELI_RATE_RP_D 0.001f14#define AC_ATC_HELI_RATE_RP_IMAX 0.4f15#define AC_ATC_HELI_RATE_RP_FF 0.15f16#define AC_ATC_HELI_RATE_RP_FILT_HZ 20.0f17#define AC_ATC_HELI_RATE_YAW_P 0.18f18#define AC_ATC_HELI_RATE_YAW_I 0.12f19#define AC_ATC_HELI_RATE_YAW_D 0.003f20#define AC_ATC_HELI_RATE_YAW_IMAX 0.4f21#define AC_ATC_HELI_RATE_YAW_FF 0.024f22#define AC_ATC_HELI_RATE_YAW_FILT_HZ 20.0f2324#define AC_ATTITUDE_HELI_ANGLE_LIMIT_THROTTLE_MAX 0.95f // Heli's use 95% of max collective before limiting frame angle25#define AC_ATTITUDE_HELI_RATE_INTEGRATOR_LEAK_RATE 0.02f26#define AC_ATTITUDE_HELI_RATE_RP_FF_FILTER 20.0f27#define AC_ATTITUDE_HELI_RATE_Y_FF_FILTER 20.0f28#define AC_ATTITUDE_HELI_HOVER_ROLL_TRIM_DEFAULT 30029#define AC_ATTITUDE_HELI_ACRO_OVERSHOOT_ANGLE_RAD ToRad(30.0f)30#define AC_ATTITUDE_HELI_INVERTED_TRANSITION_TIME 3.0f3132class AC_AttitudeControl_Heli : public AC_AttitudeControl {33public:34AC_AttitudeControl_Heli( AP_AHRS_View &ahrs,35const AP_MultiCopter &aparm,36AP_MotorsHeli& motors);3738// pid accessors39AC_PID& get_rate_roll_pid() override { return _pid_rate_roll; }40AC_PID& get_rate_pitch_pid() override { return _pid_rate_pitch; }41AC_PID& get_rate_yaw_pid() override { return _pid_rate_yaw; }42const AC_PID& get_rate_roll_pid() const override { return _pid_rate_roll; }43const AC_PID& get_rate_pitch_pid() const override { return _pid_rate_pitch; }44const AC_PID& get_rate_yaw_pid() const override { return _pid_rate_yaw; }4546// passthrough_bf_roll_pitch_rate_yaw - roll and pitch are passed through directly, body-frame rate target for yaw47void passthrough_bf_roll_pitch_rate_yaw(float roll_passthrough, float pitch_passthrough, float yaw_rate_bf_cds) override;4849// subclass non-passthrough too, for external gyro, no flybar50void input_rate_bf_roll_pitch_yaw(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds) override;5152// rate_controller_run - run lowest level body-frame rate controller and send outputs to the motors53// should be called at 100hz or more54virtual void rate_controller_run() override;5556// Update Alt_Hold angle maximum57void update_althold_lean_angle_max(float throttle_in) override;5859// use_leaky_i - controls whether we use leaky i term for body-frame to motor output stage60void use_leaky_i(bool leaky_i) override { _flags_heli.leaky_i = leaky_i; }6162// use_flybar_passthrough - controls whether we pass-through63// control inputs to swash-plate and tail64void use_flybar_passthrough(bool passthrough, bool tail_passthrough) override {65_flags_heli.flybar_passthrough = passthrough;66_flags_heli.tail_passthrough = tail_passthrough;67}6869// set_hover_roll_scalar - scales Hover Roll Trim parameter. To be used by vehicle code according to vehicle condition.70void set_hover_roll_trim_scalar(float scalar) override {_hover_roll_trim_scalar = constrain_float(scalar, 0.0f, 1.0f);}7172// get_roll_trim - angle in centi-degrees to be added to roll angle for learn hover collective. Used by helicopter to counter tail rotor thrust in hover73float get_roll_trim_cd() override;7475// Set output throttle76void set_throttle_out(float throttle_in, bool apply_angle_boost, float filt_cutoff) override;7778// calculate total body frame throttle required to produce the given earth frame throttle79float get_throttle_boosted(float throttle_in);8081// Command an euler roll and pitch angle and an euler yaw rate with angular velocity feedforward and smoothing82void input_euler_angle_roll_pitch_euler_rate_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds) override;8384// Command an euler roll, pitch and yaw angle with angular velocity feedforward and smoothing85void input_euler_angle_roll_pitch_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, bool slew_yaw) override;8687// Command a thrust vector in the earth frame and a heading angle and/or rate88void input_thrust_vector_rate_heading(const Vector3f& thrust_vector, float heading_rate_cds, bool slew_yaw = true) override;89void input_thrust_vector_heading(const Vector3f& thrust_vector, float heading_angle_cd, float heading_rate_cds) override;9091// enable/disable inverted flight92void set_inverted_flight(bool inverted) override { _inverted_flight = inverted; }9394// accessor for inverted flight flag95bool get_inverted_flight() override { return _inverted_flight; }9697// set the PID notch sample rates98void set_notch_sample_rate(float sample_rate) override;99100// user settable parameters101static const struct AP_Param::GroupInfo var_info[];102103private:104105// To-Do: move these limits flags into the heli motors class106struct AttControlHeliFlags {107uint8_t leaky_i : 1; // 1 if we should use leaky i term for body-frame rate to motor stage108uint8_t flybar_passthrough : 1; // 1 if we should pass through pilots roll & pitch input directly to swash-plate109uint8_t tail_passthrough : 1; // 1 if we should pass through pilots yaw input to tail110} _flags_heli;111112// true in inverted flight mode113bool _inverted_flight;114115// Integrate vehicle rate into _att_error_rot_vec_rad116void integrate_bf_rate_error_to_angle_errors();117118//119// body-frame rate controller120//121// rate_bf_to_motor_roll_pitch - ask the rate controller to calculate the motor outputs to achieve the target body-frame rate (in radians/sec) for roll, pitch and yaw122// outputs are sent directly to motor class123void rate_bf_to_motor_roll_pitch(const Vector3f &rate_rads, float rate_roll_target_rads, float rate_pitch_target_rads);124float rate_target_to_motor_yaw(float rate_yaw_actual_rads, float rate_yaw_rads);125126//127// throttle methods128//129130// pass through for roll and pitch131float _passthrough_roll;132float _passthrough_pitch;133134// pass through for yaw if tail_passthrough is set135float _passthrough_yaw;136137// get_roll_trim - angle in centi-degrees to be added to roll angle. Used by helicopter to counter tail rotor thrust in hover138float get_roll_trim_rad() override { return radians(get_roll_trim_cd() * 0.01); }139140// internal variables141float _hover_roll_trim_scalar = 0; // scalar used to suppress Hover Roll Trim142143144// This represents an euler axis-angle rotation vector from the vehicles145// estimated attitude to the reference (setpoint) attitude used in the attitude146// controller, in radians in the vehicle body frame of reference.147Vector3f _att_error_rot_vec_rad;148149// parameters150AP_Int8 _piro_comp_enabled; // Flybar present or not. Affects attitude controller used during ACRO flight mode151AP_Int16 _hover_roll_trim; // Angle in centi-degrees used to counter tail rotor thrust in hover152153// Roll and Pitch rate PIDs share the same defaults:154const AC_PID::Defaults rp_defaults {155AC_PID::Defaults{156.p = AC_ATC_HELI_RATE_RP_P,157.i = AC_ATC_HELI_RATE_RP_I,158.d = AC_ATC_HELI_RATE_RP_D,159.ff = AC_ATC_HELI_RATE_RP_FF,160.imax = AC_ATC_HELI_RATE_RP_IMAX,161.filt_T_hz = AC_ATTITUDE_HELI_RATE_RP_FF_FILTER,162.filt_E_hz = AC_ATC_HELI_RATE_RP_FILT_HZ,163.filt_D_hz = 0.0,164.srmax = 0,165.srtau = 1.0166}167};168AC_HELI_PID _pid_rate_roll { rp_defaults };169AC_HELI_PID _pid_rate_pitch { rp_defaults };170171AC_HELI_PID _pid_rate_yaw {172AC_PID::Defaults{173.p = AC_ATC_HELI_RATE_YAW_P,174.i = AC_ATC_HELI_RATE_YAW_I,175.d = AC_ATC_HELI_RATE_YAW_D,176.ff = AC_ATC_HELI_RATE_YAW_FF,177.imax = AC_ATC_HELI_RATE_YAW_IMAX,178.filt_T_hz = AC_ATTITUDE_HELI_RATE_Y_FF_FILTER,179.filt_E_hz = AC_ATC_HELI_RATE_YAW_FILT_HZ,180.filt_D_hz = 0.0,181.srmax = 0,182.srtau = 1.0183}184};185186};187188189