AP_SteerController.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_Logger/AP_Logger.h>
  6. class AP_SteerController {
  7. public:
  8. AP_SteerController(AP_AHRS &ahrs)
  9. : _ahrs(ahrs)
  10. {
  11. AP_Param::setup_object_defaults(this, var_info);
  12. }
  13. /* Do not allow copies */
  14. AP_SteerController(const AP_SteerController &other) = delete;
  15. AP_SteerController &operator=(const AP_SteerController&) = delete;
  16. /*
  17. return a steering servo output from -4500 to 4500 given a
  18. desired lateral acceleration rate in m/s/s. Positive lateral
  19. acceleration is to the right.
  20. */
  21. int32_t get_steering_out_lat_accel(float desired_accel);
  22. /*
  23. return a steering servo output from -4500 to 4500 given a
  24. desired yaw rate in degrees/sec. Positive yaw is to the right.
  25. */
  26. int32_t get_steering_out_rate(float desired_rate);
  27. /*
  28. return a steering servo output from -4500 to 4500 given a
  29. yaw error in centi-degrees
  30. */
  31. int32_t get_steering_out_angle_error(int32_t angle_err);
  32. /*
  33. return the steering radius (half diameter). Assumed to be half
  34. the P value.
  35. */
  36. float get_turn_radius(void) const { return _K_P * 0.5f; }
  37. void reset_I();
  38. static const struct AP_Param::GroupInfo var_info[];
  39. const AP_Logger::PID_Info& get_pid_info(void) const { return _pid_info; }
  40. void set_reverse(bool reverse) {
  41. _reverse = reverse;
  42. }
  43. private:
  44. AP_Float _tau;
  45. AP_Float _K_FF;
  46. AP_Float _K_P;
  47. AP_Float _K_I;
  48. AP_Float _K_D;
  49. AP_Float _minspeed;
  50. AP_Int16 _imax;
  51. uint32_t _last_t;
  52. float _last_out;
  53. AP_Float _deratespeed;
  54. AP_Float _deratefactor;
  55. AP_Float _mindegree;
  56. AP_Logger::PID_Info _pid_info {};
  57. AP_AHRS &_ahrs;
  58. bool _reverse;
  59. };