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.
platooning_control::PlatooningControlPlugin Class Reference

This class includes node-level logic for Platooning Control such as its publishers, subscribers, and their callback functions. Platooning Control is used for generating control commands to maintain the gap in platoon as well as generating longitudinal and lateral control commands to follow the trajectory. More...

#include <platooning_control.hpp>

Inheritance diagram for platooning_control::PlatooningControlPlugin:
Inheritance graph
Collaboration diagram for platooning_control::PlatooningControlPlugin:
Collaboration graph

Public Member Functions

 PlatooningControlPlugin (const rclcpp::NodeOptions &options)
 PlatooningControlPlugin constructor. More...
 
autoware_msgs::msg::ControlCommandStamped generate_control_signals (const carma_planning_msgs::msg::TrajectoryPlanPoint &first_trajectory_point, const geometry_msgs::msg::PoseStamped &current_pose, const geometry_msgs::msg::TwistStamped &current_twist)
 generate control signal by calculating speed and steering commands. More...
 
geometry_msgs::msg::TwistStamped compose_twist_cmd (double linear_vel, double angular_vel)
 Compose twist message from linear and angular velocity commands. More...
 
motion::motion_common::State convert_state (const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::TwistStamped &twist) const
 
rcl_interfaces::msg::SetParametersResult parameter_update_callback (const std::vector< rclcpp::Parameter > &parameters)
 Callback for dynamic parameter updates. More...
 
void current_trajectory_callback (const carma_planning_msgs::msg::TrajectoryPlan::UniquePtr tp)
 callback function for trajectory plan More...
 
autoware_msgs::msg::ControlCommandStamped compose_ctrl_cmd (double linear_vel, double steering_angle)
 Compose control message from speed and steering commands. More...
 
bool get_availability () override
 Returns availability of plugin. Always true. More...
 
std::string get_version_id () override
 Returns version id of plugn. More...
 
autoware_msgs::msg::ControlCommandStamped generate_command () override
 Extending class provided method which should generate a command message which will be published to the required topic by the base class. More...
 
carma_ros2_utils::CallbackReturn on_configure_plugin () override
 This method should be used to load parameters and will be called on the configure state transition. More...
 
- Public Member Functions inherited from carma_guidance_plugins::ControlPlugin
 ControlPlugin (const rclcpp::NodeOptions &)
 ControlPlugin constructor. More...
 
virtual ~ControlPlugin ()=default
 Virtual destructor for safe deletion. More...
 
virtual autoware_msgs::msg::ControlCommandStamped generate_command ()=0
 Extending class provided method which should generate a command message which will be published to the required topic by the base class. More...
 
std::string get_capability () override
 Get the capability string representing this plugins capabilities Method must be overriden by extending classes. Expectation is that abstract plugin type parent classes will provide a default implementation. More...
 
