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.
inlanecruising_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 */
16
18
20{
21 namespace std_ph = std::placeholders;
22
23 InLaneCruisingPluginNode::InLaneCruisingPluginNode(const rclcpp::NodeOptions &options)
24 : carma_guidance_plugins::TacticalPlugin(options),
25 plugin_name_(get_plugin_name_and_ns()),
26 version_id_("v4.0"),
28 {
29 // Declare parameters
30 config_.trajectory_time_length = declare_parameter<double>("trajectory_time_length", config_.trajectory_time_length);
31 config_.curve_resample_step_size = declare_parameter<double>("curve_resample_step_size", config_.curve_resample_step_size);
32 config_.default_downsample_ratio = declare_parameter<int>("default_downsample_ratio", config_.default_downsample_ratio);
33 config_.turn_downsample_ratio = declare_parameter<int>("turn_downsample_ratio", config_.turn_downsample_ratio);
34 config_.minimum_speed = declare_parameter<double>("minimum_speed", config_.minimum_speed);
35 config_.max_accel_multiplier = declare_parameter<double>("max_accel_multiplier", config_.max_accel_multiplier);
36 config_.lat_accel_multiplier = declare_parameter<double>("lat_accel_multiplier", config_.lat_accel_multiplier);
37 config_.back_distance = declare_parameter<double>("back_distance", config_.back_distance);
38 config_.speed_moving_average_window_size = declare_parameter<int>("speed_moving_average_window_size", config_.speed_moving_average_window_size);
39 config_.curvature_moving_average_window_size = declare_parameter<int>("curvature_moving_average_window_size", config_.curvature_moving_average_window_size);
40 config_.buffer_ending_downtrack = declare_parameter<double>("buffer_ending_downtrack", config_.buffer_ending_downtrack);
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_.tactical_plugin_service_call_timeout = declare_parameter<int>("tactical_plugin_service_call_timeout", config_.tactical_plugin_service_call_timeout);
45 }
46
47 carma_ros2_utils::CallbackReturn InLaneCruisingPluginNode::on_configure_plugin()
48 {
49 trajectory_debug_pub_ = create_publisher<carma_debug_ros2_msgs::msg::TrajectoryCurvatureSpeeds>("debug/trajectory_planning", 1);
50
52
53 get_parameter<double>("trajectory_time_length", config_.trajectory_time_length);
54 get_parameter<double>("curve_resample_step_size", config_.curve_resample_step_size);
55 get_parameter<int>("default_downsample_ratio", config_.default_downsample_ratio);
56 get_parameter<int>("turn_downsample_ratio", config_.turn_downsample_ratio);
57 get_parameter<double>("minimum_speed", config_.minimum_speed);
58 get_parameter<double>("max_accel_multiplier", config_.max_accel_multiplier);
59 get_parameter<double>("lat_accel_multiplier", config_.lat_accel_multiplier);
60 get_parameter<double>("back_distance", config_.back_distance);
61 get_parameter<int>("speed_moving_average_window_size", config_.speed_moving_average_window_size);
62 get_parameter<int>("curvature_moving_average_window_size", config_.curvature_moving_average_window_size);
63 get_parameter<double>("buffer_ending_downtrack", config_.buffer_ending_downtrack);
64 get_parameter<double>("vehicle_acceleration_limit", config_.max_accel);
65 get_parameter<double>("vehicle_lateral_accel_limit", config_.lateral_accel_limit);
66 get_parameter<bool>("enable_object_avoidance", config_.enable_object_avoidance);
67 get_parameter<int>("tactical_plugin_service_call_timeout", config_.tactical_plugin_service_call_timeout);
68
69 // Register runtime parameter update callback
70 add_on_set_parameters_callback(std::bind(&InLaneCruisingPluginNode::parameter_update_callback, this, std_ph::_1));
71
72 RCLCPP_INFO_STREAM(rclcpp::get_logger("inlanecruising_plugin"), "InLaneCruisingPlugin Params" << config_);
73
76
77 // Determine if we will enable debug publishing by checking the current log level of the node
78 auto level = rcutils_logging_get_logger_level(get_logger().get_name());
79
80 config_.publish_debug = level == RCUTILS_LOG_SEVERITY_DEBUG;
81
82 RCLCPP_INFO_STREAM(rclcpp::get_logger("inlanecruising_plugin"), "InLaneCruisingPlugin Params After Accel Change" << config_);
83
84 worker_ = std::make_shared<InLaneCruisingPlugin>(shared_from_this(), get_world_model(), config_,
85 [this](const carma_debug_ros2_msgs::msg::TrajectoryCurvatureSpeeds& msg) { trajectory_debug_pub_->publish(msg); },
88
89 //TODO: Update yield client to use the Plugin Manager capabilities query, in case someone else wants to add an alternate yield implementation
90 yield_client_ = create_client<carma_planning_msgs::srv::PlanTrajectory>("yield_plugin/plan_trajectory");
91 worker_->set_yield_client(yield_client_);
92 RCLCPP_INFO(rclcpp::get_logger("inlanecruising_plugin"), "Yield Client Set");
93
94 // Return success if everything initialized successfully
95 return CallbackReturn::SUCCESS;
96
97 }
98
99 rcl_interfaces::msg::SetParametersResult InLaneCruisingPluginNode::parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters)
100 {
101 auto error_double = update_params<double>({
102 {"trajectory_time_length", config_.trajectory_time_length},
103 {"curve_resample_step_size", config_.curve_resample_step_size},
104 {"minimum_speed", config_.minimum_speed},
105 {"max_accel_multiplier", config_.max_accel_multiplier},
106 {"lat_accel_multiplier", config_.lat_accel_multiplier},
107 {"back_distance", config_.back_distance},
108 {"buffer_ending_downtrack", config_.buffer_ending_downtrack}}, parameters); // Global acceleration limits not allowed to dynamically update
109
110 auto error_bool = update_params<bool>({
111 {"enable_object_avoidance", config_.enable_object_avoidance}}, parameters);
112
113 auto error_int = update_params<int>({
114 {"default_downsample_ratio", config_.default_downsample_ratio},
115 {"turn_downsample_ratio", config_.turn_downsample_ratio},
116 {"speed_moving_average_window_size", config_.speed_moving_average_window_size},
117 {"curvature_moving_average_window_size", config_.curvature_moving_average_window_size}}, parameters);
118
119 rcl_interfaces::msg::SetParametersResult result;
120
121 result.successful = !error_double && !error_bool && !error_int;
122
123 return result;
124 }
125
127 {
128 return true;
129 }
130
132 {
133 return version_id_;
134 }
135
137 std::shared_ptr<rmw_request_id_t> srv_header,
138 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
139 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)
140 {
141 worker_->plan_trajectory_callback(req, resp);
142 }
143
144} // namespace inlanecruising_plugin
145
146
147#include "rclcpp_components/register_node_macro.hpp"
148
149// Register the component with class_loader
150RCLCPP_COMPONENTS_REGISTER_NODE(inlanecruising_plugin::InLaneCruisingPluginNode)
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...
carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::PlanTrajectory > yield_client_
std::string get_version_id() override final
Returns the version id of this plugin.
carma_ros2_utils::CallbackReturn on_configure_plugin()
Method which is triggered when this plugin is moved from the UNCONFIGURED to INACTIVE states....
carma_ros2_utils::PubPtr< carma_debug_ros2_msgs::msg::TrajectoryCurvatureSpeeds > trajectory_debug_pub_
InLaneCruisingPluginNode(const rclcpp::NodeOptions &)
Node constructor.
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
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 > srv_header, 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...
Stuct containing the algorithm configuration values for the InLaneCruisingPlugin.