14 geometry_msgs::PoseArray
path;
15 vector<geometry_msgs::Pose> poses;
16 geometry_msgs::Pose
pose;
20 pose.position.x = e.from %
map.info.width *
map.info.resolution +
map.info.origin.position.x;
21 pose.position.y = e.from /
map.info.width *
map.info.resolution +
map.info.origin.position.y;
24 double dx = e.to %
map.info.width *
map.info.resolution +
map.info.origin.position.x - pose.position.x;
25 double dy = e.to /
map.info.width *
map.info.resolution +
map.info.origin.position.y - pose.position.y;
26 tf2::Quaternion direction;
27 direction.setRPY(0, 0, atan2(dy, dx));
28 pose.orientation = tf2::toMsg(direction);
30 poses.push_back(pose);
34 path.header.stamp = Time::now();
35 path.header.frame_id =
"local_origin_ned";
43 int rows = gridmap.info.height;
44 int cols = gridmap.info.width;
48 nodes.resize(rows*cols);
52 for (
int i=0; i<rows; i++) {
53 for (
int j=0; j<cols; j++) {
55 if (
map.data[i*cols+j] == 0) {
57 if (i>0 &&
map.data[(i-1)*cols+j] == 0) {
60 if (i<rows-1 &&
map.data[(i+1)*cols+j] == 0) {
63 if (j>0 &&
map.data[i*cols+j-1] == 0) {
66 if (j<cols-1 &&
map.data[i*cols+j+1] == 0) {
72 if (i>0 && j>0 &&
map.data[(i-1)*cols+j-1] == 0) {
73 add_edge(i*cols+j, (i-1)*cols+j-1, 1);
75 if (i<rows-1 && j<cols-1 &&
map.data[(i+1)*cols+j+1] == 0) {
76 add_edge(i*cols+j, (i+1)*cols+j+1, 1);
78 if (i<rows-1 && j>0 &&
map.data[(i+1)*cols+j-1] == 0) {
79 add_edge(i*cols+j, (i+1)*cols+j-1, 1);
81 if (i>0 && j<cols-1 &&
map.data[(i-1)*cols+j+1] == 0) {
82 add_edge(i*cols+j, (i-1)*cols+j+1, 1);
94 while (!
edges.empty()) {
122 if (
nodes[from].size() == 0) {
123 nodes[from].insert(from);
125 if (
nodes[to].size() == 0) {
126 nodes[to].insert(to);
nav_msgs::OccupancyGrid map
The grid map that needs to be covered by the MST.
vector< edge > mst_edges
Edges in Minimal-Spanning Tree.
void add_edge(int from, int to, int cost)
Add an edge to the tree.
void construct()
Generate the MST using Kruskal's algorithm.
nav_msgs::OccupancyGrid gridmap
The grid map representing the environment to be covered.
A struct that provides the comparison of edge objects.
vector< edge > get_mst_edges()
Get the edges of the MST.
int to
The ending vertex of the edge.
A class for representing edges.
geometry_msgs::Pose pose
Current position of the CPS.
int from
The starting vertex of the edge.
spanning_tree()
Constructor.
mst_path path
The coverage path.
geometry_msgs::PoseArray get_tree()
Get the generated MST for visualization.
vector< unordered_set< int > > nodes
The sets of connected vertices.
void initialize_graph(nav_msgs::OccupancyGrid gridmap, bool connect4=true)
Initialize the internal tree structure from a given grid map.
priority_queue< edge, vector< edge >, compare_edge > edges
Priority queue of edge objects sorted by cost.
bool different_sets(int a, int b)
Check whether two vertices are in different sets.