uint8_t get_type () override final
 Returns the type of this plugin according to the carma_planning_msgs::Plugin type enum. Extending classes for the specific type should override this method. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_deactivate (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_cleanup (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_shutdown (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_error (const rclcpp_lifecycle::State &, const std::string &exception_string) override final
 
- Public Member Functions inherited from carma_guidance_plugins::PluginBaseNode
 PluginBaseNode (const rclcpp::NodeOptions &)
 PluginBaseNode constructor. More...
 
virtual ~PluginBaseNode ()=default
 Virtual destructor for safe deletion. More...
 
virtual std::shared_ptr< carma_wm::WMListenerget_world_model_listener () final
 Method to return the default world model listener provided as a convience by this base class If this method or get_world_model() are not called then the world model remains uninitialized and will not create unnecessary subscriptions. More...
 
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 get_world_model_listener() are not called then the world model remains uninitialized and will not create unnecessary subscriptions. More...
 
virtual bool get_activation_status () final
 Returns the activation status of this plugin. The plugins API callbacks will only be triggered when this method returns true. More...
 
virtual uint8_t get_type ()
 Returns the type of this plugin according to the carma_planning_msgs::Plugin type enum. Extending classes for the specific type should override this method. More...
 
std::string get_plugin_name_and_ns () const
 Return the name of this plugin with namespace. NOTE: If only the name of the plugin is required, use get_plugin_name() More...
 
std::string get_plugin_name () const
 Return the name of this plugin. More...
 
virtual bool get_availability ()=0
 Get the availability status of this plugin based on the current operating environment. Method must be overriden by extending classes. More...
 
virtual std::string get_capability ()=0
 Get the capability string representing this plugins capabilities Method must be overriden by extending classes. Expectation is that abstract plugin type parent classes will provide a default implementation. More...
 
virtual std::string get_version_id ()=0
 Returns the version id of this plugin. More...
 
virtual carma_ros2_utils::CallbackReturn on_configure_plugin ()=0
 Method which is triggered when this plugin is moved from the UNCONFIGURED to INACTIVE states. This method should be used to load parameters and is required to be implemented. More...
 
virtual carma_ros2_utils::CallbackReturn on_activate_plugin ()
 Method which is triggered when this plugin is moved from the INACTIVE to ACTIVE states. This method should be used to prepare for future callbacks for plugin's capabilites. More...
 
virtual carma_ros2_utils::CallbackReturn on_deactivate_plugin ()
 Method which is triggered when this plugin is moved from the ACTIVE to INACTIVE states. This method should be used to disable any functionality which should cease execution when plugin is inactive. More...
 
virtual carma_ros2_utils::CallbackReturn on_cleanup_plugin ()
 Method which is triggered when this plugin is moved from the INACTIVE to UNCONFIGURED states. This method should be used to fully reset the plugin such that a future call to on_configure_plugin would leave the plugin in a fresh state as though just launched. More...
 
virtual carma_ros2_utils::CallbackReturn on_shutdown_plugin ()
 Method which is triggered when this plugin is moved from any state to FINALIZED This method should be used to generate any shutdown logs or final cleanup. More...
 
virtual carma_ros2_utils::CallbackReturn on_error_plugin (const std::string &exception_string)
 Method which is triggered when an unhandled exception occurs in this plugin This method should be used to cleanup such that the plugin could be moved to UNCONFIGURED state if possible. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_deactivate (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_cleanup (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_shutdown (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_error (const rclcpp_lifecycle::State &, const std::string &exception_string) override
 
 FRIEND_TEST (carma_guidance_plugins_test, connections_test)
 

Public Attributes

double trajectory_speed_ = 0.0
 
std::shared_ptr< pure_pursuit::PurePursuit > pp_
 

Private Member Functions

void platoon_info_cb (const carma_planning_msgs::msg::PlatooningInfo::SharedPtr msg)
 callback function for platoon info More...
 
double get_trajectory_speed (const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &trajectory_points)
 calculate average speed of a set of trajectory points More...
 
 FRIEND_TEST (PlatooningControlPluginTest, test_platoon_info_cb)
 
 FRIEND_TEST (PlatooningControlPluginTest, test_get_trajectory_speed)
 
 FRIEND_TEST (PlatooningControlPluginTest, test_generate_controls)
 
 FRIEND_TEST (PlatooningControlPluginTest, test_current_trajectory_callback)
 

Private Attributes

PlatooningControlPluginConfig config_
 
PlatooningControlWorker pcw_
 
PlatoonLeaderInfo platoon_leader_
 
double prev_input_time_ms_ = 0
 
long consecutive_input_counter_ = 0
 
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > trajectory_plan_sub_
 
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::PlatooningInfo > platoon_info_sub_
 
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::PlatooningInfo > platoon_info_pub_
 

Additional Inherited Members

- Protected Member Functions inherited from carma_guidance_plugins::ControlPlugin
void current_pose_callback (geometry_msgs::msg::PoseStamped::UniquePtr msg)
 
void current_twist_callback (geometry_msgs::msg::TwistStamped::UniquePtr msg)
 
virtual void current_trajectory_callback (carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
 Extending class provided method which can optionally handle trajectory plan callbacks. More...
 
- Protected Attributes inherited from carma_guidance_plugins::ControlPlugin
boost::optional< geometry_msgs::msg::PoseStamped > current_pose_
 The most recent pose message received by this node. More...
 
boost::optional< geometry_msgs::msg::TwistStamped > current_twist_
 The most recent velocity message received by this node. More...
 
boost::optional< carma_planning_msgs::msg::TrajectoryPlan > current_trajectory_
 The most recent trajectory received by this plugin. More...
 

Detailed Description

This class includes node-level logic for Platooning Control such as its publishers, subscribers, and their callback functions. Platooning Control is used for generating control commands to maintain the gap in platoon as well as generating longitudinal and lateral control commands to follow the trajectory.

Definition at line 41 of file platooning_control.hpp.

Constructor & Destructor Documentation

◆ PlatooningControlPlugin()

platooning_control::PlatooningControlPlugin::PlatooningControlPlugin ( const rclcpp::NodeOptions &  options)
explicit

PlatooningControlPlugin constructor.

Definition at line 22 of file platooning_control.cpp.

23 : carma_guidance_plugins::ControlPlugin(options), config_(PlatooningControlPluginConfig()), pcw_(PlatooningControlWorker())
24 {
25
26 // Declare parameters
27 config_.stand_still_headway_m = declare_parameter<double>("stand_still_headway_m", config_.stand_still_headway_m);
28 config_.max_accel_mps2 = declare_parameter<double>("max_accel_mps2", config_.max_accel_mps2);
29 config_.kp = declare_parameter<double>("kp", config_.kp);
30 config_.kd = declare_parameter<double>("kd", config_.kd);
31 config_.ki = declare_parameter<double>("ki", config_.ki);
32 config_.max_delta_speed_per_timestep = declare_parameter<double>("max_delta_speed_per_timestep", config_.max_delta_speed_per_timestep);
33 config_.min_delta_speed_per_timestep = declare_parameter<double>("min_delta_speed_per_timestep", config_.min_delta_speed_per_timestep);
34 config_.adjustment_cap_mps = declare_parameter<double>("adjustment_cap_mps", config_.adjustment_cap_mps);
35 config_.cmd_timestamp_ms = declare_parameter<int>("cmd_timestamp_ms", config_.cmd_timestamp_ms);
36 config_.integrator_max = declare_parameter<double>("integrator_max", config_.integrator_max);
37 config_.integrator_min = declare_parameter<double>("integrator_min", config_.integrator_min);
38
39 config_.vehicle_response_lag = declare_parameter<double>("vehicle_response_lag", config_.vehicle_response_lag);
40 config_.max_lookahead_dist = declare_parameter<double>("maximum_lookahead_distance", config_.max_lookahead_dist);
41 config_.min_lookahead_dist = declare_parameter<double>("minimum_lookahead_distance", config_.min_lookahead_dist);
42 config_.speed_to_lookahead_ratio = declare_parameter<double>("speed_to_lookahead_ratio", config_.speed_to_lookahead_ratio);
43 config_.is_interpolate_lookahead_point = declare_parameter<bool>("is_interpolate_lookahead_point", config_.is_interpolate_lookahead_point);
44 config_.is_delay_compensation = declare_parameter<bool>("is_delay_compensation", config_.is_delay_compensation);
45 config_.emergency_stop_distance = declare_parameter<double>("emergency_stop_distance", config_.emergency_stop_distance);
46 config_.speed_thres_traveling_direction = declare_parameter<double>("speed_thres_traveling_direction", config_.speed_thres_traveling_direction);
47 config_.dist_front_rear_wheels = declare_parameter<double>("dist_front_rear_wheels", config_.dist_front_rear_wheels);
48
49 config_.dt = declare_parameter<double>("dt", config_.dt);
50 config_.integrator_max_pp = declare_parameter<double>("integrator_max_pp", config_.integrator_max_pp);
51 config_.integrator_min_pp = declare_parameter<double>("integrator_min_pp", config_.integrator_min_pp);
52 config_.ki_pp = declare_parameter<double>("Ki_pp", config_.ki_pp);
53 config_.is_integrator_enabled = declare_parameter<bool>("is_integrator_enabled", config_.is_integrator_enabled);
54 config_.enable_max_adjustment_filter = declare_parameter<bool>("enable_max_adjustment_filter", config_.enable_max_adjustment_filter);
55 config_.enable_max_accel_filter = declare_parameter<bool>("enable_max_accel_filter", config_.enable_max_accel_filter);
56
57 //Global params (from vehicle config)
58 config_.vehicle_id = declare_parameter<std::string>("vehicle_id", config_.vehicle_id);
59 config_.shutdown_timeout = declare_parameter<int>("control_plugin_shutdown_timeout", config_.shutdown_timeout);
60 config_.ignore_initial_inputs = declare_parameter<int>("control_plugin_ignore_initial_inputs", config_.ignore_initial_inputs);
61
62 pcw_.ctrl_config_ = std::make_shared<PlatooningControlPluginConfig>(config_);
63
64 }
ControlPlugin base class which can be extended by user provided plugins which wish to implement the C...
std::shared_ptr< PlatooningControlPluginConfig > ctrl_config_

References platooning_control::PlatooningControlPluginConfig::adjustment_cap_mps, platooning_control::PlatooningControlPluginConfig::cmd_timestamp_ms, config_, platooning_control::PlatooningControlWorker::ctrl_config_, platooning_control::PlatooningControlPluginConfig::dist_front_rear_wheels, platooning_control::PlatooningControlPluginConfig::dt, platooning_control::PlatooningControlPluginConfig::emergency_stop_distance, platooning_control::PlatooningControlPluginConfig::enable_max_accel_filter, platooning_control::PlatooningControlPluginConfig::enable_max_adjustment_filter, platooning_control::PlatooningControlPluginConfig::ignore_initial_inputs, platooning_control::PlatooningControlPluginConfig::integrator_max, platooning_control::PlatooningControlPluginConfig::integrator_max_pp, platooning_control::PlatooningControlPluginConfig::integrator_min, platooning_control::PlatooningControlPluginConfig::integrator_min_pp, platooning_control::PlatooningControlPluginConfig::is_delay_compensation, platooning_control::PlatooningControlPluginConfig::is_integrator_enabled, platooning_control::PlatooningControlPluginConfig::is_interpolate_lookahead_point, platooning_control::PlatooningControlPluginConfig::kd, platooning_control::PlatooningControlPluginConfig::ki, platooning_control::PlatooningControlPluginConfig::ki_pp, platooning_control::PlatooningControlPluginConfig::kp, platooning_control::PlatooningControlPluginConfig::max_accel_mps2, platooning_control::PlatooningControlPluginConfig::max_delta_speed_per_timestep, platooning_control::PlatooningControlPluginConfig::max_lookahead_dist, platooning_control::PlatooningControlPluginConfig::min_delta_speed_per_timestep, platooning_control::PlatooningControlPluginConfig::min_lookahead_dist, pcw_, platooning_control::PlatooningControlPluginConfig::shutdown_timeout, platooning_control::PlatooningControlPluginConfig::speed_thres_traveling_direction, platooning_control::PlatooningControlPluginConfig::speed_to_lookahead_ratio, platooning_control::PlatooningControlPluginConfig::stand_still_headway_m, platooning_control::PlatooningControlPluginConfig::vehicle_id, and platooning_control::PlatooningControlPluginConfig::vehicle_response_lag.

Member Function Documentation

◆ compose_ctrl_cmd()

autoware_msgs::msg::ControlCommandStamped platooning_control::PlatooningControlPlugin::compose_ctrl_cmd ( double  linear_vel,
double  steering_angle 
)

Compose control message from speed and steering commands.

Parameters
linear_vellinear velocity in m/s
steering_anglesteering angle in rad
Returns
control command

Definition at line 334 of file platooning_control.cpp.

335 {
336 autoware_msgs::msg::ControlCommandStamped cmd_ctrl;
337 cmd_ctrl.header.stamp = this->now();
338 cmd_ctrl.cmd.linear_velocity = linear_vel;
339 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "ctrl command speed " << cmd_ctrl.cmd.linear_velocity);
340 cmd_ctrl.cmd.steering_angle = steering_angle;
341 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "ctrl command steering " << cmd_ctrl.cmd.steering_angle);
342
343 return cmd_ctrl;
344 }

Referenced by generate_control_signals().

Here is the caller graph for this function:

◆ compose_twist_cmd()

geometry_msgs::msg::TwistStamped platooning_control::PlatooningControlPlugin::compose_twist_cmd ( double  linear_vel,
double  angular_vel 
)

Compose twist message from linear and angular velocity commands.

Parameters
linear_vellinear velocity in m/s
angular_velangular velocity in rad/s
Returns
twist message

Definition at line 325 of file platooning_control.cpp.

326 {
327 geometry_msgs::msg::TwistStamped cmd_twist;
328 cmd_twist.twist.linear.x = linear_vel;
329 cmd_twist.twist.angular.z = angular_vel;
330 cmd_twist.header.stamp = this->now();
331 return cmd_twist;
332 }

◆ convert_state()

motion::motion_common::State platooning_control::PlatooningControlPlugin::convert_state ( const geometry_msgs::msg::PoseStamped &  pose,
const geometry_msgs::msg::TwistStamped &  twist 
) const

Definition at line 296 of file platooning_control.cpp.

297 {
298 motion::motion_common::State state;
299 state.header = pose.header;
300 state.state.x = pose.pose.position.x;
301 state.state.y = pose.pose.position.y;
302 state.state.z = pose.pose.position.z;
303 state.state.heading.real = pose.pose.orientation.w;
304 state.state.heading.imag = pose.pose.orientation.z;
305
306 state.state.longitudinal_velocity_mps = twist.twist.linear.x;
307 return state;
308 }

Referenced by generate_control_signals().

Here is the caller graph for this function:

◆ current_trajectory_callback()

void platooning_control::PlatooningControlPlugin::current_trajectory_callback ( const carma_planning_msgs::msg::TrajectoryPlan::UniquePtr  tp)
virtual

callback function for trajectory plan

Parameters
msgtrajectory plan msg

Reimplemented from carma_guidance_plugins::ControlPlugin.

Definition at line 310 of file platooning_control.cpp.

311 {
312 if (tp->trajectory_points.size() < 2) {
313 RCLCPP_WARN_STREAM(rclcpp::get_logger("platooning_control"), "PlatooningControlPlugin cannot execute trajectory as only 1 point was provided");
314 return;
315 }
316
318 prev_input_time_ms_ = this->now().nanoseconds() / 1000000;
320 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "New trajectory plan #" << consecutive_input_counter_ << " at time " << prev_input_time_ms_);
321 rclcpp::Time tp_time(tp->header.stamp);
322 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "tp header time = " << tp_time.nanoseconds() / 1000000);
323 }
boost::optional< carma_planning_msgs::msg::TrajectoryPlan > current_trajectory_
The most recent trajectory received by this plugin.

References consecutive_input_counter_, carma_guidance_plugins::ControlPlugin::current_trajectory_, and prev_input_time_ms_.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ FRIEND_TEST() [1/4]

platooning_control::PlatooningControlPlugin::FRIEND_TEST ( PlatooningControlPluginTest  ,
test_current_trajectory_callback   
)
private

◆ FRIEND_TEST() [2/4]

platooning_control::PlatooningControlPlugin::FRIEND_TEST ( PlatooningControlPluginTest  ,
test_generate_controls   
)
private

◆ FRIEND_TEST() [3/4]

platooning_control::PlatooningControlPlugin::FRIEND_TEST ( PlatooningControlPluginTest  ,
test_get_trajectory_speed   
)
private

◆ FRIEND_TEST() [4/4]

platooning_control::PlatooningControlPlugin::FRIEND_TEST ( PlatooningControlPluginTest  ,
test_platoon_info_cb   
)
private

◆ generate_command()

autoware_msgs::msg::ControlCommandStamped platooning_control::PlatooningControlPlugin::generate_command ( )
overridevirtual

Extending class provided method which should generate a command message which will be published to the required topic by the base class.

NOTE: Implementer can determine if trajectory has changed based on current_trajectory_->trajectory_id

Returns
The command message to publish

Implements carma_guidance_plugins::ControlPlugin.

Definition at line 201 of file platooning_control.cpp.

202 {
203
204 autoware_msgs::msg::ControlCommandStamped ctrl_msg;
206 return ctrl_msg;
207
208 // If it has been a long time since input data has arrived then reset the input counter and return
209 // Note: this quiets the controller after its input stream stops, which is necessary to allow
210 // the replacement controller to publish on the same output topic after this one is done.
211 double current_time_ms = this->now().nanoseconds() / 1e6;
212 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "current_time_ms = " << current_time_ms << ", prev_input_time_ms_ = " << prev_input_time_ms_ << ", input counter = " << consecutive_input_counter_);
213
214 if(current_time_ms - prev_input_time_ms_ > config_.shutdown_timeout)
215 {
216 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "returning due to timeout.");
218 return ctrl_msg;
219 }
220
221 // If there have not been enough consecutive timely inputs then return (waiting for
222 // previous control plugin to time out and stop publishing, since it uses same output topic)
224 {
225 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "returning due to first data input");
226 return ctrl_msg;
227 }
228
229 carma_planning_msgs::msg::TrajectoryPlanPoint second_trajectory_point = current_trajectory_.get().trajectory_points[1];
230
232
233 ctrl_msg = generate_control_signals(second_trajectory_point, current_pose_.get(), current_twist_.get());
234
235 return ctrl_msg;
236
237 }
boost::optional< geometry_msgs::msg::TwistStamped > current_twist_
The most recent velocity message received by this node.
boost::optional< geometry_msgs::msg::PoseStamped > current_pose_
The most recent pose message received by this node.
double get_trajectory_speed(const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &trajectory_points)
calculate average speed of a set of trajectory points
autoware_msgs::msg::ControlCommandStamped generate_control_signals(const carma_planning_msgs::msg::TrajectoryPlanPoint &first_trajectory_point, const geometry_msgs::msg::PoseStamped &current_pose, const geometry_msgs::msg::TwistStamped &current_twist)
generate control signal by calculating speed and steering commands.

