-
Notifications
You must be signed in to change notification settings - Fork 541
/
Copy pathpath.cpp
109 lines (95 loc) · 2.96 KB
/
path.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "path.h"
//###################################################
// CLEAR PATH
//###################################################
void Path::clear() {
Node3D* node = new Node3D();
path.poses.clear();
pathNodes.markers.clear();
pathVehicles.markers.clear();
addNode(node, 0);
addVehicle(node, 1);
publishPath();
publishPathNodes();
publishPathVehicles();
delete node;
}
//###################################################
// TRACE PATH
//###################################################
// __________
// TRACE PATH
void Path::tracePath(const Node3D* node, int i) {
if (i == 0) {
path.header.stamp = ros::Time::now();
}
if (node == nullptr) { return; }
addSegment(node);
addNode(node, i);
i++;
addVehicle(node, i);
i++;
if (node->getPred() == node) {
std::cout << "loop";
return;
}
tracePath(node->getPred(), i);
}
// ___________
// ADD SEGMENT
void Path::addSegment(const Node3D* node) {
geometry_msgs::PoseStamped vertex;
vertex.pose.position.x = node->getX()*constants::cellSize;
vertex.pose.position.y = node->getY()*constants::cellSize;
vertex.pose.position.z = 0;
vertex.pose.orientation.x = 0;
vertex.pose.orientation.y = 0;
vertex.pose.orientation.z = 0;
vertex.pose.orientation.w = 0;
path.poses.push_back(vertex);
}
// ________
// ADD NODE
void Path::addNode(const Node3D* node, int i) {
visualization_msgs::Marker pathNode;
// delete all previous markers
if (i == 0) {
pathNode.action = 3;
}
pathNode.header.frame_id = "path";
pathNode.header.stamp = ros::Time(0);
pathNode.id = i;
pathNode.type = visualization_msgs::Marker::SPHERE;
pathNode.scale.x = 0.1;
pathNode.scale.y = 0.1;
pathNode.scale.z = 0.1;
pathNode.color.a = 1.0;
pathNode.color.r = purple.red;
pathNode.color.g = purple.green;
pathNode.color.b = purple.blue;
pathNode.pose.position.x = node->getX()*constants::cellSize;
pathNode.pose.position.y = node->getY()*constants::cellSize;
pathNodes.markers.push_back(pathNode);
}
void Path::addVehicle(const Node3D* node, int i) {
visualization_msgs::Marker pathVehicle;
// delete all previous markers
if (i == 1) {
pathVehicle.action = 3;
}
pathVehicle.header.frame_id = "path";
pathVehicle.header.stamp = ros::Time(0);
pathVehicle.id = i;
pathVehicle.type = visualization_msgs::Marker::CUBE;
pathVehicle.scale.x = constants::length - constants::bloating * 2;
pathVehicle.scale.y = constants::width - constants::bloating * 2;
pathVehicle.scale.z = 1;
pathVehicle.color.a = 0.1;
pathVehicle.color.r = teal.red;
pathVehicle.color.g = teal.green;
pathVehicle.color.b = teal.blue;
pathVehicle.pose.position.x = node->getX()*constants::cellSize;
pathVehicle.pose.position.y = node->getY()*constants::cellSize;
pathVehicle.pose.orientation = tf::createQuaternionMsgFromYaw(node->getT());
pathVehicles.markers.push_back(pathVehicle);
}