AC_Loiter.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <AP_Common/AP_Common.h>
  3. #include <AP_Param/AP_Param.h>
  4. #include <AP_Math/AP_Math.h>
  5. #include <AP_Common/Location.h>
  6. #include <AP_InertialNav/AP_InertialNav.h>
  7. #include <AC_AttitudeControl/AC_PosControl.h>
  8. #include <AC_AttitudeControl/AC_AttitudeControl.h>
  9. #include <AC_Avoidance/AC_Avoid.h>
  10. class AC_Loiter
  11. {
  12. public:
  13. /// Constructor
  14. AC_Loiter(const AP_InertialNav& inav, const AP_AHRS_View& ahrs, AC_PosControl& pos_control, const AC_AttitudeControl& attitude_control);
  15. /// init_target to a position in cm from ekf origin
  16. void init_target(const Vector3f& position);
  17. /// initialize's position and feed-forward velocity from current pos and velocity
  18. void init_target();
  19. /// reduce response for landing
  20. void soften_for_landing();
  21. /// set pilot desired acceleration in centi-degrees
  22. // dt should be the time (in seconds) since the last call to this function
  23. void set_pilot_desired_acceleration(float euler_roll_angle_cd, float euler_pitch_angle_cd, float dt);
  24. /// gets pilot desired acceleration, body frame, [forward,right]
  25. Vector2f get_pilot_desired_acceleration() const { return Vector2f(_desired_accel.x, _desired_accel.y); }
  26. /// clear pilot desired acceleration
  27. void clear_pilot_desired_acceleration() { _desired_accel.zero(); }
  28. /// get vector to stopping point based on a horizontal position and velocity
  29. void get_stopping_point_xy(Vector3f& stopping_point) const;
  30. /// get horizontal distance to loiter target in cm
  31. float get_distance_to_target() const { return _pos_control.get_distance_to_target(); }
  32. /// get bearing to target in centi-degrees
  33. int32_t get_bearing_to_target() const { return _pos_control.get_bearing_to_target(); }
  34. /// get maximum lean angle when using loiter
  35. float get_angle_max_cd() const;
  36. /// run the loiter controller
  37. void update();
  38. /// get desired roll, pitch which should be fed into stabilize controllers
  39. float get_roll() const { return _pos_control.get_roll(); }
  40. float get_pitch() const { return _pos_control.get_pitch(); }
  41. static const struct AP_Param::GroupInfo var_info[];
  42. protected:
  43. // sanity check parameters
  44. void sanity_check_params();
  45. /// updates desired velocity (i.e. feed forward) with pilot requested acceleration and fake wind resistance
  46. /// updated velocity sent directly to position controller
  47. void calc_desired_velocity(float nav_dt);
  48. // references and pointers to external libraries
  49. const AP_InertialNav& _inav;
  50. const AP_AHRS_View& _ahrs;
  51. AC_PosControl& _pos_control;
  52. const AC_AttitudeControl& _attitude_control;
  53. // parameters
  54. AP_Float _angle_max; // maximum pilot commanded angle in degrees. Set to zero for 2/3 Angle Max
  55. AP_Float _speed_cms; // maximum horizontal speed in cm/s while in loiter
  56. AP_Float _accel_cmss; // loiter's max acceleration in cm/s/s
  57. AP_Float _brake_accel_cmss; // loiter's acceleration during braking in cm/s/s
  58. AP_Float _brake_jerk_max_cmsss;
  59. AP_Float _brake_delay; // delay (in seconds) before loiter braking begins after sticks are released
  60. // loiter controller internal variables
  61. Vector2f _desired_accel; // slewed pilot's desired acceleration in lat/lon frame
  62. Vector2f _predicted_accel;
  63. Vector2f _predicted_euler_angle;
  64. Vector2f _predicted_euler_rate;
  65. float _brake_timer;
  66. float _brake_accel;
  67. };