References config_, consecutive_input_counter_, carma_guidance_plugins::ControlPlugin::current_pose_, carma_guidance_plugins::ControlPlugin::current_trajectory_, carma_guidance_plugins::ControlPlugin::current_twist_, generate_control_signals(), get_trajectory_speed(), platooning_control::PlatooningControlPluginConfig::ignore_initial_inputs, prev_input_time_ms_, platooning_control::PlatooningControlPluginConfig::shutdown_timeout, and trajectory_speed_.

Here is the call graph for this function:

◆ generate_control_signals()

autoware_msgs::msg::ControlCommandStamped platooning_control::PlatooningControlPlugin::generate_control_signals ( const carma_planning_msgs::msg::TrajectoryPlanPoint &  first_trajectory_point,
const geometry_msgs::msg::PoseStamped &  current_pose,
const geometry_msgs::msg::TwistStamped &  current_twist 
)

generate control signal by calculating speed and steering commands.

Parameters
point0start point of control window
point_endend point of control wondow

Definition at line 272 of file platooning_control.cpp.

273 {
274 pcw_.set_current_speed(trajectory_speed_); //TODO why this and not the actual vehicle speed? Method name suggests different use than this.
275 // pcw_.set_current_speed(current_twist_.get());
277 pcw_.generate_speed(first_trajectory_point);
278
279 motion::control::controller_common::State state_tf = convert_state(current_pose, current_twist);
280 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Forced from frame_id: " << state_tf.header.frame_id << ", into: " << current_trajectory_.get().header.frame_id);
281
282 current_trajectory_.get().header.frame_id = state_tf.header.frame_id;
283
285
286 pp_->set_trajectory(autoware_traj_plan);
287 const auto cmd{pp_->compute_command(state_tf)};
288
289 auto steer_cmd = cmd.front_wheel_angle_rad; //autoware sets the front wheel angle as the calculated steer. https://github.com/usdot-fhwa-stol/autoware.auto/blob/3450f94fa694f51b00de272d412722d65a2c2d3e/AutowareAuto/src/control/pure_pursuit/src/pure_pursuit.cpp#L88
290
291 autoware_msgs::msg::ControlCommandStamped ctrl_msg = compose_ctrl_cmd(pcw_.speedCmd_, steer_cmd);
292
293 return ctrl_msg;
294 }
motion::motion_common::State convert_state(const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::TwistStamped &twist) const
autoware_msgs::msg::ControlCommandStamped compose_ctrl_cmd(double linear_vel, double steering_angle)
Compose control message from speed and steering commands.
std::shared_ptr< pure_pursuit::PurePursuit > pp_
void set_leader(const PlatoonLeaderInfo &leader)
Sets the platoon leader object using info from msg.
void set_current_speed(double speed)
set current speed
void generate_speed(const carma_planning_msgs::msg::TrajectoryPlanPoint &point)
Generates speed commands (in m/s) based on the trajectory point.
autoware_auto_msgs::msg::Trajectory process_trajectory_plan(const carma_planning_msgs::msg::TrajectoryPlan &tp, double vehicle_response_lag)
Given a carma type of trajectory_plan, generate autoware type of trajectory accounting for speed_lag ...

