20 namespace std_ph = std::placeholders;
23 : carma_ros2_utils::CarmaLifecycleNode(options)
40 auto error = update_params<bool>(
46 auto error2 = update_params<std::string>(
52 auto error3 = update_params<uint8_t>(
57 rcl_interfaces::msg::SetParametersResult result;
59 result.successful = !error && !error2 && !error3;
80 external_objects_sub_ = create_subscription<carma_perception_msgs::msg::ExternalObjectList>(
"external_objects", 10,
83 roadway_obstacles_sub_ = create_subscription<carma_perception_msgs::msg::RoadwayObstacleList>(
"roadway_obstacles", 10,
91 return CallbackReturn::SUCCESS;
96 RCLCPP_DEBUG_STREAM( get_logger(),
"external_objects_callback called");
99 RCLCPP_DEBUG_STREAM( get_logger(),
"external_objects_callback called, but visualization is not enabled.");
103 visualization_msgs::msg::MarkerArray viz_msg;
105 visualization_msgs::msg::Marker marker;
106 viz_msg.markers.reserve(msg->objects.size() + 1);
108 marker.action = visualization_msgs::msg::Marker::DELETEALL;
109 viz_msg.markers.push_back(marker);
114 for (
auto obj : msg->objects) {
115 visualization_msgs::msg::Marker marker;
117 marker.header = msg->header;
122 if (obj.object_type == carma_perception_msgs::msg::ExternalObject::PEDESTRIAN) {
124 marker.color.r = 1.0;
125 marker.color.g = 0.0;
126 marker.color.b = 0.0;
127 marker.color.a = 1.0;
132 marker.color.r = 0.0;
133 marker.color.g = 0.0;
134 marker.color.b = 1.0;
135 marker.color.a = 1.0;
138 marker.pose = obj.pose.pose;
139 marker.pose.position.z = std::max(1.0, obj.size.z);
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");
147 marker.action = visualization_msgs::msg::Marker::ADD;
151 marker.scale.x = std::max(1.0, obj.size.x) * 2;
152 marker.scale.y = std::max(1.0, obj.size.y) * 2;
153 marker.scale.z = std::max(1.0, obj.size.z) * 2;
155 viz_msg.markers.push_back(marker);
168 size_t size_swap = viz_msg.markers.size();
171 if (viz_msg.markers.size() < old_size) {
173 for (
size_t i = viz_msg.markers.size();
i < old_size; ++
i) {
174 visualization_msgs::msg::Marker marker;
176 marker.action = visualization_msgs::msg::Marker::DELETE;
177 viz_msg.markers.push_back(marker);
182 old_size = size_swap;
187 RCLCPP_DEBUG_STREAM( get_logger(),
"roadway_obstacles_callback called");
190 RCLCPP_DEBUG_STREAM( get_logger(),
"roadway_obstacles_callback called, but visualization is not enabled.");
194 visualization_msgs::msg::MarkerArray viz_msg;
196 visualization_msgs::msg::Marker marker;
197 viz_msg.markers.reserve(msg->roadway_obstacles.size() + 1);
199 marker.action = visualization_msgs::msg::Marker::DELETEALL;
200 viz_msg.markers.push_back(marker);
203 for (
auto obj : msg->roadway_obstacles) {
204 visualization_msgs::msg::Marker marker;
206 marker.header = obj.object.header;
211 if (obj.object.object_type == carma_perception_msgs::msg::ExternalObject::PEDESTRIAN) {
213 marker.color.r = 1.0;
214 marker.color.g = 0.0;
215 marker.color.b = 0.0;
216 marker.color.a = 1.0;
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;
227 marker.color.r = 0.0;
228 marker.color.g = 0.0;
229 marker.color.b = 1.0;
230 marker.color.a = 1.0;
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;
238 marker.scale.y = obj.object.size.y * 2.0;
239 marker.scale.z = obj.object.size.z * 2.0;
241 viz_msg.markers.push_back(marker);
254#include "rclcpp_components/register_node_macro.hpp"
This node provides RViz visualization messages for recieved ExternalObject and RoadwayObstacle messag...
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 > ¶meters)
Example callback for dynamic parameter updates.
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > roadway_obstacles_viz_pub_
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::SubPtr< carma_perception_msgs::msg::ExternalObjectList > external_objects_sub_
size_t prev_roadway_obstacles_size_
size_t prev_external_objects_size_
Node(const rclcpp::NodeOptions &)
Node constructor.
carma_ros2_utils::SubPtr< carma_perception_msgs::msg::RoadwayObstacleList > roadway_obstacles_sub_
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > external_objects_viz_pub_
void external_objects_callback(carma_perception_msgs::msg::ExternalObjectList::UniquePtr msg)
External objects callback. Converts the message to a visualization message to republish.
auto to_string(const UtmZone &zone) -> std::string
Stuct containing the algorithm configuration values for object_visualizer.
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.