Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
marker.cpp
Go to the documentation of this file.
2
4
5visualization_msgs::msg::Marker marker_from_position(
6 const common_lib::structures::Position& position, const std::string& name_space, const int id,
7 const std::string& color, float scale, const std::string& frame_id, const std::string& shape,
8 int action) {
9 std::array<float, 4> color_array = marker_color_map().at(color);
10
11 auto marker = visualization_msgs::msg::Marker();
12
13 marker.header.frame_id = frame_id;
14 marker.header.stamp = rclcpp::Clock().now();
15 marker.ns = name_space;
16 marker.id = id;
17 marker.type = marker_shape_map().at(shape);
18 marker.action = action;
19
20 marker.pose.orientation.x = 0.0;
21 marker.pose.orientation.y = 0.0;
22 marker.pose.orientation.z = 0.0;
23 marker.pose.orientation.w = 1.0;
24
25 marker.pose.position.x = position.x;
26 marker.pose.position.y = position.y;
27 marker.pose.position.z = 0.1;
28
29 marker.scale.x = scale;
30 marker.scale.y = scale;
31 marker.scale.z = scale;
32
33 marker.color.r = color_array[0];
34 marker.color.g = color_array[1];
35 marker.color.b = color_array[2];
36 marker.color.a = color_array[3];
37
38 return marker;
39}
40
41visualization_msgs::msg::Marker lines_marker_from_triangulations(
42 const std::vector<std::pair<Point, Point>>& triangulations, const std::string& name_space,
43 const std::string& frame_id, int id, const std::string& color, float scale, int action) {
44 std::array<float, 4> color_array = marker_color_map().at(color);
45
46 visualization_msgs::msg::Marker marker;
47 marker.header.frame_id = frame_id;
48 marker.header.stamp = rclcpp::Clock().now();
49 marker.ns = name_space;
50 marker.id = id;
51 marker.type = visualization_msgs::msg::Marker::LINE_LIST;
52 marker.action = action;
53
54 marker.pose.orientation.w = 1.0;
55 marker.scale.x = scale;
56
57 marker.color.r = color_array[0];
58 marker.color.g = color_array[1];
59 marker.color.b = color_array[2];
60 marker.color.a = color_array[3];
61
62 for (const auto& [point1, point2] : triangulations) {
63 geometry_msgs::msg::Point p1, p2;
64 p1.x = point1.x();
65 p1.y = point1.y();
66 p1.z = 0.0;
67
68 p2.x = point2.x();
69 p2.y = point2.y();
70 p2.z = 0.0;
71
72 marker.points.push_back(p1);
73 marker.points.push_back(p2);
74 }
75
76 return marker;
77}
78
79visualization_msgs::msg::MarkerArray velocity_hover_markers(
80 const std::vector<common_lib::structures::PathPoint>& path_array, const std::string& name_space,
81 const std::string& frame_id, float scale, int every_nth) {
82 visualization_msgs::msg::MarkerArray marker_array;
83
84 std::array<float, 4> color_array = {1.0f, 1.0f, 1.0f, 0.8f};
85
86 for (size_t i = 0; i < path_array.size(); i += every_nth) {
87 visualization_msgs::msg::Marker sphere_marker;
88 sphere_marker.header.frame_id = frame_id;
89 sphere_marker.header.stamp = rclcpp::Clock().now();
90 sphere_marker.ns = name_space + "_sphere";
91 sphere_marker.id = static_cast<int>(i);
92 sphere_marker.type = visualization_msgs::msg::Marker::SPHERE;
93 sphere_marker.action = visualization_msgs::msg::Marker::ADD;
94
95 sphere_marker.pose.position.x = path_array[i].position.x;
96 sphere_marker.pose.position.y = path_array[i].position.y;
97 sphere_marker.pose.position.z = 0.1;
98 sphere_marker.pose.orientation.w = 1.0;
99
100 sphere_marker.scale.x = scale;
101 sphere_marker.scale.y = scale;
102 sphere_marker.scale.z = scale;
103
104 sphere_marker.color.r = color_array[0];
105 sphere_marker.color.g = color_array[1];
106 sphere_marker.color.b = color_array[2];
107 sphere_marker.color.a = color_array[3];
108
109 marker_array.markers.push_back(sphere_marker);
110
111 visualization_msgs::msg::Marker text_marker;
112 text_marker.header.frame_id = frame_id;
113 text_marker.header.stamp = rclcpp::Clock().now();
114 text_marker.ns = name_space + "_text";
115 text_marker.id = static_cast<int>(i);
116 text_marker.type = visualization_msgs::msg::Marker::TEXT_VIEW_FACING;
117 text_marker.action = visualization_msgs::msg::Marker::ADD;
118
119 text_marker.pose.position.x = path_array[i].position.x;
120 text_marker.pose.position.y = path_array[i].position.y;
121 text_marker.pose.position.z = 0.5;
122 text_marker.pose.orientation.w = 1.0;
123
124 std::ostringstream velocity_text;
125 velocity_text << std::fixed << std::setprecision(1) << path_array[i].ideal_velocity << " m/s";
126
127 text_marker.text = velocity_text.str();
128 text_marker.scale.z = 0.3;
129
130 text_marker.color.r = 1.0f;
131 text_marker.color.g = 1.0f;
132 text_marker.color.b = 1.0f;
133 text_marker.color.a = 1.0f;
134
135 marker_array.markers.push_back(text_marker);
136 }
137
138 return marker_array;
139}
140
141} // namespace common_lib::communication
const std::map< std::string, std::array< float, 4 >, std::less<> > & marker_color_map()
Definition marker.hpp:21
visualization_msgs::msg::MarkerArray velocity_hover_markers(const std::vector< common_lib::structures::PathPoint > &path_array, const std::string &name_space, const std::string &frame_id, float scale=0.2f, int every_nth=1)
Creates sphere markers at each path point with velocity in the marker namespace When you hover over t...
Definition marker.cpp:79
const std::map< std::string, int, std::less<> > & marker_shape_map()
Definition marker.hpp:31
visualization_msgs::msg::Marker marker_from_position(const common_lib::structures::Position &position, const std::string &name_space, const int id, const std::string &color="red", float scale=0.5, const std::string &frame_id="map", const std::string &shape="sphere", int action=visualization_msgs::msg::Marker::ADD)
Converts a position to a marker.
Definition marker.cpp:5
visualization_msgs::msg::Marker lines_marker_from_triangulations(const std::vector< std::pair< Point, Point > > &triangulations, const std::string &name_space, const std::string &frame_id, int id, const std::string &color, float scale, int action)
Converts a vector of triangulation edges to a marker.
Definition marker.cpp:41