References compose_ctrl_cmd(), config_, convert_state(), carma_guidance_plugins::ControlPlugin::current_trajectory_, platooning_control::PlatooningControlWorker::generate_speed(), pcw_, platoon_leader_, pp_, basic_autonomy::waypoint_generation::process_trajectory_plan(), platooning_control::PlatooningControlWorker::set_current_speed(), platooning_control::PlatooningControlWorker::set_leader(), platooning_control::PlatooningControlWorker::speedCmd_, trajectory_speed_, and platooning_control::PlatooningControlPluginConfig::vehicle_response_lag.

Referenced by generate_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_availability()

bool platooning_control::PlatooningControlPlugin::get_availability ( )
overridevirtual

Returns availability of plugin. Always true.

Implements carma_guidance_plugins::PluginBaseNode.

Definition at line 346 of file platooning_control.cpp.

346 {
347 return true; // TODO for user implement actual check on availability if applicable to plugin
348 }

◆ get_trajectory_speed()

double platooning_control::PlatooningControlPlugin::get_trajectory_speed ( const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &  trajectory_points)
private

calculate average speed of a set of trajectory points

Parameters
trajectory_pointsset of trajectory points
Returns
trajectory speed

Definition at line 355 of file platooning_control.cpp.

356 {
357 double trajectory_speed = 0;
358
359 double dx1 = trajectory_points[trajectory_points.size()-1].x - trajectory_points[0].x;
360 double dy1 = trajectory_points[trajectory_points.size()-1].y - trajectory_points[0].y;
361 double d1 = sqrt(dx1*dx1 + dy1*dy1);
362 double t1 = (rclcpp::Time((trajectory_points[trajectory_points.size()-1].target_time)).nanoseconds() - rclcpp::Time(trajectory_points[0].target_time).nanoseconds())/1e9;
363
364 double avg_speed = d1/t1;
365 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "trajectory_points size = " << trajectory_points.size() << ", d1 = " << d1 << ", t1 = " << t1 << ", avg_speed = " << avg_speed);
366
367 for(size_t i = 0; i < trajectory_points.size() - 2; i++ )
368 {
369 double dx = trajectory_points[i + 1].x - trajectory_points[i].x;
370 double dy = trajectory_points[i + 1].y - trajectory_points[i].y;
371 double d = sqrt(dx*dx + dy*dy);
372 double t = rclcpp::Time((trajectory_points[i + 1].target_time)).seconds() - rclcpp::Time(trajectory_points[i].target_time).seconds();
373 double v = d/t;
374 if(v > trajectory_speed)
375 {
376 trajectory_speed = v;
377 }
378 }
379
380 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "trajectory speed: " << trajectory_speed);
381 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "avg trajectory speed: " << avg_speed);
382
383 return avg_speed; //TODO: why are 2 speeds being calculated? Which should be returned?
384
385 }

