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::PlatooningControlWorker Class Reference

This is the worker class for platoon controller. It is responsible for generating and smoothing the speed and steering control commands from trajectory points. More...

#include <platooning_control_worker.hpp>

Collaboration diagram for platooning_control::PlatooningControlWorker:
Collaboration graph

Public Member Functions

 PlatooningControlWorker ()
 Default constructor for platooning control worker. More...
 
double get_last_speed_command () const
 Returns latest speed command. More...
 
void generate_speed (const carma_planning_msgs::msg::TrajectoryPlanPoint &point)
 Generates speed commands (in m/s) based on the trajectory point. More...
 
void set_leader (const PlatoonLeaderInfo &leader)
 Sets the platoon leader object using info from msg. More...
 
void set_current_speed (double speed)
 set current speed More...
 

Public Attributes

PlatoonLeaderInfo platoon_leader
 
std::shared_ptr< PlatooningControlPluginConfigctrl_config_ = std::make_shared<PlatooningControlPluginConfig>()
 
double speedCmd = 0
 
double currentSpeed = 0
 
double lastCmdSpeed = 0.0
 
double speedCmd_ = 0
 
double steerCmd_ = 0
 
double angVelCmd_ = 0
 
double desired_gap_ = ctrl_config_->stand_still_headway_m
 
double actual_gap_ = 0.0
 
bool last_cmd_set_ = false
 

Private Attributes

PIDController pid_ctrl_
 
double dist_to_front_vehicle
 

Detailed Description

This is the worker class for platoon controller. It is responsible for generating and smoothing the speed and steering control commands from trajectory points.

Definition at line 59 of file platooning_control_worker.hpp.

Constructor & Destructor Documentation

◆ PlatooningControlWorker()

platooning_control::PlatooningControlWorker::PlatooningControlWorker ( )

Default constructor for platooning control worker.

Definition at line 25 of file platooning_control_worker.cpp.

26 {
27 pid_ctrl_ = PIDController();
28
29 }

References pid_ctrl_.

Member Function Documentation

◆ generate_speed()

void platooning_control::PlatooningControlWorker::generate_speed ( const carma_planning_msgs::msg::TrajectoryPlanPoint &  point)

Generates speed commands (in m/s) based on the trajectory point.

Parameters
pointtrajectory point

Definition at line 35 of file platooning_control_worker.cpp.

36 {
37 double speed_cmd = 0;
38
39 if (!last_cmd_set_)
40 {
41 // last speed command for smooth speed transition
43 last_cmd_set_ = true;
44 }
45
46 PlatoonLeaderInfo leader = platoon_leader;
47 if(!leader.staticId.empty() && leader.staticId != ctrl_config_->vehicle_id)
48 {
49 double controllerOutput = 0.0;
50
51
52 double leaderCurrentPosition = leader.vehiclePosition;
53 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "The current leader position is " << leaderCurrentPosition);
54
55 double desiredHostPosition = leaderCurrentPosition - desired_gap_;
56 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "desiredHostPosition = " << desiredHostPosition);
57
58 double hostVehiclePosition = leaderCurrentPosition - actual_gap_;
59 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "hostVehiclePosition = " << hostVehiclePosition);
60
61 controllerOutput = pid_ctrl_.calculate(desiredHostPosition, hostVehiclePosition);
62
63 double adjSpeedCmd = controllerOutput + leader.commandSpeed;
64 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Adjusted Speed Cmd = " << adjSpeedCmd << "; Controller Output = " << controllerOutput
65 << "; Leader CmdSpeed= " << leader.commandSpeed << "; Adjustment Cap " << ctrl_config_->adjustment_cap_mps);
66 // After we get a adjSpeedCmd, we apply three filters on it if the filter is enabled
67 // First: we do not allow the difference between command speed of the host vehicle and the leader's commandSpeed higher than adjustmentCap
68
69 speed_cmd = adjSpeedCmd;
70 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "A speed command is generated from command generator: " << speed_cmd << " m/s");
71
72 if(ctrl_config_->enable_max_adjustment_filter)
73 {
74 if(speed_cmd > leader.commandSpeed + ctrl_config_->adjustment_cap_mps) {
75 speed_cmd = leader.commandSpeed + ctrl_config_->adjustment_cap_mps;
76 } else if(speed_cmd < leader.commandSpeed - ctrl_config_->adjustment_cap_mps) {
77 speed_cmd = leader.commandSpeed - ctrl_config_->adjustment_cap_mps;
78 }
79 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "The adjusted cmd speed after max adjustment cap is " << speed_cmd << " m/s");
80 }
81
82 }
83
84 else if (leader.staticId == ctrl_config_->vehicle_id)
85 {
86 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Host vehicle is the leader");
87 speed_cmd = currentSpeed;
88
89 if(ctrl_config_->enable_max_adjustment_filter)
90 {
91 if(speed_cmd > ctrl_config_->adjustment_cap_mps)
92 {
93 speed_cmd = ctrl_config_->adjustment_cap_mps;
94 }
95
96 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "The adjusted leader cmd speed after max adjustment cap is " << speed_cmd << " m/s");
97 }
98
100 }
101
102 else
103 {
104 // If there is no leader available, the vehicle will stop. This means there is a mis-communication between platooning strategic and control plugins.
105 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "There is no leader available");
106 speed_cmd = 0.0;
108 }
109
110
111
112 // Third: we allow do not a large gap between two consecutive speed commands
113 if(ctrl_config_->enable_max_accel_filter) {
114
115 double max = lastCmdSpeed + (ctrl_config_->max_accel_mps2 * (ctrl_config_->cmd_timestamp_ms / 1000.0));
116 double min = lastCmdSpeed - (ctrl_config_->max_accel_mps2 * (ctrl_config_->cmd_timestamp_ms / 1000.0));
117 if(speed_cmd > max) {
118 speed_cmd = max;
119 } else if (speed_cmd < min) {
120 speed_cmd = min;
121 }
122 lastCmdSpeed = speed_cmd;
123 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "The speed command after max accel cap is: " << speed_cmd << " m/s");
124 }
125
126 speedCmd_ = speed_cmd;
127
129
130 }
double calculate(double setpoint, double pv)
function to calculate control command based on setpoint and process vale
std::shared_ptr< PlatooningControlPluginConfig > ctrl_config_

