ELEC0021 : Programming and Control
Laboratory Exercise on Feedback Control Systems
1 Learning Objectives
• To learn how to build Simulink models for feedback control systems and observe and measure the behaviour of such systems.
• To be able to relate feedback control theory to simulation and numerical results using widely-used software tools like Matlab and Simulink.
2 Preparation
2.1 Reading
Consult the notes “ ELEC0021: Matlab and Simulink basics for Control Systems Design" and watch the Youtube videos, available from the Moodle page of the ELEC0021 module (Preparation section for the Control Lab). The notes discuss how you can use MATLAB commands and Simulink environment to perform. the tasks for this lab. The videos introduce some of the topics you will find in the Lab.
It is mandatory that you read the `About the software' part of this document and familiarise yourself with Simulink as part of your pre-lab preparation.
2.2 Checklist
Make sure you are familiar with the following terms before the lab session:
• Stable, Marginally stable and unstable systems
• Steady-state error
• Feedback path, forward path
• Forward path transfer function
• Open-loop transfer function and closed-loop transfer function
• Loop gain
• Characteristic equation
3 About the software
For this Lab you need to use Matlab and Matlab Simulink. Simulink is a graphical tool that allows us to simulate feedback control systems. Open Simulink by simply typing simulink at the MATLAB prompt. Once Simulink has loaded, create a new model by pressing CTRL+N (or click the \New Model" button). You can begin placing components from the component library by dragging and dropping them in the model space. You can make connections by dragging the connection wires to the input junctions. You can zoom in/out by pressing CTRL+\+" / CTRL+ \{". You can change the simulation time by setting the value in the related box, and then run your model by pressing the green \run" button.
Components: For this lab, you will need to be concerned with a small fraction of Simulink's component library. In particular, you should be familiar with the following:
• “Continuous" library: Integrator, Transfer Fcn
• “ Math Operations" library: Gain, Sum, Trigonometric Function
• “Sinks" library: Scope (used for viewing the system output), ToWorkspace (used to transfer a signal to Matlab), and the Simulation Data Inspector
• “Sources" library: Ramp, Sine Wave, Step (which generate the corresponding signals) Modications of Components: You can modify component properties by clicking on them and changing the default settings given by Simulink. For example:
• double-clicking on the “Gain" component, you can alter the gain parameter (you can also use expressions, such as 10.3/2.5)
• double-clicking on the “Sum" component you can change the signs
• double-clicking the “Scope" to open the scope output; right-clicking on the scope output and selecting “Autoscale" will automatically scale the output range of the scope
• double-clicking on the “ToWorkspace" component and changing the “Save format" to “Array"; after you run the simulation, you will then be getting the outputs in the workspace variable “ simout"
4 Lab tasks
This Lab is composed of three parts: Lab A, Lab B and Lab C.
Lab A: Cruise Control
Learning Goals
• Compare and contrast open-loop and feedback control.
• Implement a simple open-loop controller in Simulink.
• Analyse the performance of an open-loop controller.
• Implement a proportional controller in Simulink.
• Analyse the performance of a proportional controller.
Introduction and review
Cruise control is possibly the most intuitive of all control applications. The goal of cruise control is to accelerate to and maintain a desired speed. If the vehicle slows down, the motor should be fed gas (or electricity, depending on the type of vehicle) to increase the speed. If the vehicle moves too quickly, the supply to the motor should be reduced, slowing the vehicle down.
This is the basic premise for any control scheme: configure the system's inputs to achieve a desired output.
There are two basic strategies that can be used for cruise control: open-loop control and feedback control.
1. In open-loop control, information about the vehicle is used to decide how much gas or electricity should be supplied to the motor. No information about the current speed of the vehicle is used. For example, suppose that you know exactly how far to push the gas pedal down to reach a maximum speed of 60mph. Place a bar that lodges the gas pedal in that location. This is an open-loop controller with a setpoint of 60mph.
Open-loop control: the controller decides what the input should be with no knowledge of the current speed. This is called "open-loop" control since there is no feedback.
2. In feedback control, the vehicle's current speed is used to calculate how much gas or electricity should be supplied to the motor. If the vehicle is not moving fast enough, the supply is increased. If it moves too quickly, the supply is decreased.
Feedback control: the controller decides what the input should be based on the difference between the current and desired speed (called the setpoint). This is called "feedback" control because the output of the system is "fed back" into the controller.
In this lab, you will implement and test cruise control algorithms using both open-loop and feedback control.
Part 1 : Open-loop control
In this part of the lab, you will implement and test a simple gain open-loop controller. The setpoint is the desired value of the output (in this case, the desired speed). The plant is the system to be controlled (the vehicle) .
A simple open-loop control scheme. The controller multiplies the setpoint by a gain, k .
In this scheme, the setpoint is specified first. Then, the controller multiplies the setpoint by the appropriate gain to produce the desired output. If the behaviour of the plant is linear, then a change in the setpoint will result in a proportional change in the output.
Task 1. Open the provided virtual vehicle model VirtualVehicle.slx and implement the simple gain open- loop controller. To do so, add and or delete blocks so that it matches the Simulink diagram below.
Simple open-loop control Simulink model
Hint: Double-click anywhere on the Simulink canvas and type the name of the block you want to add.
To create the model, use:
• AConstantblock with a value of 50 (this represents the setpoint of 50 mph) . Double-click the constant block to change its value.
• TwoGainblocks. The first is the gain controller. The second gain block should convert from m/s to mph, so set its value to 2.237.
• AScopeblock so that you can observe the speed.
• Double-click the vehicle image to open the virtual vehicle dialog parameters. Set the Traction force saturation limit to 14800 and the Disturbance type to none.
Task 2. Set the controller gain to 100. Does the vehicle reach the setpoint of 50 mph? Reflect on why. Task 3. Identify the value of the controller gain that causes the vehicle to reach a top speed of 50 mph.
Task 4. Suppose that the plant is linear and the gain is set to the value you identified in Task 3. If the setpoint is changed to 70 mph, what top speed will be reached?
Task 5. In this task, you will check if the plant displays linear behaviour.
a. Change the setpoint in the Simulink model to 60 mph. What is the final speed of the vehicle (round to the nearest mph)?
b. Increase the setpoint to 70 mph. What is the final speed of the vehicle (round to the nearest mph)?
Task 6. Based on your observations in Task 5, is the plant linear?
Task 7. Consider the case where a vehicle drives up a hill. To view this in the model, perform the following.
• Double-click the virtual vehicle block and set the Disturbance type to hill. Set the disturbance height to 50 m.
• Change the setpoint to 50 mph. Run the model. What do you notice? Can you motivate why?
• View the vehicle speed in the scope. What is the minimum speed reached while driving up the hill in mph?
• Save the plot in the scope as a figure suitable to be included in a report to motivate your previous answer (choose a suitable zoom, properly define axis names and title, define a legend if suitable, white background, readable values and fonts, … ).
Part 2 : Feedback control
The main drawback of open-loop control is that it cannot account for disturbances in the system. For example, driving up a hill poses a real challenge for the open-loop cruise controller developed in the last section. On the other hand, a feedback controller modifies its behaviour based on the system's current state. When driving up a hill, the feedback control loop will increase the engine supply as the car begins to slow.
A simple feedback controller is the proportional controller. It can be summarized in two steps:
1. Take the difference between the setpoint (desired speed) and the output variable (current speed). This difference is the error e(t) .
2. Multiply the error term by a constant gain kp to generate the control signal u(t) . This provides the input to the plant.
Block diagram of a proportional feedback controller. The error e(t) is computed as the difference between
the setpoint and the output variable. The control signal u(t) is proportional to the error e(t) .
Note that the proportional controller can be thought of as a PID controller (proportional-integral-derivative controller) without the integral or derivative terms.
In this part of the lab, you will implement and test a proportional controller.
Task 8. Open the provided virtual vehicle model VirtualVehicle.slx and implement the proportional controller. To do so, modify the model so that it matches the Simulink diagram below.
Virtual vehicle with a proportional controller
Open the virtual vehicle dialog parameters. Set the Traction force saturation limit to 14800, the Disturbance type to none, and turn on braking by checking Allow braking.
Task 9. Set kp= 1 . Run the model and observe the output in the scope. What is the maximum speed reached in mph (round to the nearest hundredth)?
Hint: You can measure values in the scope using Cursor Measurements. From the Scope menu, select Tools > Measurements > Cursor measurements. Select and drag the vertical lines to change the measurement location.
Task 10. The speed reached by the vehicle is nowhere near the setpoint of 50 mph. The input to the
virtual vehicle model has units of Newtons, so a gain of 1 is far too low to achieve the desired speed. Set k,= 5000 and rerun the model. What is the maximum speed reached in mph (round to the nearest tenth)?
Task 11. Try several different setpoints with the gain value. Does the feedback controller work across a broad range of requested speeds?
Task 12. Notice that even with K,=5000 , the system still does not exactly reach the setpoint. To understand why this happening, connect a scope to the output of the Gain block kp. Also, reset the setpoint to 50 mph. By connecting the scope to the output of the gain block, you areviewing the control signal u(t) . You should notice that the control signal is very large at the start of the simulation. At this time, there is a significant difference between the setpoint and the current speed, so the error is substantial. This induces the car to accelerate quickly. When the current speed is close to the setpoint, the control signal diminishes alongside the error. What is the steady value of the control signal?
In the steady state, the control signal is nonzero and is, in fact, quite large. However, the vehicle does not continue to accelerate because of the frictional forces acting against the vehicle. This implies that when the vehicle reaches its steady state, there is a difference between the speed of the vehicle and the setpoint. This is known as steady-state error. What is the steady-state error in the considered scenario?
Adding an integral term to the controller (creating a PI controller) is one method to reduce the steady-state error.
Task 13. Feedback control is often more robust than open-loop control. To view this in the model, perform. the following.
• Double-click the virtual vehicle block and set the Disturbance type to hill. Set the disturbance height to 50 m.
• Ensure that the setpoint is 50 mph and then run the model. Notice in the Mechanics Explorer that the car slows down while going up the hill.
a. What is the minimum speed reached while driving up the hill in mph (round to the nearest mph)?
b. Does the proportional controller control perform better or worse than the open-loop controller while the vehicle is driving up the hill?
Lab B: Vehicle Transfer Function Model
Learning Goals
• Derive the transfer function of a first order system.
• Compare the transfer function and virtual vehicle responses.
• Identify the model parameters for the virtual vehicle.
While designing a controller, you typically do not use the real system. Instead, you identify a model of the system and use it to design a suitable controller. In this lab, you will construct a transfer function model of a virtual vehicle. You will validate the model and analyse how it behaves in the presence of a disturbance
(driving up a hill).
First order transfer function model
In a very simple representation, a vehicle can be modelled as a mass with two forces acting on it. The engine generates a force in the forward direction. In the opposite direction, a frictional force slows the vehicle down.
Diagram of a simple vehicle model driving on a flat road
In this model, the variables and parameters are:
• x , , 求 : the position (m), velocity (m/s), and acceleration (m/s2) of the vehicle in the direction of travel, respectively
• u : traction force generated by the engine (N)
• m : vehicle mass (kg)
• b : coefficient of friction (N · s/m)
The differential equation model is constructed using Newton's second law:
mi=-bi+u (1)
The traction force is considered to be the input to the system and is therefore labelled u . A cruise control system attempts to determine the value of u to achieve a desired response.
In this part of the lab, you will solve for the velocity transfer function and compute the step response in MATLAB.
Task 1. Rewrite the equation of motion ( 1) in terms of the velocity, v=i.
Task 2. Compthe(ute) velocity transfer function:
G(s) = U(s)/V(S)
where U(s) is the Laplace transform of u and V(s) is the Laplace transform of the velocity v(t) . Use zero initial conditions.
Task 3. Suppose that the vehicle has a mass m= 1000 kg and a coefficient of friction b = 150 N · s/m. Define the transfer function in MATLAB usingtf.
Task 4. Plot the step response for the first 60 seconds using thestepfunction. The step function has the syntax step(sys,Tfinal)
where sys is a dynamic system (here, the transfer function G) and Tfinal is the simulation stop time. Save the plot as a figure. What is the steady state value for the step response?
Task 5. With only a 1 N force applied to a 1000 kg vehicle, the maximum speed is very low. Increase the
force applied to the vehicle to 5000 N by multiplying the transfer function by 5000. Then, recompute the step response.
a. What is the maximum speed achieved by the vehicle with this input in m/s?
b. What is the maximum speed in mph? Virtual vehicle
The velocity transfer function estimates how a vehicle will respond to variations of the input force, u . These may or may not match the characteristics of the actual vehicle under consideration. In this part, you will
compare the response of the virtual vehicle to the velocity transfer function.
Task 6. Open the virtual vehicle model VirtualVehicle.slx and run it. You should notice in the
Mechanics Explorer that the vehicle doesn't move. This is because no traction force is applied to the vehicle.
Task 7. Modify the Simulink model so that it computes the step response of the virtual vehicle. Double-
click the vehicle image to open the virtual vehicle dialog parameters. Set the Traction force saturation limit to
14800 and the Disturbance type to none.
Task 8. Run the model using . The vehicle may not appear to move (it should move, but very slowly),
because only a 1 N force is applied by a step input. Double-click the scope to view the velocity. What is the steady-state velocity?
a. What is the maximum speed reached in m/s (the default unit of the vehicle model)?
b. For a first order system, the time constant T is defined as the amount of time it takes to reach 63% of the final value. What is the time constant of the virtual vehicle?
Hint: You can use the cursor measurement to identify the value from the scope. Using the cursor will not provide the exact answer, but the value estimated using the cursor is acceptable. Ensure the step time on the Step block is zero.
Task 9 . Add aTransfer Fcnblock with the numerator and denominator set to match the transfer function you defined in the previous part of this lab (double click the Transfer Fcn block to adjust its parameters). Then, connect it to the model as shown below.
Simulink model that computes the virtual vehicle and the velocity transfer function step response simultaneously
Run the model and observe the velocity comparison in the scope.
Tip: You can add a legend to the plot. From the Scope menu, select View >
Legend. a. Does the virtual vehicle appear to have the step response of a first order system? b. Do the models share the same time constant?
c. Do the models approach the same final velocity?