AP_Navigation.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /// @file AP_Navigation.h
  2. /// @brief generic navigation controller interface
  3. /*
  4. This defines a generic interface for navigation controllers. Each
  5. specific controller should be a subclass of this generic
  6. interface. All variables used by controllers should be in their
  7. own class.
  8. */
  9. #pragma once
  10. #include <AP_Common/AP_Common.h>
  11. class AP_Navigation {
  12. public:
  13. // return the desired roll angle in centi-degrees to move towards
  14. // the target waypoint
  15. virtual int32_t nav_roll_cd(void) const = 0;
  16. // return the desired lateral acceleration in m/s/s to move towards
  17. // the target waypoint
  18. virtual float lateral_acceleration(void) const = 0;
  19. // note: all centi-degree values returned in AP_Navigation should
  20. // be wrapped at -18000 to 18000 in centi-degrees.
  21. // return the tracking bearing that the navigation controller is
  22. // using in centi-degrees. This is used to display an arrow on
  23. // ground stations showing the effect of the cross-tracking in the
  24. // controller
  25. virtual int32_t nav_bearing_cd(void) const = 0;
  26. // return the difference between the vehicles current course and
  27. // the nav_bearing_cd() in centi-degrees. A positive value means
  28. // the vehicle is tracking too far to the left of the correct
  29. // bearing.
  30. virtual int32_t bearing_error_cd(void) const = 0;
  31. // return the target bearing in centi-degrees. This is the bearing
  32. // from the vehicles current position to the target waypoint. This
  33. // should be calculated in the update_*() functions below.
  34. virtual int32_t target_bearing_cd(void) const = 0;
  35. // return the crosstrack error in meters. This is the distance in
  36. // the X-Y plane that we are off the desired track
  37. virtual float crosstrack_error(void) const = 0;
  38. virtual float crosstrack_error_integrator(void) const { return 0; }
  39. // return the distance in meters at which a turn should commence
  40. // to allow the vehicle to neatly move to the next track in the
  41. // mission when approaching a waypoint. Assumes 90 degree turn
  42. virtual float turn_distance(float wp_radius) const = 0;
  43. // return the distance in meters at which a turn should commence
  44. // to allow the vehicle to neatly move to the next track in the
  45. // mission when approaching a waypoint
  46. virtual float turn_distance(float wp_radius, float turn_angle) const = 0;
  47. // return the target loiter radius for the current location that
  48. // will not cause excessive airframe loading
  49. virtual float loiter_radius(const float radius) const = 0;
  50. // update the internal state of the navigation controller, given
  51. // the previous and next waypoints. This is the step function for
  52. // navigation control for path following between two points. This
  53. // function is called at regular intervals (typically 10Hz). The
  54. // main flight code will call an output function (such as
  55. // nav_roll_cd()) after this function to ask for the new required
  56. // navigation attitude/steering.
  57. virtual void update_waypoint(const struct Location &prev_WP, const struct Location &next_WP, float dist_min = 0.0f) = 0;
  58. // update the internal state of the navigation controller for when
  59. // the vehicle has been commanded to circle about a point. This
  60. // is the step function for navigation control for circling. This
  61. // function is called at regular intervals (typically 10Hz). The
  62. // main flight code will call an output function (such as
  63. // nav_roll_cd()) after this function to ask for the new required
  64. // navigation attitude/steering.
  65. virtual void update_loiter(const struct Location &center_WP, float radius, int8_t loiter_direction) = 0;
  66. // update the internal state of the navigation controller, given a
  67. // fixed heading. This is the step function for navigation control
  68. // for a fixed heading. This function is called at regular
  69. // intervals (typically 10Hz). The main flight code will call an
  70. // output function (such as nav_roll_cd()) after this function to
  71. // ask for the new required navigation attitude/steering.
  72. virtual void update_heading_hold(int32_t navigation_heading_cd) = 0;
  73. // update the internal state of the navigation controller for
  74. // level flight on the current heading. This is the step function
  75. // for navigation control for level flight. This function is
  76. // called at regular intervals (typically 10Hz). The main flight
  77. // code will call an output function (such as nav_roll_cd()) after
  78. // this function to ask for the new required navigation
  79. // attitude/steering.
  80. virtual void update_level_flight(void) = 0;
  81. // return true if we have reached the target loiter location. This
  82. // may be a fuzzy decision, depending on internal navigation
  83. // parameters. For example the controller may return true only
  84. // when on the circular path around the waypoint, and not when
  85. // tracking towards the center. This function is only valid when
  86. // the update_loiter() method is used
  87. virtual bool reached_loiter_target(void) = 0;
  88. // notify Navigation controller that a new waypoint has just been
  89. // processed. This means that until we handle an update_XXX() function
  90. // the data is stale with old navigation information.
  91. virtual void set_data_is_stale(void) = 0;
  92. // return true if a new waypoint has been processed by mission
  93. // controller but the navigation controller still has old stale data
  94. // from previous waypoint navigation handling. This gets cleared on
  95. // every update_XXXXXX() call.
  96. virtual bool data_is_stale(void) const = 0;
  97. virtual void set_reverse(bool reverse) = 0;
  98. // add new navigation controllers to this enum. Users can then
  99. // select which navigation controller to use by setting the
  100. // NAV_CONTROLLER parameter
  101. enum ControllerType {
  102. CONTROLLER_DEFAULT = 0,
  103. CONTROLLER_L1 = 1
  104. };
  105. };