2019-05-10 02:59:31 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
2019-06-14 01:22:20 -03:00
|
|
|
#include <AP_Common/AP_ExpandingArray.h>
|
2019-05-10 02:59:31 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Visibility graph used by Dijkstra's algorithm for path planning around fence, stay-out zones and moving obstacles
|
|
|
|
*/
|
|
|
|
class AP_OAVisGraph {
|
|
|
|
public:
|
|
|
|
AP_OAVisGraph();
|
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_OAVisGraph(const AP_OAVisGraph &other) = delete;
|
|
|
|
AP_OAVisGraph &operator=(const AP_OAVisGraph&) = delete;
|
|
|
|
|
|
|
|
// types of items held in graph
|
|
|
|
enum OAType : uint8_t {
|
|
|
|
OATYPE_SOURCE = 0,
|
|
|
|
OATYPE_DESTINATION,
|
2019-07-15 01:11:25 -03:00
|
|
|
OATYPE_INTERMEDIATE_POINT,
|
2019-05-10 02:59:31 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// support up to 255 items of each type
|
|
|
|
typedef uint8_t oaid_num;
|
|
|
|
|
|
|
|
// id for uniquely identifying objects held in visibility graphs and paths
|
|
|
|
class OAItemID {
|
|
|
|
public:
|
|
|
|
OAType id_type;
|
|
|
|
oaid_num id_num;
|
|
|
|
bool operator ==(const OAItemID &i) const { return ((id_type == i.id_type) && (id_num == i.id_num)); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VisGraphItem {
|
|
|
|
OAItemID id1; // first item's id
|
|
|
|
OAItemID id2; // second item's id
|
|
|
|
float distance_cm; // distance between the items
|
|
|
|
};
|
|
|
|
|
|
|
|
// clear all elements from graph
|
|
|
|
void clear() { _num_items = 0; }
|
|
|
|
|
|
|
|
// get number of items in visibility graph table
|
2019-07-15 01:11:25 -03:00
|
|
|
uint16_t num_items() const { return _num_items; }
|
2019-05-10 02:59:31 -03:00
|
|
|
|
|
|
|
// add item to visiblity graph, returns true on success, false if graph is full
|
|
|
|
bool add_item(const OAItemID &id1, const OAItemID &id2, float distance_cm);
|
|
|
|
|
|
|
|
// allow accessing graph as an array, 0 indexed
|
|
|
|
// Note: no protection against out-of-bounds accesses so use with num_items()
|
2019-07-15 01:11:25 -03:00
|
|
|
const VisGraphItem& operator[](uint16_t i) const { return _items[i]; }
|
2019-05-10 02:59:31 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-06-14 01:22:20 -03:00
|
|
|
AP_ExpandingArray<VisGraphItem> _items;
|
2019-07-15 01:11:25 -03:00
|
|
|
uint16_t _num_items;
|
2019-05-10 02:59:31 -03:00
|
|
|
};
|