Annex
Annex
2 Matlab code 9
2.1 Matlab Initiation Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Matlab Code for Plotting Results . . . . . . . . . . . . . . . . . . . . . . . . 19
2.3 Matlab Code for comparing vehicle layouts . . . . . . . . . . . . . . . . . . 25
2
List of Figures
3
Matlab model architecture
1.1 Drivetrain
4
1.2. Traction control Block 5
Figure 1.5: Schematic of the Simulink inverter block for the vehicle model.
Figure 1.6: Detail of the inverter operation, where the the rotor phase angle and motor
current are used to obtain the estimated output current of the inverter.
Figure 1.7: Implements a limiter to keep the inverter power output bellow the motor’s
torque and power limits.
1.5. PMAC motor 7
Figure 1.8: Block representing the PMSM motor operation, where the currents generated
by the inverter block are transformed into mechanical torque.
Figure 1.9: PMAC Ideal motor block, which converts the three phase input current into
a torque output
1.6 Gearbox
Figure 1.11: Schematic of the gearbox block for the vehicles model
8 Matlab model architecture
1.7 Tires
Figure 1.12: Schematic of the tire block for the vehicles model
Figure 1.13: Schematic of the environment block tasked with accounting for rolling resis-
tance, aerodynamic drag and road incline
Matlab code
1 %% l o a d d r i v i n g c y c l e s
2 clear all ;
3 close all ;
4 clc ;
5
7 %% S i m u l a t i o n Parameters
8 tstop = 780; % s i m u l a t i o n run time [
sec ]
9 tstep = .01; % maximum s i m u l a t i o n
step [ sec ]
10
11 %% D r i v e r model p a r a m e t e r s y . q
12 Ti = 5 0 ; % i n t e g r a l time c o n s t a n t
13 Kv = 6 5 0 ; % proportional gain
14
15
16 %% T r a n s m i s s i o n Parameters
17
18 g r a t i o =5.5;
19 g_rat_electric = 3.06;
20
21 %% Wheel Parameters
22 rw = 0 . 6 6 8 / 2 ; % wheel r a d i u s f o r
275/40/ r 1 8 t i r e [m]
23
24 %% C h a s i s s p a r a m e t e r s
25 S_weight =800;
26
9
10 Matlab code
21700 c e l l [ Ah ]
29 cell_nom_v = 3 . 7 ; %c e l l ’ s nominal v o l t a g e
30 cell_max_v = 4 . 2 ; %c e l l ’ s maximum
a l l o w a b l e v o l t a g e [V]
31 cell_cutoff_v =3.2; %c e l l ’ s l o w e r cut−o f f
v o l t a g e [V]
32 c e l l _ e n e r g y=c e l l _ c a p a c i t y ∗ cell_nom_v ; %t o t a l c e l l e n e r g y [Wh]
33 cell_nom_curr =15; %c e l l ’ s maximum
c o n t i n u o u s c u r r e n t [A]
34 cell_max_curr =20; %c e l l ’ s maximum
i n t a n t a n e u s c u r r e n t [A]
35
36
37
38 success = false ;
39 while ~ success
40 b = i n p u t ( ’ S e l e c t t h e g e a r r a t i o f o r t h e v e h i c l e (0= d e f a u l t ,
1=s h o r t , 2=medium o r 3= t a l l ) ’);
41 switch b
42 case 0
43 d i s p ( ’ The g e a r r a t i o w i l l remain u n a l t e r e d ( 5 . 5 : 1 ) ’
)
44 success = true ;
45 case 1
46 g r a t i o =3;
47 d i s p ( ’ The g e a r r a t i o s e l e c t e d i s 3 : 1 ’ )
48 success = true ;
49 case 2
50 g r a t i o =5;
51 d i s p ( ’ The g e a r r a t i o s e l e c t e d i s 5 : 1 ’ )
52 success = true ;
53 case 3
54 g r a t i o =7;
55 d i s p ( ’ The g e a r r a t i o s e l e c t e d i s 7 : 1 ’ )
56 success = true ;
57 otherwise
58 d i s p ( ’ P l e a s e , s e l e c t one o f t h e a v a i l a b l e o p t i o n s ’ )
59 success = false ;
60 end
61 end
62
63 success = false ;
64 while ~ success
2.1. Matlab Initiation Code 11
65 b = i n p u t ( ’ S e l e c t t h e d e s i r e d b a t t e r y pack s i z e (1= s m a l l , 2=
medium o r 3= l a r g e ) ’);
66 switch b
67 case 1
68 d i s p ( ’ The b a t t e r y s i z e i s 30 kWh ’ )
69 batt_cap = 30
70 success = true ;
71 case 2
72 d i s p ( ’ The b a t t e r y s i z e i s 50 kWh ’ )
73 batt_cap = 5 0 ;
74 success = true ;
75 case 3
76 d i s p ( ’ The b a t t e r y s i z e i s 70 kWh ’ )
77 batt_cap = 7 0 ;
78 success = true ;
79 otherwise
80 d i s p ( ’ P l e a s e , s e l e c t one o f t h e a v a i l a b l e o p t i o n s ’ )
81 success = false ;
82 end
83 end
84 success = false ;
85 while ~ success
86 b = i n p u t ( ’ S e l e c t t h e number o f motors f o r t h e FRONT a x l e (
choose 0 , 1 or 2) ’);
87 switch b
88 case 0
89 d i s p ( ’ The f r o n t a x l e o f t h e v e h i c l e i s not d r i v e n
by any motor ’ )
90 front_motor = 0 ;
91 success = true ;
92 case 1
93 d i s p ( ’ Front a x l e has 1 motor powering both w h e e l s ’ )
94 front_motor = 1 ;
95 success = true ;
96 case 2
97 d i s p ( ’ Front a x l e has 2 i n d i v i d u a l motors on each
wheel ’ )
98 front_motor = 2 ;
99 success = true ;
100 otherwise
101 d i s p ( ’ P l e a s e , s e l e c t one o f t h e a v a i l a b l e o p t i o n s ’ )
102 success = false ;
103 end
12 Matlab code
104 end
105 success = false ;
106 while ~ success
107 b = i n p u t ( ’ S e l e c t t h e number o f motors f o r t h e REAR a x l e (
choose 0 , 1 or 2) ’);
108 switch b
109 case 0
110 d i s p ( ’ The Rear a x l e o f t h e v e h i c l e i s not d r i v e n by
any motor ’ )
111 rear_motor = 0 ;
112 success = true ;
113 case 1
114 d i s p ( ’ Rear a x l e has 1 motor powering both w h e e l s ’ )
115 rear_motor = 1 ;
116 success = true ;
117 case 2
118 d i s p ( ’ Rear a x l e has 2 i n d i v i d u a l motors on each
wheel ’ )
119 rear_motor = 2 ;
120 success = true ;
121 otherwise
122 disp ( ’ Please , s e l e c t one o f t h e a v a i l a b l e o p t i o n s ’ )
123 success = false ;
124 end
125 end
126
127 %% B a t t e r y pack c h r a c t e r i s t i c s
128
%t r a n s f o r m s t h e c h o s e n b a t t e r y e n e r g y from kWh t o J u l e s
136 SOC_0 = 8 0 ;
% I n i t i a l battery s t a t e of charge [%]
137 Vbat=c e l l _ s e r i e s ∗ 3 . 7 ;
%b a t t e r y pack nominal v o l t a g e [V]
138
139
140 %% C a l c u l a t e s t h e w e i g h t o f t h e b a t t e r y
141
142
143 c e l l s _ w e i g h t =( b a t t _ c e l l s ∗ 0 . 0 6 9 ) ;
144 batt_weight=c e l l s _ w e i g h t ∗ 1 . 5 ;
%b a t t e r y pack w e i g h t asumming each c e l l w e i g h t s 69 g
145 max_curr=cell_max_curr ∗ c e l l s _ p a r a l l e l ;
%max b a t t e r y output c u r r e n t assuming peack d i s c h a r g e
o f 15A
146 nom_curr=cell_nom_curr ∗ c e l l s _ p a r a l l e l ;
%nominal b a t t e r y output c u r r e n t assuming peack
d i s c h a r g e o f 10A
147 max_batt_pwr=max_curr∗batt_nom_v∗1 e −3;
%maximum b a t t e r y power output i n kW
148 batt_pwr=nom_curr∗batt_nom_v∗1 e −3;
%nominal b a t t e r y power output
149
150 %% I n v e r t e r p a r a m e t e r s
151 inv_eff =0.98;
152 regen_eff =0.8;
153
165
166 %% C a l c u l a t e s t h e t o t a l mass o f t h e v e h i c e l g i v e n p r e v i o u s
inputs
167 base_weight = 1 1 0 0 ; %w e i g h t
of the base v e h i c l e c h a s i s witchout powertrain
168 M_weight =140; %wheig
f o r each added motor i n kg ( t e s l a motor taken a s r e f e r e n c e )
169 motor_weight = M_weight ∗ ( rear_motor+front_motor ) ; %
c a l c u l a t e s t h e t o t a l w e i g h t o f a l l motors e x i s t e n t i n t h e
vehicle
170 Mv = ( base_weight+batt_weight+motor_weight ) ; %
c a l c u l a t e s t h e t o t a l v e h i c l e w e i g h t used f o r t h e dynamic
equations
171
172 %% C a l c u l a t e s t h e t i r e v e r t i c a l f o r c e
173
174
204
205
210 %% I n v e r t e r Parameters
211 eta_inv = . 9 6 5 ; % Inverter E f f i c i e n c y ( constant )
212
213 %% Torque v e c t o r i n g p a r a m e t e r s
214 opt_slip =0.18; %optimum t i r e s l i p r a t i o
215 Tv_gain =800;
216
217 %% V e h i c l e p h y s i c a l p a r a m e t e r s
218 Mv = 1 4 2 0 ; % V e h i c l e curb w e i g h t + 120 kg
p a s s e n g e r and c a r g 0
219 W_d = 0 . 5 ; % V e h i c l e s weight d i s t r i b u t i o n fore −
a f t (0 −1)
220 Cd = 0 . 2 6 ; % C o e f f i c i e n t o f Drag
221 Cr = 0 . 0 1 ; % Coefficient of Friction
222 Av = 2 . 7 5 ; % Front a r e a [m^ 2 ]
223 rho_air = 1 . 2 0 4 ; % Air d e n s i t y [ kg /m^ 3 ]
224 g r a d e =0; % Grade o f t h e road � [ ]
225 grav = 9 . 8 1 ;
226 motoreff_T=l i n s p a c e ( 0 , 3 0 0 , 1 0 1 ) ;
227
228 %% Sample t i m e s
229 s_time = 0 . 0 1 ;
230 %% t i r e model p a r a m e t e r s f o r f r i c t i o n c a l c u l a t i o n
231
243
250 %i c e road
251 b_i = 4 ;
252 c_i = 2 ;
253 d_i = 0 . 1 ;
254 e_i = 1 ;
255
256 %% T i r e s e l e c t o r
257
258 %%s e l e c t s s u r f a c e f o r l e f t t i r e
259 %c l c
260
285 e_l=e_w ;
286 else
287 d i s p ( ’ S e l e c t a c o r r e c t s u r f a c e type f o r t h e l e f t t i r e . ’ )
288
289 end
290
291
1 close all ;
2
5 success = false ;
6 while ~ success
7 b = i n p u t ( ’Do you want t o s a v e t h e g e n e r a t e d p l o t s ? 1=y e s 2=
no ’);
8 switch b
9 case 1
10 d i s p ( ’ The p l o t s w i l l be saved t o s e l e c e d f o l d e r ’ )
11 save = 1 ;
12 success = true ;
13 case 2
14 d i s p ( ’ The p l o t s w i l l not be saved ’ )
15 save = 2 ;
16 success = true ;
17 otherwise
18 d i s p ( ’ P l e a s e , s e l e c t one o f t h e a v a i l a b l e o p t i o n s ’ )
19 success = false ;
20 end
21 end
22
23 figure (1) ;
24 h o l d on ;
25 p l o t ( s p e e d s . time / 6 0 , R_speed . s i g n a l s . v a l u e s ( : , 1 ) ∗ 3 . 6 , ’ b ’ , ’
LineWidth ’ , 0 . 7 ) ;
26 plot1 . Color (4) = 0 . 2 ;
27 p l o t ( s p e e d s . time / 6 0 , L_speed . s i g n a l s . v a l u e s ( : , 1 ) ∗ 3 . 6 , ’ r ’ , ’
LineWidth ’ , 0 . 6 ) ;
28 plot1 . Color (4) = 0 . 2 ;
29 p l o t ( s p e e d s . time / 6 0 , Cm_speed . s i g n a l s . v a l u e s ( : , 1 ) ∗ 3 . 6 , ’ y ’ , ’
LineWidth ’ , 0 . 5 ) ;
30 p l o t ( s p e e d s . time / 6 0 , Ve_speed . s i g n a l s . v a l u e s ( : , 1 ) ∗ 3 . 6 , ’ k ’ , ’
LineWidth ’ , 0 . 4 ) ;
31 l e g e n d ( ’ Right wheel s p e e d ’ , ’ L e f t wheel s p e e d ’ , ’ R e f e r e n c e Speed ’ ,
’ V e h i c l e sp e e d ’ ) ;
32 t i t l e ( ’ Vehicle speeds ’ ) ;
33 y l a b e l ( ’ Speed [ km/h ] ’ ) ;
34 s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
20 Matlab code
35 xlim ( [ 0 8 ] ) ;
36 g r i d on ;
37 i f s a v e==1
38 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ v e h i c l e _ s p e e d s ’ ) , ’ png ’ ) ;
39 else
40 end
41
42 figure (2) ;
43 h o l d on ;
44 p l o t ( F o r c e s . time / 6 0 , L e f t _ t o r q u e . s i g n a l s . v a l u e s ( : , 1 ) , ’ b ’ , ’
LineWidth ’ , 1 ) ;
45 p l o t ( F o r c e s . time / 6 0 , Right_torque . s i g n a l s . v a l u e s ( : , 1 ) , ’ r ’ , ’
LineWidth ’ , 0 . 7 ) ;
46 p l o t ( F o r c e s . time / 6 0 , Commanded_torque . s i g n a l s . v a l u e s ( : , 1 ) , ’ k ’ ,
’ LineWidth ’ , 0 . 4 ) ;
47 l e g e n d ( ’ L e f t t i r e t o r q u e ’ , ’ Right t i r e t o r q u e ’ , ’ Torque command ’
);
48 t i t l e ( ’ V e h i c l e output t o r q u e ’ ) ;
49 y l a b e l ( ’ Torque [Nm] ’ ) ;
50 x l a b e l ( ’ Time [ s ] ’ ) ;
51 s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
52 xlim ( [ 0 8 ] ) ;
53 g r i d on ;
54 i f s a v e==1
55 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ torque_output ’ ) , ’ png ’ ) ;
56 else
57 end
58
59 figure (3) ;
60 h o l d on ;
61 p l o t ( d i s t . s i g n a l s . v a l u e s ( : , 1 ) , SOC. s i g n a l s . v a l u e s ( : , 1 ) , ’ b ’ , ’
LineWidth ’ , 1 . 5 ) ;
62 t i t l e ( ’ B a t t e r y SOC vs . D i s t a n c e t r a v e l l e d ’ ) ;
63 l e g e n d ( ’ B a t t e r y SOC] ’ ) ;
64 y l a b e l ( ’ B a t t e r y SOC [ % ] ’ ) ;
65 x l a b e l ( ’ D i s t a n c e [ km ] ’ ) ;
66 g r i d on ;
67 i f s a v e==1
68 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ t e v e l l e d _ d i s t a n c e ’ ) , ’ png ’ ) ;
69 else
70 end
71 %
72 % figure (4) ;
2.2. Matlab Code for Plotting Results 21
73 % h o l d on
74 % p l o t (P . time / 6 0 , P . s i g n a l s . v a l u e s ( : , 1 )−Pmec . s i g n a l s . v a l u e s ( : , 1 )
, ’ b ’ , ’ LineWidth ’ , 1 . 5 ) ;
75 % p l o t ( Pmec . time / 6 0 , Pmec . s i g n a l s . v a l u e s ( : , 1 ) , ’ r ’ , ’ LineWidth ’ ,
1.5) ;
76 % l e g e n d ( ’ P e l e c t r i c ’ , ’ Pmecanic ’ ) ;
77 % t i t l e ( ’ V e h i c l e power output ’ ) ;
78 % y l a b e l ( ’ I n s t . Power [kW] ’ ) ;
79 % s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
80 % g r i d on ;
81 % i f s a v e==1
82 % s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ power_output ’ ) , ’ png ’ ) ;
83 % else
84 % end
85
86 figure (4) ;
87 h o l d on
88 p l o t ( a e r o _ l o s s e s . time / 6 0 , a e r o _ l o s s e s . s i g n a l s . v a l u e s ( : , 1 ) , ’ b ’ ,
’ LineWidth ’ , 1 ) ;
89 p l o t ( a e r o _ l o s s e s . time / 6 0 , r o l l i n g _ l o s s e s . s i g n a l s . v a l u e s ( : , 1 ) , ’m
’ , ’ LineWidth ’ , 1 ) ;
90 p l o t ( a e r o _ l o s s e s . time / 6 0 , i n c l i n e _ l o s s e s . s i g n a l s . v a l u e s ( : , 1 ) , ’ r
’ , ’ LineWidth ’ , 0 . 7 ) ;
91 p l o t ( a e r o _ l o s s e s . time / 6 0 , s p e e d s . s i g n a l s . v a l u e s ( : , 1 ) , ’ k ’ , ’
LineWidth ’ , 1 . 2 ) ;
92 l e g e n d ( ’ Aero l o s s e s ’ , ’ R o l l i n g r e s i t a n c e l o s s e s ’ , ’ I n c l i n e l o s s e s
’ , ’ V e h i c l e sp e e d ’ ) ;
93 t i t l e ( ’ Power l o s s e s due t o t h e environment ’ ) ;
94 y l a b e l ( ’ Power [kW] ’ ) ;
95 x l a b e l ( ’ Time [ s ] ’ ) ;
96 s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
97 xlim ( [ 0 8 ] ) ;
98 g r i d on ;
99 i f s a v e==1
100 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ p o w e r _ l o s s e s _ v e h i c l e ’ ) , ’ png ’ ) ;
101 else
102 end
103
’ , ’ LineWidth ’ , 0 . 5 ) ;
108 p l o t ( d c d c _ l o s s e s . time / 6 0 , i n v e r t e r _ l o s s e s . s i g n a l s . v a l u e s ( : , 1 ) , ’
m’ , ’ LineWidth ’ , 0 . 5 ) ;
109 p l o t ( d c d c _ l o s s e s . time / 6 0 , d c d c _ l o s s e s . s i g n a l s . v a l u e s ( : , 1 ) , ’ r ’ ,
’ LineWidth ’ , 0 . 5 ) ;
110 t i t l e ( ’ Drivetrain losses ’ ) ;
111 l e g e n d ( ’ Motor l o s s e s ’ , ’ Gearbox l o s s e s ’ , ’ I n v e r t e r l o s s e s ’ , ’ DcDc
losses ’) ;
112 y l a b e l ( ’ Power l o s s e s [kW] ’ ) ;
113 x l a b e l ( ’ Time [ min ] ’ ) ;
114 xlim ( [ 0 8 ] ) ;
115 g r i d on ;
116 i f s a v e==1
117 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ d r i v e t r a i n _ l o s s e s ’ ) , ’ png ’ ) ;
118 else
119 end
120
143 a x i s ( [ 0 1200 0 3 5 0 ] ) ;
144 c o n t o u r ( motoreff_w , motoreff_T , m o t o r e f f ) ;
145 p l o t ( s p e e d s . s i g n a l s . v a l u e s ( : , 2 ) /rw∗ g r a t i o , F o r c e s . s i g n a l s . v a l u e s
( : , 1 ) ∗rw/ g r a t i o , ’ k ’ , ’ LineWidth ’ , 1 ) ;
146 t i t l e ( ’ Motor e f f i c e n c y ’ ) ;
147 x l a b e l ( ’ Motor Angular Speed [ rad / s ] ’ ) ;
148 y l a b e l ( ’ Motor Torque [Nm] ’ ) ;
149 l e g e n d ( ’ Motor E f f i c i e n c y ’ , ’ Drive c y c l e ’ ) ;
150 i f s a v e == 1
151 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ M o t o r _ e f f i c i e n c y ’ ) , ’ png ’ ) ;
152 else
153 end
154
211 g r i d on ;
212 i f s a v e==1
213 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ e l e v a t i o n _ p r o f i l e ’ ) , ’ png ’ ) ;
214 else
2.3. Matlab Code for comparing vehicle layouts 25
215 end
216
7 s a v e ( ’ d r i v e t r a i n _ l o s s e s _ s i n g l e . mat ’ , ’ d r i v e t r a i n _ l o s s e s _ s i n g l e ’ ) ;
8 s a v e ( ’ s l i p _ r i g h t _ s i n g l e . mat ’ , ’ s l i p _ r i g h t _ s i n g l e ’ ) ;
1 close all ;
2
5 success = false ;
6 while ~ success
7 b = i n p u t ( ’Do you want t o s a v e t h e g e n e r a t e d p l o t s ? 1=y e s 2=
no ’);
8 switch b
9 case 1
10 d i s p ( ’ The p l o t s w i l l be saved t o s e l e c e d f o l d e r ’ )
11 save = 1 ;
12 success = true ;
13 case 2
14 d i s p ( ’ The p l o t s w i l l not be saved ’ )
15 save = 2 ;
16 success = true ;
17 otherwise
18 d i s p ( ’ P l e a s e , s e l e c t one o f t h e a v a i l a b l e o p t i o n s ’ )
19 success = false ;
20 end
21 end
22
23
30 l o a d ( ’ d r i v e t r a i n _ l o s s e s _ s i n g l e . mat ’ ) ;
31 l o a d ( ’ s l i p _ r i g h t _ s i n g l e . mat ’ ) ;
32
42
43 figure (1) ;
44 h o l d on ;
45 p l o t ( Ve_speed_triple . time / 6 0 , Ve_speed_triple . s i g n a l s . v a l u e s
( : , 1 ) ∗ 3 . 6 , ’ b ’ , ’ LineWidth ’ , 0 . 7 ) ;
46 p l o t ( Ve_speed_single . time / 6 0 , Ve_speed_single . s i g n a l s . v a l u e s
( : , 1 ) ∗ 3 . 6 , ’ r ’ , ’ LineWidth ’ , 0 . 7 ) ;
47 l e g e n d ( ’ Layout 2 ’ , ’ Layout 1 ’ ) ;
48 t i t l e ( ’ Vehicle speeds ’ ) ;
49 y l a b e l ( ’ Speed [ km/h ] ’ ) ;
50 x l a b e l ( ’ Time [ min ] ’ ) ;
51 %s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
52 g r i d on ;
53 i f s a v e==1
54 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ vehicle_speeds_comp ’ ) , ’ png ’ ) ;
55 else
56 end
57
58
59 figure (2) ;
60 h o l d on ;
61 p l o t ( Ve_speed_triple . time / 6 0 , 2∗ L e f t _ t o r q u e _ t r i p l e . s i g n a l s .
v a l u e s ( : , 1 ) , ’ b ’ , ’ LineWidth ’ , 1 ) ;
62 p l o t ( Ve_speed_single . time / 6 0 , 2∗ L e f t _ t o r q u e _ s i n g l e . s i g n a l s .
v a l u e s ( : , 1 ) , ’ r ’ , ’ LineWidth ’ , 0 . 7 ) ;
63 l e g e n d ( ’ Layout 2 ’ , ’ Layout 1 ’ ) ;
64 t i t l e ( ’ V e h i c l e output t o r q u e ’ ) ;
65 y l a b e l ( ’ Torque [Nm] ’ ) ;
66 x l a b e l ( ’ Time [ min ] ’ ) ;
67 %s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
68 g r i d on ;
28 Matlab code
69 i f s a v e==1
70 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ vehicle_torque_comp ’ ) , ’ png ’ ) ;
71 else
72 end
73
74
75 figure (3) ;
76 h o l d on ;
77 p l o t ( d i s t _ t r i p l e . s i g n a l s . v a l u e s ( : , 1 ) , SOC_triple . s i g n a l s . v a l u e s
( : , 1 ) , ’ b ’ , ’ LineWidth ’ , 0 . 6 ) ;
78 p l o t ( d i s t _ s i n g l e . s i g n a l s . v a l u e s ( : , 1 ) , SOC_single . s i g n a l s . v a l u e s
( : , 1 ) , ’ r ’ , ’ LineWidth ’ , 0 . 6 ) ;
79 t i t l e ( ’ B a t t e r y SOC vs . D i s t a n c e t r a v e l l e d ’ ) ;
80 l e g e n d ( ’ Layout 2 ’ , ’ Layout 1 ’ ) ;
81 y l a b e l ( ’ B a t t e r y SOC [ % ] ’ ) ;
82 x l a b e l ( ’ D i s t a n c e [ km ] ’ ) ;
83 g r i d on ;
84 i f s a v e==1
85 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’SOC_comp ’ ) , ’ png ’ ) ;
86 else
87 end
88
89
90 figure (4) ;
91 h o l d on
92 p l o t ( Pmec_triple . time / 6 0 , Pmec_triple . s i g n a l s . v a l u e s ( : , 1 ) , ’ b ’ ,
’ LineWidth ’ , 0 . 5 ) ;
93 p l o t ( Pmec_single . time / 6 0 , Pmec_single . s i g n a l s . v a l u e s ( : , 1 ) , ’ r ’ ,
’ LineWidth ’ , 0 . 5 ) ;
94 l e g e n d ( ’ Layout 2 ’ , ’ Layout 1 ’ ) ;
95 t i t l e ( ’ Mechanical power output ’ ) ;
96 y l a b e l ( ’ Power output [kW] ’ ) ;
97 x l a b e l ( ’ Time [ min ] ’ ) ;
98 %s e t ( gca , ’ XTickLabel ’ , [ ] ) ;
99 g r i d on ;
100 i f s a v e==1
101 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’Pmec_comp ’ ) , ’ png ’ ) ;
102 else
103 end
104
105
108 p l o t ( d r i v e t r a i n _ l o s s e s _ t r i p l e . time / 6 0 , d r i v e t r a i n _ l o s s e s _ t r i p l e .
s i g n a l s . v a l u e s ( : , 1 ) , ’ b ’ , ’ LineWidth ’ , 0 . 5 ) ;
109 p l o t ( d r i v e t r a i n _ l o s s e s _ s i n g l e . time / 6 0 , d r i v e t r a i n _ l o s s e s _ s i n g l e .
s i g n a l s . v a l u e s ( : , 1 ) , ’ r ’ , ’ LineWidth ’ , 0 . 5 ) ;
110 t i t l e ( ’ Drivetrain losses ’ ) ;
111 l e g e n d ( ’ Layout 2 ’ , ’ Layout 1 ’ )
112 y l a b e l ( ’ Power l o s s e s [W] ’ ) ;
113 x l a b e l ( ’ Time [ min ] ’ ) ;
114 g r i d on ;
115 i f s a v e==1
116 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ d r i v e t r a i n _ l o s s e s _ c o m p ’ ) , ’ png ’
);
117 else
118 end
119
120
144 xlim ( [ 0 8 ] )
145
146 g r i d on ;
147 i f s a v e==1
148 s a v e a s ( g c f , s t r c a t ( f i g u r e s d i r , ’ distance_comp ’ ) , ’ png ’ ) ;
149 else
150 end
151
152