References process_bag::i.

Referenced by generate_command().

Here is the caller graph for this function:

◆ get_version_id()

std::string platooning_control::PlatooningControlPlugin::get_version_id ( )
overridevirtual

Returns version id of plugn.

Implements carma_guidance_plugins::PluginBaseNode.

Definition at line 350 of file platooning_control.cpp.

350 {
351 return "v1.0";
352 }

◆ on_configure_plugin()

carma_ros2_utils::CallbackReturn platooning_control::PlatooningControlPlugin::on_configure_plugin ( )
overridevirtual

This method should be used to load parameters and will be called on the configure state transition.

Implements carma_guidance_plugins::PluginBaseNode.

Definition at line 114 of file platooning_control.cpp.

115 {
116 // Reset config
117 config_ = PlatooningControlPluginConfig();
118
119 // Load parameters
120 get_parameter<double>("stand_still_headway_m", config_.stand_still_headway_m);
121 get_parameter<double>("max_accel_mps2", config_.max_accel_mps2);
122 get_parameter<double>("kp", config_.kp);
123 get_parameter<double>("kd", config_.kd);
124 get_parameter<double>("ki", config_.ki);
125 get_parameter<double>("max_delta_speed_per_timestep", config_.max_delta_speed_per_timestep);
126 get_parameter<double>("min_delta_speed_per_timestep", config_.min_delta_speed_per_timestep);
127 get_parameter<double>("adjustment_cap_mps", config_.adjustment_cap_mps);
128 get_parameter<int>("cmd_timestamp_ms", config_.cmd_timestamp_ms);
129 get_parameter<double>("integrator_max", config_.integrator_max);
130 get_parameter<double>("integrator_min", config_.integrator_min);
131
132 get_parameter<std::string>("vehicle_id", config_.vehicle_id);
133 get_parameter<int>("control_plugin_shutdown_timeout", config_.shutdown_timeout);
134 get_parameter<int>("control_plugin_ignore_initial_inputs", config_.ignore_initial_inputs);
135 get_parameter<bool>("enable_max_adjustment_filter", config_.enable_max_adjustment_filter);
136 get_parameter<bool>("enable_max_accel_filter", config_.enable_max_accel_filter);
137
138 //Pure Pursuit params
139 get_parameter<double>("vehicle_response_lag", config_.vehicle_response_lag);
140 get_parameter<double>("maximum_lookahead_distance", config_.max_lookahead_dist);
141 get_parameter<double>("minimum_lookahead_distance", config_.min_lookahead_dist);
142 get_parameter<double>("speed_to_lookahead_ratio", config_.speed_to_lookahead_ratio);
143 get_parameter<bool>("is_interpolate_lookahead_point", config_.is_interpolate_lookahead_point);
144 get_parameter<bool>("is_delay_compensation", config_.is_delay_compensation);
145 get_parameter<double>("emergency_stop_distance", config_.emergency_stop_distance);
146 get_parameter<double>("speed_thres_traveling_direction", config_.speed_thres_traveling_direction);
147 get_parameter<double>("dist_front_rear_wheels", config_.dist_front_rear_wheels);
148
149 get_parameter<double>("dt", config_.dt);
150 get_parameter<double>("integrator_max_pp", config_.integrator_max_pp);
151 get_parameter<double>("integrator_min_pp", config_.integrator_min_pp);
152 get_parameter<double>("Ki_pp", config_.ki_pp);
153 get_parameter<bool>("is_integrator_enabled", config_.is_integrator_enabled);
154
155
156 RCLCPP_INFO_STREAM(rclcpp::get_logger("platooning_control"), "Loaded Params: " << config_);
157
158 // create config for pure_pursuit worker
159 pure_pursuit::Config cfg{
168 };
169
170 pure_pursuit::IntegratorConfig i_cfg;
171 i_cfg.dt = config_.dt;
172 i_cfg.integrator_max_pp = config_.integrator_max_pp;
173 i_cfg.integrator_min_pp = config_.integrator_min_pp;
174 i_cfg.Ki_pp = config_.ki_pp;
175 i_cfg.integral = 0.0; // accumulator of integral starts from 0
176 i_cfg.is_integrator_enabled = config_.is_integrator_enabled;
177
178 pp_ = std::make_shared<pure_pursuit::PurePursuit>(cfg, i_cfg);
179
180 // Register runtime parameter update callback
181 add_on_set_parameters_callback(std::bind(&PlatooningControlPlugin::parameter_update_callback, this, std_ph::_1));
182
183
184 // Trajectory Plan Subscriber
185 trajectory_plan_sub_ = create_subscription<carma_planning_msgs::msg::TrajectoryPlan>("platooning_control/plan_trajectory", 1,
186 std::bind(&PlatooningControlPlugin::current_trajectory_callback, this, std_ph::_1));
187
188 // Platoon Info Subscriber
189 platoon_info_sub_ = create_subscription<carma_planning_msgs::msg::PlatooningInfo>("platoon_info", 1, std::bind(&PlatooningControlPlugin::platoon_info_cb, this, std_ph::_1));
190
191
192 //Control Publishers
193 platoon_info_pub_ = create_publisher<carma_planning_msgs::msg::PlatooningInfo>("platooning_info", 1);
194
195
196 // Return success if everthing initialized successfully
197 return CallbackReturn::SUCCESS;
198 }
void platoon_info_cb(const carma_planning_msgs::msg::PlatooningInfo::SharedPtr msg)
callback function for platoon info
void current_trajectory_callback(const carma_planning_msgs::msg::TrajectoryPlan::UniquePtr tp)
callback function for trajectory plan
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::PlatooningInfo > platoon_info_sub_
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::PlatooningInfo > platoon_info_pub_
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > trajectory_plan_sub_

