20 namespace std_ph = std::placeholders;
23 : carma_ros2_utils::CarmaLifecycleNode(options)
37 auto error_2 = update_params<std::string>({
41 rcl_interfaces::msg::SetParametersResult result;
43 result.successful = !error && !error_2;
52 RCLCPP_DEBUG_STREAM(get_logger(),
"Executing stub behavior for plugin discovery MVP...");
53 std::map<std::string, std::string> out;
58 std::string control_plugin2 =
"platooning_control";
59 std::string control_plugin_topic2 =
"/guidance/plugins/platooning_control/plan_trajectory";
60 out[control_plugin2] = control_plugin_topic2;
67 RCLCPP_INFO_STREAM(get_logger(),
"TrajectoryExecutor trying to configure");
77 RCLCPP_INFO_STREAM(get_logger(),
"Loaded params: " <<
config_);
83 plan_sub_ = create_subscription<carma_planning_msgs::msg::TrajectoryPlan>(
"trajectory", 5,
85 state_sub_ = create_subscription<carma_planning_msgs::msg::GuidanceState>(
"state", 5,
88 cur_traj_ = std::unique_ptr<carma_planning_msgs::msg::TrajectoryPlan>();
90 RCLCPP_DEBUG_STREAM(get_logger(),
"Setting up publishers for control plugin topics...");
92 std::map<std::string, carma_ros2_utils::PubPtr<carma_planning_msgs::msg::TrajectoryPlan>> control_plugin_topics;
95 for (
auto it = discovered_control_plugins.begin(); it != discovered_control_plugins.end(); it++)
97 RCLCPP_DEBUG_STREAM(get_logger(),
"Trajectory executor discovered control plugin " << it->first.c_str() <<
" listening on topic " << it->second.c_str());
98 carma_ros2_utils::PubPtr<carma_planning_msgs::msg::TrajectoryPlan> control_plugin_pub = create_publisher<carma_planning_msgs::msg::TrajectoryPlan>(it->second, 1000);
99 control_plugin_topics.insert(std::make_pair(it->first, control_plugin_pub));
103 RCLCPP_DEBUG_STREAM(get_logger(),
"TrajectoryExecutor component initialized succesfully!");
106 return CallbackReturn::SUCCESS;
115 std::chrono::milliseconds(timer_period_ms),
118 return CallbackReturn::SUCCESS;
123 RCLCPP_DEBUG_STREAM(get_logger(),
"TrajectoryExecutor tick start!");
127 std::string control_plugin =
cur_traj_->trajectory_points[0].controller_plugin_name;
129 if (control_plugin ==
"default" || control_plugin ==
"") {
133 std::map<std::string, carma_ros2_utils::PubPtr<carma_planning_msgs::msg::TrajectoryPlan>>::iterator it =
traj_publisher_map_.find(control_plugin);
135 RCLCPP_DEBUG_STREAM(get_logger(),
"Found match for control plugin " << control_plugin.c_str() <<
" at point " <<
timesteps_since_last_traj_ <<
" in current trajectory!");
138 std::ostringstream description_builder;
139 description_builder <<
"No match found for control plugin "
140 << control_plugin <<
" at point "
143 throw std::invalid_argument(description_builder.str());
147 RCLCPP_DEBUG_STREAM(get_logger(),
"Awaiting initial trajectory publication...");
150 RCLCPP_DEBUG_STREAM(get_logger(),
"TrajectoryExecutor tick completed succesfully!");
156 RCLCPP_DEBUG_STREAM(get_logger(),
"Received new trajectory plan!");
157 RCLCPP_DEBUG_STREAM(get_logger(),
"New Trajectory plan ID: " << msg->trajectory_id);
158 RCLCPP_DEBUG_STREAM(get_logger(),
"New plan contains " << msg->trajectory_points.size() <<
" points");
160 cur_traj_ = std::unique_ptr<carma_planning_msgs::msg::TrajectoryPlan>(move(msg));
162 RCLCPP_INFO_STREAM(get_logger(),
"Successfully swapped trajectories!");
176#include "rclcpp_components/register_node_macro.hpp"
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > ¶meters)
Example callback for dynamic parameter updates.
int timesteps_since_last_traj_
TrajectoryExecutor(const rclcpp::NodeOptions &)
Constructor for TrajectoryExecutor.
void onNewTrajectoryPlan(carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
Callback to be invoked when a new trajectory plan is received on our inbound plan topic.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > plan_sub_
void guidanceStateMonitor(carma_planning_msgs::msg::GuidanceState::UniquePtr msg)
Monitor the guidance state and set the current trajector as null_ptr.
rclcpp::TimerBase::SharedPtr timer_
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > state_sub_
std::map< std::string, std::string > queryControlPlugins()
Helper function to query control plugin registration system.
std::unique_ptr< carma_planning_msgs::msg::TrajectoryPlan > cur_traj_
void onTrajEmitTick()
Timer callback to be invoked at our output tickrate. Outputs current trajectory plan to the first con...
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
std::map< std::string, carma_ros2_utils::PubPtr< carma_planning_msgs::msg::TrajectoryPlan > > traj_publisher_map_
carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &)
Struct containing the algorithm configuration values for trajectory_executor.
std::string default_control_plugin_topic
double trajectory_publish_rate
std::string default_control_plugin