Skip to content

Commit 2ab5843

Browse files
committed
Update Vehicle1D component. Add tests.
1 parent da9b5d6 commit 2ab5843

File tree

198 files changed

+3830
-9226
lines changed

Some content is hidden

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

198 files changed

+3830
-9226
lines changed

Components/DcDcConverter/DcDcConverterElec_refsub.mdl

Lines changed: 32 additions & 31 deletions
Large diffs are not rendered by default.

Components/Vehicle1D/harnessModels/Vehicle1D_harness_model.mdl renamed to Components/Vehicle1D/Harness/Vehicle1D_Component_harness_model.mdl

Lines changed: 721 additions & 937 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
%% Set-Up script for Vehicle1D component
2+
% This script is run automatically when harness model opens.
3+
% If you edit this file, make sure to run this to update variables
4+
% before running harness model for simulation.
5+
6+
% Copyright 2020-2022 The MathWorks, Inc.
7+
8+
Vehicle1D_refsub_Basic_params

Components/Vehicle1D/README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
1-
# Component / Vehicle 1D
1+
# Vehicle1D Component
22

3-
Component to compute the longitudinal speed of a road vehicle.
3+
This is a model of longitudinal vehicle,
4+
which computes the longitudinal speed of a road vehicle.
45

5-
The default main component subsystem uses
6+
The main model file of this component is
7+
8+
- `Vehicle1D_refsub_Basic.mdl`
9+
10+
which is designed as a reusable component
11+
as a referenced subsystem.
12+
You can use it in a Subsystem Reference block.
13+
The primary block of the main model is
614
[Longitudinal Vehicle block][url-1] from Simscape Driveline.
715

816
[url-1]:https://www.mathworks.com/help/physmod/sdl/ref/longitudinalvehicle.html
917

10-
## Harness Model
18+
`Harness` folder contains the following harness model
19+
to run simulation with the Vehicle1D component.
20+
21+
- `Vehicle1D_Component_harness_model.mdl`
1122

12-
<img src="images/image_Vehicle1D_harness_model.png"
13-
width="700" alt="Harness Model for Longitudinal Vehicle Component">
23+
## Test Cases
1424

15-
## Main Component Subsystem
25+
`TestCases` folder contains Live Scripts
26+
that are used to visually inspect the simulation behaviors
27+
of the model in various simulation scenarios as follows.
1628

17-
<img src="images/image_Vehicle1D_refsub_Driveline.png"
18-
width="700" alt="Vehicle 1D Component">
29+
- Constant ...
30+
All inputs are constant.
31+
This is used to check that the harness model runs.
1932

20-
## Vehicle Property
33+
- Coastdown ...
34+
Simulation starts with a constant vehicle speed
35+
with no driving torque on the flat ground.
36+
Vehicle naturally comes to a complete stop.
2137

22-
<img src="images/image_Vehicle1D_Driveline_ResistingForcePower.png"
23-
width="500" alt="Vehicle resisting force and power">
38+
- Brake ...
39+
Vehicle starts going down hill.
40+
Then brake is applied to slow down the vehicle speed.
2441

