AP_OAPathPlanner.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include <AP_Common/AP_Common.h>
  3. #include <AP_Common/Location.h>
  4. #include <AP_Param/AP_Param.h>
  5. #include <AP_HAL/AP_HAL.h>
  6. #include "AP_OABendyRuler.h"
  7. #include "AP_OADijkstra.h"
  8. #include "AP_OADatabase.h"
  9. /*
  10. * This class provides path planning around fence, stay-out zones and moving obstacles
  11. */
  12. class AP_OAPathPlanner {
  13. public:
  14. AP_OAPathPlanner();
  15. /* Do not allow copies */
  16. AP_OAPathPlanner(const AP_OAPathPlanner &other) = delete;
  17. AP_OAPathPlanner &operator=(const AP_OAPathPlanner&) = delete;
  18. // get singleton instance
  19. static AP_OAPathPlanner *get_singleton() {
  20. return _singleton;
  21. }
  22. // perform any required initialisation
  23. void init();
  24. /// returns true if all pre-takeoff checks have completed successfully
  25. bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const;
  26. // object avoidance processing return status enum
  27. enum OA_RetState : uint8_t {
  28. OA_NOT_REQUIRED = 0, // object avoidance is not required
  29. OA_PROCESSING, // still calculating alternative path
  30. OA_ERROR, // error during calculation
  31. OA_SUCCESS // success
  32. };
  33. // provides an alternative target location if path planning around obstacles is required
  34. // returns true and updates result_origin and result_destination with an intermediate path
  35. OA_RetState mission_avoidance(const Location &current_loc,
  36. const Location &origin,
  37. const Location &destination,
  38. Location &result_origin,
  39. Location &result_destination) WARN_IF_UNUSED;
  40. // enumerations for _TYPE parameter
  41. enum OAPathPlanTypes {
  42. OA_PATHPLAN_DISABLED = 0,
  43. OA_PATHPLAN_BENDYRULER = 1,
  44. OA_PATHPLAN_DIJKSTRA = 2
  45. };
  46. static const struct AP_Param::GroupInfo var_info[];
  47. private:
  48. // avoidance thread that continually updates the avoidance_result structure based on avoidance_request
  49. void avoidance_thread();
  50. bool start_thread();
  51. // an avoidance request from the navigation code
  52. struct avoidance_info {
  53. Location current_loc;
  54. Location origin;
  55. Location destination;
  56. Vector2f ground_speed_vec;
  57. uint32_t request_time_ms;
  58. } avoidance_request, avoidance_request2;
  59. // an avoidance result from the avoidance thread
  60. struct {
  61. Location destination; // destination vehicle is trying to get to (also used to verify the result matches a recent request)
  62. Location origin_new; // intermediate origin. The start of line segment that vehicle should follow
  63. Location destination_new; // intermediate destination vehicle should move towards
  64. uint32_t result_time_ms; // system time the result was calculated (used to verify the result is recent)
  65. OA_RetState ret_state; // OA_SUCCESS if the vehicle should move along the path from origin_new to destination_new
  66. } avoidance_result;
  67. // parameters
  68. AP_Int8 _type; // avoidance algorith to be used
  69. AP_Float _lookahead; // object avoidance will look this many meters ahead of vehicle
  70. AP_Float _margin_max; // object avoidance will ignore objects more than this many meters from vehicle
  71. // internal variables used by front end
  72. HAL_Semaphore_Recursive _rsem; // semaphore for multi-thread use of avoidance_request and avoidance_result
  73. bool _thread_created; // true once background thread has been created
  74. AP_OABendyRuler *_oabendyruler; // Bendy Ruler algorithm
  75. AP_OADijkstra *_oadijkstra; // Dijkstra's algorithm
  76. AP_OADatabase _oadatabase; // Database of dynamic objects to avoid
  77. #if !HAL_MINIMIZE_FEATURES
  78. uint32_t avoidance_latest_ms; // last time Dijkstra's or BendyRuler algorithms ran
  79. #endif
  80. static AP_OAPathPlanner *_singleton;
  81. };
  82. namespace AP {
  83. AP_OAPathPlanner *ap_oapathplanner();
  84. };