References platooning_control::PlatooningControlPluginConfig::adjustment_cap_mps, platooning_control::PlatooningControlPluginConfig::cmd_timestamp_ms, config_, current_trajectory_callback(), platooning_control::PlatooningControlPluginConfig::dist_front_rear_wheels, platooning_control::PlatooningControlPluginConfig::dt, platooning_control::PlatooningControlPluginConfig::emergency_stop_distance, platooning_control::PlatooningControlPluginConfig::enable_max_accel_filter, platooning_control::PlatooningControlPluginConfig::enable_max_adjustment_filter, platooning_control::PlatooningControlPluginConfig::ignore_initial_inputs, platooning_control::PlatooningControlPluginConfig::integrator_max, platooning_control::PlatooningControlPluginConfig::integrator_max_pp, platooning_control::PlatooningControlPluginConfig::integrator_min, platooning_control::PlatooningControlPluginConfig::integrator_min_pp, platooning_control::PlatooningControlPluginConfig::is_delay_compensation, platooning_control::PlatooningControlPluginConfig::is_integrator_enabled, platooning_control::PlatooningControlPluginConfig::is_interpolate_lookahead_point, platooning_control::PlatooningControlPluginConfig::kd, platooning_control::PlatooningControlPluginConfig::ki, platooning_control::PlatooningControlPluginConfig::ki_pp, platooning_control::PlatooningControlPluginConfig::kp, platooning_control::PlatooningControlPluginConfig::max_accel_mps2, platooning_control::PlatooningControlPluginConfig::max_delta_speed_per_timestep, platooning_control::PlatooningControlPluginConfig::max_lookahead_dist, platooning_control::PlatooningControlPluginConfig::min_delta_speed_per_timestep, platooning_control::PlatooningControlPluginConfig::min_lookahead_dist, parameter_update_callback(), platoon_info_cb(), platoon_info_pub_, platoon_info_sub_, pp_, platooning_control::PlatooningControlPluginConfig::shutdown_timeout, platooning_control::PlatooningControlPluginConfig::speed_thres_traveling_direction, platooning_control::PlatooningControlPluginConfig::speed_to_lookahead_ratio, platooning_control::PlatooningControlPluginConfig::stand_still_headway_m, trajectory_plan_sub_, platooning_control::PlatooningControlPluginConfig::vehicle_id, and platooning_control::PlatooningControlPluginConfig::vehicle_response_lag.

