AP_OABendyRuler.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <AP_Common/AP_Common.h>
  3. #include <AP_Common/Location.h>
  4. #include <AP_Math/AP_Math.h>
  5. #include <AP_HAL/AP_HAL.h>
  6. /*
  7. * BendyRuler avoidance algorithm for avoiding the polygon and circular fence and dynamic objects detected by the proximity sensor
  8. */
  9. class AP_OABendyRuler {
  10. public:
  11. AP_OABendyRuler() {}
  12. /* Do not allow copies */
  13. AP_OABendyRuler(const AP_OABendyRuler &other) = delete;
  14. AP_OABendyRuler &operator=(const AP_OABendyRuler&) = delete;
  15. // send configuration info stored in front end parameters
  16. void set_config(float lookahead, float margin_max) { _lookahead = MAX(lookahead, 1.0f); _margin_max = MAX(margin_max, 0.0f); }
  17. // run background task to find best path and update avoidance_results
  18. // returns true and populates origin_new and destination_new if OA is required. returns false if OA is not required
  19. bool update(const Location& current_loc, const Location& destination, const Vector2f &ground_speed_vec, Location &origin_new, Location &destination_new);
  20. private:
  21. // calculate minimum distance between a path and any obstacle
  22. float calc_avoidance_margin(const Location &start, const Location &end);
  23. // calculate minimum distance between a path and the circular fence (centered on home)
  24. // on success returns true and updates margin
  25. bool calc_margin_from_circular_fence(const Location &start, const Location &end, float &margin);
  26. // calculate minimum distance between a path and the polygon fence
  27. // on success returns true and updates margin
  28. bool calc_margin_from_polygon_fence(const Location &start, const Location &end, float &margin);
  29. // calculate minimum distance between a path and proximity sensor obstacles
  30. // on success returns true and updates margin
  31. bool calc_margin_from_object_database(const Location &start, const Location &end, float &margin);
  32. // configuration parameters
  33. float _lookahead; // object avoidance will look this many meters ahead of vehicle
  34. float _margin_max; // object avoidance will ignore objects more than this many meters from vehicle
  35. // internal variables used by background thread
  36. float _current_lookahead; // distance (in meters) ahead of the vehicle we are looking for obstacles
  37. };