Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
object_visualizer::Node Class Reference

This node provides RViz visualization messages for recieved ExternalObject and RoadwayObstacle messages in carma-platform. More...

#include <object_visualizer_node.hpp>

Inheritance diagram for object_visualizer::Node:
Inheritance graph
Collaboration diagram for object_visualizer::Node:
Collaboration graph

Public Member Functions

 Node (const rclcpp::NodeOptions &)
 Node constructor. More...
 
rcl_interfaces::msg::SetParametersResult parameter_update_callback (const std::vector< rclcpp::Parameter > &parameters)
 Example callback for dynamic parameter updates. More...
 
void external_objects_callback (carma_perception_msgs::msg::ExternalObjectList::UniquePtr msg)
 External objects callback. Converts the message to a visualization message to republish. More...
 
void roadway_obstacles_callback (carma_perception_msgs::msg::RoadwayObstacleList::UniquePtr msg)
 Roadway obstacles callback. Converts the message to a visualization message to republish. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &)
 

Private Member Functions

void clear_and_update_old_objects (visualization_msgs::msg::MarkerArray &viz_msg, size_t &old_size)
 Adds a marker deletion for a number of markers which is the delta between the new marker count and the previously published count. More...
 

Private Attributes

carma_ros2_utils::SubPtr< carma_perception_msgs::msg::ExternalObjectList > external_objects_sub_
 
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::RoadwayObstacleList > roadway_obstacles_sub_
 
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > external_objects_viz_pub_
 
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > roadway_obstacles_viz_pub_
 
Config config_
 
size_t prev_external_objects_size_ = 0
 
size_t prev_roadway_obstacles_size_ = 0
 

Detailed Description

This node provides RViz visualization messages for recieved ExternalObject and RoadwayObstacle messages in carma-platform.

Definition at line 36 of file object_visualizer_node.hpp.

Constructor & Destructor Documentation

◆ Node()

object_visualizer::Node::Node ( const rclcpp::NodeOptions &  options)
explicit

Node constructor.

Definition at line 22 of file object_visualizer_node.cpp.

23 : carma_ros2_utils::CarmaLifecycleNode(options)
24 {
25 // Create initial config
26 config_ = Config();
27
28 // Declare parameters
29 config_.enable_external_objects_viz = declare_parameter<bool>("enable_external_objects_viz", config_.enable_external_objects_viz);
30 config_.enable_roadway_objects_viz = declare_parameter<bool>("enable_roadway_objects_viz", config_.enable_roadway_objects_viz);
31 config_.external_objects_viz_ns = declare_parameter<std::string>("external_objects_viz_ns", config_.external_objects_viz_ns);
32 config_.roadway_obstacles_viz_ns = declare_parameter<std::string>("roadway_obstacles_viz_ns", config_.roadway_obstacles_viz_ns);
33 config_.marker_shape = declare_parameter<uint8_t>("marker_shape", config_.marker_shape);
34
35 }
std::string external_objects_viz_ns
External Objects marker rviz namespace.
bool enable_roadway_objects_viz
If true then RViz markers will be forwarded for received carma_perception_msgs/RoadwayObstacleList me...
bool enable_external_objects_viz
If true then RViz markers will be forwarded for received carma_perception_msgs/ExternalObjectList mes...
std::string roadway_obstacles_viz_ns
Roadway Obstacles marker rviz namespace.

References config_, object_visualizer::Config::enable_external_objects_viz, object_visualizer::Config::enable_roadway_objects_viz, object_visualizer::Config::external_objects_viz_ns, object_visualizer::Config::marker_shape, and object_visualizer::Config::roadway_obstacles_viz_ns.

Member Function Documentation

◆ clear_and_update_old_objects()

void object_visualizer::Node::clear_and_update_old_objects ( visualization_msgs::msg::MarkerArray &  viz_msg,
size_t &  old_size 
)
private

Adds a marker deletion for a number of markers which is the delta between the new marker count and the previously published count.

ASSUMPTION: The marker array's ids are already recomputed starting from zero, such that tracking ids is not needed.

Parameters
[in/out]viz_msg The marker array to add deletion markers to
[in/out]old_size The size of the previous published marker array. The positive delta between this and the size of the viz_msg determines the number of deletions added

Definition at line 166 of file object_visualizer_node.cpp.

