Emmeskay MIL-SIL Tutorial
Emmeskay MIL-SIL Tutorial
Emmeskay MIL-SIL Tutorial
http://www.emmeskay.com/ info@emmeskay.com
EMMESKAY, INC.
47119, Five Mile Road Plymouth, MI 48170 USA Phone: (734) 207 5564 FAX: (734) 207 5556
Overview
Introduction Power Window Model MIL SIL HIL Review
COPYRIGHT EMMESKAY
Introduction
Goals of this tutorial
Describe differences between MIL, SIL & HIL Give a walkthrough of how to actually go from MIL to SIL using Real-Time Workshop
COPYRIGHT EMMESKAY
Introduction
Different stages of the development process (V-diagram) require different kinds of models
MIL = Model-in-the-Loop SIL = Software-in-the-Loop HIL = Hardware-in-the-Loop
COPYRIGHT EMMESKAY
Introduction: MIL
Model exists entirely in native simulation tool (e.g., Simulink / Stateflow) Good for control algorithm development
Controller
u
Plant
y
COPYRIGHT EMMESKAY
Introduction: SIL
Part of the model exists in native simulation tool (e.g., Simulink / Stateflow), and part as executable C-code (e.g., S-function) Good for testing controller implementations in C-code Controller
u
C-code
Plant
y
COPYRIGHT EMMESKAY
Introduction: HIL
Part of the model runs in a real-time simulator, and part may exist as physical hardware (e.g., ECU) Good for testing interactions with hardware
Controller
u
Plant
y
COPYRIGHT EMMESKAY
Overview
Introduction Power Window Model MIL SIL HIL Review
COPYRIGHT EMMESKAY
COPYRIGHT EMMESKAY
user interface
10
COPYRIGHT EMMESKAY
right-click on a subsystem and select Block Choice to see other available subsystem choices
11 COPYRIGHT EMMESKAY
13
COPYRIGHT EMMESKAY
simple plant model integrates acceleration and velocity to predict window position
14
COPYRIGHT EMMESKAY
PW Model: Console
Overview
Introduction Power Window Model MIL SIL HIL Review
16
COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
Run the existing model in Simulink for MIL
17
COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
Controlling the model
Original model controls inputs via 5 toggle switches
obstacle driver up driver down passenger up passenger down
Enhancements
Replace 5 toggle switches with from Workspace blocks so you can run automated model testing through an m-script
18 COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
replace toggle switches with from Workspace blocks change constant = 0 to bypass ObstacleLogic Stateflow chart (use ObstIntro variable directly from Workspace)
19 COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
Sample script will:
open specific test model select specific subsystems from library set specific input conditions (test vector) execute simulation compare results to known good
20
COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
model = 2; % model configuration input = 2; % input conditions output = 2; % expected results plotit = 1; % show plot of results?
% set model configuration switch model case 1 % original Mathworks model modelname = 'PW_demoCS.mdl'; open(modelname) set_param('PW_demoCS/PW_controller','BlockChoice','simpleSL_controller'); set_param('PW_demoCS/PW_controller/simpleSL_controller/PW_MainController','BlockChoice','MainControllerLogic'); case 2 % model modified to shortcut console Stateflow diagram modelname = 'PW_demoCS_Modified.mdl'; open(modelname) set_param('PW_demoCS_Modified/PW_controller','BlockChoice','simpleSL_controller'); set_param('PW_demoCS_Modified/PW_controller/simpleSL_controller/PW_MainController','BlockChoice','MainControllerLogic'); case 3 % model using S-function representation of controller subsystem modelname = 'PW_demoCS_Modified_SIL.mdl'; open(modelname) set_param('PW_demoCS_Modified_SIL/PW_controller','BlockChoice','Controller_Sfunction'); end
21
COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
% set input conditions switch input case 1 % passenger raises at 2s, driver lowers at 9s tDU = [0;10]; DrvUpCmd = [0;0]; tDD = [0;6;6;9;9;10]; DrvDownCmd = [0;0;1;1;0;0]; tPU = [0;2;2;7;7;10]; PassUpCmd = [0;0;1;1;0;0]; tPD = [0;10]; PassDownCmd = [0;0]; tOi = [0;10]; ObstIntro = [0;0]; case 2 % passenger raises at 2s, obstruction at 3s tDU = [0;10]; DrvUpCmd = [0;0]; tDD = [0;10]; DrvDownCmd = [0;0]; tPU = [0;2;2;2.1;2.1;10]; PassUpCmd = [0;0;1;1;0;0]; tPD = [0;10]; PassDownCmd = [0;0]; tOi = [0;3;3;10]; ObstIntro = [0;0;1;1]; end
% check outputs for pass / fail switch output case 1 % window raised at 2s up to 0.4m and lowers at 9s back to 0m expected = load('ExpectedResult1.mat'); rms_error = minimum_rms( ... [position.time, position.signals.values], ... [expected.position.time, expected.position.signals.values]); if rms_error < 0.01, result = 1, else, result = 0, end if plotit plot(expected.position.time, expected.position.signals.values,'b', ... position.time, position.signals.values, 'r--') legend('Expected Results','Actual Results') end case 2 % window raised at 2s up to 0.25m and lowers at 3s back to 0m expected = load('ExpectedResult2.mat'); rms_error = minimum_rms( ... [position.time, position.signals.values], ... [expected.position.time, expected.position.signals.values]); if rms_error < 0.01, result = 1, else, result = 0, end if plotit plot(expected.position.time, expected.position.signals.values,'b', ... position.time, position.signals.values, 'r--') legend('Expected Results','Actual Results') end end
22 COPYRIGHT EMMESKAY
Model-in-the-Loop (MIL)
Running the script for test case shown above results in the following:
>> PW_openloop result = 1
23
COPYRIGHT EMMESKAY
Overview
Introduction Power Window Model MIL SIL HIL Review
24
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
Convert controller to S-function for SIL
25
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
How do you create the S-function for the controller subsystem?
Right-click on controller subsystem and select Real-Time Workshop / Generate S-Function Click Build
26
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
Is that all there is to it?
No, not really We want to eventually run this in a HIL system HIL means you run the model in real-time Therefore, must get this model to run with a fixed-step solver
27
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
1. Create S-function
a. Change model to fixed-step solver
Note: The original model wont run with fixed-step solvers as is. See Potential Gotcha #1 below.
28 COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
1. Create S-function
a. Change model to fixed-step solver b. Build S-function from controller subsystem c. A new model will open in Simulink
29
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
2. Bring S-function into library
a. Copy new model b. Right-click controller: Go To Library Block
30
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
2. Bring S-function into library
a. b. c. d. e. Copy new model Right-click controller: Go To Library Block In library, select Edit / Unlock Library Paste new model into library Rename new model
31
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
Unlock library
32
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
2. Bring S-function into library
a. b. c. d. e. f. g. Copy new model Right-click controller: Go To Library Block In library, select Edit / Unlock Library Paste new model into library Rename new model Double-click PW_controller Check new model to make it available as a block choice and click OK h. Save library and close it
33 COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
34
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
3. Run the SIL system
a. Select the new S-function for the controller subsystem b. Simulate the model
Select new S-function model for controller block choice
35
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
Potential Gotcha #1
When trying to run MIL with a fixed step solver, you get this error:
The problem is that original model does not run properly with fixed step solvers because of the triggered subsystems. You must insert Rate Transition blocks to let the subsystems communicate in fixed step. Fixing the two triggered subsystems in the simpleSL_controller will allow the model to run in fixed-step.
36 COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
Software-in-the-Loop (SIL)
COPYRIGHT EMMESKAY
Software-in-the-Loop (SIL)
Potential Gotcha #2:
When running Generate S-function, you get the following error:
The problem is that the variables used in the from Workspace blocks were not declared first. Run the script (see MIL) to define values for these variables and try again.
39
COPYRIGHT EMMESKAY
Overview
Introduction Power Window Model MIL SIL HIL Review
40
COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
Build real-time system on simulator for HIL
41
COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
Use Real-Time Workshop to build a version of the model that will run on real-time simulator. Use software tools to control the inputs to the real-time simulation. Automate testing, if desired. Contact us to know more about your hardware and software options.
42
COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
How will your software control the model inputs?
Some software can only change the value of constant blocks Some software can only change the value of workspace signals
We want to build a model that will work with either setup Start from MIL model again to extract the source model blocks, not the S-function
43 COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
Use a switch to control whether model inputs come from constant blocks or workspace.
44
COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
1. Build the model for Real-Time
a. Turn off Block reduction option
This option will restructure the model for simulation speed, but that prevents us from controlling specific blocks directly from a realtime simulator (HIL). It must be turned off to build a HIL model.
45
COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
1. Build the model for Real-Time
a. Turn off Block reduction option b. Specify the target system c. Click Build
Use the Browse button to find your target platform for the build.
Hardware-in-the-Loop (HIL)
2. Run model and hardware together in realtime simulator
a. Could use any number of platforms, so we wont show this step
3. Analyze results
a. b. c. d. Store signals from test Read into MATLAB Compare to expected results Report as Pass / Fail
47
COPYRIGHT EMMESKAY
Hardware-in-the-Loop (HIL)
After loading .mat file into workspace
48
COPYRIGHT EMMESKAY
Overview
Introduction Power Window Model MIL SIL HIL Review
49
COPYRIGHT EMMESKAY
Review
Started with a simple Power Window model Modified it for automated testing
from workspace blocks testing script
Review
MIL: ran the model in automated testing to validate the control algorithm SIL: built S-functions of controller to validate the C-code implementation HIL: built MIL for real-time simulator to validate the hardware performance
51
COPYRIGHT EMMESKAY