2542
*Copyright 2022 The MathWorks, Inc.*
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
classdef Vehicle1D_Component_UnitTest_MQC < matlab.unittest.TestCase
2+
% Class implementation of unit test
3+
%
4+
% These are tests to achieve the Minimum Quality Criteria (MQC).
5+
% MQC is achieved when all runnables (models, scripts, functions) run
6+
% without any errors.
7+
%
8+
% You can run this test by opening in MATLAB Editor and clicking
9+
% Run Tests button or Run Current Test button.
10+
% You can also run this test using test runner (*_runtests.m)
11+
% which can not only run tests but also generates summary and
12+
% measures code coverage report.
13+
14+
% Copyright 2021-2022 The MathWorks, Inc.
15+
16+
methods (Test)
17+
18+
%% Component's top folder
19+
20+
function MQC_run_Basic_params(~)
21+
close all
22+
bdclose all
23+
Vehicle1D_refsub_Basic_params
24+
close all
25+
bdclose all
26+
end
27+
28+
%% Component Harness folder
29+
30+
function MQC_run_harness_model_with_Basic_refsub(~)
31+
close all
32+
bdclose all
33+
mdl = "Vehicle1D_Component_harness_model";
34+
load_system(mdl)
35+
Vehicle1D_Component_harness_setup
36+
simIn = Simulink.SimulationInput(mdl);
37+
simIn = setModelParameter(simIn, StopTime="100");
38+
sim(simIn);
39+
close all
40+
bdclose all
41+
end
42+
43+
function MQC_run_setup(~)
44+
close all
45+
bdclose all
46+
Vehicle1D_Component_harness_setup
47+
close all
48+
bdclose all
49+
end
50+
51+
%% Component TestCases folder
52+
53+
function MQC_run_testcase_Brake(~)
54+
close all
55+
bdclose all
56+
Vehicle1D_Component_testcase_Brake
57+
close all
58+
bdclose all
59+
end
60+
61+
function MQC_run_testcase_Coastdown(~)
62+
close all
63+
bdclose all
64+
Vehicle1D_Component_testcase_Coastdown
65+
close all
66+
bdclose all
67+
end
68+
69+
function MQC_run_testcase_Constant(~)
70+
close all
71+
bdclose all
72+
Vehicle1D_Component_testcase_Constant
73+
close all
74+
bdclose all
75+
end
76+
77+
%% Utility folder
78+
79+
function MQC_run_harness_reset(~)
80+
close all
81+
bdclose all
82+
Vehicle1D_Component_resetHarnessModel
83+
close all
84+
bdclose all
85+
end
86+
87+
end % methods (Test)
88+
end % classdef
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
%% Run unit tests
2+
% This script runs unit tests and generates a test result summary in XML
3+
% and a MATLAB code coverage report in HTML.
4+
5+
% Copyright 2022 The MathWorks, Inc.
6+
7+
RelStr = matlabRelease().Release;
8+
disp("This is MATLAB " + RelStr + ".")
9+
10+
TargetName = "Vehicle1D_Component";
11+
12+
TopFolder = fullfile(currentProject().RootFolder, "Components", "Vehicle1D");
13+
14+
%% Test suite
15+
16+
suite = matlab.unittest.TestSuite.fromFile( ...
17+
fullfile(TopFolder, "Test", "Vehicle1D_Component_UnitTest_MQC.m"));
18+
19+
%% Test runner
20+
21+
runner = matlab.unittest.TestRunner.withTextOutput( ...
22+
OutputDetail = matlab.unittest.Verbosity.Detailed );
23+
24+
%% JUnit Style Test Result
25+
26+
% Test result file is created. Don't check its existance.
27+
TestResultFile = "TestResults_" + RelStr + ".xml";
28+
29+
plugin = matlab.unittest.plugins.XMLPlugin.producingJUnitFormat( ...
30+
fullfile(TopFolder, "Test", TestResultFile));
31+
32+
addPlugin(runner, plugin)
33+
34+
%% MATLAB Code Coverage Report
35+
36+
CoverageReportFolder = fullfile(TopFolder, "coverage" + RelStr);
37+
if not(isfolder(CoverageReportFolder))
38+
mkdir(CoverageReportFolder)
39+
end
40+
41+
CoverageReportFile = RelStr + "_" + TargetName + ".html";
42+
43+
coverageReport = matlab.unittest.plugins.codecoverage.CoverageReport( ...
44+
CoverageReportFolder, ...
45+
MainFile = CoverageReportFile );
46+
47+
plugin = matlab.unittest.plugins.CodeCoveragePlugin.forFile( ...
48+
[ ...
49+
fullfile(TopFolder, "Harness", "Vehicle1D_Component_harness_setup.m"), ...
50+
fullfile(TopFolder, "Test", "Vehicle1D_Component_UnitTest_MQC.m"), ...
51+
fullfile(TopFolder, "TestCases", "Vehicle1D_Component_testcase_Brake.mlx"), ...
52+
fullfile(TopFolder, "TestCases", "Vehicle1D_Component_testcase_Coastdown.mlx"), ...
53+
fullfile(TopFolder, "TestCases", "Vehicle1D_Component_testcase_Constant.mlx"), ...
54+
fullfile(TopFolder, "Utility", "Vehicle1D_Component_plotResults.m"), ...
55+
fullfile(TopFolder, "Utility", "Vehicle1D_Component_resetHarnessModel.m"), ...
56+
fullfile(TopFolder, "Vehicle1D_refsub_Basic_params.m")], ...
57+
Producing = coverageReport );
58+
59+
addPlugin(runner, plugin)
60+
61+
%%
62+
63+
results = run(runner, suite);
64+
65+
assertSuccess(results)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function fig = Vehicle1D_Component_plotResults(nvpairs)
2+
% plots the simulation result.
3+
4+
% Copyright 2022 The MathWorks, Inc.
5+
6+
arguments
7+
nvpairs.SimData timetable
8+
nvpairs.FigureHeight (1,1) {mustBePositive} = 300
9+
end
10+
11+
sigNames = [ ...
12+
"Axle torque input", ...
13+
"Brake force", ...
14+
"Road inclination", ...
15+
"Road grade", ...
16+
"G force", ...
17+
"Vehicle speed kph", ...
18+
"Vehicle speed mph", ...
19+
"Axle speed" ];
20+
21+
for i = 1 : numel(sigNames)
22+
fig = plotSimulationResultSignal(SimData = nvpairs.SimData, SignalName = sigNames(i));
23+
fig.Position(4) = nvpairs.FigureHeight;
24+
end
25+
26+
end % function

0 commit comments

Comments
 (0)