docs/10_Control/how_to_tune_control_parameters.md
The objective of the control module is to generate control commands to the vehicle based on planning trajectory and the current car status.
The output control command governs functions such as steering, throttle, and brake in the canbus.
The controllers include a lateral controller that manages the steering commands and a longitudinal controller that manages the throttle and brakes commands .
The lateral controller is an LQR-Based Optimal Controller. The dynamic model of this controller is a simple bicycle model with side slip. It is divided into two categories, including a closed loop and an open loop.
The longitudinal controller is configured as a cascaded PID + Calibration table. It is divided into two categories, including a closed loop and an open loop.
Tool like diagnostics and realtime_plot are useful for controller tuning and can be found under apollo/modules/tools/.
The lateral controller is designed for minimal tuning effort. The basic lateral controller tuning steps for all vehicles are:
Set all elements in matrix_q to zero.
Increase the third element of matrix_q, which defines the heading error weighting, to minimize the heading error.
Increase the first element of matrix_q, which defines the lateral error weighting to minimize the lateral error.
For a Lincoln MKZ, there are four elements that refer to the diagonal elements of the state weighting matrix Q:
Tune the weighting parameters by following the basic lateral controller tuning steps listed above in Lateral Controller Tuning. An example is shown below.
lat_controller_conf {
matrix_q: 0.05
matrix_q: 0.0
matrix_q: 1.0
matrix_q: 0.0
}
When tuning a vehicle type that is other than a Lincoln MKZ, first update the vehicle-related physical parameters as shown in the example below. Then, follow the basic lateral controller tuning steps listed above in Lateral Controller Tuning and define the matrix Q parameters.
An example is shown below.
lat_controller_conf {
cf: 155494.663
cr: 155494.663
wheelbase: 2.85
mass_fl: 520
mass_fr: 520
mass_rl: 520
mass_rr: 520
eps: 0.01
steer_transmission_ratio: 16
steer_single_direction_max_degree: 470
}
The longitudinal controller is composed of Cascaded PID controllers that include one station controller and a high/low speed controller with different gains for different speeds. Apollo manages tuning in open loop and closed loop by:
The high speed controller code is used mainly to track the desired speed above a certain speed value. For example:
high_speed_pid_conf {
integrator_enable: true
integrator_saturation_level: 0.3
kp: 1.0
ki: 0.3
kd: 0.0
}
kp, ki, and kd to zero.kp to reduce the rising time of step response to velocity changes.ki to reduce velocity controller steady state error.Once you obtain relatively accurate speed tracking performance for the higher speed, you can start tuning the low speed PID controller for a comfortable acceleration rate from the start point.
low_speed_pid_conf {
integrator_enable: true
integrator_saturation_level: 0.3
kp: 0.5
ki: 0.3
kd: 0.0
}
Note: Apollo usually sets the switch speed to be a coasting speed when the gear switches to Drive.
Apollo uses the station controller for the vehicle to track the station error between the vehicle trajectory reference and the vehicle position. A station controller tuning example is shown below.
station_pid_conf {
integrator_enable: true
integrator_saturation_level: 0.3
kp: 0.3
ki: 0.0
kd: 0.0
}
"Vehicle dynamics and control." Rajamani, Rajesh. Springer Science & Business Media, 2011.
"Optimal Trajectory generation for dynamic street scenarios in a Frenet Frame", M. Werling et., ICRA2010