Example: Modeling a Cruise Control System in Simulink


Physical setup and system equations
Building the model
Open-loop response
Extracting the Model
Implementing PI control
Closed-loop response

Physical setup and system equations

The model of the cruise control system is relatively simple. If the inertia of the wheels is neglected, and it is assumed that friction (which is proportional to the car's speed) is what is opposing the motion of the car, then the problem is reduced to the simple mass and damper system shown below.

Using Newton's law, modeling equations for this system becomes:

(1)
where u is the force from the engine. For this example, let's assume that


m = 1000kg
b = 50Nsec/m
u = 500N

Building the Model

This system will be modeled by summing the forces acting on the mass and integrating the acceleration to give the velocity. Open Simulink and open a new model window. First, we will model the integral of acceleration

Since the acceleration (dv/dt) is equal to the sum of the forces divided by mass, we will divide the incoming signal by the mass.

Now, we will add in the forces which are represented in Equation (1). First, we will add in the damping force.

The second force acting on the mass is the control input, u. We will apply a step input.

Open-loop response

To simulate this system, first, an appropriate simulation time must be set.

The physical parameters must now be set. Run the following commands at the MATLAB prompt:

Run the simulation (Ctrl-t or Start on the Simulation menu). When the simulation is finished, double-click on the scope and hit its autoscale button. You should see the following output.

Extracting a Linear Model into MATLAB

A linear model of the system (in state space or transfer function form) can be extracted from a Simulink model into MATLAB. This is done through the use of In and Out Connection blocks and the MATLAB function linmod.

Save your file as "ccmodel.mdl" (select Save As from the File menu). MATLAB will extract the linear model from the saved model file, not from the open model window. At the MATLAB prompt, enter the following commands:

You should see the following output, providing both state-space and transfer function models of the system. To verify the model extraction, we will generate an open-loop step response of the extracted transfer function in MATLAB. We will multiply the numerator by 500 to simulate a step input of 500N. Enter the following command in MATLAB. You should see the following plot which is equivalent to the Scope's output.

Implementing PI Control

In the cruise control example a PI controller was designed with Kp=800 and Ki=40 to give the desired response. We will implement this in Simulink by first containing the open-loop system from earlier in this page in a Subsystem block.

Now, we will build a PI controller around the plant model. First, we will feed back the plant output.

The output of the Sum block will provide the error signal. From this, we will generate proportional and integral components.

Now we will add the proportional and integral components and apply the sum to the plant.

Finally, we will apply a step input and view the output on a scope.

You can download our version of the closed-loop system here.

In this example, we constructed a PI controller from fundamental blocks. As an alternative, we could have used a Transfer Function block (from the Linear block library) to implement this in one step, as shown below.

You can download this model here.

Closed-loop response

To simulate this system, first, an appropriate simulation time must be set. Select Parameters from the Simulation menu and enter "10" in the Stop Time field. The design requirements included a rise time of less than 5 sec, so we simulate for 10 sec to view the output. The physical parameters must now be set. Run the following commands at the MATLAB prompt: Run the simulation (Ctrl-t or Start on the Simulation menu). When the simulation is finished, double-click on the scope and hit its autoscale button. You should see the following output.


Simulink Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam

Cruise Control Examples
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

Tutorials
MATLAB Basics | MATLAB Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink Basics | Simulink Modeling | Examples