AP_OAVisGraph.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include <AP_Common/AP_Common.h>
  3. #include <AP_Common/AP_ExpandingArray.h>
  4. #include <AP_HAL/AP_HAL.h>
  5. /*
  6. * Visibility graph used by Dijkstra's algorithm for path planning around fence, stay-out zones and moving obstacles
  7. */
  8. class AP_OAVisGraph {
  9. public:
  10. AP_OAVisGraph();
  11. /* Do not allow copies */
  12. AP_OAVisGraph(const AP_OAVisGraph &other) = delete;
  13. AP_OAVisGraph &operator=(const AP_OAVisGraph&) = delete;
  14. // types of items held in graph
  15. enum OAType : uint8_t {
  16. OATYPE_SOURCE = 0,
  17. OATYPE_DESTINATION,
  18. OATYPE_FENCE_POINT
  19. };
  20. // support up to 255 items of each type
  21. typedef uint8_t oaid_num;
  22. // id for uniquely identifying objects held in visibility graphs and paths
  23. class OAItemID {
  24. public:
  25. OAType id_type;
  26. oaid_num id_num;
  27. bool operator ==(const OAItemID &i) const { return ((id_type == i.id_type) && (id_num == i.id_num)); }
  28. };
  29. struct VisGraphItem {
  30. OAItemID id1; // first item's id
  31. OAItemID id2; // second item's id
  32. float distance_cm; // distance between the items
  33. };
  34. // clear all elements from graph
  35. void clear() { _num_items = 0; }
  36. // get number of items in visibility graph table
  37. uint8_t num_items() const { return _num_items; }
  38. // add item to visiblity graph, returns true on success, false if graph is full
  39. bool add_item(const OAItemID &id1, const OAItemID &id2, float distance_cm);
  40. // allow accessing graph as an array, 0 indexed
  41. // Note: no protection against out-of-bounds accesses so use with num_items()
  42. const VisGraphItem& operator[](uint8_t i) const { return _items[i]; }
  43. private:
  44. AP_ExpandingArray<VisGraphItem> _items;
  45. uint8_t _num_items;
  46. };