# Design Controller for Vehicle Platooning

This example shows how to design a controller for vehicle platooning applications. In a platoon of vehicles, every following vehicle maintains a constant spacing from its preceding vehicle. Vehicles travelling in tightly spaced platoons can improve traffic flow, safety, and fuel economy.

Platooning has the following control objectives [1].

• Individual vehicle stability — Spacing error for each following vehicle converges to zero if the preceding vehicle is traveling at constant speed.

• String stability — Spacing errors do not amplify as they propagate towards the tail of the vehicle string.

### Platooning Model

In this example, there are five vehicles in the platoon. Every vehicle is modeled as a truck-trailer system with the following parameters. All lengths are in meters.

```L1 = 6; % Truck length L2 = 10; % Trailer length M1 = 1; % Interconnection length```

The lead vehicle follows a given acceleration profile. Each trailing vehicle has a controller that controls its acceleration.

```mdl = 'fiveVehiclePlatoon'; open_system(mdl)```

### Controller Design

In this example, the trailing vehicles all use the same controller design, which has the following structure.

`${\mathit{a}}_{\mathrm{ego}}={\mathit{C}}_{1}{\mathit{a}}_{\mathrm{lead}}+\left(1-{\mathit{C}}_{1}\right){\mathit{a}}_{\mathrm{front}}-{\mathit{K}}_{1}\left({\mathit{v}}_{\mathrm{ego}}-{\mathit{v}}_{\mathrm{lead}}\right)-{\mathit{K}}_{2}\left({\mathit{x}}_{\mathrm{ego}}-{\mathit{x}}_{\mathrm{front}}+\mathit{L}\right)$`

Here:

• ${\mathit{a}}_{\mathrm{ego}}$, ${\mathit{v}}_{\mathrm{ego}}$, and ${\mathit{x}}_{\mathrm{ego}}$ are the respective acceleration, velocity, and position of the ego vehicle, that is, the trailing vehicle under control.

• ${\mathit{a}}_{\mathrm{front}}$ and ${\mathit{v}}_{\mathrm{front}}$ are the acceleration and velocity of the vehicle directly in front of the ego vehicle.

• ${\mathit{a}}_{\mathrm{lead}}$ and ${\mathit{x}}_{\mathrm{lead}}$ are the acceleration and position of the lead vehicle in the platoon.

Each vehicle obtains this information from onboard sensors and wireless communication with the other vehicles in the platoon.

The parameters for the controller are as follows.

• $\mathit{L}$ is the desired following distance.

• ${\mathit{C}}_{1}$ is a constant.

• ${\mathit{K}}_{1}$ is a constant.

• ${\mathit{K}}_{2}$ is a PID controller.

The controller minimizes the velocity error ${\mathit{v}}_{\mathrm{lead}}-{\mathit{v}}_{\mathrm{ego}}$ using controller ${\mathit{K}}_{1}$, and minimizes the spacing error ${\mathit{x}}_{\mathrm{ego}}-{\mathit{x}}_{\mathrm{front}}+\mathit{L}$ using ${\mathit{K}}_{2}$.

Define the initial controller parameters.

```L = L1 + L2 + M1 + 5; % Front-to-front vehicle spacing C1 = 0.8; % Constant gain K1 = 8; % Constant gain K2 = [2,1]; % PD gains for spacing control [P,D]```

Run the simulation.

`sim(mdl);`

In the top plot, the velocity of each following vehicle converges to the lead velocity. In the bottom plot, the spacing between vehicles converges to the desired spacing.

### PID Tuning

To improve performance, you can tune the gains of the PID controller. As an example, tune the spacing PID controller ${\mathit{K}}_{2}$ for the 4th vehicle in the platoon.

Open the controller.

`open_system([mdl '/4th with controller/controller/K2'])`

In the block parameters, under Select tuning method, select `Transfer Function Based (PID Tuner App)`. Click Tune.

In the PID Tuner app, tune the response time and transient behavior of the controller. For example, a Response Time $3$ seconds and a Transient Behavior factor of 0.6 produce a PID controller with a faster response and no overshoot.

To update the controller parameters in the model, click Update Block.

For this example, open and simulate a Simulink model with the tuned parameters of the 4th controller set.

```mdlTuned = 'fiveVehiclePlatoonTuned'; open_system(mdlTuned) sim(mdlTuned);```

In the spacing plot, the error for the 4th vehicle converges faster than in the previous simulation.

Since the trailing vehicles use the same controller design, set the ${\mathit{K}}_{2}$ gains for the other trailing vehicles to the tuned gains from the 4th vehicle.

```% Obtained tuned controller gains. pTuned = get_param([mdlTuned '/4th with controller/controller/K2'],'P'); dTuned = get_param([mdlTuned '/4th with controller/controller/K2'],'D'); % Set gains in other controllers. set_param([mdlTuned '/3rd with controller/controller/K2'],'P',pTuned) set_param([mdlTuned '/3rd with controller/controller/K2'],'D',dTuned) set_param([mdlTuned '/2nd with controller/controller/K2'],'P',pTuned) set_param([mdlTuned '/2nd with controller/controller/K2'],'D',dTuned) set_param([mdlTuned '/1st with controller/controller/K2'],'P',pTuned) set_param([mdlTuned '/1st with controller/controller/K2'],'D',dTuned)```

Simulate the model with all the trailing vehicle controllers ${\mathit{K}}_{2}$ controllers tuned.

`sim(mdlTuned);`

The error for all the trailing vehicles converge faster than in the original simulation.

### References

[1] Rajamani, Rajesh. Vehicle Dynamics and Control. 2. ed. Mechanical Engineering Series. New York, NY Heidelberg: Springer, 2012.