# Longitudinal Controller Stanley

**Libraries:**

Automated Driving Toolbox /
Vehicle Control

## Description

The Longitudinal Controller Stanley block computes the acceleration and deceleration commands, in meters per second, that control the velocity of the vehicle. Specify the reference velocity, current velocity, and current driving direction. The controller computes these commands using the Stanley method [1], which the block implements as a discrete proportional-integral (PI) controller with integral anti-windup. For more details, see Algorithms.

You can also compute the steering angle command of a vehicle using the Stanley method. See the Lateral Controller Stanley block.

## Ports

### Input

### Output

## Parameters

## Algorithms

The Longitudinal Controller Stanley block implements a discrete proportional-integral (PI) controller with integral anti-windup, as described by the Anti-windup method (Simulink) parameter of the PID Controller block. The block uses this equation:

$$u(k)=({K}_{\text{p}}+{K}_{\text{i}}\frac{{T}_{\text{s}}\text{\hspace{0.17em}}z}{z-1})\text{\hspace{0.17em}}e(k)$$

*u*(*k*) is the control signal at the*k*th time step.*K*_{p}is the proportional gain, as set by the**Proportional gain, Kp**parameter.*K*_{i}is the integral gain, as set by the**Integral gain, Ki**parameter.*T*_{s}is the sample time of the block in seconds, as set by the**Sample time (s)**parameter.*e*(*k*) is the velocity error (**CurrVelocity**–**RefVelocity**) at the*k*th time step. For each*k*, this error is equal to the difference between the current velocity and reference velocity inputs (**CurrVelocity**–**RefVelocity**).

The control signal, *u*, determines the value of
acceleration command **AccelCmd** and deceleration command
**DecelCmd**. The block saturates the acceleration and
deceleration commands to respective ranges of [0,
*M*_{A}] and [0,
*M*_{D}], where:

*M*_{A}is value of the**Maximum longitudinal acceleration (m/s^2)**parameter.*M*_{D}is the value of the**Maximum longitudinal deceleration (m/s^2)**parameter.

At each time step, only one of the **AccelCmd**
and **DecelCmd** port values is positive, and the other port
value is `0`

. In other words, the vehicle can either accelerate or decelerate
in one time step, but it cannot do both at one time.

The direction of motion, as specified in the **Direction** input port,
determines which command is positive at the given time step.

Direction Port Value | Control Signal Value u(k) | AccelCmd Port Value | DecelCmd Port Value | Description |
---|---|---|---|---|

`1` (forward motion) |
| positive real scalar | `0` | Vehicle speeds up as it travels forward |

| `0` | positive real scalar | Vehicle slows down as it travels forward | |

`-1` (reverse motion) |
| `0` | positive real scalar | Vehicle slows down as it travels in reverse |

| positive real scalar | `0` | Vehicle speeds up as it travels in reverse |

## References

[1] Hoffmann, Gabriel M., Claire J.
Tomlin, Michael Montemerlo, and Sebastian Thrun. "Autonomous Automobile Trajectory Tracking
for Off-Road Driving: Controller Design, Experimental Validation and Racing."
*American Control Conference*. August 2007, pp. 2296–2301.
doi:10.1109/ACC.2007.4282788.

## Extended Capabilities

## Version History

**Introduced in R2019a**

## See Also

### Blocks

- Lateral Controller Stanley | Path Smoother Spline | PID Controller (Simulink) | Velocity Profiler