The problem
Cruise control is the simplest closed-loop function in a car, but it shows every core idea of control design: a non-linear plant, actuator limits, disturbances from slope and wind, and the trade-off between fast response and comfort. In an EV the motor can both drive and regenerate, so the controller can hold speed downhill too. This project builds the plant and the controller from first principles.
Objectives
- Model vehicle longitudinal dynamics with aerodynamic drag, rolling resistance and grade.
- Model a motor torque limit and a simple regenerative braking range.
- Design a PI or PID speed controller and tune it with the PID Tuner.
- Test response to setpoint steps, hills and headwind.
- Measure overshoot, settling time, steady-state error and energy use.
What you need
Tools and toolboxes
- Simulink — Vehicle model, PID Controller block, test signals and Simulation Data Inspector.
- Control System Toolbox — pidtune and the PID Tuner app on the hand-linearised plant, plus step and margin analysis. Manual tuning is possible on a base Simulink licence.
- Simulink Control Design — Optional: Model Linearizer and linearize to extract the plant directly from the Simulink model, and tuning the PID Controller block in place. The hand derivation in step 4 works without it.
Software
- MATLAB R2023b or later
- Simulink
- Example vehicle parameters (mass, drag coefficient, frontal area, tyre radius, gear ratio)
Extra parts and data
None beyond the software above.
Key concepts
- Road-load equation
- F = m·g·Crr·cosθ + ½·ρ·Cd·A·v² + m·g·sinθ + m·a. Motor force must overcome rolling resistance, drag and grade, and the remainder accelerates the car.
- PID control
- The controller output is Kp·e + Ki·∫e dt + Kd·de/dt. The integral term removes steady error on a hill; the derivative term damps the response but amplifies noise.
- Linearisation
- The plant is non-linear because drag depends on v². Around a cruise speed it can be approximated by a first-order linear system, which lets standard tuning tools be used.
- Actuator saturation
- The motor cannot exceed its torque limit. When the controller asks for more, the integrator can wind up and cause overshoot later.
Step-by-step guide
- 1
Choose vehicle parameters
Use example values for a compact EV: mass 1500 kg including driver, Cd 0.3, frontal area 2.2 m², Crr 0.01, tyre radius 0.3 m, single gear ratio 9 and a motor with 250 N·m peak torque. Write them in a MATLAB script. Compute the steady force needed at 60, 80 and 100 km/h on level road by hand using the road-load equation.
Checkpoint: A parameter script and a hand-calculated table of steady force at three speeds.
- 2
Build the vehicle model
In Simulink, compute drag, rolling and grade forces with Gain, Math Function and Trigonometric Function blocks, subtract them from motor force (torque times gear ratio divided by tyre radius) and divide by mass. Integrate acceleration to get speed with an Integrator block limited at zero so the car cannot roll backwards on level ground. Use a fixed-step ode4 solver at 10 ms.
Checkpoint: With constant torque equal to the hand-calculated value at 80 km/h, the simulated speed settles at 80 km/h.
- 3
Add the actuator
Add a Saturation block limiting motor torque between −100 N·m (regenerative braking) and +250 N·m, and a first-order lag of about 50 ms for motor torque response. Add a speed-dependent torque limit above base speed using a 1-D Lookup Table if the motor has a constant-power region. Test with a full-torque step. Log torque, motor speed and power so the constant-power limit can be checked on a plot. Confirm that the power never exceeds the chosen rating at high speed.
Checkpoint: Acceleration from 0 to 100 km/h at full torque takes a plausible time for the chosen parameters, and torque never exceeds the limits.
- 4
Linearise the plant
Derive a transfer function from torque to speed at 80 km/h by hand, or with Model Linearizer or linearize if Simulink Control Design is available: m·dv/dt = F − ρ·Cd·A·v0·Δv gives a first-order system with time constant m/(ρ·Cd·A·v0). Compare the linear step response with the non-linear model for a small torque step. Repeat the linearisation at 40 and 100 km/h and compare time constants. The change shows why a controller tuned at one speed can behave differently at another.
Checkpoint: Linear and non-linear responses to a small torque step agree closely, and the time constant matches the hand derivation.
- 5
Design the controller
Insert a PID Controller block with speed error as input and torque request as output. Open the PID Tuner (pidTuner) on the linearised plant and choose a PI controller with a response time of about 5 s and a phase margin above 60 degrees. Enable clamping anti-windup with the saturation limits. Save the gains to the parameter script. Check the design on the non-linear model at the tuning speed before moving on. If the PID Tuner suggests a derivative term, note that speed measurements are noisy and add a derivative filter.
Checkpoint: The PID Tuner reports the target response time and phase margin, and the closed-loop step response shows little overshoot.
- 6
Test setpoint changes
Apply steps from 60 to 80 and from 80 to 100 km/h, and a step down from 100 to 70 km/h that requires regeneration. Log speed, torque and error in the Simulation Data Inspector. Measure overshoot, settling time to within 1 km/h and peak torque using stepinfo or a custom script. Run each test at the tuning speed and at a different speed to see the effect of the plant changing with speed. Record the results in a table for the report.
Checkpoint: Overshoot under 1 km/h and settling within about 10 s for each step, with torque saturating briefly only during large steps.
- 7
Test disturbances
Apply a road profile with a 5 per cent uphill section and a 5 per cent downhill section using a lookup of grade against distance. Add a 10 m/s headwind by modifying relative air speed in the drag term. Check that the integral action removes steady error on the hill and that regeneration holds speed downhill. Make the hill long enough for the controller to settle on it. Record the peak speed error and the time to recover within 1 km/h for each disturbance case.
Checkpoint: Speed deviation on entering the hill stays within 2 km/h and returns to zero error; downhill speed is held using negative torque.
- 8
Tuning study
Sweep Kp and Ki over a range with a sim() loop and record overshoot, settling time, peak torque, energy used over a test route and a comfort metric such as RMS jerk. Compare P, PI and PID versions. Show how aggressive tuning saves little time but increases jerk and energy. Use the same route for every run so energy and jerk values are comparable. Mark the chosen gains on the plot and explain why that point was selected.
Checkpoint: A table or Pareto plot of settling time against RMS jerk for the tested gains.
- 9
Report
Present the model equations, parameter table, linearisation, controller design and test results with plots. Discuss the effect of saturation and the role of anti-windup. State that the model ignores tyre slip, driveline compliance and driver override logic, and how each would change the design. Include the parameter script and the test scripts in an appendix so the results can be reproduced. Note any test where the controller did not meet its target and suggest the cause.
Checkpoint: A report with reproducible plots and a clear final gain choice justified by the tuning study.
Testing & validation
- Steady speed at a constant torque matches the road-load hand calculation.
- Linear model matches the non-linear model near the operating point.
- Setpoint and hill tests meet overshoot and settling targets.
- Torque stays within motor limits in all tests.
Expected results
A non-linear EV longitudinal model with a tuned PI cruise controller, verified on setpoint changes, hills and wind, with a tuning study showing the trade-off between responsiveness, comfort and energy.
Take it further
- Gain-schedule the controller across speed.
- Add adaptive cruise control with a lead vehicle and gap control.
- Add a speed-limit-aware energy-saving mode.
- Generate code for the controller and run it in software-in-the-loop.
Viva and review questions
Why is integral action needed for cruise control on a hill?
A hill adds a constant disturbance force. A proportional controller alone needs a steady error to produce the extra torque, while the integrator builds up the torque and drives the error to zero.
Why does the plant time constant change with speed?
The linearised drag term depends on cruise speed, so at higher speed the damping is larger and the time constant shorter.
What does anti-windup do here?
It stops the integrator from growing while the torque is saturated, which prevents a large overshoot when the car finally reaches the setpoint after a long climb.
Learn it at DIYguru
These DIYguru courses and programmes teach what this project needs.
