Carma-platform v4.11.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.
platooning_tactical_plugin_node.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
17#include <carma_ros2_utils/timers/ROSTimerFactory.hpp>
19
21{
22 namespace std_ph = std::placeholders;
23
24 Node::Node(const rclcpp::NodeOptions &options)
25 : carma_guidance_plugins::TacticalPlugin(options)
26 {
27 // Create initial config
29
30 // Declare parameters
31 config_.trajectory_time_length = declare_parameter<double>("trajectory_time_length", config_.trajectory_time_length);
32 config_.curve_resample_step_size = declare_parameter<double>("curve_resample_step_size", config_.curve_resample_step_size);
33 config_.default_downsample_ratio = declare_parameter<int>("default_downsample_ratio", config_.default_downsample_ratio);
34 config_.turn_downsample_ratio = declare_parameter<int>("turn_downsample_ratio", config_.turn_downsample_ratio);
35 config_.minimum_speed = declare_parameter<double>("minimum_speed", config_.minimum_speed);
36 config_.max_accel_multiplier = declare_parameter<double>("max_accel_multiplier", config_.max_accel_multiplier);
37 config_.lat_accel_multiplier = declare_parameter<double>("lat_accel_multiplier", config_.lat_accel_multiplier);
38 config_.back_distance = declare_parameter<double>("back_distance", config_.back_distance);
39 config_.speed_moving_average_window_size = declare_parameter<int>("speed_moving_average_window_size", config_.speed_moving_average_window_size);
40 config_.curvature_moving_average_window_size = declare_parameter<int>("curvature_moving_average_window_size", config_.curvature_moving_average_window_size);
41 config_.max_accel = declare_parameter<double>("vehicle_acceleration_limit", config_.max_accel);
42 config_.lateral_accel_limit = declare_parameter<double>("vehicle_lateral_accel_limit", config_.lateral_accel_limit);
43 config_.enable_object_avoidance = declare_parameter<bool>("enable_object_avoidance", config_.enable_object_avoidance);
44 config_.buffer_ending_downtrack = declare_parameter<double>("buffer_ending_downtrack", config_.buffer_ending_downtrack);
45
48
49 RCLCPP_INFO_STREAM(get_logger(), "PlatooningTacticalPlugin Params" << config_);
50
51 }
52
53 rcl_interfaces::msg::SetParametersResult Node::parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters)
54 {
55 auto error = update_params<bool>({
56 {"enable_object_avoidance", config_.enable_object_avoidance}
57 }, parameters);
58
59 auto error2 = update_params<int>({
60 {"default_downsample_ratio", config_.default_downsample_ratio},
61 {"turn_downsample_ratio", config_.turn_downsample_ratio},
62 {"speed_moving_average_window_size", config_.speed_moving_average_window_size},
63 {"curvature_moving_average_window_size", config_.curvature_moving_average_window_size}
64 }, parameters);
65
66 auto error3 = update_params<double>({
67 {"trajectory_time_length", config_.trajectory_time_length},
68 {"curve_resample_step_size", config_.curve_resample_step_size},
69 {"minimum_speed", config_.minimum_speed},
70 {"max_accel_multiplier", config_.max_accel_multiplier},
71 {"lat_accel_multiplier", config_.lat_accel_multiplier},
72 {"back_distance", config_.back_distance},
73 {"buffer_ending_downtrack", config_.buffer_ending_downtrack}
74 }, parameters); // Accel limits system wide and not allowed to be updated per node
75
78
79 rcl_interfaces::msg::SetParametersResult result;
80
81 result.successful = !error && !error2 && !error3;
82
83 if (result.successful && worker_)
84 {
85 worker_->set_config(config_);
86 }
87
88 return result;
89 }
90
91 carma_ros2_utils::CallbackReturn Node::on_configure_plugin()
92 {
93 // Reset config
95
96 // Load parameters
97 get_parameter<double>("trajectory_time_length", config_.trajectory_time_length);
98 get_parameter<double>("curve_resample_step_size", config_.curve_resample_step_size);
99 get_parameter<int>("default_downsample_ratio", config_.default_downsample_ratio);
100 get_parameter<int>("turn_downsample_ratio", config_.turn_downsample_ratio);
101 get_parameter<double>("minimum_speed", config_.minimum_speed);
102 get_parameter<double>("max_accel_multiplier", config_.max_accel_multiplier);
103 get_parameter<double>("lat_accel_multiplier", config_.lat_accel_multiplier);
104 get_parameter<double>("back_distance", config_.back_distance);
105 get_parameter<int>("speed_moving_average_window_size", config_.speed_moving_average_window_size);
106 get_parameter<int>("curvature_moving_average_window_size", config_.curvature_moving_average_window_size);
107 get_parameter<double>("vehicle_acceleration_limit", config_.max_accel);
108 get_parameter<double>("vehicle_lateral_accel_limit", config_.lateral_accel_limit);
109 get_parameter<bool>("enable_object_avoidance", config_.enable_object_avoidance);
110 get_parameter<double>("buffer_ending_downtrack", config_.buffer_ending_downtrack);
111
114
115 RCLCPP_INFO_STREAM(get_logger(), "PlatooningTacticalPlugin Params" << config_);
116
117 // Register runtime parameter update callback
118 add_on_set_parameters_callback(std::bind(&Node::parameter_update_callback, this, std_ph::_1));
119
120 basic_autonomy::set_logger(get_logger().get_child("basic_autonomy"));
121 worker_ = std::make_shared<PlatooningTacticalPlugin>(get_world_model(), config_,
122 std::make_shared<carma_ros2_utils::timers::ROSTimerFactory>(shared_from_this()));
123
124 // Return success if everything initialized successfully
125 return CallbackReturn::SUCCESS;
126 }
127
129 std::shared_ptr<rmw_request_id_t>,
130 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
131 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)
132 {
133 if (!worker_)
134 return;
135
136 worker_->plan_trajectory_cb(*req, *resp);
137 }
138
140 return true;
141 }
142
143 std::string Node::get_version_id() {
144 return "v4.0";
145 }
146
147} // platooning_tactical_plugin
148
149#include "rclcpp_components/register_node_macro.hpp"
150
151// Register the component with class_loader
152RCLCPP_COMPONENTS_REGISTER_NODE(platooning_tactical_plugin::Node)
virtual carma_wm::WorldModelConstPtr get_world_model() final
Method to return the default world model provided as a convience by this base class If this method or...
ROS node for the PlatooningTacticalPlugin to initialize and configure parameters and publishers/subsc...
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Example callback for dynamic parameter updates.
std::shared_ptr< PlatooningTacticalPlugin > worker_
std::string get_version_id() override
Returns the version id of this plugin.
carma_ros2_utils::CallbackReturn on_configure_plugin()
This method should be used to load parameters and will be called on the configure state transition.
Node(const rclcpp::NodeOptions &)
Node constructor.
bool get_availability() override
Get the availability status of this plugin based on the current operating environment....
void plan_trajectory_callback(std::shared_ptr< rmw_request_id_t >, carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req, carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp) override
Extending class provided callback which should return a planned trajectory based on the provided traj...
void set_logger(rclcpp::Logger logger)
Replace the module-level logger used by all basic_autonomy functions.
Definition: log.cpp:33
rclcpp::Logger get_logger()
Return the module-level logger used by all basic_autonomy functions.
Definition: log.cpp:32
Stuct containing the algorithm configuration values for the PlatooningTacticalPlugin.