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

This class includes logic for PID controller. PID controller is used in this plugin to maintain the inter-vehicle gap by adjusting the speed. More...

#include <pid_controller.hpp>

Collaboration diagram for platooning_control::PIDController:
Collaboration graph

Public Member Functions

 PIDController ()
 Constructor for the PID controller class. More...
 
double calculate (double setpoint, double pv)
 function to calculate control command based on setpoint and process vale More...
 
void reset ()
 

Public Attributes

std::shared_ptr< PlatooningControlPluginConfigconfig_ = std::make_shared<PlatooningControlPluginConfig>()
 plugin config object More...
 

Private Attributes

double _pre_error = 0.0
 
double _integral = 0.0
 

Detailed Description

This class includes logic for PID controller. PID controller is used in this plugin to maintain the inter-vehicle gap by adjusting the speed.

Definition at line 27 of file pid_controller.hpp.

Constructor & Destructor Documentation

◆ PIDController()

platooning_control::PIDController::PIDController ( )

Constructor for the PID controller class.

Definition at line 22 of file pid_controller.cpp.

22{}

Member Function Documentation

◆ calculate()

double platooning_control::PIDController::calculate ( double  setpoint,
double  pv 
)

function to calculate control command based on setpoint and process vale

Parameters
setpointdesired value
pvcurrent value
Returns
the manipulated variable given a setpoint and current process value

Definition at line 24 of file pid_controller.cpp.

24 {
25 // Calculate error
26 double error = setpoint - pv;
27 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"),"PID error: " << error);
28
29 // Proportional term
30 double Pout = config_->kp * error;
31 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Proportional term: " << Pout);
32
33 // Integral term
34 _integral += error * config_->dt;
35 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"),"Integral term: " << _integral);
36
37 if (_integral > config_->integrator_max){
38 _integral = config_->integrator_max;
39 }
40 else if (_integral < config_->integrator_min){
41 _integral = config_->integrator_min;
42 }
43 double Iout = config_->ki * _integral;
44 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Iout: " << Iout);
45
46 // Derivative term
47 double derivative = (error - _pre_error) / config_->dt;
48 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "derivative term: " << derivative);
49 double Dout = config_->kd * derivative;
50 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "Dout: " << Dout);
51
52 // Calculate total output
53 double output = Pout + Iout + Dout;
54 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("platooning_control"), "total controller output: " << output);
55
56 // Restrict to max/min
57 if( output > config_->max_delta_speed_per_timestep )
58 output = config_->max_delta_speed_per_timestep;
59 else if( output < config_->min_delta_speed_per_timestep )
60 output = config_->min_delta_speed_per_timestep;
61 // Save error to previous error
62 _pre_error = error;
63
64 return output;
65
66 }
std::shared_ptr< PlatooningControlPluginConfig > config_
plugin config object

References _integral, _pre_error, and config_.

Referenced by platooning_control::PlatooningControlWorker::generate_speed().

Here is the caller graph for this function:

◆ reset()

void platooning_control::PIDController::reset ( )

Definition at line 68 of file pid_controller.cpp.

68 {
69 _integral = 0.0;
70 _pre_error = 0.0;
71 }

References _integral, and _pre_error.

Referenced by platooning_control::PlatooningControlWorker::generate_speed().

Here is the caller graph for this function:

Member Data Documentation

◆ _integral

double platooning_control::PIDController::_integral = 0.0
private

Definition at line 66 of file pid_controller.hpp.

Referenced by calculate(), and reset().

◆ _pre_error

double platooning_control::PIDController::_pre_error = 0.0
private

Definition at line 65 of file pid_controller.hpp.

Referenced by calculate(), and reset().

◆ config_

std::shared_ptr<PlatooningControlPluginConfig> platooning_control::PIDController::config_ = std::make_shared<PlatooningControlPluginConfig>()

plugin config object

Definition at line 39 of file pid_controller.hpp.

Referenced by calculate().


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