AC_AttitudeControl.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. #pragma once
  2. /// @file AC_AttitudeControl.h
  3. /// @brief ArduCopter attitude control library
  4. #include <AP_Common/AP_Common.h>
  5. #include <AP_Param/AP_Param.h>
  6. #include <AP_Math/AP_Math.h>
  7. #include <AP_AHRS/AP_AHRS_View.h>
  8. #include <AP_Motors/AP_Motors.h>
  9. #include <AC_PID/AC_PID.h>
  10. #include <AC_PID/AC_P.h>
  11. #define AC_ATTITUDE_CONTROL_ANGLE_P 4.5f // default angle P gain for roll, pitch and yaw
  12. #define AC_ATTITUDE_ACCEL_RP_CONTROLLER_MIN_RADSS radians(40.0f) // minimum body-frame acceleration limit for the stability controller (for roll and pitch axis)
  13. #define AC_ATTITUDE_ACCEL_RP_CONTROLLER_MAX_RADSS radians(720.0f) // maximum body-frame acceleration limit for the stability controller (for roll and pitch axis)
  14. #define AC_ATTITUDE_ACCEL_Y_CONTROLLER_MIN_RADSS radians(10.0f) // minimum body-frame acceleration limit for the stability controller (for yaw axis)
  15. #define AC_ATTITUDE_ACCEL_Y_CONTROLLER_MAX_RADSS radians(120.0f) // maximum body-frame acceleration limit for the stability controller (for yaw axis)
  16. #define AC_ATTITUDE_CONTROL_SLEW_YAW_DEFAULT_CDS 6000 // constraint on yaw angle error in degrees. This should lead to maximum turn rate of 10deg/sec * Stab Rate P so by default will be 45deg/sec.
  17. #define AC_ATTITUDE_CONTROL_ACCEL_RP_MAX_DEFAULT_CDSS 4500.0f//110000.0f // default maximum acceleration for roll/pitch axis in centidegrees/sec/sec
  18. #define AC_ATTITUDE_CONTROL_ACCEL_Y_MAX_DEFAULT_CDSS 22000//27000.0f // default maximum acceleration for yaw axis in centidegrees/sec/sec
  19. #define AC_ATTITUDE_RATE_CONTROLLER_TIMEOUT 1.0f // body-frame rate controller timeout in seconds
  20. #define AC_ATTITUDE_RATE_RP_CONTROLLER_OUT_MAX 1.0f // body-frame rate controller maximum output (for roll-pitch axis)
  21. #define AC_ATTITUDE_RATE_YAW_CONTROLLER_OUT_MAX 1.0f // body-frame rate controller maximum output (for yaw axis)
  22. #define AC_ATTITUDE_THRUST_ERROR_ANGLE radians(30.0f) // Thrust angle error above which yaw corrections are limited
  23. #define AC_ATTITUDE_400HZ_DT 0.0025f // delta time in seconds for 400hz update rate
  24. #define AC_ATTITUDE_CONTROL_RATE_BF_FF_DEFAULT 1 // body-frame rate feedforward enabled by default
  25. #define AC_ATTITUDE_CONTROL_ANGLE_LIMIT_TC_DEFAULT 1.0f // Time constant used to limit lean angle so that vehicle does not lose altitude
  26. #define AC_ATTITUDE_CONTROL_ANGLE_LIMIT_THROTTLE_MAX 0.8f // Max throttle used to limit lean angle so that vehicle does not lose altitude
  27. #define AC_ATTITUDE_CONTROL_ANGLE_LIMIT_MIN 10.0f // Min lean angle so that vehicle can maintain limited control
  28. #define AC_ATTITUDE_CONTROL_MIN_DEFAULT 0.1f // minimum throttle mix default
  29. #define AC_ATTITUDE_CONTROL_MAN_DEFAULT 0.1f // manual throttle mix default
  30. #define AC_ATTITUDE_CONTROL_MAX_DEFAULT 0.5f // maximum throttle mix default
  31. #define AC_ATTITUDE_CONTROL_MAX 5.0f // maximum throttle mix default
  32. #define AC_ATTITUDE_CONTROL_THR_MIX_DEFAULT 0.5f // ratio controlling the max throttle output during competing requests of low throttle from the pilot (or autopilot) and higher throttle for attitude control. Higher favours Attitude over pilot input
  33. class AC_AttitudeControl {
  34. public:
  35. AC_AttitudeControl( AP_AHRS_View &ahrs,
  36. const AP_Vehicle::MultiCopter &aparm,
  37. AP_Motors& motors,
  38. float dt) :
  39. _p_angle_roll(AC_ATTITUDE_CONTROL_ANGLE_P),
  40. _p_angle_pitch(AC_ATTITUDE_CONTROL_ANGLE_P),
  41. _p_angle_yaw(AC_ATTITUDE_CONTROL_ANGLE_P),
  42. _dt(dt),
  43. _angle_boost(0),
  44. _use_sqrt_controller(true),
  45. _throttle_rpy_mix_desired(AC_ATTITUDE_CONTROL_THR_MIX_DEFAULT),
  46. _throttle_rpy_mix(AC_ATTITUDE_CONTROL_THR_MIX_DEFAULT),
  47. _ahrs(ahrs),
  48. _aparm(aparm),
  49. _motors(motors)
  50. {
  51. AP_Param::setup_object_defaults(this, var_info);
  52. //self define init start-------------------
  53. ATOM_sensor_Roll=0.0;
  54. ATOM_sensor_pitch=0.0;
  55. ATOM_sensor_yaw=0.0;
  56. ATOM_sensor_RollRate=0.0;
  57. ATOM_sensor_pitchRate=0.0;
  58. ATOM_sensor_yawRate=0.0;
  59. //self define init end-------------------
  60. }
  61. //self define start-------------------
  62. float ATOM_sensor_Roll;
  63. float ATOM_sensor_pitch;
  64. float ATOM_sensor_yaw;
  65. float ATOM_sensor_RollRate;
  66. float ATOM_sensor_pitchRate;
  67. float ATOM_sensor_yawRate;
  68. void update_ATOM_sensor(float r,float p,float y,float rr,float pr,float yr)
  69. {
  70. ATOM_sensor_Roll = r;
  71. ATOM_sensor_pitch =p;
  72. ATOM_sensor_yaw = y;
  73. ATOM_sensor_RollRate = rr;
  74. ATOM_sensor_pitchRate =pr;
  75. ATOM_sensor_yawRate = yr;
  76. }
  77. float Offset_ver;
  78. int32_t change_angle;
  79. int16_t roll_pitch_back_orign;
  80. float deta_angle_901;
  81. float angle_geiding;
  82. uint8_t Hor_ver_choose;
  83. void update_Hor_Ver_Choose(uint8_t c){Hor_ver_choose = c;}
  84. //self define end-------------------
  85. // Empty destructor to suppress compiler warning
  86. virtual ~AC_AttitudeControl() {}
  87. void input_euler_angle_roll_pitch_yaw_quat_control(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, bool slew_yaw);
  88. // pid accessors
  89. AC_P& get_angle_roll_p() { return _p_angle_roll; }
  90. AC_P& get_angle_pitch_p() { return _p_angle_pitch; }
  91. AC_P& get_angle_yaw_p() { return _p_angle_yaw; }
  92. virtual AC_PID& get_rate_roll_pid() = 0;
  93. virtual AC_PID& get_rate_pitch_pid() = 0;
  94. virtual AC_PID& get_rate_yaw_pid() = 0;
  95. // get the roll acceleration limit in centidegrees/s/s or radians/s/s
  96. float get_accel_roll_max() const { return _accel_roll_max; }
  97. float get_accel_roll_max_radss() const { return radians(_accel_roll_max * 0.01f); }
  98. // Sets the roll acceleration limit in centidegrees/s/s
  99. void set_accel_roll_max(float accel_roll_max) { _accel_roll_max = accel_roll_max; }
  100. // Sets and saves the roll acceleration limit in centidegrees/s/s
  101. void save_accel_roll_max(float accel_roll_max) { _accel_roll_max.set_and_save(accel_roll_max); }
  102. // get the pitch acceleration limit in centidegrees/s/s or radians/s/s
  103. float get_accel_pitch_max() const { return _accel_pitch_max; }
  104. float get_accel_pitch_max_radss() const { return radians(_accel_pitch_max * 0.01f); }
  105. // Sets the pitch acceleration limit in centidegrees/s/s
  106. void set_accel_pitch_max(float accel_pitch_max) { _accel_pitch_max = accel_pitch_max; }
  107. // Sets and saves the pitch acceleration limit in centidegrees/s/s
  108. void save_accel_pitch_max(float accel_pitch_max) { _accel_pitch_max.set_and_save(accel_pitch_max); }
  109. // get the yaw acceleration limit in centidegrees/s/s or radians/s/s
  110. float get_accel_yaw_max() const { return _accel_yaw_max; }
  111. float get_accel_yaw_max_radss() const { return radians(_accel_yaw_max * 0.01f); }
  112. // Sets the yaw acceleration limit in centidegrees/s/s
  113. void set_accel_yaw_max(float accel_yaw_max) { _accel_yaw_max = accel_yaw_max; }
  114. // Sets and saves the yaw acceleration limit in centidegrees/s/s
  115. void save_accel_yaw_max(float accel_yaw_max) { _accel_yaw_max.set_and_save(accel_yaw_max); }
  116. // set the rate control input smoothing time constant
  117. void set_input_tc(float input_tc) { _input_tc = constrain_float(input_tc, 0.0f, 1.0f); }
  118. // Ensure attitude controller have zero errors to relax rate controller output
  119. void relax_attitude_controllers();
  120. // reset rate controller I terms
  121. void reset_rate_controller_I_terms();
  122. // Sets attitude target to vehicle attitude
  123. void set_attitude_target_to_current_attitude() { _ahrs.get_quat_body_to_ned(_attitude_target_quat); }
  124. // Sets yaw target to vehicle heading
  125. void set_yaw_target_to_current_heading() { shift_ef_yaw_target(degrees(_ahrs.yaw - _attitude_target_euler_angle.z) * 100.0f); }
  126. // Shifts earth frame yaw target by yaw_shift_cd. yaw_shift_cd should be in centidegrees and is added to the current target heading
  127. void shift_ef_yaw_target(float yaw_shift_cd);
  128. // handle reset of attitude from EKF since the last iteration
  129. void inertial_frame_reset();
  130. // Command a Quaternion attitude with feedforward and smoothing
  131. void input_quaternion(Quaternion attitude_desired_quat);
  132. // Command an euler roll and pitch angle and an euler yaw rate with angular velocity feedforward and smoothing
  133. virtual void input_euler_angle_roll_pitch_euler_rate_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds);
  134. // Command an euler roll, pitch and yaw angle with angular velocity feedforward and smoothing
  135. virtual void input_euler_angle_roll_pitch_yaw(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_angle_cd, bool slew_yaw);
  136. // Command euler yaw rate and pitch angle with roll angle specified in body frame with multicopter style controls
  137. // (used only by tailsitter quadplanes)
  138. virtual void input_euler_rate_yaw_euler_angle_pitch_bf_roll_m(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds);
  139. // Command euler yaw rate and pitch angle with roll angle specified in body frame with plane style controls
  140. // (used only by tailsitter quadplanes)
  141. virtual void input_euler_rate_yaw_euler_angle_pitch_bf_roll_p(float euler_roll_angle_cd, float euler_pitch_angle_cd, float euler_yaw_rate_cds);
  142. // Command an euler roll, pitch, and yaw rate with angular velocity feedforward and smoothing
  143. void input_euler_rate_roll_pitch_yaw(float euler_roll_rate_cds, float euler_pitch_rate_cds, float euler_yaw_rate_cds);
  144. // Command an angular velocity with angular velocity feedforward and smoothing
  145. virtual void input_rate_bf_roll_pitch_yaw(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
  146. // Command an angular velocity with angular velocity feedforward and smoothing
  147. void input_rate_bf_roll_pitch_yaw_2(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
  148. // Command an angular velocity with angular velocity smoothing using rate loops only with integrated rate error stabilization
  149. void input_rate_bf_roll_pitch_yaw_3(float roll_rate_bf_cds, float pitch_rate_bf_cds, float yaw_rate_bf_cds);
  150. // Command an angular step (i.e change) in body frame angle
  151. virtual void input_angle_step_bf_roll_pitch_yaw(float roll_angle_step_bf_cd, float pitch_angle_step_bf_cd, float yaw_angle_step_bf_cd);
  152. // Run angular velocity controller and send outputs to the motors
  153. virtual void rate_controller_run() = 0;
  154. // Convert a 321-intrinsic euler angle derivative to an angular velocity vector
  155. void euler_rate_to_ang_vel(const Vector3f& euler_rad, const Vector3f& euler_rate_rads, Vector3f& ang_vel_rads);
  156. // Convert an angular velocity vector to a 321-intrinsic euler angle derivative
  157. // Returns false if the vehicle is pitched 90 degrees up or down
  158. bool ang_vel_to_euler_rate(const Vector3f& euler_rad, const Vector3f& ang_vel_rads, Vector3f& euler_rate_rads);
  159. // Specifies whether the attitude controller should use the square root controller in the attitude correction.
  160. // This is used during Autotune to ensure the P term is tuned without being influenced by the acceleration limit of the square root controller.
  161. void use_sqrt_controller(bool use_sqrt_cont) { _use_sqrt_controller = use_sqrt_cont; }
  162. // Return 321-intrinsic euler angles in centidegrees representing the rotation from NED earth frame to the
  163. // attitude controller's target attitude.
  164. // **NOTE** Using vector3f*deg(100) is more efficient than deg(vector3f)*100 or deg(vector3d*100) because it gives the
  165. // same result with the fewest multiplications. Even though it may look like a bug, it is intentional. See issue 4895.
  166. Vector3f get_att_target_euler_cd() const { return _attitude_target_euler_angle * degrees(100.0f); }
  167. // Return the body-to-NED target attitude used by the quadplane-specific attitude control input methods
  168. Quaternion get_attitude_target_quat() const { return _attitude_target_quat; }
  169. // Return the angle between the target thrust vector and the current thrust vector.
  170. float get_att_error_angle_deg() const { return degrees(_thrust_error_angle); }
  171. // Set x-axis angular velocity in centidegrees/s
  172. void rate_bf_roll_target(float rate_cds) { _rate_target_ang_vel.x = radians(rate_cds * 0.01f); }
  173. // Set y-axis angular velocity in centidegrees/s
  174. void rate_bf_pitch_target(float rate_cds) { _rate_target_ang_vel.y = radians(rate_cds * 0.01f); }
  175. // Set z-axis angular velocity in centidegrees/s
  176. void rate_bf_yaw_target(float rate_cds) { _rate_target_ang_vel.z = radians(rate_cds * 0.01f); }
  177. // Return roll rate step size in radians/s that results in maximum output after 4 time steps
  178. float max_rate_step_bf_roll();
  179. // Return pitch rate step size in radians/s that results in maximum output after 4 time steps
  180. float max_rate_step_bf_pitch();
  181. // Return yaw rate step size in radians/s that results in maximum output after 4 time steps
  182. float max_rate_step_bf_yaw();
  183. // Return roll step size in radians that results in maximum output after 4 time steps
  184. float max_angle_step_bf_roll() { return max_rate_step_bf_roll() / _p_angle_roll.kP(); }
  185. // Return pitch step size in radians that results in maximum output after 4 time steps
  186. float max_angle_step_bf_pitch() { return max_rate_step_bf_pitch() / _p_angle_pitch.kP(); }
  187. // Return yaw step size in radians that results in maximum output after 4 time steps
  188. float max_angle_step_bf_yaw() { return max_rate_step_bf_yaw() / _p_angle_yaw.kP(); }
  189. // Return angular velocity in radians used in the angular velocity controller
  190. Vector3f rate_bf_targets() const { return _rate_target_ang_vel; }
  191. // Enable or disable body-frame feed forward
  192. void bf_feedforward(bool enable_or_disable) { _rate_bf_ff_enabled = enable_or_disable; }
  193. // Enable or disable body-frame feed forward and save
  194. void bf_feedforward_save(bool enable_or_disable) { _rate_bf_ff_enabled.set_and_save(enable_or_disable); }
  195. // Return body-frame feed forward setting
  196. bool get_bf_feedforward() { return _rate_bf_ff_enabled; }
  197. // Enable or disable body-frame feed forward
  198. void accel_limiting(bool enable_or_disable);
  199. // Update Alt_Hold angle maximum
  200. virtual void update_althold_lean_angle_max(float throttle_in) = 0;
  201. // Set output throttle
  202. virtual void set_throttle_out(float throttle_in, bool apply_angle_boost, float filt_cutoff) = 0;
  203. // get throttle passed into attitude controller (i.e. throttle_in provided to set_throttle_out)
  204. float get_throttle_in() const { return _throttle_in; }
  205. // Return throttle increase applied for tilt compensation
  206. float angle_boost() const { return _angle_boost; }
  207. // Return tilt angle limit for pilot input that prioritises altitude hold over lean angle
  208. float get_althold_lean_angle_max() const;
  209. // Return configured tilt angle limit in centidegrees
  210. float lean_angle_max() const { return _aparm.angle_max; }
  211. // Proportional controller with piecewise sqrt sections to constrain second derivative
  212. static float sqrt_controller(float error, float p, float second_ord_lim, float dt);
  213. // Inverse proportional controller with piecewise sqrt sections to constrain second derivative
  214. static float stopping_point(float first_ord_mag, float p, float second_ord_lim);
  215. // calculates the velocity correction from an angle error. The angular velocity has acceleration and
  216. // deceleration limits including basic jerk limiting using smoothing_gain
  217. static float input_shaping_angle(float error_angle, float smoothing_gain, float accel_max, float target_ang_vel, float dt);
  218. // limits the acceleration and deceleration of a velocity request
  219. static float input_shaping_ang_vel(float target_ang_vel, float desired_ang_vel, float accel_max, float dt);
  220. // calculates the expected angular velocity correction from an angle error based on the AC_AttitudeControl settings.
  221. // This function can be used to predict the delay associated with angle requests.
  222. void input_shaping_rate_predictor(const Vector2f &error_angle, Vector2f& target_ang_vel, float dt) const;
  223. // translates body frame acceleration limits to the euler axis
  224. void ang_vel_limit(Vector3f& euler_rad, float ang_vel_roll_max, float ang_vel_pitch_max, float ang_vel_yaw_max) const;
  225. // translates body frame acceleration limits to the euler axis
  226. Vector3f euler_accel_limit(const Vector3f &euler_rad, const Vector3f &euler_accel);
  227. // thrust_heading_rotation_angles - calculates two ordered rotations to move the att_from_quat quaternion to the att_to_quat quaternion.
  228. // The first rotation corrects the thrust vector and the second rotation corrects the heading vector.
  229. void thrust_heading_rotation_angles(Quaternion& att_to_quat, const Quaternion& att_from_quat, Vector3f& att_diff_angle, float& thrust_vec_dot);
  230. // Calculates the body frame angular velocities to follow the target attitude
  231. void attitude_controller_run_quat();
  232. // sanity check parameters. should be called once before take-off
  233. virtual void parameter_sanity_check() {}
  234. // return true if the rpy mix is at lowest value
  235. virtual bool is_throttle_mix_min() const { return true; }
  236. // control rpy throttle mix
  237. virtual void set_throttle_mix_min() {}
  238. virtual void set_throttle_mix_man() {}
  239. virtual void set_throttle_mix_max() {}
  240. virtual void set_throttle_mix_value(float value) {}
  241. virtual float get_throttle_mix(void) const { return 0; }
  242. // enable use of flybass passthrough on heli
  243. virtual void use_flybar_passthrough(bool passthrough, bool tail_passthrough) {}
  244. // use_leaky_i - controls whether we use leaky i term for body-frame to motor output stage on heli
  245. virtual void use_leaky_i(bool leaky_i) {}
  246. // set_hover_roll_scalar - scales Hover Roll Trim parameter. To be used by vehicle code according to vehicle condition.
  247. virtual void set_hover_roll_trim_scalar(float scalar) {}
  248. // passthrough_bf_roll_pitch_rate_yaw - roll and pitch are passed through directly, body-frame rate target for yaw
  249. virtual void passthrough_bf_roll_pitch_rate_yaw(float roll_passthrough, float pitch_passthrough, float yaw_rate_bf_cds) {};
  250. // provide feedback on whether arming would be a good idea right now:
  251. bool pre_arm_checks(const char *param_prefix,
  252. char *failure_msg,
  253. const uint8_t failure_msg_len);
  254. // enable inverted flight on backends that support it
  255. virtual void set_inverted_flight(bool inverted) {}
  256. // User settable parameters
  257. static const struct AP_Param::GroupInfo var_info[];
  258. protected:
  259. // Update rate_target_ang_vel using attitude_error_rot_vec_rad
  260. Vector3f update_ang_vel_target_from_att_error(const Vector3f &attitude_error_rot_vec_rad);
  261. // Return angle in radians to be added to roll angle. Used by heli to counteract
  262. // tail rotor thrust in hover. Overloaded by AC_Attitude_Heli to return angle.
  263. virtual float get_roll_trim_rad() { return 0;}
  264. // Return the yaw slew rate limit in radians/s
  265. float get_slew_yaw_rads() { return radians(_slew_yaw * 0.01f); }
  266. // Maximum rate the yaw target can be updated in Loiter, RTL, Auto flight modes
  267. AP_Float _slew_yaw;
  268. // Maximum angular velocity (in degrees/second) for earth-frame roll, pitch and yaw axis
  269. AP_Float _ang_vel_roll_max;
  270. AP_Float _ang_vel_pitch_max;
  271. AP_Float _ang_vel_yaw_max;
  272. // Maximum rotation acceleration for earth-frame roll axis
  273. AP_Float _accel_roll_max;
  274. // Maximum rotation acceleration for earth-frame pitch axis
  275. AP_Float _accel_pitch_max;
  276. // Maximum rotation acceleration for earth-frame yaw axis
  277. AP_Float _accel_yaw_max;
  278. // Enable/Disable body frame rate feed forward
  279. AP_Int8 _rate_bf_ff_enabled;
  280. // Enable/Disable angle boost
  281. AP_Int8 _angle_boost_enabled;
  282. // angle controller P objects
  283. AC_P _p_angle_roll;
  284. AC_P _p_angle_pitch;
  285. AC_P _p_angle_yaw;
  286. // Angle limit time constant (to maintain altitude)
  287. AP_Float _angle_limit_tc;
  288. // rate controller input smoothing time constant
  289. AP_Float _input_tc;
  290. // Intersampling period in seconds
  291. float _dt;
  292. // This represents a 321-intrinsic rotation in NED frame to the target (setpoint)
  293. // attitude used in the attitude controller, in radians.
  294. Vector3f _attitude_target_euler_angle;
  295. // This represents the angular velocity of the target (setpoint) attitude used in
  296. // the attitude controller as 321-intrinsic euler angle derivatives, in radians per
  297. // second.
  298. Vector3f _attitude_target_euler_rate;
  299. // This represents a quaternion rotation in NED frame to the target (setpoint)
  300. // attitude used in the attitude controller.
  301. Quaternion _attitude_target_quat;
  302. // This represents the angular velocity of the target (setpoint) attitude used in
  303. // the attitude controller as an angular velocity vector, in radians per second in
  304. // the target attitude frame.
  305. Vector3f _attitude_target_ang_vel;
  306. // This represents the angular velocity in radians per second in the body frame, used in the angular
  307. // velocity controller.
  308. Vector3f _rate_target_ang_vel;
  309. // This represents a quaternion attitude error in the body frame, used for inertial frame reset handling.
  310. Quaternion _attitude_ang_error;
  311. // The angle between the target thrust vector and the current thrust vector.
  312. float _thrust_error_angle;
  313. // throttle provided as input to attitude controller. This does not include angle boost.
  314. float _throttle_in = 0.0f;
  315. // This represents the throttle increase applied for tilt compensation.
  316. // Used only for logging.
  317. float _angle_boost;
  318. // Specifies whether the attitude controller should use the square root controller in the attitude correction.
  319. // This is used during Autotune to ensure the P term is tuned without being influenced by the acceleration limit of the square root controller.
  320. bool _use_sqrt_controller;
  321. // Filtered Alt_Hold lean angle max - used to limit lean angle when throttle is saturated using Alt_Hold
  322. float _althold_lean_angle_max = 0.0f;
  323. // desired throttle_low_comp value, actual throttle_low_comp is slewed towards this value over 1~2 seconds
  324. float _throttle_rpy_mix_desired;
  325. // mix between throttle and hover throttle for 0 to 1 and ratio above hover throttle for >1
  326. float _throttle_rpy_mix;
  327. // References to external libraries
  328. const AP_AHRS_View& _ahrs;
  329. const AP_Vehicle::MultiCopter &_aparm;
  330. AP_Motors& _motors;
  331. protected:
  332. /*
  333. state of control monitoring
  334. */
  335. struct {
  336. float rms_roll_P;
  337. float rms_roll_D;
  338. float rms_pitch_P;
  339. float rms_pitch_D;
  340. float rms_yaw;
  341. } _control_monitor;
  342. // update state in ControlMonitor
  343. void control_monitor_filter_pid(float value, float &rms_P);
  344. void control_monitor_update(void);
  345. // true in inverted flight mode
  346. bool _inverted_flight;
  347. public:
  348. // log a CTRL message
  349. void control_monitor_log(void);
  350. // return current RMS controller filter for each axis
  351. float control_monitor_rms_output_roll(void) const;
  352. float control_monitor_rms_output_roll_P(void) const;
  353. float control_monitor_rms_output_roll_D(void) const;
  354. float control_monitor_rms_output_pitch_P(void) const;
  355. float control_monitor_rms_output_pitch_D(void) const;
  356. float control_monitor_rms_output_pitch(void) const;
  357. float control_monitor_rms_output_yaw(void) const;
  358. };
  359. #define AC_ATTITUDE_CONTROL_LOG_FORMAT(msg) { msg, sizeof(AC_AttitudeControl::log_Attitude), \
  360. "ATT", "cccccCC", "RollIn,Roll,PitchIn,Pitch,YawIn,Yaw,NavYaw" }