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.
stop_and_wait_plugin_node.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-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 StopandWaitNode::StopandWaitNode(const rclcpp::NodeOptions &options)
24 : carma_guidance_plugins::TacticalPlugin(options),version_id_("v4.0"),plugin_name_(get_plugin_name_and_ns())
25 {
26 // Create initial config
28
29 // Declare parameters
30 config_.minimal_trajectory_duration = declare_parameter<double>("minimal_trajectory_duration", config_.minimal_trajectory_duration);
31 config_.stop_timestep = declare_parameter<double>("stop_timestep", config_.stop_timestep);
32 config_.trajectory_step_size = declare_parameter<double>("trajectory_step_size", config_.trajectory_step_size);
33 config_.accel_limit_multiplier = declare_parameter<double>("accel_limit_multiplier", config_.accel_limit_multiplier);
34 config_.accel_limit = declare_parameter<double>("vehicle_acceleration_limit", config_.accel_limit);
35 config_.crawl_speed = declare_parameter<double>("crawl_speed", config_.crawl_speed);
36 config_.centerline_sampling_spacing = declare_parameter<double>("centerline_sampling_spacing", config_.centerline_sampling_spacing);
37 config_.default_stopping_buffer = declare_parameter<double>("default_stopping_buffer", config_.default_stopping_buffer);
38 config_.tactical_plugin_service_call_timeout = declare_parameter<int>("tactical_plugin_service_call_timeout", config_.tactical_plugin_service_call_timeout);
39 config_.enable_object_avoidance = declare_parameter<bool>("enable_object_avoidance", config_.enable_object_avoidance);
40
41 }
42
43 rcl_interfaces::msg::SetParametersResult StopandWaitNode::parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters)
44 {
45
46 auto error = update_params<double>({
47 {"minimal_trajectory_duration", config_.minimal_trajectory_duration},
48 {"stop_timestep", config_.stop_timestep},
49 {"trajectory_step_size", config_.trajectory_step_size},
50 {"accel_limit_multiplier", config_.accel_limit_multiplier},
51 {"crawl_speed", config_.crawl_speed},
52 {"centerline_sampling_spacing", config_.centerline_sampling_spacing},
53 {"default_stopping_buffer", config_.default_stopping_buffer}
54 }, parameters); // vehicle_acceleration_limit not updated as it's global param
55
56 rcl_interfaces::msg::SetParametersResult result;
57
58 result.successful = !error;
59
60 return result;
61 }
62
63 carma_ros2_utils::CallbackReturn StopandWaitNode::on_configure_plugin()
64 {
65
66 get_parameter<double>("minimal_trajectory_duration", config_.minimal_trajectory_duration);
67 get_parameter<double>("stop_timestep", config_.stop_timestep);
68 get_parameter<double>("trajectory_step_size", config_.trajectory_step_size);
69 get_parameter<double>("accel_limit_multiplier", config_.accel_limit_multiplier);
70 get_parameter<double>("vehicle_acceleration_limit", config_.accel_limit);
71 get_parameter<double>("crawl_speed", config_.crawl_speed);
72 get_parameter<double>("centerline_sampling_spacing", config_.centerline_sampling_spacing);
73 get_parameter<double>("default_stopping_buffer", config_.default_stopping_buffer);
74 get_parameter<int>("tactical_plugin_service_call_timeout", config_.tactical_plugin_service_call_timeout);
75 get_parameter<bool>("enable_object_avoidance", config_.enable_object_avoidance);
76
77 RCLCPP_INFO_STREAM(rclcpp::get_logger("stop_and_wait_plugin"),"Done loading parameters: " << config_);
78
79 // Register runtime parameter update callback
80 add_on_set_parameters_callback(std::bind(&StopandWaitNode::parameter_update_callback, this, std_ph::_1));
81
82 plugin_ = std::make_shared<StopandWait>(shared_from_this(), get_world_model(), config_,plugin_name_,version_id_);
83
84 yield_client_ = create_client<carma_planning_msgs::srv::PlanTrajectory>("yield_plugin/plan_trajectory");
85 plugin_->set_yield_client(yield_client_);
86 RCLCPP_INFO(rclcpp::get_logger("stop_and_wait_plugin"), "Yield Client Set");
87
88 // Return success if everything initialized successfully
89 return CallbackReturn::SUCCESS;
90 }
91
93 std::shared_ptr<rmw_request_id_t> srv_header,
94 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
95 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)
96 {
97 plugin_->plan_trajectory_cb(req, resp);
98 }
99
101 {
102 return true;
103 }
104
106 {
107 return version_id_;
108 }
109
110} // stop_and_wait_plugin
111
112#include "rclcpp_components/register_node_macro.hpp"
113
114// Register the component with class_loader
115RCLCPP_COMPONENTS_REGISTER_NODE(stop_and_wait_plugin::StopandWaitNode)
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...
std::shared_ptr< StopandWait > plugin_
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
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...
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()
This method should be used to load parameters and will be called on the configure state transition.
StopandWaitNode(const rclcpp::NodeOptions &)
Node constructor.
bool get_availability() override
Get the availability status of this plugin based on the current operating environment....
Stuct containing the algorithm configuration values for the stop_and_wait_plugin.