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.
mobilitypath_visualizer.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2019-2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <rclcpp/rclcpp.hpp>
20#include <functional>
21#include <std_msgs/msg/string.hpp>
22#include <carma_ros2_utils/carma_lifecycle_node.hpp>
23#include <string>
24#include <vector>
25#include <visualization_msgs/msg/marker_array.hpp>
26#include <carma_v2x_msgs/msg/mobility_path.hpp>
27#include <unordered_map>
28#include <lanelet2_extension/projection/local_frame_projector.h>
29
31
32
34
41 {
42 double red = 0.0;
43 double green = 0.0;
44 double blue = 0.0;
45 };
46
47 class MobilityPathVisualizer :public carma_ros2_utils::CarmaLifecycleNode
48 {
49
50 public:
51
52
56 MobilityPathVisualizer(const rclcpp::NodeOptions &);
57
64 visualization_msgs::msg::MarkerArray composeVisualizationMarker(const carma_v2x_msgs::msg::MobilityPath& msg, const MarkerColor& color);
65
71 geometry_msgs::msg::Point ECEFToMapPoint(const carma_v2x_msgs::msg::LocationECEF& ecef_point) const;
72
80 visualization_msgs::msg::MarkerArray composeLabelMarker(const visualization_msgs::msg::MarkerArray& host_marker, const std::vector<visualization_msgs::msg::MarkerArray>& cav_markers) const;
81
91 std::vector<visualization_msgs::msg::MarkerArray> matchTrajectoryTimestamps(const visualization_msgs::msg::MarkerArray& host_marker,
92 const std::vector<visualization_msgs::msg::MarkerArray>& cav_markers) const;
93
94
99 void georeferenceCallback(std_msgs::msg::String::UniquePtr msg);
100
102 // Overrides
104 carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &);
105
106 carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &);
107
108 private:
109
110 // publisher
111 carma_ros2_utils::PubPtr<visualization_msgs::msg::MarkerArray> host_marker_pub_;
112 carma_ros2_utils::PubPtr<visualization_msgs::msg::MarkerArray> cav_marker_pub_;
113 carma_ros2_utils::PubPtr<visualization_msgs::msg::MarkerArray> label_marker_pub_;
114
115 // subscriber
116 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::MobilityPath> host_mob_path_sub_;
117 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::MobilityPath> cav_mob_path_sub_;
118 carma_ros2_utils::SubPtr<std_msgs::msg::String> georeference_sub_;
119
120 // initialize this node before running
122
123 std::string georeference_{""};
124 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_;
125
127
128 // Timers
129 rclcpp::TimerBase::SharedPtr timer_;
130
131 // callbacks
132 void callbackMobilityPath(carma_v2x_msgs::msg::MobilityPath::UniquePtr msg);
133 void timer_callback();
134
135 // latest msgs
136 std::unordered_map<std::string, carma_v2x_msgs::msg::MobilityPath> latest_cav_mob_path_msg_;
137
138 // marker msgs
139 visualization_msgs::msg::MarkerArray host_marker_;
140 std::vector<visualization_msgs::msg::MarkerArray> cav_markers_;
141 visualization_msgs::msg::MarkerArray label_marker_;
142
143 // helper variable
144 std::unordered_map<std::string, size_t> prev_marker_list_size_;
146
147 };
148
149}
150
151
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > label_marker_pub_
visualization_msgs::msg::MarkerArray composeLabelMarker(const visualization_msgs::msg::MarkerArray &host_marker, const std::vector< visualization_msgs::msg::MarkerArray > &cav_markers) const
Compose a label marker that displays whether if any of the cav's path cross with that of host (respec...
std::unordered_map< std::string, carma_v2x_msgs::msg::MobilityPath > latest_cav_mob_path_msg_
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityPath > cav_mob_path_sub_
carma_ros2_utils::SubPtr< std_msgs::msg::String > georeference_sub_
std::vector< visualization_msgs::msg::MarkerArray > matchTrajectoryTimestamps(const visualization_msgs::msg::MarkerArray &host_marker, const std::vector< visualization_msgs::msg::MarkerArray > &cav_markers) const
Matches timestamps of CAV's individual points of cav_markers to that of host_marker and interpolates ...
std::unordered_map< std::string, size_t > prev_marker_list_size_
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > cav_marker_pub_
visualization_msgs::msg::MarkerArray label_marker_
MobilityPathVisualizer(const rclcpp::NodeOptions &)
Constructor.
std::vector< visualization_msgs::msg::MarkerArray > cav_markers_
carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &)
geometry_msgs::msg::Point ECEFToMapPoint(const carma_v2x_msgs::msg::LocationECEF &ecef_point) const
Accepts ECEF point in cm to convert to a point in map in meters.
visualization_msgs::msg::MarkerArray composeVisualizationMarker(const carma_v2x_msgs::msg::MobilityPath &msg, const MarkerColor &color)
Compose a visualization marker for mobilitypath messages.
void callbackMobilityPath(carma_v2x_msgs::msg::MobilityPath::UniquePtr msg)
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
void georeferenceCallback(std_msgs::msg::String::UniquePtr msg)
Callback for map projection string to define lat/lon -> map conversion.
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > host_marker_pub_
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityPath > host_mob_path_sub_
Stuct containing the algorithm configuration values for <package_name>