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.
trajectory_visualizer::TrajectoryVisualizer Class Reference

#include <trajectory_visualizer.hpp>

Inheritance diagram for trajectory_visualizer::TrajectoryVisualizer:
Inheritance graph
Collaboration diagram for trajectory_visualizer::TrajectoryVisualizer:
Collaboration graph

Public Member Functions

 TrajectoryVisualizer (const rclcpp::NodeOptions &)
 TrajectoryVisualizer constructor. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &)
 

Private Member Functions

void callbackPlanTrajectory (carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
 

Private Attributes

carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > traj_sub_
 
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > traj_marker_pub_
 
Config config_
 
double max_speed_
 
size_t prev_marker_list_size_ = 0
 

Detailed Description

Definition at line 35 of file trajectory_visualizer.hpp.

Constructor & Destructor Documentation

◆ TrajectoryVisualizer()

trajectory_visualizer::TrajectoryVisualizer::TrajectoryVisualizer ( const rclcpp::NodeOptions &  options)
explicit

TrajectoryVisualizer constructor.

Definition at line 26 of file trajectory_visualizer.cpp.

27 : carma_ros2_utils::CarmaLifecycleNode(options)
28 {
29 // Create initial config
30 config_ = Config();
31
32 // Declare parameters
33 config_.max_speed = declare_parameter<double>("max_speed", config_.max_speed);
34 }

References config_, and trajectory_visualizer::Config::max_speed.

Member Function Documentation

◆ callbackPlanTrajectory()

void trajectory_visualizer::TrajectoryVisualizer::callbackPlanTrajectory ( carma_planning_msgs::msg::TrajectoryPlan::UniquePtr  msg)
private

Definition at line 56 of file trajectory_visualizer.cpp.

57 {
58 if (msg->trajectory_points.size() == 0)
59 {
60 RCLCPP_WARN_STREAM(this->get_logger(),"No trajectory point in plan_trajectory! Returning");
61 }
62 visualization_msgs::msg::MarkerArray tmp_marker_array;
63 // display by markers the velocity between each trajectory point/target time.
64 visualization_msgs::msg::Marker marker;
65 marker.header.frame_id = "map";
66 marker.header.stamp = this->now();
67 marker.type = visualization_msgs::msg::Marker::ARROW;
68 marker.action = visualization_msgs::msg::Marker::ADD;
69 marker.ns = "trajectory_visualizer";
70
71
72 marker.scale.x = 2;
73 marker.scale.y = 2;
74 marker.scale.z = 1;
75 marker.frame_locked = true;
76
77 size_t count = std::max(prev_marker_list_size_, msg->trajectory_points.size());
78
79 for (size_t i = 1; i < count; i++)
80 {
81 marker.id = i;
82
83 if (i >= msg->trajectory_points.size()) { // If we need to delete previous points
84 marker.action = visualization_msgs::msg::Marker::DELETE;
85 tmp_marker_array.markers.push_back(marker);
86 continue;
87 }
88
89 double max_speed = config_.max_speed * MPH_TO_MS;
90 double speed = max_speed;
91
92 rclcpp::Time t2 = msg->trajectory_points[i].target_time;
93 rclcpp::Time t1 = msg->trajectory_points[i - 1].target_time;
94
95 if (validateTime(t2) && validateTime(t1) && t2 > t1 ) {
96 rclcpp::Duration dt = t2 - t1;
97
98 double dx = msg->trajectory_points[i].x - msg->trajectory_points[i-1].x;
99 double dy = msg->trajectory_points[i].y - msg->trajectory_points[i-1].y;
100 double dist = sqrt(dx * dx + dy * dy);
101
102 speed = dist/ dt.seconds();
103 }
104
105
106
107 // map color to the scale of the speed
108 // red being the highest, green being the lowest (0ms)
109
110 RCLCPP_DEBUG_STREAM(this->get_logger(),"Speed:" << speed << "ms, max_speed:" << max_speed << "ms");
111 if (speed > max_speed)
112 {
113 RCLCPP_DEBUG_STREAM(this->get_logger(),"Speed was big, so capped at " << max_speed << "ms");
114 speed = max_speed;
115 }
116
117 marker.color.r = 0.0f;
118 marker.color.g = 0.0f;
119 marker.color.b = 0.0f;
120 marker.color.a = 1.0f;
121
122
123 double ratio = speed / max_speed;
124 if (ratio >= 0.75f)
125 {
126 marker.color.r = 1.0f;
127 }
128 else if (ratio >= 0.5f)
129 {
130 marker.color.b = 1.0f;
131 }
132 else if (ratio >= 0.25)
133 {
134 marker.color.b = 1.0f;
135 marker.color.g = 1.0f;
136
137 }
138 else if (ratio >= 0.0)
139 {
140 marker.color.g = 1.0f;
141 }
142
143 if (speed < 1.0) // Less than 2.5 mph is usually stopping
144 {
145 // Gray
146 marker.color.r = 0.5f;
147 marker.color.g = 0.5f;
148 marker.color.b = 0.5f;
149 }
150
151 marker.points = {};
152 geometry_msgs::msg::Point start;
153 start.x = msg->trajectory_points[i-1].x;
154 start.y = msg->trajectory_points[i-1].y;
155
156 geometry_msgs::msg::Point end;
157 end.x = msg->trajectory_points[i].x;
158 end.y = msg->trajectory_points[i].y;
159 marker.points.push_back(start);
160 marker.points.push_back(end);
161
162 tmp_marker_array.markers.push_back(marker);
163 }
164
165 prev_marker_list_size_ = msg->trajectory_points.size();
166 traj_marker_pub_->publish(tmp_marker_array);
167 }
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > traj_marker_pub_
bool validateTime(const rclcpp::Time &time)

References config_, process_bag::i, trajectory_visualizer::Config::max_speed, trajectory_visualizer::MPH_TO_MS, prev_marker_list_size_, traj_marker_pub_, and trajectory_visualizer::validateTime().

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 trajectory_visualizer::TrajectoryVisualizer::handle_on_configure ( const rclcpp_lifecycle::State &  )

Definition at line 36 of file trajectory_visualizer.cpp.

37 {
38 // Setup subscribers
39 traj_sub_ = create_subscription<carma_planning_msgs::msg::TrajectoryPlan>("plan_trajectory", 50,std::bind(&TrajectoryVisualizer::callbackPlanTrajectory,this,std_ph::_1));
40 // Setup publisher
41 traj_marker_pub_ = create_publisher<visualization_msgs::msg::MarkerArray>("trajectory_visualizer", 1);
42
43 // Return success if everything initialized successfully
44 return CallbackReturn::SUCCESS;
45 }
void callbackPlanTrajectory(carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > traj_sub_

References callbackPlanTrajectory(), traj_marker_pub_, and traj_sub_.

Here is the call graph for this function:

Member Data Documentation

◆ config_

Config trajectory_visualizer::TrajectoryVisualizer::config_
private

Definition at line 46 of file trajectory_visualizer.hpp.

Referenced by TrajectoryVisualizer(), and callbackPlanTrajectory().

◆ max_speed_

double trajectory_visualizer::TrajectoryVisualizer::max_speed_
private

Definition at line 52 of file trajectory_visualizer.hpp.

◆ prev_marker_list_size_

size_t trajectory_visualizer::TrajectoryVisualizer::prev_marker_list_size_ = 0
private

Definition at line 54 of file trajectory_visualizer.hpp.

Referenced by callbackPlanTrajectory().

◆ traj_marker_pub_

carma_ros2_utils::PubPtr<visualization_msgs::msg::MarkerArray> trajectory_visualizer::TrajectoryVisualizer::traj_marker_pub_
private

Definition at line 43 of file trajectory_visualizer.hpp.

Referenced by callbackPlanTrajectory(), and handle_on_configure().

◆ traj_sub_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::TrajectoryPlan> trajectory_visualizer::TrajectoryVisualizer::traj_sub_
private

Definition at line 40 of file trajectory_visualizer.hpp.

Referenced by handle_on_configure().


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