AP_PitchController.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #include <AP_AHRS/AP_AHRS.h>
  3. #include <AP_Common/AP_Common.h>
  4. #include <AP_Vehicle/AP_Vehicle.h>
  5. #include "AP_AutoTune.h"
  6. #include <AP_Logger/AP_Logger.h>
  7. #include <AP_Math/AP_Math.h>
  8. class AP_PitchController {
  9. public:
  10. AP_PitchController(AP_AHRS &ahrs, const AP_Vehicle::FixedWing &parms)
  11. : aparm(parms)
  12. , autotune(gains, AP_AutoTune::AUTOTUNE_PITCH, parms)
  13. , _ahrs(ahrs)
  14. {
  15. AP_Param::setup_object_defaults(this, var_info);
  16. }
  17. /* Do not allow copies */
  18. AP_PitchController(const AP_PitchController &other) = delete;
  19. AP_PitchController &operator=(const AP_PitchController&) = delete;
  20. int32_t get_rate_out(float desired_rate, float scaler);
  21. int32_t get_servo_out(int32_t angle_err, float scaler, bool disable_integrator);
  22. void reset_I();
  23. /*
  24. reduce the integrator, used when we have a low scale factor in a quadplane hover
  25. */
  26. void decay_I() {
  27. // this reduces integrator by 95% over 2s
  28. _pid_info.I *= 0.995f;
  29. }
  30. void autotune_start(void) { autotune.start(); }
  31. void autotune_restore(void) { autotune.stop(); }
  32. const AP_Logger::PID_Info& get_pid_info(void) const { return _pid_info; }
  33. static const struct AP_Param::GroupInfo var_info[];
  34. AP_Float &kP(void) { return gains.P; }
  35. AP_Float &kI(void) { return gains.I; }
  36. AP_Float &kD(void) { return gains.D; }
  37. AP_Float &kFF(void) { return gains.FF; }
  38. private:
  39. const AP_Vehicle::FixedWing &aparm;
  40. AP_AutoTune::ATGains gains;
  41. AP_AutoTune autotune;
  42. AP_Int16 _max_rate_neg;
  43. AP_Float _roll_ff;
  44. uint32_t _last_t;
  45. float _last_out;
  46. AP_Logger::PID_Info _pid_info;
  47. int32_t _get_rate_out(float desired_rate, float scaler, bool disable_integrator, float aspeed);
  48. float _get_coordination_rate_offset(float &aspeed, bool &inverted) const;
  49. AP_AHRS &_ahrs;
  50. };