167 {
168 size_t size_swap = viz_msg.markers.size();
169
170 // Delete any markers from the previous message that are no longer in the current message
171 if (viz_msg.markers.size() < old_size) {
172
173 for (size_t i = viz_msg.markers.size(); i < old_size; ++i) {
174 visualization_msgs::msg::Marker marker;
175 marker.id = i;
176 marker.action = visualization_msgs::msg::Marker::DELETE;
177 viz_msg.markers.push_back(marker);
178 }
179
180 }
181
182 old_size = size_swap; // Assign the new size of added objects to the old size
183 }

References process_bag::i.

Referenced by external_objects_callback(), and roadway_obstacles_callback().

Here is the caller graph for this function:

◆ external_objects_callback()

void object_visualizer::Node::external_objects_callback ( carma_perception_msgs::msg::ExternalObjectList::UniquePtr  msg)

External objects callback. Converts the message to a visualization message to republish.

Parameters
msgThe received message

Definition at line 94 of file object_visualizer_node.cpp.

95 {
96 RCLCPP_DEBUG_STREAM( get_logger(), "external_objects_callback called");
97
99 RCLCPP_DEBUG_STREAM( get_logger(), "external_objects_callback called, but visualization is not enabled.");
100 return;
101 }
102
103 visualization_msgs::msg::MarkerArray viz_msg;
104 //delete all markers before adding new ones
105 visualization_msgs::msg::Marker marker;
106 viz_msg.markers.reserve(msg->objects.size() + 1); //+1 to account for delete all marker
107 marker.id = 0;
108 marker.action = visualization_msgs::msg::Marker::DELETEALL;
109 viz_msg.markers.push_back(marker);
110
111
112 size_t id = 0; // We always count the id from zero so we can delete markers later in a consistent manner
113
114 for (auto obj : msg->objects) {
115 visualization_msgs::msg::Marker marker;
116
117 marker.header = msg->header;
118
120
121 // Pedestrian's will be represented as red box
122 if (obj.object_type == carma_perception_msgs::msg::ExternalObject::PEDESTRIAN) {
123
124 marker.color.r = 1.0;
125 marker.color.g = 0.0;
126 marker.color.b = 0.0;
127 marker.color.a = 1.0;
128
129 } // All other detected objects will be blue
130 else {
131
132 marker.color.r = 0.0;
133 marker.color.g = 0.0;
134 marker.color.b = 1.0;
135 marker.color.a = 1.0;
136 }
137
138 marker.pose = obj.pose.pose;
139 marker.pose.position.z = std::max(1.0, obj.size.z); // lifts the marker above ground so that it doesn't clip
140
141 marker.id = id;
142 if (static_cast<int>(config_.marker_shape) < 1 || static_cast<int>(config_.marker_shape) > 3)
143 {
144 throw std::invalid_argument("Marker shape is not valid: " + std::to_string(static_cast<int>(config_.marker_shape)) + ". Please choose from 1: CUBE, 2: SPHERE, 3: CYLINDER");
145 }
146 marker.type = config_.marker_shape;
147 marker.action = visualization_msgs::msg::Marker::ADD;
148
149 // overwrite size in case any previous stack doesn't provide size
150 // such as carma_cooperative_perception at the moment
151 marker.scale.x = std::max(1.0, obj.size.x) * 2; // Size in carma is half the length/width/height
152 marker.scale.y = std::max(1.0, obj.size.y) * 2;
153 marker.scale.z = std::max(1.0, obj.size.z) * 2;
154
155 viz_msg.markers.push_back(marker);
156
157 id++;
158 }
159
161
162 external_objects_viz_pub_->publish(viz_msg);
163
164 }
void clear_and_update_old_objects(visualization_msgs::msg::MarkerArray &viz_msg, size_t &old_size)
Adds a marker deletion for a number of markers which is the delta between the new marker count and th...
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > external_objects_viz_pub_
auto to_string(const UtmZone &zone) -> std::string
Definition: utm_zone.cpp:21

References clear_and_update_old_objects(), config_, object_visualizer::Config::enable_external_objects_viz, object_visualizer::Config::external_objects_viz_ns, external_objects_viz_pub_, object_visualizer::Config::marker_shape, prev_external_objects_size_, and carma_cooperative_perception::to_string().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn object_visualizer::Node::handle_on_configure ( const rclcpp_lifecycle::State &  )

Definition at line 64 of file object_visualizer_node.cpp.