Here is the call graph for this function:

◆ parameter_update_callback()

rcl_interfaces::msg::SetParametersResult platooning_control::PlatooningControlPlugin::parameter_update_callback ( const std::vector< rclcpp::Parameter > &  parameters)

Callback for dynamic parameter updates.

Definition at line 66 of file platooning_control.cpp.

67 {
68 auto error_double = update_params<double>({
69 {"stand_still_headway_m", config_.stand_still_headway_m},
70 {"max_accel_mps2", config_.max_accel_mps2},
71 {"kp", config_.kp},
72 {"kd", config_.kd},
73 {"ki", config_.ki},
74 {"max_delta_speed_per_timestep", config_.max_delta_speed_per_timestep},
75 {"min_delta_speed_per_timestep", config_.min_delta_speed_per_timestep},
76 {"adjustment_cap_mps", config_.adjustment_cap_mps},
77 {"integrator_max", config_.integrator_max},
78 {"integrator_min", config_.integrator_min},
79
80 {"vehicle_response_lag", config_.vehicle_response_lag},
81 {"max_lookahead_dist", config_.max_lookahead_dist},
82 {"min_lookahead_dist", config_.min_lookahead_dist},
83 {"speed_to_lookahead_ratio", config_.speed_to_lookahead_ratio},
84 {"emergency_stop_distance",config_.emergency_stop_distance},
85 {"speed_thres_traveling_direction", config_.speed_thres_traveling_direction},
86 {"dist_front_rear_wheels", config_.dist_front_rear_wheels},
87 {"dt", config_.dt},
88 {"integrator_max_pp", config_.integrator_max_pp},
89 {"integrator_min_pp", config_.integrator_min_pp},
90 {"Ki_pp", config_.ki_pp},
91 }, parameters);
92
93 auto error_int = update_params<int>({
94 {"cmd_timestamp_ms", config_.cmd_timestamp_ms},
95 }, parameters);
96
97 auto error_bool = update_params<bool>({
98 {"is_interpolate_lookahead_point", config_.is_interpolate_lookahead_point},
99 {"is_delay_compensation",config_.is_delay_compensation},
100 {"is_integrator_enabled", config_.is_integrator_enabled},
101 {"enable_max_adjustment_filter", config_.enable_max_adjustment_filter},
102 {"enable_max_accel_filter", config_.enable_max_accel_filter},
103 }, parameters);
104
105 // vehicle_id, control_plugin_shutdown_timeout and control_plugin_ignore_initial_inputs are not updated as they are global params
106 rcl_interfaces::msg::SetParametersResult result;
107
108 result.successful = !error_double && !error_int && !error_bool;
109
110 return result;
111
112 }

References platooning_control::PlatooningControlPluginConfig::adjustment_cap_mps, platooning_control::PlatooningControlPluginConfig::cmd_timestamp_ms, config_, platooning_control::PlatooningControlPluginConfig::dist_front_rear_wheels, platooning_control::PlatooningControlPluginConfig::dt, platooning_control::PlatooningControlPluginConfig::emergency_stop_distance, platooning_control::PlatooningControlPluginConfig::enable_max_accel_filter, platooning_control::PlatooningControlPluginConfig::enable_max_adjustment_filter, platooning_control::PlatooningControlPluginConfig::integrator_max, platooning_control::PlatooningControlPluginConfig::integrator_max_pp, platooning_control::PlatooningControlPluginConfig::integrator_min, platooning_control::PlatooningControlPluginConfig::integrator_min_pp, platooning_control::PlatooningControlPluginConfig::is_delay_compensation, platooning_control::PlatooningControlPluginConfig::is_integrator_enabled, platooning_control::PlatooningControlPluginConfig::is_interpolate_lookahead_point, platooning_control::PlatooningControlPluginConfig::kd, platooning_control::PlatooningControlPluginConfig::ki, platooning_control::PlatooningControlPluginConfig::ki_pp, platooning_control::PlatooningControlPluginConfig::kp, platooning_control::PlatooningControlPluginConfig::max_accel_mps2, platooning_control::PlatooningControlPluginConfig::max_delta_speed_per_timestep, platooning_control::PlatooningControlPluginConfig::max_lookahead_dist, platooning_control::PlatooningControlPluginConfig::min_delta_speed_per_timestep, platooning_control::PlatooningControlPluginConfig::min_lookahead_dist, platooning_control::PlatooningControlPluginConfig::speed_thres_traveling_direction, platooning_control::PlatooningControlPluginConfig::speed_to_lookahead_ratio, platooning_control::PlatooningControlPluginConfig::stand_still_headway_m, and platooning_control::PlatooningControlPluginConfig::vehicle_response_lag.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ platoon_info_cb()

void platooning_control::PlatooningControlPlugin::platoon_info_cb ( const carma_planning_msgs::msg::PlatooningInfo::SharedPtr  msg)
private

callback function for platoon info

Parameters
msgplatoon info msg

Definition at line 239 of file platooning_control.cpp.

240 {
241
242 platoon_leader_.staticId = msg->leader_id;
243 platoon_leader_.vehiclePosition = msg->leader_downtrack_distance;
244 platoon_leader_.commandSpeed = msg->leader_cmd_speed;
245 // TODO: index is 0 temp to test the leader state
246 platoon_leader_.NumberOfVehicleInFront = msg->host_platoon_position;
248
249 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Platoon leader leader id: " << platoon_leader_.staticId);
250 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Platoon leader leader pose: " << platoon_leader_.vehiclePosition);
251 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Platoon leader leader cmd speed: " << platoon_leader_.commandSpeed);
252
253 carma_planning_msgs::msg::PlatooningInfo platooning_info_msg = *msg;
254
255 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "platooning_info_msg.actual_gap: " << platooning_info_msg.actual_gap);
256
257 if (platooning_info_msg.actual_gap > 5.0)
258 {
259 platooning_info_msg.actual_gap -= 5.0; // TODO: temporary: should be vehicle length
260 }
261
262 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "platooning_info_msg.actual_gap: " << platooning_info_msg.actual_gap);
263 // platooing_info_msg.desired_gap = pcw_.desired_gap_;
264 // platooing_info_msg.actual_gap = pcw_.actual_gap_;
265 pcw_.actual_gap_ = platooning_info_msg.actual_gap;
266 pcw_.desired_gap_ = platooning_info_msg.desired_gap;
267
268 platooning_info_msg.host_cmd_speed = pcw_.speedCmd_;
269 platoon_info_pub_->publish(platooning_info_msg);
270 }

References platooning_control::PlatooningControlWorker::actual_gap_, platooning_control::PlatoonLeaderInfo::commandSpeed, platooning_control::PlatooningControlWorker::desired_gap_, platooning_control::PlatoonLeaderInfo::leaderIndex, platooning_control::PlatoonLeaderInfo::NumberOfVehicleInFront, pcw_, platoon_info_pub_, platoon_leader_, platooning_control::PlatooningControlWorker::speedCmd_, platooning_control::PlatoonLeaderInfo::staticId, and platooning_control::PlatoonLeaderInfo::vehiclePosition.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

Member Data Documentation

◆ config_

PlatooningControlPluginConfig platooning_control::PlatooningControlPlugin::config_
private

◆ consecutive_input_counter_

long platooning_control::PlatooningControlPlugin::consecutive_input_counter_ = 0
private

Definition at line 123 of file platooning_control.hpp.

Referenced by current_trajectory_callback(), and generate_command().

◆ pcw_

PlatooningControlWorker platooning_control::PlatooningControlPlugin::pcw_
private

◆ platoon_info_pub_

carma_ros2_utils::PubPtr<carma_planning_msgs::msg::PlatooningInfo> platooning_control::PlatooningControlPlugin::platoon_info_pub_
private

Definition at line 144 of file platooning_control.hpp.

Referenced by on_configure_plugin(), and platoon_info_cb().

◆ platoon_info_sub_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::PlatooningInfo> platooning_control::PlatooningControlPlugin::platoon_info_sub_
private

Definition at line 141 of file platooning_control.hpp.

Referenced by on_configure_plugin().

◆ platoon_leader_

PlatoonLeaderInfo platooning_control::PlatooningControlPlugin::platoon_leader_
private

Definition at line 121 of file platooning_control.hpp.

Referenced by generate_control_signals(), and platoon_info_cb().

◆ pp_

std::shared_ptr<pure_pursuit::PurePursuit> platooning_control::PlatooningControlPlugin::pp_

Definition at line 109 of file platooning_control.hpp.

Referenced by generate_control_signals(), and on_configure_plugin().

◆ prev_input_time_ms_

double platooning_control::PlatooningControlPlugin::prev_input_time_ms_ = 0
private

Definition at line 122 of file platooning_control.hpp.

Referenced by current_trajectory_callback(), and generate_command().

◆ trajectory_plan_sub_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::TrajectoryPlan> platooning_control::PlatooningControlPlugin::trajectory_plan_sub_
private

Definition at line 140 of file platooning_control.hpp.

Referenced by on_configure_plugin().

◆ trajectory_speed_

double platooning_control::PlatooningControlPlugin::trajectory_speed_ = 0.0

Definition at line 67 of file platooning_control.hpp.

Referenced by generate_command(), and generate_control_signals().


The documentation for this class was generated from the following files: