Simulation of Dynamic Systems - using Matlab - Simulink or Scilab - Xcos
These notes provide an introduction to using Matlab - Simulink and Scilab - Xcos to model dynamic systems. The steps and methodology are essentially the same regardless of whether Simulink or Xcos are being used. There are differences between some of the Simulink blocks and some of the Xcos blocks, but a someone who has used Simulink will have little difficulty taking up Xcos.
Xcos is available as part of Scilab (which is 'Free and Open Source Software') as a free download from: www.scilab.org.
There are a large number of good texts covering Matlab (rather fewer covering Simulink), but hardly any textbooks covering the use of Scilab and Xcos.
The examples used in these pages are based on the theme of automobiles, their engines and transmissions, which are used to show how different aspects of model can be connected. together.
No prior knowledge of Matlab - Simulink is assumed, but it is suggested that you read the Matlab - Simulink notes before studying the examples listed below in section 7.
For people who do not have access to Matlab and Simulink, the open source software package 'Scilab', similar to Matlab with a graphical component 'Xcos', which is similar to Simulink, is ideal.
a) The note here describes in general terms how to set about developing a model for a complex system
2. Background to Automotive Fuel Systems
For the first 80 years of the automobile, the petrol / air mixture was formed by a carburettor. Despite considerable improvements over the years it was becoming clear by the late 1970s that the carburettor was nearing the limits of its capabilities and the increasing requirements for improved economy and reduced exhaust emissions indicated that a better way of providing the mixture was needed.
Some systems exercising control by a combination of mechanical and electronic devices had been developed by the late 1970s, but it was the developments in electronics in the 1980s and 1990s which lowered the costs of these systems and led to their widespread introduction, so that now there are virtually no new petrol powered cars sold that do not have a fuel injection / engine management system.
For introductory information about fuel injection systems, have a look at the first web site in section 10, below.
3. System Basics
The primary control on the mass of fuel to be injected is the mass flow rate of air into the engine. Although the stoichiometric ratio for air to petrol is about 14.7:1 this in practice needs to be changed significantly for starting, running while the engine is warming up and accelerating (made richer) and economical cruising (made leaner) and for coasting with the throttle closed no fuel is injected until the engine revs. drop below about 1600 rpm. To achieve this a number of sensors provide data for a microprocessor and this is then compared with an operating 'map' and the signal to open the injector for the appropriate length of time is produced and sent to the injectors.
Fuel is supplied at constant pressure to the injectors, typically 266 kPa, so (ignoring very slight possible density changes) the mass of fuel injected is proportional to the time that the injector is open.
Early systems - circa. early 1980s - e.g. Bosch L Jetronic - controlled by a bulky box of electronics:
used a hinged flap, lightly spring loaded, in the inlet tract to measure the air mass flow, however this in itself introduced a pressure drop which slightly lowered the engine efficency and more modern systems (e.g. Bosch LE Jetronic) use hot wire anemometry to compute the air mass flow as this does not cause a significant pressure drop. The electronics were also much more compact.
The key components of the inlet tract are shown above, figure 2.
4. Suggested Initial Assumptions - some of these figures are rounded
i) Ambient air pressure is 100 000 N/m2
ii) The density of air is 1.25 kg/m3
iii) Energy released when petrol is burnt: 46 000 000 J/kg
iv) For 'ideal' combustion the stoichiometric ratio of air to petrol is 14.7:1
v) There is no pressure drop across the hot wire device.
5. Possible Approaches to the Modeling
i) The most basic approach is to assume that the engine torque is proportional to the throttle opening and only one gear ratio is used. This could be modeled with Simulink as shown in the diagram below:
A major problem with the above model is that the engine torque is not just proportional to throttle opening in the transient phase and for the model to be realistic this - and many other factors - needs to be considered.
ii) To determine the build up of engine torque as the throttle is opened,
it is necessary to consider the air mass flow, which will be governed by the pressure
values, P1, P2 and P3 (see figure 2, above). For P3 it is assumed that the inlet
valve is open and the piston is descending.
At low engine speeds the drop in pressure P2 - P3 will be small, this will increase as the engine speeds up and as a first approximation it can be assumed that the pressure drop P2 - P3 is proportional to the engine speed. From typical engine data it might be assumed that at maximum engine revs this pressure drop is about 0.2 P2, ie P3 = 0.8 P2
If it is assumed that the max. engine rpm are 5000, then for any engine speed 'N' between 0 and 5000 the relationship between P2 and P3 is given by:
The relationship between P1 and P2 is somewhat more complex. The flow past the
throttle plate will be roughly proportional to the pressure drop across the plate
and to the projected (perpendicular to the airflow direction) throttle open area
(cross section open area, csoa).
When the throttle is fully open the pressure drop P1 - P2 will be very small at low engine revs and will increase as the engine revs increase.
When the throttle is almost closed the engine is acting as a pump and has to work to pull the air in past the throttle at low revs. (one of the reasons for the low efficiency of petrol engines in heavy city traffic) which results in a large value of P1 - P2, with P2 possibly having a value of about 40kN/m2. At high engine speeds when the throttle is closed the value of P2 will be even lower, about 20kN/m2
NB: It should be noted that choked flow occurs once the pressure ratio: P1/P2 exceeds a critical value. This is given by:
(Pupstream/Pdownstream)crit = ((gamma + 1)/2)(gamma/(gamma - 1))
For gamma = 1.35, the critical pressure ratio is 1.86
If it is assumed that the P1 = 100 000 N/m2, then even if the pressure P2 drops below 53600 N/m2, there will be no further increase in mass flow rate.
Keeping this limitation in mind, it is therefore possible to write an equation for the air mass flow in the form:
6. A suggested methodology for setting up the model
a) Look up the specified maximum engine power output and the engine rpm at which it is developed.
b) Work out how much fuel has to be burnt per second to provide this power. To do this you will have to estimate what the efficiency of the engine is at maximum power output, probably between 30 and 35 % for a petrol engine.
c) Work out the air mass flow rate to burn this fuel under perfect combustion conditions.
d) For tick over (assume 800 - 1000 rpm), when the engine is working as an air pump drawing in air, use vdp (v = the volume of air drawn in per second and dp = the pressure drop from atmospheric to the pressure of the air in the cylinders during the induction stroke) to determine the power absorbed by the pumping in of the air. Again allow for an efficiency of about 30% and calculate the required fuel and then air mass flow rates.
e) The information from (c) and (d) can be used to determine a value of Kt.
With the above information it should be possible to build a more complex and
accurate model of the engine under transient conditions.
f) The steps described so far give the net output power. This can be divided by the engine angular velocity to give the torque. However this needs slight modification, a small number must be added, eg 0.1, as otherwise the calculation will fail immediately due to a 'divide by zero' error.
g) With the net torque available, this can be divided by the total equivalent vehicle inertia at the engine (using a 'Gain' block), to give the angular acceleration of the engine. Examples of how to determine the equivalent inertia of the vehicle are given in some of the module notes.
h) The angular acceleration of the engine can be passed through an 'Integration' block (from the 'Continuous' group) to give the engine angular velocity.
i) The appropriate gain factor can be applied to the engine angular velocity to give the vehicle velocity.
Further elaboration is possible by:
Using 'Switch' elements to change gear based on the vehicle speed.
Introducing a wind resistance component using the vehicle frontal cross section area, drag coefficient and speed.
Once the model starts to get at all complicated, changes in the model often have effects that are very difficult to predict. It is important to make use of lots of 'scopes to see what is happening in different parts of the model when trying to assess how realistic it is.
b) The note here describes how to set up a simple model in Matlab Simulink to simulate single degree of freedom spring - mass - damper system.
The diagram below shows an Xcos model to simulate the above single degree of freedom spring - mass - damper system:
c) The note here, Vehicle Acceleration 1, describes how to set up a simple model to simulate the acceleration of a car driven by constant torque with air resistance proportional to velocity2
d) The note here, Vehicle Acceleration 2, develops the model in (c) to include simulating a gear change by using a switch element.
e) The note here, Vehicle Acceleration 3, develops the model in (c) to include simulating the variation in engine torque with engine speed by using a linear interpolation look up table.
e2) The note here, Vehicle Acceleration 3b, combines the two previous models by incorporating a one dimensional look up table with gear changes.
e3) This model here, Vehicle Acceleration 3c, introduces greater realism in the gear changing process by putting in a time delay which simulates zero torque transmission during the gear change.
f) The note here, Vehicle Acceleration 4, develops the model in (e) to include simulating the variation in engine torque with engine speed and throttle opening by using a linear interpolation two dimensional look up table.
For information about setting up a 2D look up table in Simulink, click here
g) In this example (fuel1), Vehicle Acceleration 5, a somewhat different approach is taken using throttle position and engine rpm as the inputs to a 2d look up table whose output is assumed to be air mass flow rate.
h) In this model (fuel4), Vehicle Acceleration 7, the pressure drop across the throttle, the effect this has on the air mass flow rate and the cross section area opened by the throttle for the air to flow through are all considered. Again a single gear is assumed.
j) In this Simulink model model (fuel5), Vehicle Acceleration 8, the pressure drop across the throttle plate and across the inlet valve are both considered.
'Bosch Automotive Handbook', 5th Ed., 2000, ISBN: 0-7680-0669-4
'The Motor Vehicle', by K Newton, W Steeds, T K Garrett, 9th Ed., Iliffe, 1972, ISBN: 0 592 00070 2
'Internal Combustion Engines - Applied Thermosciences', by C R Ferguson and A T Kirkpatrick, John Wiley and Sons, 2001, 2nd Ed., ISBN: 0-471-35617-4.
'Introduction to Modeling and Control of Internal Combustion Engine Systems', by L Guzzella and C H Onder, Springer, 2004, ISBN: 3-540-22274-x.
'Design and Simulation of Four Stroke Engines', by G P Blair, SAE, 1999, ISBN: 0-7680-0440-3.
'Introduction to Matlab 6 for Engineers', by W J Palm III, McGraw-Hill, 2001, ISBN: 0-07-234983-2.
Web Site How Stuff Works - Auto
10. Websites about Bosch fuel injection systems, etc.:
David J Grieve. Modified: 21st January 2015, 10 October 2014, 14th March 2011.