References actual_gap_, platooning_control::PIDController::calculate(), platooning_control::PlatoonLeaderInfo::commandSpeed, ctrl_config_, currentSpeed, desired_gap_, last_cmd_set_, lastCmdSpeed, pid_ctrl_, platoon_leader, platooning_control::PIDController::reset(), speedCmd_, platooning_control::PlatoonLeaderInfo::staticId, and platooning_control::PlatoonLeaderInfo::vehiclePosition.

Referenced by platooning_control::PlatooningControlPlugin::generate_control_signals().

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

◆ get_last_speed_command()

double platooning_control::PlatooningControlWorker::get_last_speed_command ( ) const

Returns latest speed command.

Returns
lastest speed command in m/s

Definition at line 31 of file platooning_control_worker.cpp.

31 {
32 return speedCmd_;
33 }

References speedCmd_.

◆ set_current_speed()

void platooning_control::PlatooningControlWorker::set_current_speed ( double  speed)

set current speed

Parameters
speedspeed value

Definition at line 137 of file platooning_control_worker.cpp.

137 {
138 currentSpeed = speed;
139
140 }

References currentSpeed.

Referenced by platooning_control::PlatooningControlPlugin::generate_control_signals().

Here is the caller graph for this function:

◆ set_leader()

void platooning_control::PlatooningControlWorker::set_leader ( const PlatoonLeaderInfo leader)

Sets the platoon leader object using info from msg.

Parameters
leaderleader information msg received from strategic plugin

Definition at line 133 of file platooning_control_worker.cpp.

133 {
134 platoon_leader = leader;
135 }

References platoon_leader.

Referenced by platooning_control::PlatooningControlPlugin::generate_control_signals().

Here is the caller graph for this function:

Member Data Documentation

◆ actual_gap_

double platooning_control::PlatooningControlWorker::actual_gap_ = 0.0

◆ angVelCmd_

double platooning_control::PlatooningControlWorker::angVelCmd_ = 0

Definition at line 106 of file platooning_control_worker.hpp.

◆ ctrl_config_

std::shared_ptr<PlatooningControlPluginConfig> platooning_control::PlatooningControlWorker::ctrl_config_ = std::make_shared<PlatooningControlPluginConfig>()

◆ currentSpeed

double platooning_control::PlatooningControlWorker::currentSpeed = 0

Definition at line 102 of file platooning_control_worker.hpp.

Referenced by generate_speed(), and set_current_speed().

◆ desired_gap_

double platooning_control::PlatooningControlWorker::desired_gap_ = ctrl_config_->stand_still_headway_m

◆ dist_to_front_vehicle

double platooning_control::PlatooningControlWorker::dist_to_front_vehicle
private

Definition at line 117 of file platooning_control_worker.hpp.

◆ last_cmd_set_

bool platooning_control::PlatooningControlWorker::last_cmd_set_ = false

Definition at line 109 of file platooning_control_worker.hpp.

Referenced by generate_speed().

◆ lastCmdSpeed

double platooning_control::PlatooningControlWorker::lastCmdSpeed = 0.0

Definition at line 103 of file platooning_control_worker.hpp.

Referenced by generate_speed().

◆ pid_ctrl_

PIDController platooning_control::PlatooningControlWorker::pid_ctrl_
private

Definition at line 115 of file platooning_control_worker.hpp.

Referenced by PlatooningControlWorker(), and generate_speed().

◆ platoon_leader

PlatoonLeaderInfo platooning_control::PlatooningControlWorker::platoon_leader

Definition at line 96 of file platooning_control_worker.hpp.

Referenced by generate_speed(), and set_leader().

◆ speedCmd

double platooning_control::PlatooningControlWorker::speedCmd = 0

Definition at line 101 of file platooning_control_worker.hpp.

◆ speedCmd_

◆ steerCmd_

double platooning_control::PlatooningControlWorker::steerCmd_ = 0

Definition at line 105 of file platooning_control_worker.hpp.


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