65 {
66 // Reset config
67 config_ = Config();
68
69 // Load parameters
70 get_parameter<bool>("enable_external_objects_viz", config_.enable_external_objects_viz);
71 get_parameter<bool>("enable_roadway_objects_viz", config_.enable_roadway_objects_viz);
72 get_parameter<std::string>("external_objects_viz_ns", config_.external_objects_viz_ns);
73 get_parameter<std::string>("roadway_obstacles_viz_ns", config_.roadway_obstacles_viz_ns);
74 get_parameter<uint8_t>("marker_shape", config_.marker_shape);
75
76 // Register runtime parameter update callback
77 add_on_set_parameters_callback(std::bind(&Node::parameter_update_callback, this, std_ph::_1));
78
79 // Setup subscribers
80 external_objects_sub_ = create_subscription<carma_perception_msgs::msg::ExternalObjectList>("external_objects", 10,
81 std::bind(&Node::external_objects_callback, this, std_ph::_1));
82
83 roadway_obstacles_sub_ = create_subscription<carma_perception_msgs::msg::RoadwayObstacleList>("roadway_obstacles", 10,
84 std::bind(&Node::roadway_obstacles_callback, this, std_ph::_1));
85
86 // Setup publishers
87 external_objects_viz_pub_ = create_publisher<visualization_msgs::msg::MarkerArray>("external_objects_viz", 10);
88 roadway_obstacles_viz_pub_ = create_publisher<visualization_msgs::msg::MarkerArray>("roadway_obstacles_viz", 10);
89
90 // Return success if everthing initialized successfully
91 return CallbackReturn::SUCCESS;
92 }
void roadway_obstacles_callback(carma_perception_msgs::msg::RoadwayObstacleList::UniquePtr msg)
Roadway obstacles callback. Converts the message to a visualization message to republish.
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Example callback for dynamic parameter updates.
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > roadway_obstacles_viz_pub_
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::ExternalObjectList > external_objects_sub_
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::RoadwayObstacleList > roadway_obstacles_sub_
void external_objects_callback(carma_perception_msgs::msg::ExternalObjectList::UniquePtr msg)
External objects callback. Converts the message to a visualization message to republish.

References config_, object_visualizer::Config::enable_external_objects_viz, object_visualizer::Config::enable_roadway_objects_viz, external_objects_callback(), external_objects_sub_, object_visualizer::Config::external_objects_viz_ns, external_objects_viz_pub_, object_visualizer::Config::marker_shape, parameter_update_callback(), roadway_obstacles_callback(), roadway_obstacles_sub_, object_visualizer::Config::roadway_obstacles_viz_ns, and roadway_obstacles_viz_pub_.

Here is the call graph for this function:

◆ parameter_update_callback()

rcl_interfaces::msg::SetParametersResult object_visualizer::Node::parameter_update_callback ( const std::vector< rclcpp::Parameter > &  parameters)

Example callback for dynamic parameter updates.

Definition at line 37 of file object_visualizer_node.cpp.

38 {
39 // Update parameters
40 auto error = update_params<bool>(
41 {
42 {"enable_external_objects_viz", config_.enable_external_objects_viz},
43 {"enable_roadway_objects_viz", config_.enable_roadway_objects_viz}
44 }, parameters);
45
46 auto error2 = update_params<std::string>(
47 {
48 {"external_objects_viz_ns", config_.external_objects_viz_ns},
49 {"roadway_obstacles_viz_ns", config_.roadway_obstacles_viz_ns}
50 }, parameters);
51
52 auto error3 = update_params<uint8_t>(
53 {
54 {"marker_shape", config_.marker_shape}
55 }, parameters);
56
57 rcl_interfaces::msg::SetParametersResult result;
58
59 result.successful = !error && !error2 && !error3;
60
61 return result;
62 }

References config_, object_visualizer::Config::enable_external_objects_viz, object_visualizer::Config::enable_roadway_objects_viz, object_visualizer::Config::external_objects_viz_ns, object_visualizer::Config::marker_shape, and object_visualizer::Config::roadway_obstacles_viz_ns.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ roadway_obstacles_callback()

void object_visualizer::Node::roadway_obstacles_callback ( carma_perception_msgs::msg::RoadwayObstacleList::UniquePtr  msg)

Roadway obstacles callback. Converts the message to a visualization message to republish.

Parameters
msgThe received message

Definition at line 185 of file object_visualizer_node.cpp.

186 {
187 RCLCPP_DEBUG_STREAM( get_logger(), "roadway_obstacles_callback called");
188
190 RCLCPP_DEBUG_STREAM( get_logger(), "roadway_obstacles_callback called, but visualization is not enabled.");
191 return;
192 }
193
194 visualization_msgs::msg::MarkerArray viz_msg;
195 //delete all markers before adding new ones
196 visualization_msgs::msg::Marker marker;
197 viz_msg.markers.reserve(msg->roadway_obstacles.size() + 1); //+1 to account for delete all marker
198 marker.id = 0;
199 marker.action = visualization_msgs::msg::Marker::DELETEALL;
200 viz_msg.markers.push_back(marker);
201
202 size_t id = 0; // We always count the id from zero so we can delete markers later in a consistent manner
203 for (auto obj : msg->roadway_obstacles) {
204 visualization_msgs::msg::Marker marker;
205
206 marker.header = obj.object.header;
207
209
210 // Pedestrian's will be represented as a red box
211 if (obj.object.object_type == carma_perception_msgs::msg::ExternalObject::PEDESTRIAN) {
212
213 marker.color.r = 1.0;
214 marker.color.g = 0.0;
215 marker.color.b = 0.0;
216 marker.color.a = 1.0;
217
218 } // Connected vehicles will be green
219 else if (obj.connected_vehicle_type.type != carma_perception_msgs::msg::ConnectedVehicleType::NOT_CONNECTED){
220 marker.color.r = 0.0;
221 marker.color.g = 1.0;
222 marker.color.b = 0.0;
223 marker.color.a = 1.0;
224 } // All other detected objects will be blue
225 else {
226
227 marker.color.r = 0.0;
228 marker.color.g = 0.0;
229 marker.color.b = 1.0;
230 marker.color.a = 1.0;
231 }
232
233 marker.id = id;
234 marker.type = visualization_msgs::msg::Marker::CUBE;
235 marker.action = visualization_msgs::msg::Marker::ADD;
236 marker.pose = obj.object.pose.pose;
237 marker.scale.x = obj.object.size.x * 2.0; // Size in carma is half the length/width/height
238 marker.scale.y = obj.object.size.y * 2.0;
239 marker.scale.z = obj.object.size.z * 2.0;
240
241 viz_msg.markers.push_back(marker);
242
243 id++;
244 }
245
247
248 roadway_obstacles_viz_pub_->publish(viz_msg);
249
250 }

References clear_and_update_old_objects(), config_, object_visualizer::Config::enable_roadway_objects_viz, prev_roadway_obstacles_size_, object_visualizer::Config::roadway_obstacles_viz_ns, and roadway_obstacles_viz_pub_.

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ config_

Config object_visualizer::Node::config_
private

◆ external_objects_sub_

carma_ros2_utils::SubPtr<carma_perception_msgs::msg::ExternalObjectList> object_visualizer::Node::external_objects_sub_
private

Definition at line 41 of file object_visualizer_node.hpp.

Referenced by handle_on_configure().

◆ external_objects_viz_pub_

carma_ros2_utils::PubPtr<visualization_msgs::msg::MarkerArray> object_visualizer::Node::external_objects_viz_pub_
private

Definition at line 45 of file object_visualizer_node.hpp.

Referenced by external_objects_callback(), and handle_on_configure().

◆ prev_external_objects_size_

size_t object_visualizer::Node::prev_external_objects_size_ = 0
private

Definition at line 52 of file object_visualizer_node.hpp.

Referenced by external_objects_callback().

◆ prev_roadway_obstacles_size_

size_t object_visualizer::Node::prev_roadway_obstacles_size_ = 0
private

Definition at line 53 of file object_visualizer_node.hpp.

Referenced by roadway_obstacles_callback().

◆ roadway_obstacles_sub_

carma_ros2_utils::SubPtr<carma_perception_msgs::msg::RoadwayObstacleList> object_visualizer::Node::roadway_obstacles_sub_
private

Definition at line 42 of file object_visualizer_node.hpp.

Referenced by handle_on_configure().

◆ roadway_obstacles_viz_pub_

carma_ros2_utils::PubPtr<visualization_msgs::msg::MarkerArray> object_visualizer::Node::roadway_obstacles_viz_pub_
private

Definition at line 46 of file object_visualizer_node.hpp.

Referenced by handle_on_configure(), and roadway_obstacles_callback().


The documentation for this class was generated from the following files: