# 6.8: Modeling and PID Controller Example - Cruise Control for an Electric Vehicle

Author: Alex Dowling

## 8.1 Introduction

Controls principles developed in this course can be applied to non-chemical engineering systems such as automobiles. Some companies, such as NAVTEQ, are developing adaptive cruise control products that use information about the upcoming terrain to shift gears in a more intelligent manner which improves speed regulation and fuel economy. This case study will examine the basics of develop a speed controller for an electric vehicle.

An electric vehicle was chosen for the following reasons:

• Electric vehicles are interesting from an engineering perspective and may become a reality for consumers in the future
• Torque produced by an electric motor is instantaneous (for all practical purposes). Thus actuator lag can be ignored, simplifying the development of said controller.
• Some electric vehicles feature motors directly integrated into the hub of the drive wheel(s). This eliminates the need for a transmission and simplifies vehicle dynamics models.

## 8.2 Forces

As shown in the free body diagram below, there are six forces acting on the vehicle:

1. Rolling Resistance
2. Aerodynamic Drag
3. Aerodynamic Lift
4. Gravity
5. Normal
6. Motor

### 8.2.1 Rolling Resistance

Rolling resistance is due the tires deforming when contacting the surface of a road and varies depending on the surface being driven on. It can be model using the following equation:

$F_{R R}=C_{r r 1} v+C_{r r 2} F_{N}$

The two rolling resistance constants can be determined experimentally and may be provided by the tire manufacture. is the normal force.

### 8.2.2 Aerodynamic Drag

Aerodynamic drag is caused by the momentum loss of air particles as they flow over the hood of the vehicle. The aerodynamic drag of a vehicle can be modeled using the following equation:

• is the density of air. At 20°C and 101kPa, the density of air is 1.2041 kg/m3.
• is the coefficient of drag for the vehicle times the reference area. Typical values for automobiles are listed here.
• is the velocity of the vehicle.

### 8.2.3 Aerodynamic Lift

Aerodynamic lift is caused by pressure difference between the roof and underside of the vehicle. Lift can be modeled using the following equation:

• is the density of air. At 20°C and 101kPa, the density of air is 1.2041 kg/m3.
• is the coefficient of lift for the vehicle times the reference area.
• is the velocity of the vehicle.

### 8.2.4 Gravity

In the diagram above, there is a component of gravity both in the dimension normal to the road and in the dimension the vehicle is traveling. Using simple trigonometry, the component in the dimension of travel can be calculated as follows:

$F_{G, t r a v e l}=m g \sin (-\theta)$

• $$m$$ is the mass of the vehicle.
• $$g$$ is the acceleration due to gravity.

### 8.2.5 Normal Force

The normal force is the force excerted by the road on the vehicle's tires. Because the vehicle is not moving up or down (relative to the road), the magnitude of the normal forces equals the magnitude of the force due to gravity in the direction normal to the road.

• $$m$$ is the mass of the vehicle.
• $$g$$ is the acceleration due to gravity.

### 8.2.6 Motor

The torque produced by an electric motor is roughly proportional to the current flowing through the stater of the motor. In this case study, the current applied to the motor will be controlled to regulate speed. Applying a negative current will cause the vehicle to regeneratively brake.

$\tau=k_{\text {motor}} I$

$F_{M}=\frac{\tau}{r}=\frac{k_{\text {motor }} I}{r}$

• is the torque produced by the motor.
• is the current flowing through the motor.
• is the radius of the tire.
• is a constant.

## 8.3 Newton's Second Law

Using Newton's Second Law, a differential for the vehicle's speed can be obtained.

$m a=\sum F=F_{M}-F_{d r a g}-F_{R R}+F_{G, \text {travel}}$

Substituting in the expressions for various forces detailed above yields the following:

Further substituting the expression for normal forces yields the following:

Substituting for results in the following:

Grouping like turns results in the following:

In order to simply the remaining analysis, several constants are defined as follows:

$\beta=r C_{r r 1}$

$\gamma=r C_{r r 2} m g \cos (-\theta)-r m g \sin (-\theta)$

Substituting these into the differential equation results in the following expression:

$\frac{d v}{d t}=\frac{\tau-\alpha v^{2}-\beta v-\gamma(\theta)}{m r}$

It is important that (and thus also ) is a function of vehicle position.

## 8.4 PID Controller

One way to regulate vehicle speed is to control the torque generated by the electric motor. If the motor torque is greater than the resistive torque acting on the vehicle (a summation of aerodynamic drag, rolling resistance, etc.) the vehicle will accelerate. If the motor torque is less than the resistive torque, the vehicle will slow down.

### 8.4.1 Expression for Phase Current

For an electric motor, the phase current flowing through the motor is proportional to the torque produced. Thus one strategy for controlling the vehicles speed is to controller the motor phase current.

Using a PID controller architecture, the expression for motor current is the following:

$I=K_{c}\left(v_{s e t}-v\right)+\frac{1}{\tau_{I}} \int(v-v_{set}) d t+\tau_{D} \frac{d\left(v_{s e t}-v\right)}{d t}+C_{offset}$

### 8.4.2 Differential Equation for Velocity

Substituting this expression into the differential equation for vehicle position results in the following:

Defining another variable $$x_1$$ allows for the removal of the integral from the expression.

$\frac{d x_{1}}{d t}=v_{s e t}-v$

$\frac{d v}{d t}=\frac{k_{\text {motor}}\left[K_{c}\left(v_{\text {isct }}-v\right)+\frac{x_{1}}{\tau_{l}}+\tau_{D} \frac{d\left(v_{a=t}-v\right)}{d t}+ C_{offset} \right]-\alpha v^{2}-\beta v-\gamma(\theta).}{m r}$

If all changes in $$v_{set}$$ are gradual then $$\frac{d v_{set}}{d t} \approx 0$$. Applying this simplification results in the following expression:

$\frac{d v}{d t}=\frac{k_{\text {motor }}\left[K_{c}\left(v_{\text {set }}-v\right)+\frac{x_{1}}{\tau_{1}}-\tau_{D} \frac{d v}{d t}+C_{\text {offset }}\right]-\alpha v^{2}-\beta v-\gamma(\theta)}{m r}$

Using a little algebra, an expression for can be obtained as follows:

$\frac{d v}{d t}=\frac{k_{\text {motor}} K_{c}\left(v_{\text {set}}^{k_{\text {motor}}} x_{1} | k_{\text {motor}} C_{\text {cffses}}^{2}\right)^{\alpha}(\theta)}{\dot{k}_{\text {motor}} l_{L}+mr}$

### 8.4.3 Find Fixed Point

The fixed point can be obtained by setting the derivatives to zero and solving the system of equation.

System of Equations:

Solution

$x_{1}=\frac{\left.-\tau_{I}\left(k_{\text {motor}} C_{\text {offset}}-\alpha v_{\text {set}}^{2}-\beta v_{\text {set}}-\gamma(\theta)\right]\right)}{k_{\text {motor}}}$

$v=v_{s e t}$

As expected, a fixed point exists when the set velocity equals the actual velocity of the vehicle.

### 8.4.4 Linearize System of ODEs

Before the stability of the system can be (easily) examined, the system must be linearized around a fixed point.

Note: To simply the matrix expressions in section the following notation will be used:

$y_{i}^{\prime}=\frac{d y_{i}}{d t}$

Overall a linearized system of ODEs has the following form:

$\left[\begin{array}{c} y_{1}^{\prime} \\ y_{2}^{\prime} \\ \vdots \\ y_{n}^{\prime} \end{array}\right]=\mathbf{J}\left[\begin{array}{c} y_{1} \\ y_{2} \\ \vdots \\ y_{n} \end{array}\right]+\left[\begin{array}{c} k_{1} \\ k_{2} \\ \vdots \\ k_{n} \end{array}\right]$

The first step of linearizing any system of ODEs to calculate the Jacobian. For this particular system, the Jacobian can be calculated as follows:

$\mathbf{J}=\left[\begin{array}{cc} \frac{\partial v^{\prime}}{\partial v} & \frac{\partial v^{\prime}}{\partial x_{1}} \\ \frac{\partial x_{1}^{\prime}}{\partial v} & \frac{\partial x_{1}^{\prime}}{\partial x_{1}} \end{array}\right]=\left[\begin{array}{cc} \frac{-k_{m o t o r} K_{c}-m r[2 \alpha v+\beta]}{m r+k_{m o t o r} \tau_{D}} & \frac{k_{\text {motor }}}{t_{l}\left(m r+k_{\text {motor }} \tau_{D}\right)} \\ -1 & 0 \end{array}\right]$

The Jacobian is then evaluated at the fixed point:

$\mathbf{J}=\left[\begin{array}{cc} \frac{-k_{\text {motor }} K_{c}-m r\left[2 \alpha v_{\text {set }}+\beta\right]}{m r+k_{\text {motor }} \tau_{D}} & \frac{k_{\text {motor }}}{t_{I}\left(m r+k_{\text {motor }} \tau_{D}\right)} \\ -1 & 0 \end{array}\right]$

The next step if to calculate the vector of constants. For this particular system, said vector can be calculated as follows:

$\left[\begin{array}{c} k_{v} \\ k_{x_{1}} \end{array}\right]=\left[\begin{array}{c} \frac{\left.-\left(-k_{\text {motor}} K_{c}-2 \alpha v_{s e t}-\beta\right]\right) v_{s e t}}{\left(m r+k_{\text {motor}} \tau_{D}\right)}+\frac{\left.\left(k_{\text {motor}} C_{\text {offset}}-\alpha v_{\text {set}}^{2}-\beta v_{\text {set}}-\gamma(\theta)\right]\right)}{\left(m r+k_{\text {motor}} \tau_{D}\right)} \\ v_{\text {set}} \end{array}\right]$

Combining the Jacobian and vector of constants results in the following linearized system:

$\left[\begin{array}{l} v^{\prime} \\ x_{1}^{\prime} \end{array}\right]=\mathbf{J}\left[\begin{array}{l} v \\ x_{1} \end{array}\right]+\left[\begin{array}{l} k_{v} \\ k_{x_{1}} \end{array}\right]$

### 8.4.5 Stability Analysis

To assess the stability of the controller, the eigenvalues of the Jacobian in the linearized systems of ODEs can be examined. In general, an eigenvalue (lambda) is the solution to the following equation:

Using a computer to solve said equation, the eigenvalues of this particular system can be found to be the following:

For the system to be stable, the real component of all eigenvalues must be non-positive. The following inequality must be true for a stable controller:

For the system to not oscillate, the imaginary component of all eigenvalues must be zero. The following inequality must be true for a non-oscillating controller:

Interestingly, neither of these criteria depend on the grade of the road (θ). However, during the analysis, it was assumed that θ is constant. For most roads, this is not the case; θ is actually a function of vehicle position. In order to add this additional level of detail, the original system of ODEs needs to be revised:

Unfortunately for any normal road, the grade is not a simple (or even explicate) function of position (s). This prevents an in depth analytical analysis of stability. However for a very smooth road with very gradual changes in grade, the stability of the controller should be unaffected.

### 8.4.6 Example Electric Vehicle

Simulating the system also for other properties of the controller to be examined. This section presents the results from simulating a specified fictitious electric vehicle.

Parameters

For the fictitious electric vehicle simulated in this analysis, the following parameters were used. These parameters are roughly based on the parameters one would expect to see in a typical electric automobile.

Root Locus Plots

Using the parameters above, Root Locus Plots of the system were constructed to numerically explore the stability. The following controller constants were used when constructing the plots:

These Root Locus plots show that the controller with said constants is both stable and does not oscillate.

Phase Portrait

A phase portrait of the system with the following parameters was also constructed:

The phase portrait shows that the system is both stable and does not oscillate, as predicted by the Root Locus plots.

Driving Simulation on Level Terrain

The vehicle was simulated starting at 10 m/s and accelerating to 25 m/s via cruise control on level terrain (). For this simulation, the following constants were used:

Interestingly this graph shows oscillation, despite the Root Locus plots and phase diagrams. It is important to remember, however, that the Root Locus plot and stability methods involve linearizing the system. It is possible the linearized system is not a good approximation of the system.

It is also important to remember that this particular example involves a large set point change, which can induce oscillations in certain systems.

Driving Simulation on Unlevel Terrain

In order to explore how the controller behaves on a road with a non-zero grade, a route with hills was constructed from the following equation, where h is elevation and s is position.:

The vehicle was simulated driving said road starting with the following initial conditions and controller constants:

Initial Conditions

Controller Constants

The current controller tuning is inadequate for this road. There are vary large variations in velocity. In order to reduce these variation, the propartional gain Kc was increased by a factor of 5. Below are the results:

Using the Optimization Toolbox in MATLAB, the controller was optimized by minimizing the sum of the errors (difference between vehicle velocity and set velocity) on this particular segment of road. Below are the optimized controller constants and a plot of the velocity profile:

This example shows the power of optimization and model predictive control.

## Summary

This example demonstrates the following:

1. Modeling a simple, non-chemical engineering system.
2. Develop a PID controller for said physical dynamical system.
3. Manipulate said system to develop an system of differential equations.
4. Find fixed point(s) for said system.
5. Linearize said system of differential equations.
6. Find the eigenvalues of said linearized system.
7. Construct Root Locus plots for said linearized system.
8. Construct a phase portrait for said dynamical system.
9. Simulate said dynamical system under various conditions.
10. Demonstrate the idea of model predictive control by optimize said controller under a specific scenario.