Skip to content

Commit a6071b1

Browse files
committed
Update the HEV speed tracking model and related files.
1 parent 0c2c581 commit a6071b1

File tree

85 files changed

+612
-323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+612
-323
lines changed
-92 Bytes
Binary file not shown.
-81 Bytes
Binary file not shown.

Components/DrivePattern/utils/DrivePattern_InputSignalBuilder.m

Lines changed: 178 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -52,65 +52,6 @@
5252

5353
end
5454

55-
function plotSignals(inpObj, nvpairs)
56-
%%
57-
arguments
58-
inpObj
59-
nvpairs.ParentFigure (1,1) matlab.ui.Figure
60-
end
61-
62-
syncedInputs = synchronize( ...
63-
inpObj.VehSpd, ...
64-
inpObj.VehAcc );
65-
66-
addUnitString = @(tt) ...
67-
string(tt.Properties.VariableNames) ...
68-
+ " (" + string(tt.Properties.VariableUnits) + ")";
69-
70-
dispLbl = { ...
71-
addUnitString(inpObj.VehSpd)
72-
addUnitString(inpObj.VehAcc) };
73-
74-
if not(inpObj.VisiblePlot_tf)
75-
% Invisible figure.
76-
inpObj.ParentFigure = figure('Visible', 'off');
77-
elseif isfield(nvpairs, 'ParentFigure')
78-
% This function's ParentFigure option is specified.
79-
inpObj.ParentFigure = nvpairs.ParentFigure;
80-
else
81-
% Create a new figure.
82-
inpObj.ParentFigure = figure; % Do not use Visible='on'
83-
end
84-
85-
stk = stackedplot( inpObj.ParentFigure, syncedInputs );
86-
stk.LineWidth = inpObj.LineWidth;
87-
stk.GridVisible = 'on';
88-
stk.DisplayLabels = dispLbl;
89-
% stackedplot does not have Interpreter=off setting for the title.
90-
% To prevent '_' from being interpreted as a subscript directive,
91-
% replace it with a space.
92-
% Note that title() does not work with stackedplot either.
93-
stk.Title = strrep(inpObj.FunctionName, '_', ' ');
94-
95-
% Making the figure taller than the default plot window height can
96-
% make the top part of the window go outside the monitor screen.
97-
% To prevent it, lower the x position of the window,
98-
% assuming that lowering the window position is safer
99-
% because the visibility of the window top is more important
100-
% that of the window bottom.
101-
pos = inpObj.ParentFigure.Position;
102-
h_orig = pos(4);
103-
w = inpObj.FigureWidth;
104-
h_new = inpObj.FigureHeight;
105-
inpObj.ParentFigure.Position = [pos(1), pos(2)-(h_new-h_orig), w, h_new];
106-
107-
if inpObj.SavePlot_tf
108-
exportgraphics(gca, inpObj.SavePlotImageFileName)
109-
end % if
110-
end % function
111-
112-
%% Patterns
113-
11455
function signalData = Constant(inpObj, nvpairs)
11556
%%
11657
arguments
@@ -141,133 +82,13 @@ function plotSignals(inpObj, nvpairs)
14182

14283
end % function
14384

144-
function signalData = Step3(inpObj, nvpairs)
145-
%%
146-
arguments
147-
inpObj
148-
nvpairs.VehSpdUnit {mustBeMember(nvpairs.VehSpdUnit, {'m/s', 'km/hr', 'mph'})} = "km/hr"
149-
nvpairs.VehSpd_1 (1,1) double {mustBeNonnegative} = 0
150-
nvpairs.VehSpd_2 (1,1) double {mustBeNonnegative} = 100
151-
nvpairs.VehSpd_3 (1,1) double {mustBeNonnegative} = 0
152-
nvpairs.VehSpd_1to2_ChangeStartTime (1,1) duration = seconds(10)
153-
nvpairs.VehSpd_1to2_ChangeEndTime (1,1) duration = seconds(10+30)
154-
nvpairs.VehSpd_2to3_ChangeStartTime (1,1) duration = seconds(40+20)
155-
nvpairs.VehSpd_2to3_ChangeEndTime (1,1) duration = seconds(60+30)
156-
nvpairs.StopTime (1,1) duration = seconds(90+10)
157-
end
158-
159-
% Record the function name for convenience.
160-
ds = dbstack;
161-
thisFunctionFullName = ds(1).name;
162-
inpObj.FunctionName = extractAfter(thisFunctionFullName, ".");
163-
164-
inpObj.StopTime = nvpairs.StopTime;
165-
t_end = seconds(nvpairs.StopTime);
166-
167-
unitStr = nvpairs.VehSpdUnit;
168-
169-
x1 = nvpairs.VehSpd_1;
170-
x2 = nvpairs.VehSpd_2;
171-
x3 = nvpairs.VehSpd_3;
172-
t1 = seconds(nvpairs.VehSpd_1to2_ChangeStartTime);
173-
t2 = seconds(nvpairs.VehSpd_1to2_ChangeEndTime);
174-
t3 = seconds(nvpairs.VehSpd_2to3_ChangeStartTime);
175-
t4 = seconds(nvpairs.VehSpd_2to3_ChangeEndTime);
176-
assert( 0.01 < t1 )
177-
assert( t1 < t2 )
178-
assert( t2+0.01 < t3 )
179-
assert( t3 < t4 )
180-
assert( t4+0.01 < t_end )
181-
BuildSignal_VehSpd(inpObj, unitStr, ...
182-
'Data', [x1 x1 x1 x2 x2 x2 x3 x3 x3], ...
183-
'Time', seconds([0 0.01 t1 t2 t2+0.01 t3 t4 t4+0.01 t_end]));
184-
185-
if inpObj.Plot_tf
186-
plotSignals(inpObj);
187-
end
188-
189-
signalData = BundleSignals(inpObj);
190-
191-
end % function
192-
193-
function signalData = Step5(inpObj, nvpairs)
194-
%%
195-
arguments
196-
inpObj
197-
nvpairs.VehSpdUnit {mustBeMember(nvpairs.VehSpdUnit, {'m/s', 'km/hr', 'mph'})} = "km/hr"
198-
199-
nvpairs.VehSpd_1 (1,1) double {mustBeNonnegative} = 10
200-
nvpairs.VehSpd_2 (1,1) double {mustBeNonnegative} = 20
201-
nvpairs.VehSpd_3 (1,1) double {mustBeNonnegative} = 30
202-
nvpairs.VehSpd_4 (1,1) double {mustBeNonnegative} = 40
203-
nvpairs.VehSpd_5 (1,1) double {mustBeNonnegative} = 50
204-
205-
nvpairs.VehSpd_1_ChangeStartTime (1,1) duration = seconds(30)
206-
nvpairs.VehSpd_1_ChangeEndTime (1,1) duration = seconds(30 + 10)
207-
208-
nvpairs.VehSpd_2_ChangeStartTime (1,1) duration = seconds(40 + 30)
209-
nvpairs.VehSpd_2_ChangeEndTime (1,1) duration = seconds(70 + 10)
210-
211-
nvpairs.VehSpd_3_ChangeStartTime (1,1) duration = seconds(80 + 30)
212-
nvpairs.VehSpd_3_ChangeEndTime (1,1) duration = seconds(110 + 10)
213-
214-
nvpairs.VehSpd_4_ChangeStartTime (1,1) duration = seconds(120 + 30)
215-
nvpairs.VehSpd_4_ChangeEndTime (1,1) duration = seconds(150 + 10)
216-
217-
nvpairs.StopTime (1,1) duration = seconds(160 + 40)
218-
end
219-
220-
% Record the function name for convenience.
221-
ds = dbstack;
222-
thisFunctionFullName = ds(1).name;
223-
inpObj.FunctionName = extractAfter(thisFunctionFullName, ".");
224-
225-
inpObj.StopTime = nvpairs.StopTime;
226-
t_end = seconds(nvpairs.StopTime);
227-
228-
unitStr = nvpairs.VehSpdUnit;
229-
230-
x1 = nvpairs.VehSpd_1;
231-
x2 = nvpairs.VehSpd_2;
232-
x3 = nvpairs.VehSpd_3;
233-
x4 = nvpairs.VehSpd_4;
234-
x5 = nvpairs.VehSpd_5;
235-
t1 = seconds(nvpairs.VehSpd_1_ChangeStartTime);
236-
t2 = seconds(nvpairs.VehSpd_1_ChangeEndTime);
237-
t3 = seconds(nvpairs.VehSpd_2_ChangeStartTime);
238-
t4 = seconds(nvpairs.VehSpd_2_ChangeEndTime);
239-
t5 = seconds(nvpairs.VehSpd_3_ChangeStartTime);
240-
t6 = seconds(nvpairs.VehSpd_3_ChangeEndTime);
241-
t7 = seconds(nvpairs.VehSpd_4_ChangeStartTime);
242-
t8 = seconds(nvpairs.VehSpd_4_ChangeEndTime);
243-
assert( 0.01 < t1 )
244-
assert( t1 < t2 )
245-
assert( t2+0.01 < t3 )
246-
assert( t3 < t4 )
247-
assert( t4+0.01 < t5 )
248-
assert( t5 < t6 )
249-
assert( t6+0.01 < t7 )
250-
assert( t7 < t8 )
251-
assert( t8+0.01 < t_end )
252-
BuildSignal_VehSpd(inpObj, unitStr, ...
253-
'Data', [x1 x1 x1 x2 x2 x2 x3 x3 x3 x4 x4 x4 x5 x5 x5], ...
254-
'Time', seconds([0 0.01 t1 t2 t2+0.01 t3 t4 t4+0.01 t5 t6 t6+0.01 t7 t8 t8+0.01 t_end]));
255-
256-
if inpObj.Plot_tf
257-
plotSignals(inpObj);
258-
end
259-
260-
signalData = BundleSignals(inpObj);
261-
262-
end % function
263-
26485
function signalData = Accelerate_Decelerate(inpObj, nvpairs)
26586
%%
26687
arguments
26788
inpObj
26889
nvpairs.Acceleration_StartTime = seconds(10)
26990
nvpairs.Acceleration_EndTime = seconds(10 + 30)
270-
nvpairs.PeakSpeed = 120
91+
nvpairs.PeakSpeed = 100
27192
nvpairs.VehSpdUnit {mustBeMember(nvpairs.VehSpdUnit, {'m/s', 'km/hr', 'mph'})} = "km/hr"
27293
nvpairs.Deceleration_StartTime = seconds(40 + 90)
27394
nvpairs.Deceleration_EndTime = seconds(130 + 60)
@@ -416,6 +237,183 @@ function plotSignals(inpObj, nvpairs)
416237

