Electric Vehicle Drive Simulation With MATLAB/Simulink
Electric Vehicle Drive Simulation With MATLAB/Simulink
Electric Vehicle Drive Simulation With MATLAB/Simulink
David McDonald
LSSU Sault Ste Marie, MI 49783
dmcdonald@lssu.edu
Abstract
The paper presents the simulation of a basic electric vehicle motor-drive system that is used to
investigate power flow during both motoring and regeneration. The simulation assumes a DC
permanent magnet motor, an ideal motor controller combined with a proportional-integral
controller, and the electric vehicle battery. The model can be used to evaluate the electric drives
energy flow and efficiency for specific speed and torque load conditions. Some of the key
system parameters were specified and others were modeled as ideal. A stable
MATLAB/Simulink model was developed and validated. It was then used to determine the
system performance and energy flow over a given set of motoring and regeneration speed/torque
conditions. The model could be used to augment instruction in energy conversion or vehicle
systems courses.
Introduction
This past year electric vehicles were mass produced for the first time in history, and there is a
need to include more learning experiences that are related to that topic. The 2010 2020 time
period has been described as the upcoming tipping point the transition from the Internal
Combustion Engine (ICE) as the prime mover of vehicles to electric propulsion systems. 1
Education is really the important foundation for where the industry is headed in this field. 2
Currently there are no ABET accredited Automotive Engineering or Technology degree
programs that contain electric vehicle courses3. A literature search for electric vehicle
educational revealed a few single-offering or special topics courses,4-9 The Department of
Energy has awarded funds under the Advanced Electric Drive Vehicle Education Program to
support the development of new courses for graduate, undergraduate, secondary students,
teachers, technicians, emergency responders, and the general public. 10, 11 However, industry is
largely training engineers in-house, and educational experiences in this technology are needed
now to prepare a well trained and educated workforce to support the development of Smart Grid
and Electric Vehicle applications.
In addition to the growth in new technology, the design process in industry has also experienced
significant change in recent years. Model-Based Design is now commonly used in automotive,
aeronautical, and other industries for complex embedded systems. 12-15 Traditional design
workflow follows a sequential path that involves: a) Requirements, b) Design, c)
Proceedings of the 2012 North-Central Section Conference
Copyright American Society for Engineering Education
Implementation, and d) Test and validation. Problems with traditional design can develop when:
1) specifications must be read and understood by different engineers on different teams, 2)
application engineers have to rewrite design engineers algorithms, or 3) the problem is not
found until the testing phase.
Model-Based Design uses models early in the process to create executable specifications that
allow engineers to immediately validate and verify specifications against the requirements.
Engineers then share models that can demonstrate the performance of the subsystems and
components, and also use the automatic code generation capability of Simulink/Real Time and
Embedded Coder to facilitate Hardware In the Loop (HIL) testing.
Simulation is a key tool that facilitates design while reducing the cost of product development.
As the design process evolves engineers can perform Model-In-The-Loop (MIL), Software-InThe-Loop (SIL), and Hardware-In-The-Loop (HIL) development modeling model is the design.
By integrating simulation within the design process engineers can decrease both design costs and
design time thus enabling companies to complete and test designed items.
Drive Cycle
To assist in the design process, vehicle driving tests and vehicle driving simulations are
completed to help support the design process to determine if the design is appropriate for the
desired application.
A driving cycle is a set of second-by-second set of vehicle velocity values that the simulated
vehicle is to attain during the simulation. The need of a drive cycle is to reduce the quantity of
expensive on-road tests, and also reduce both the time of test and fatigue of the test engineer.
The drive cycle process brings the road to the dynamometer or to the computer simulation.
Drive cycles are used in vehicle simulations to model the drive system and predict the
performance of the drive system. There are many standard driving cycles used for testing road
vehicles for fuel economy and other purposes. Some driving cycles are developed theoretically,
and others are direct measurements of a representative driving pattern. A driving cycle can
include frequent speed changes or extended periods at constant speed. An example of vehicle
simulator is ADVISOR produced by AVL Engineering16 and other on-line road load and fuel
economy simulations.17
the rolling resistance, air resistance, and gradient resistances are known or can be calculated.
Information on these calculations is available in literature.18-20
Motor
Model
Road Torque
160
Battery
Model
PI Controller
Model
KP
VH
VH
RoadTrq
0.0001
VH
VL
TRQ
VL
VL
Torque
IH
B Err
Kval
Road Speed
2999.8
Kp
KP
RoadSpd
PH
IL
SPD
IH
EA
Speed
MtrMdl
BErr
BErr
PI
KI
IL
0.004
IH
Ki
KI
CtrlMdl
PICtrl
BattMdl
Kval
Memory with 0.1IC
The model does not include power loss due to friction and other rotational losses of hysteresis,
eddy current, and windage. The model also does not include the time lag due to energy storage
in the rotor inertia. The motor model is based on the following equations.
Developed Torque is proportional to armature current:
Equation 1:
Td(Nm) = Km*IA(Amp)
Motor armature input or terminal voltage is equal to the sum of developed voltage plus resistance
and inductance voltage drops. In addition, the motor High Side voltage and current are directly
connected to, and therefore identical to, the motor controller High Side voltage and current.
Motor Controller:
The motor controller is assumed to be an ideal controller with no power loss and no time lag.
The controller simply raises the battery voltage to meet the higher voltage needs of the motor.
The dimensionless constant gain or K ratio of the input and output voltages is determined in
order to meet the motors needs. The same K ratio is used to adjust the current so that input and
output power values are equal.
Proceedings of the 2012 North-Central Section Conference
Copyright American Society for Engineering Education
High side current is equal to 1/K times the low side voltage:
Equation 5: IH = (1/K)*VL
Battery:
The battery is modeled as a voltage source with an internal resistance. The model accounts for
internal power loss in the resistance of the battery. There is no time lag component in the model.
The battery is assumed to have a constant internal voltage, E B . The battery terminal voltage,VB ,
is equal to the sum of the internal voltage and resistance voltage drop. The battery voltage and
battery current are equal to the controller low side voltage and current.
Equation 6: VB (Volt) = IA(Amp) *RA(Ohm) + EB(Volt). Battery model calculation
VL (Volt) = IL(Amp) *RA(Ohm) + EB(Volt).
Assuming: VB = VL and IA = IL
The battery model uses the current and voltage information from the Motor Controller to
calculate the required batterys internal voltage. This voltage is compared with the actual E B
value to create a battery voltage error, BEER, and that error is used by the PI controller model to
adjust the loop gain.
Equation 7: BERR = EB (actual) - EB (calculated)
PI Calculation
1/Km
1/1.7189
TRQ
Torque
0.3
Ra = 0.3
VH = Ea+IR + Ldi/dt
IaRa
IH
VH
Gain
di/dt
du/dt
L = 0.015
0.015
IH = TRQ/Km
IH
Derivative
PH = VH * IH
2*pi / 60
Speed (rev/min)
2
PH
Km = 1.7189
Power
Km
0.105
1.7189
EA = Speed (rad/sec) * Km
SPD
Gain5
EA
Gain1
MOTOR CONTROLLER
VH / K
VH
1
1
VH
VL = VH / K
VL
Product1
2
Kval
IH
IL = K * IH
IL
3
IH
Product
K * IH
BATTERY MODEL
VL
1
VL
RBat = 0.01
IL
2
IL
0.01
B Err
B Err
RBAT
200
Eb
Eb = 200
PI Controller Model: The block model includes Equation 8 for the controller.
The Gain (K) of the Motor Controller is determined by the output of the PI Controller model.
The gain has an initial starting value of 0.1. This value was preset within the controllers
integration block to minimize the possibility of a Simulink simulation error due to an algebraic
loop. An algebraic loop is basically a divide by zero operation when the simulation is trying to
solve the set of linear equations.
The PI Controller checks to see that the output is not zero. If the output is zero then the
controller outputs a small value ( 0.001). This is done to prevent model analysis failure due to
dividing by zero when solving the linear equations. The controller also includes a gain limiting
block to prevent excess feedback signals.
The block is shown below in Figure 6: PI Controller Model Block
PI BLOCK
IF INPUT TO MIDDLE (2ND INPUT) IS ABOUT ZERO,
THEN THE SWITCH PASSES THE TOP (1ST INPUT) VALUE.
KP = 0.001
Multiply
Kp
KP1
1
0.001
Kp
BErr
ABS
Mult1
BErr
KI
|u|
Mult
Multiply
PI
IC = 0.1
3
Ki
~= 0
1
s
Abs
Switch
Saturation
Integ
1/s Integrate
PI
K = BErr*(Kp + KI/s)
ROAD SPEED,
TORQUE & POWER
RoadSTPvals
REQUIRED BATTERY
VOLTAGE, CURRENT
AND POWER
MOTOR VOLTAGE
CURRENT, POWER
MtrVIPvals
BattVIPvals
VL
Simulink Look Up
Tables Used for Specified
Speed and Torque Values
RdP
RdSpd
VH
TRQ
BattVIP
VH
IH
SPD
1-D T(u)
IH
EA
Motor Mdl
SysClock
RdSpdVals
SimTimeVals
VL
KP
MOTOR MODEL TO
DETERMINE VOLTAGE
CURRENT AND POWER
DRAW FROM THE
BATTERY
0.0001
VL
Kv al
PH
BV
IL BC
RoadPwr
RdTrqVals
Kval
BP
RdTrq
1-D T(u)
BattErrVal
B Err
IL
BErr PI
IL
Motor Controller
Kp
0.004
Battery Mdl
Ki
PI Controller
KI
Memory
-220
80
0
85
0 ];
100 ];
10
20
30
40
50
Time(sec)
Required Road Torque
60
70
80
90
100
10
20
30
40
50
Time(sec)
Required Road Power
60
70
80
90
100
90
100
RoadTrq(Nm)
400
200
0
-200
-400
Road Power(Kw)
x 10
1
0
-1
0
10
20
30
40
50
Time(sec)
60
70
80
Figure 9: Road Speed, Torque and Power Curves Showing Motoring and Regeneration
10
20
30
40
50
Time(sec)
Required Road Torque
60
70
80
90
100
10
20
30
40
50
Time(sec)
Required Road Power
60
70
80
90
100
90
100
RoadTrq(Nm)
400
200
0
-200
-400
Road Power(Kw)
x 10
1
0
-1
0
10
20
30
40
50
Time(sec)
60
70
80
Figure 10: Motor Voltage, Current and Power Curves Showing Motoring and Regeneration
proportional to current. Thus as the torque requirement increases, then the motor must draw
more battery current.
Motoring and Regeneration
The Battery Power plot in Figure 11 shows both Motoring and Regeneration. When both current
and voltage are positive values then the DC Motor is providing torque in the direction of rotation
and power is being transferred to the load. This is normal motoring operation. However, when
the motor current is in the opposite polarity of the voltage, then the motor is being pushed and
acting as a generator with current flow back into the battery.
Battery Energy
The energy dissipated in motoring and recaptured in regeneration was determined by performing
numerical integration of the power curve. Figure 11: Battery Voltage, Current and Power Power
(Watt) is to the change of Energy(Joules) with Time (Seconds). Therefore the integral of the
power curve is equal to energy in Watt*Seconds. The numerical integration was performed in
MATLAB using the trapezoidal rule function, trapz(power,time). The resulting value was then
divided by 3600 to get energy in WattHours.
Battery Voltage (Volt)
300
200
100
0
0
10
20
30
40
50
Time(sec)
Battery Current (Amp)
60
70
80
90
100
10
20
30
40
50
Time(sec)
Battery Power
60
70
80
90
100
90
100
600
400
200
0
-200
-400
4
Motor Power (Watts)
Motor Current(Amps)
Motor Voltage(Volts)
400
x 10
3
2
(+V)*(+I)= +P Motoring
(+V)*(-I)= -P Regeneration
1
0
-1
0
10
20
30
40
50
Time(sec)
60
70
80
200
100
Max Positive Battery Error = 76.9
-100
Max Negative Battery Error = -200
-200
-300
20
40
60
80
Time(sec)
100
Controller Gain
The Gain (K) of the Motor Controller is determined by the output of the PI Controller model. A
plot of the value of the Controller Gain (K) during the simulation is shown below in Figure 13:
Controller Gain K Value. The controller gain increases during the time when the motor speed is
increasing, and decreases when the motor speed is decreasing.
The gain has an initial starting value of 0.1. This was preset within the controller in the 1/s
integration block. This value is set in the simulation by opening up the 1/s block. The addition
of the Initial Condition on the integration block helps to minimize the possibility of a Simulink
simulation error due to an algebraic loop. An algebraic loop is basically a divide by zero
operation when the simulation is trying to solve the set of linear equations.
Controller Gain (K)
3.5
Max K value = 2.82
3
2.5
Gain
2
1.5
1
0.5
Min K value = 0.1 Set by PI
0
-0.5
20
40
60
Time(sec)
80
100
Summary:
Simulation is a very real and necessary part of electric vehicle development and needs to be
integrated into learning experiences within engineering education. Simulation-based testing in
the form of Hardware-In-The-Loop testing is also a very necessary part of current engineering
development especially in advanced systems such as hybrid and electric vehicle drive systems
that rely heavily on complex embedded system subsystems. Student learning experiences that
include simulation based design and testing are necessary to include in undergraduate
engineering education in order to prepare students for current industry employment.
Proceedings of the 2012 North-Central Section Conference
Copyright American Society for Engineering Education
Acknowledgement:
A portion of the simulation presented here was developed by the author as part of an open ended
project in the course AEV 5010 Introduction to Advanced Electric Vehicles. The course is part
of the new Advanced Electric Vehicles graduate degree program at the University of Detroit
Mercy22. The course was taught in Fall 2011 by Dr. M Abul Masrur and used the textbook
Hybrid Electric Vehicles that is listed in the references. In addition to teaching at UDMercy, Dr
Masrur is a research engineer at the US Army RDECOM-TARDEC where he does research
related to hybrid electric vehicles. He was previously with the Scientific Research Labs at Ford
Motor Company.
References:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
http://www.virtual-car.org/wheels/wheels-road-load-calculation.html
http://www1.eere.energy.gov/vehiclesandfuels/pdfs/success/advisor_simulation_tool.pdf
Fundamentals of Vehicle Dynamics, Gillespie, SAE, ISBN 1-56091-199-9 pgs 110-115
Hybrid Electric Vehicles, Mi, Masrur & Gao, Wiley, ISBN 978-0-470-74773-5 pgs42-45
Electric and Hybrid Vehicles Design Fundamentals 2nd Ed. Iqbal Husain, CEC Press, ISBN: 9781-4398-1175-7
Td(Nm) = Km*IA(Amp)
High side current is equal to 1/K times the low side voltage:
Equation 5: IH = (1/K)*VL
The battery terminal voltage,VB , is equal to the sum of the internal voltage and resistance
voltage drop. The battery voltage and battery current are equal to the controller low side voltage
and current.
Equation 6: VB (Volt) = IA(Amp) *RA(Ohm) + EB(Volt). Battery model calculation
VL (Volt) = IL(Amp) *RA(Ohm) + EB(Volt).
Equation 7: BERR = EB (actual) - EB (calculated)
Assuming: VB = VL and IA = IL
Error Voltage Calculation
The PI controller accepts the BERR signal from the Battery Model and uses proportional (Kp) and
integral (Ki) to calculate the gain K value that is used by the Motor Controller.
Equation 8: K = ( Kp + s*KI)*BERR
PI Calculation
% The data from the Scope blocks are stored in structures, and the
% structures are copied to the MATLAB Workspace.
%
% Run the Simulation
sim('AEVAssign2.mdl')
%
When the script runs the resulting key data is displayed on Scopes in the simulation and loaded into the
MATLAB Workspace as a structure. The individual signals need to be retrieved from the structures so
the data can be plotted. This section also uses numerical integration to determine the energy during
motoring and regeneration.
%% Part 3: Retrieve signal data from MATLAB Workspace.
%
% Data values for each model Scope are packaged as a Structure and saved
% to the MATLAB Workspace. The following commands retrieve each set
% of variable data from the structures in preparation for plotting.
%
% Time data from the Save to Workspace block
Time = TimeVal.signals.values;
%
% Road Torque, Speed, Power data from the Motor Model Block
RoadTrq = RdTSP.signals(1,1).values;
RoadSpd = RdTSP.signals(1,2).values;
RoadPwr = RdTSP.signals(1,3).values;
%
% Motor Voltage, Current and Power from the Motor Model Block
MtrV = MtrVIP.signals(1,1).values;
MtrI = MtrVIP.signals(1,2).values;
MtrP = MtrVIP.signals(1,3).values;
%
% Battery Voltage, Current and Power from the Battery Model Block
BattV = BattVIP.signals(1,1).values;
BattP = BattVIP.signals(1,2).values;
BattI = BattVIP.signals(1,3).values;
%
% Battery Eb voltage error from the BattErr structure
BattErr = BErr.signals.values;
%
% Motor Controller Gain K value from the Controller structure
K
= Kval.signals.values;
%% Calculate Battery Energy
%
% Used Trapezoidal Rule to determine the integral of battery power from
% zero until the polarity changed to negative. The array index just before
% polarity change was 5211.
%
% Energy Used Motoring
BattE_WHr_Mtr = trapz(Time(1:5211),BattP(1:5211))/3600;
Proceedings of the 2012 North-Central Section Conference
Copyright American Society for Engineering Education
%
% Repeated to find energy recaptured by regeneration.
BattE_WHr_Gen = trapz(Time(5211:10001),BattP(5211:10001))/3600;
The last portion of the MATLAB script plots the data from the Simulation. Because of the length of the
code it is divided into three sections. The first section plots the Road and Motor Data.
%% Part 4: Plot the data in MATLAB Figures
% Plot Road Torque, Speed, Power
%------------------------------------------------------------------------% Plot Road Speed
figure(1)
subplot(3,1,1)
plot(Time,RoadSpd,'k'),xlabel('Time(sec)'),ylabel('Road Speed (MPH)'),grid on
title('Required Road Speed')
axis([ -5 105 -500 3500 ]);
%
% Plot Road Torque
subplot(3,1,2)
plot(Time,RoadTrq,'k'),xlabel('Time(sec)'),ylabel('RoadTrq(Nm)'),grid on
title('Required Road Torque')
axis([ -5 105 -400 500 ]);
%
% Plot Road Power
subplot(3,1,3)
plot(Time,RoadPwr,'k'),xlabel('Time(sec)'),ylabel('Road Power(Kw)'),grid on
title('Required Road Power')
axis([ -5 105 -120000 200000 ]);
text(5,150000,'(+T)*(+S)= +P = 1st Quadrant = Motoring');
text(55,150000,'(-T)*(+S)= -P = 4th Quadrant = Regeneration');
% Plot Motor Voltage, Current, and Power
%------------------------------------------------------------------------figure(2)
% Plot Motor Voltage
subplot(3,1,1)
plot(Time,MtrV,'k'),xlabel('Time(sec)'),ylabel('Motor Voltage (Volts)'),grid on
title('Motor Voltage(Volts)')
axis([ -5 105 -400 600 ]);
% Plot Motor Current
subplot(3,1,2)
plot(Time,MtrI,'k'),xlabel('Time(sec)'),ylabel('Motor Current (Amps)'),grid on
title('Motor Current (Amps)')
axis([ -5 105 -500 500 ]);
% Plot Motor Power
subplot(3,1,3)
plot(Time,MtrP,'k'),xlabel('Time(sec)'),ylabel('Motor Power (Watts)'),grid on
title('Motor Power')
Proceedings of the 2012 North-Central Section Conference
Copyright American Society for Engineering Education