123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #pragma once
- #include <AP_Common/AP_Common.h>
- #include <AP_Common/Location.h>
- #include <AP_Math/AP_Math.h>
- #include <AP_HAL/AP_HAL.h>
- #include "AP_OAVisGraph.h"
- class AP_OADijkstra {
- public:
- AP_OADijkstra();
-
- AP_OADijkstra(const AP_OADijkstra &other) = delete;
- AP_OADijkstra &operator=(const AP_OADijkstra&) = delete;
-
- void set_fence_margin(float margin) { _polyfence_margin = MAX(margin, 0.0f); }
-
- enum AP_OADijkstra_State : uint8_t {
- DIJKSTRA_STATE_NOT_REQUIRED = 0,
- DIJKSTRA_STATE_ERROR,
- DIJKSTRA_STATE_SUCCESS
- };
-
-
- AP_OADijkstra_State update(const Location ¤t_loc, const Location &destination, Location& origin_new, Location& destination_new);
- private:
-
- bool polygon_fence_enabled() const;
-
- bool check_polygon_fence_updated() const;
-
-
- bool create_polygon_fence_with_margin(float margin_cm);
-
-
-
- bool create_polygon_fence_visgraph();
-
-
-
-
- bool calc_shortest_path(const Location &origin, const Location &destination);
-
- bool _polyfence_with_margin_ok;
- bool _polyfence_visgraph_ok;
- bool _shortest_path_ok;
- Location _destination_prev;
- uint8_t _path_idx_returned;
-
- float _polyfence_margin = 10;
- AP_ExpandingArray<Vector2f> _polyfence_pts;
- uint8_t _polyfence_numpoints;
- uint32_t _polyfence_update_ms;
-
- AP_OAVisGraph _polyfence_visgraph;
- AP_OAVisGraph _source_visgraph;
- AP_OAVisGraph _destination_visgraph;
-
-
-
-
- bool update_visgraph(AP_OAVisGraph& visgraph, const AP_OAVisGraph::OAItemID& oaid, const Vector2f &position, bool add_extra_position = false, Vector2f extra_position = Vector2f(0,0));
- typedef uint8_t node_index;
- struct ShortPathNode {
- AP_OAVisGraph::OAItemID id;
- bool visited;
- node_index distance_from_idx;
- float distance_cm;
- };
- AP_ExpandingArray<ShortPathNode> _short_path_data;
- node_index _short_path_data_numpoints;
-
-
- void update_visible_node_distances(node_index curr_node_idx);
-
-
- bool find_node_from_id(const AP_OAVisGraph::OAItemID &id, node_index &node_idx) const;
-
-
- bool find_closest_node_idx(node_index &node_idx) const;
-
- AP_ExpandingArray<AP_OAVisGraph::OAItemID> _path;
- uint8_t _path_numpoints;
- Vector2f _path_source;
- Vector2f _path_destination;
-
- bool get_shortest_path_point(uint8_t point_num, Vector2f& pos);
- };
|