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.
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 }
39
40 rcl_interfaces::msg::SetParametersResult StopandWaitNode::parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters)
41 {
42
43 auto error = update_params<double>({
44 {"minimal_trajectory_duration", config_.minimal_trajectory_duration},
45 {"stop_timestep", config_.stop_timestep},
46 {"trajectory_step_size", config_.trajectory_step_size},
47 {"accel_limit_multiplier", config_.accel_limit_multiplier},
48 {"crawl_speed", config_.crawl_speed},
49 {"centerline_sampling_spacing", config_.centerline_sampling_spacing},
50 {"default_stopping_buffer", config_.default_stopping_buffer}
51 }, parameters); // vehicle_acceleration_limit not updated as it's global param
52
53 rcl_interfaces::msg::SetParametersResult result;
54
55 result.successful = !error;
56
57 return result;
58 }
59
60 carma_ros2_utils::CallbackReturn StopandWaitNode::on_configure_plugin()
61 {
62
63 get_parameter<double>("minimal_trajectory_duration", config_.minimal_trajectory_duration);
64 get_parameter<double>("stop_timestep", config_.stop_timestep);
65 get_parameter<double>("trajectory_step_size", config_.trajectory_step_size);
66 get_parameter<double>("accel_limit_multiplier", config_.accel_limit_multiplier);
67 get_parameter<double>("vehicle_acceleration_limit", config_.accel_limit);
68 get_parameter<double>("crawl_speed", config_.crawl_speed);
69 get_parameter<double>("centerline_sampling_spacing", config_.centerline_sampling_spacing);
70 get_parameter<double>("default_stopping_buffer", config_.default_stopping_buffer);
71
72 RCLCPP_INFO_STREAM(rclcpp::get_logger("stop_and_wait_plugin"),"Done loading parameters: " << config_);
73
74 // Register runtime parameter update callback
75 add_on_set_parameters_callback(std::bind(&StopandWaitNode::parameter_update_callback, this, std_ph::_1));
76
77 plugin_ = std::make_shared<StopandWait>(shared_from_this(), get_world_model(), config_,plugin_name_,version_id_);
78
79 // Return success if everything initialized successfully
80 return CallbackReturn::SUCCESS;
81 }
82
84 std::shared_ptr<rmw_request_id_t> srv_header,
85 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
86 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)
87 {
88 plugin_->plan_trajectory_cb(req, resp);
89 }
90
92 {
93 return true;
94 }
95
97 {
98 return version_id_;
99 }
100
101} // stop_and_wait_plugin
102
103#include "rclcpp_components/register_node_macro.hpp"
104
105// Register the component with class_loader
106RCLCPP_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...
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....
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 stop_and_wait_plugin.