17#include <rclcpp/rclcpp.hpp>
24 namespace std_ph = std::placeholders;
27 : carma_ros2_utils::CarmaLifecycleNode(options)
41 traj_marker_pub_ = create_publisher<visualization_msgs::msg::MarkerArray>(
"trajectory_visualizer", 1);
44 return CallbackReturn::SUCCESS;
49 int64_t sec64 =
static_cast<int64_t
>(floor(time.seconds()));
50 if (sec64 < std::numeric_limits<int32_t>::min() || sec64 > std::numeric_limits<int32_t>::max())
58 if (msg->trajectory_points.size() == 0)
60 RCLCPP_WARN_STREAM(this->get_logger(),
"No trajectory point in plan_trajectory! Returning");
62 visualization_msgs::msg::MarkerArray tmp_marker_array;
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";
75 marker.frame_locked =
true;
79 for (
size_t i = 1;
i < count;
i++)
83 if (
i >= msg->trajectory_points.size()) {
84 marker.action = visualization_msgs::msg::Marker::DELETE;
85 tmp_marker_array.markers.push_back(marker);
90 double speed = max_speed;
92 rclcpp::Time t2 = msg->trajectory_points[
i].target_time;
93 rclcpp::Time t1 = msg->trajectory_points[
i - 1].target_time;
96 rclcpp::Duration dt = t2 - t1;
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);
102 speed = dist/ dt.seconds();
110 RCLCPP_DEBUG_STREAM(this->get_logger(),
"Speed:" << speed <<
"ms, max_speed:" << max_speed <<
"ms");
111 if (speed > max_speed)
113 RCLCPP_DEBUG_STREAM(this->get_logger(),
"Speed was big, so capped at " << max_speed <<
"ms");
117 marker.color.r = 0.0f;
118 marker.color.g = 0.0f;
119 marker.color.b = 0.0f;
120 marker.color.a = 1.0f;
123 double ratio = speed / max_speed;
126 marker.color.r = 1.0f;
128 else if (ratio >= 0.5f)
130 marker.color.b = 1.0f;
132 else if (ratio >= 0.25)
134 marker.color.b = 1.0f;
135 marker.color.g = 1.0f;
138 else if (ratio >= 0.0)
140 marker.color.g = 1.0f;
146 marker.color.r = 0.5f;
147 marker.color.g = 0.5f;
148 marker.color.b = 0.5f;
152 geometry_msgs::msg::Point start;
153 start.x = msg->trajectory_points[
i-1].x;
154 start.y = msg->trajectory_points[
i-1].y;
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);
162 tmp_marker_array.markers.push_back(marker);
171#include "rclcpp_components/register_node_macro.hpp"
TrajectoryVisualizer(const rclcpp::NodeOptions &)
TrajectoryVisualizer constructor.
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
void callbackPlanTrajectory(carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
carma_ros2_utils::PubPtr< visualization_msgs::msg::MarkerArray > traj_marker_pub_
size_t prev_marker_list_size_
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > traj_sub_
bool validateTime(const rclcpp::Time &time)
max_speed values for trajectory_visualizer