417238
end % function
418239

240+
function signalData = Step3(inpObj, nvpairs)
241+
%%
242+
arguments
243+
inpObj
244+
nvpairs.VehSpdUnit {mustBeMember(nvpairs.VehSpdUnit, {'m/s', 'km/hr', 'mph'})} = "km/hr"
245+
nvpairs.VehSpd_1 (1,1) double {mustBeNonnegative} = 0
246+
nvpairs.VehSpd_2 (1,1) double {mustBeNonnegative} = 100
247+
nvpairs.VehSpd_3 (1,1) double {mustBeNonnegative} = 0
248+
nvpairs.VehSpd_1to2_ChangeStartTime (1,1) duration = seconds(10)
249+
nvpairs.VehSpd_1to2_ChangeEndTime (1,1) duration = seconds(10+30)
250+
nvpairs.VehSpd_2to3_ChangeStartTime (1,1) duration = seconds(40+20)
251+
nvpairs.VehSpd_2to3_ChangeEndTime (1,1) duration = seconds(60+30)
252+
nvpairs.StopTime (1,1) duration = seconds(90+10)
253+
end
254+
255+
% Record the function name for convenience.
256+
ds = dbstack;
257+
thisFunctionFullName = ds(1).name;
258+
inpObj.FunctionName = extractAfter(thisFunctionFullName, ".");
259+
260+
inpObj.StopTime = nvpairs.StopTime;
261+
t_end = seconds(nvpairs.StopTime);
262+
263+
unitStr = nvpairs.VehSpdUnit;
264+
265+
x1 = nvpairs.VehSpd_1;
266+
x2 = nvpairs.VehSpd_2;
267+
x3 = nvpairs.VehSpd_3;
268+
t1 = seconds(nvpairs.VehSpd_1to2_ChangeStartTime);
269+
t2 = seconds(nvpairs.VehSpd_1to2_ChangeEndTime);
270+
t3 = seconds(nvpairs.VehSpd_2to3_ChangeStartTime);
271+
t4 = seconds(nvpairs.VehSpd_2to3_ChangeEndTime);
272+
assert( 0.01 < t1 )
273+
assert( t1 < t2 )
274+
assert( t2+0.01 < t3 )
275+
assert( t3 < t4 )
276+
assert( t4+0.01 < t_end )
277+
BuildSignal_VehSpd(inpObj, unitStr, ...
278+
'Data', [x1 x1 x1 x2 x2 x2 x3 x3 x3], ...
279+
'Time', seconds([0 0.01 t1 t2 t2+0.01 t3 t4 t4+0.01 t_end]));
280+
281+
if inpObj.Plot_tf
282+
plotSignals(inpObj);
283+
end
284+
285+
signalData = BundleSignals(inpObj);
286+
287+
end % function
288+
289+
function signalData = Step5(inpObj, nvpairs)
290+
%%
291+
arguments
292+
inpObj
293+
nvpairs.VehSpdUnit {mustBeMember(nvpairs.VehSpdUnit, {'m/s', 'km/hr', 'mph'})} = "km/hr"
294+
295+
nvpairs.VehSpd_1 (1,1) double {mustBeNonnegative} = 10
296+
nvpairs.VehSpd_2 (1,1) double {mustBeNonnegative} = 20
297+
nvpairs.VehSpd_3 (1,1) double {mustBeNonnegative} = 30
298+
nvpairs.VehSpd_4 (1,1) double {mustBeNonnegative} = 40
299+
nvpairs.VehSpd_5 (1,1) double {mustBeNonnegative} = 50
300+
301+
nvpairs.VehSpd_1_ChangeStartTime (1,1) duration = seconds(30)
302+
nvpairs.VehSpd_1_ChangeEndTime (1,1) duration = seconds(30 + 10)
303+
304+
nvpairs.VehSpd_2_ChangeStartTime (1,1) duration = seconds(40 + 30)
305+
nvpairs.VehSpd_2_ChangeEndTime (1,1) duration = seconds(70 + 10)
306+
307+
nvpairs.VehSpd_3_ChangeStartTime (1,1) duration = seconds(80 + 30)
308+
nvpairs.VehSpd_3_ChangeEndTime (1,1) duration = seconds(110 + 10)
309+
310+
nvpairs.VehSpd_4_ChangeStartTime (1,1) duration = seconds(120 + 30)
311+
nvpairs.VehSpd_4_ChangeEndTime (1,1) duration = seconds(150 + 10)
312+
313+
nvpairs.StopTime (1,1) duration = seconds(160 + 40)
314+
end
315+
316+
% Record the function name for convenience.
317+
ds = dbstack;
318+
thisFunctionFullName = ds(1).name;
319+
inpObj.FunctionName = extractAfter(thisFunctionFullName, ".");
320+
321+
inpObj.StopTime = nvpairs.StopTime;
322+
t_end = seconds(nvpairs.StopTime);
323+
324+
unitStr = nvpairs.VehSpdUnit;
325+
326+
x1 = nvpairs.VehSpd_1;
327+
x2 = nvpairs.VehSpd_2;
328+
x3 = nvpairs.VehSpd_3;
329+
x4 = nvpairs.VehSpd_4;
330+
x5 = nvpairs.VehSpd_5;
331+
t1 = seconds(nvpairs.VehSpd_1_ChangeStartTime);
332+
t2 = seconds(nvpairs.VehSpd_1_ChangeEndTime);
333+
t3 = seconds(nvpairs.VehSpd_2_ChangeStartTime);
334+
t4 = seconds(nvpairs.VehSpd_2_ChangeEndTime);
335+
t5 = seconds(nvpairs.VehSpd_3_ChangeStartTime);
336+
t6 = seconds(nvpairs.VehSpd_3_ChangeEndTime);
337+
t7 = seconds(nvpairs.VehSpd_4_ChangeStartTime);
338+
t8 = seconds(nvpairs.VehSpd_4_ChangeEndTime);
339+
assert( 0.01 < t1 )
340+
assert( t1 < t2 )
341+
assert( t2+0.01 < t3 )
342+
assert( t3 < t4 )
343+
assert( t4+0.01 < t5 )
344+
assert( t5 < t6 )
345+
assert( t6+0.01 < t7 )
346+
assert( t7 < t8 )
347+
assert( t8+0.01 < t_end )
348+
BuildSignal_VehSpd(inpObj, unitStr, ...
349+
'Data', [x1 x1 x1 x2 x2 x2 x3 x3 x3 x4 x4 x4 x5 x5 x5], ...
350+
'Time', seconds([0 0.01 t1 t2 t2+0.01 t3 t4 t4+0.01 t5 t6 t6+0.01 t7 t8 t8+0.01 t_end]));
351+
352+
if inpObj.Plot_tf
353+
plotSignals(inpObj);
354+
end
355+
356+
signalData = BundleSignals(inpObj);
357+
358+
end % function
359+
360+
function plotSignals(inpObj, nvpairs)
361+
%%
362+
arguments
363+
inpObj
364+
nvpairs.ParentFigure (1,1) matlab.ui.Figure
365+
end
366+
367+
syncedInputs = synchronize( ...
368+
inpObj.VehSpd, ...
369+
inpObj.VehAcc );
370+
371+
addUnitString = @(tt) ...
372+
string(tt.Properties.VariableNames) ...
373+
+ " (" + string(tt.Properties.VariableUnits) + ")";
374+
375+
dispLbl = { ...
376+
addUnitString(inpObj.VehSpd)
377+
addUnitString(inpObj.VehAcc) };
378+
379+
if not(inpObj.VisiblePlot_tf)
380+
% Invisible figure.
381+
inpObj.ParentFigure = figure('Visible', 'off');
382+
elseif isfield(nvpairs, 'ParentFigure')
383+
% This function's ParentFigure option is specified.
384+
inpObj.ParentFigure = nvpairs.ParentFigure;
385+
else
386+
% Create a new figure.
387+
inpObj.ParentFigure = figure; % Do not use Visible='on'
388+
end
389+
390+
stk = stackedplot( inpObj.ParentFigure, syncedInputs );
391+
stk.LineWidth = inpObj.LineWidth;
392+
stk.GridVisible = 'on';
393+
stk.DisplayLabels = dispLbl;
394+
% stackedplot does not have Interpreter=off setting for the title.
395+
% To prevent '_' from being interpreted as a subscript directive,
396+
% replace it with a space.
397+
% Note that title() does not work with stackedplot either.
398+
stk.Title = strrep(inpObj.FunctionName, '_', ' ');
399+
400+
% Making the figure taller than the default plot window height can
401+
% make the top part of the window go outside the monitor screen.
402+
% To prevent it, lower the x position of the window,
403+
% assuming that lowering the window position is safer
404+
% because the visibility of the window top is more important
405+
% that of the window bottom.
406+
pos = inpObj.ParentFigure.Position;
407+
h_orig = pos(4);
408+
w = inpObj.FigureWidth;
409+
h_new = inpObj.FigureHeight;
410+
inpObj.ParentFigure.Position = [pos(1), pos(2)-(h_new-h_orig), w, h_new];
411+
412+
if inpObj.SavePlot_tf
413+
exportgraphics(gca, inpObj.SavePlotImageFileName)
414+
end % if
415+
end % function
416+
419417
end % methods
420418

421419
methods (Access = private)

0 commit comments

Comments
 (0)