Matlab Simulink DLL in CANape
Matlab Simulink DLL in CANape
Vector Informatik GmbH Dipl.- Ing. Andreas Patzer Dipl.- Ing.(FH) Gernot Knig
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. V2.92 2007-08-08
Agenda
> Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 2
Matlab/Simulink Version 7.0, 7.1, 7.2 (R2006a), 7.3 (R2006b), 7.4 (R2007a) Microsoft C++ Compiler 6.0, 7.1 (Visual Studio 2003) and 8.0 (Visual Studio 2005) Microsoft C++ Compiler 8.0 needs Matlab Simulink 7.2 (R2006a) at least
u u
The current CANape Realtime Target 6.2.0 or above is necessary. To use Simulink DLLs CANape Graph Version 5.0 or above is necessary (CANape 6.5 is recommended).
This documentation is based on Matlab/Simulink 7.4 (R2007a), CANape 6.5 and CANape Realtime Target 6.2.2
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 3
Agenda
Version / Software Information > Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 4
Install the CANape Real-Time Target (DLL) for the Matlab/Simulink Real Time Workshop. The CANape Real-Time Target is included in the CANape MATLAB Integration Package that comes with CANape. Please find further information in Readme.htm which will be displayed after the installation.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 5
Agenda
Version / Software Information Installation of CANape Realtime Target > Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 6
Configuration of Matlab
u u
Choose your preferred compiler in Matlab by using the command: >> mex setup Answer the question: Would you like mex to locate installed compilers [y]/n? with "yes" and make your decision
The Matlab search path (File -> Set Path) will be set automatically. If your model couldnt be created be sure that the following entries are on top of the list
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 7
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab > Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 8
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 9
Each model should have one input block and one output block at least.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 10
u u
Insert your algorithm Of course, it is possible to insert multiple Input-/OutputBlocks In CANape 6.5, the mapping between the model and real signals in CANape can be done by naming conventions. If the same name of an IO in the model and in e.g. an A2L- or DBC-file is used, CANape can map them automatically.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 11
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model > Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 12
A2L
DLL
MAP
INI
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 14
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 15
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 16
Alternative 1:
u
The Simulink DLL has a time raster defined in the Real Time Workshop options. The DLL gets the actual time from CANape. The DLL itself calculates in the defined time raster. In CANape the time raster of the DLL is defined in the measurement list and is independent from the Real Time Workshop based raster
Alternative 2:
u
In both cases CANape and the Simulink DLL are working time synchronized together. To realize fast communication (time raster below 10ms) between CANape and the model DLL please set the following CANape option: Tools -> Options-> Driver -> Make sure that a CANcardXL is used in the system!
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 17
Select FixedStep
Define time rate of the model 0.1 means: The model is running in a 100ms raster.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 18
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 19
The generated files (DLL, A2L, map file and source files) are located under: <model name>_cnp_rtw
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 20
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model > Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 21
Measurement signals and parameters of Simulink blocks that should be accessible by CANape have to be defined as Simulink Data Objects in the MATLAB Workspace with: X = ASAP2.Parameter X = ASAP2.Signal or
The target will automatically generate an ASAP2 file for the model. Additional information needed in the ASAP2 file has to be added to the Simulink data objects: Matlab Version 7 x.Value = xxxx x.Min = xxx x.Max = xxx Matlab Version 6 x.Value = xxx x.PhysicalMin_ASAP2 = xxx x.PhysicalMax_ASAP2 = xxx
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 22
Signals and Parameters must have Storage Class Exported Global Important: Define a start value e. g. 1
StorageClass ExportedGlobal
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 23
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 24
StorageClass ExportedGlobal
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 25
/* Conversion method */ COMPU_METHOD_1 /* Resolution (Not used) */ /* Accuracy (Not used) */ /* Lower limit */ /* Upper limit */ ECU_ADDRESS 0 0
-100.0 100.0 0
/begin IF_DATA CANAPE_EXT 100 LINK_MAP "Signal_1" 0x0 0x0 0 0x0 0 0x0 0x0 /end IF_DATA /end MEASUREMENT
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 26
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters > Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 27
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 28
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 29
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 30
In this case, the input of the model is mapped to a signal channel1 of the ECU XCPsim. This signal can be measured in different modes. The selection is done here.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 31
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 32
By selecting the measurement mode of the input signals (in this case channel1), the model itself will be called by CANape in the same mode (on XCPsim 10ms event of the ECU). To measure a signal out of the model, an event in the model can be used. Its called <modelname> calculated. This event occurs, after the model is ready with the calculation cycle.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 33
ECU XCPsim
CANape
testword0 testword1
Simulink DLL
asap2demo_test1
Download mode
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 34
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 35
CANape reads the A2L file and tries to go online with the device. If this does not work, stay offline and open Driver parameters
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 36
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 37
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 38
Now the DLL is integrated as a Device in CANape, with XCP over DLL port
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 39
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 40
INI 1.) Select the Simulink model INI file 2.) Select the device, described with the model A2L A2L
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape > Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 42
Model Explorer
This description based on the functionality of the code generation with RealTime Workshop and the usage of the CANape Target. In the make process, there is a Matlab call: VSaveModel(<modelname>) to generate the model description file and the EMF files of the model. If you does not use the CANape Target or even not the RealTime Workshop for code generating, you can use the Model Explorer anyway in CANape. The next slide shows, how to use VSaveModel ()
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 43
Model Explorer
Generate Data Without CANape Target and Realtime Workshop Model is developed in Simulink Type in Matlab Command Window: VSaveModel (<Modelname>) (VSaveModel is a Matlab Script developed by Vector which is part of the Matlab Integration Package)
EMF-Files from the model and its subsystems and a description file (INI) are generated, e.g.:
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 44
Model Explorer
Example
The Model Explorer shows the Simulink model in nearly the same way like Simulink. To generate the description file and the EMF files, a Matlab / Simulink is necessary. For the usage of the Model Explorer in CANape, the user does not need an own Matlab / Simulink license.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 45
Model Explorer
Navigation
Simple click into subsystem (mouse pointer is shown as a hand) brings you down into the subsystem
Slide: 46
Double Click into subsystem brings you up to the higher level hierarchy
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector.
Model Explorer
Navigation
When a parameter in a block is defined as a A2L parameter, a tooltip occurs. By double click into the block, the parameter windows come up. Even the CANape measurements is running, you can open and close the parameter windows.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 47
Model Explorer
Navigation Right mouse click into Explorer: With extended tool tip, all Simulink parameters are shown
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 48
Model Explorer
Navigation Right mouse click onto an object, offers the possibility to find the object in the model.
Drag the object and drop it into an already existing window or into CANape to open a new window.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 49
Model Explorer
Navigation
Right mouse click onto the object let you jump directly to the right page and the object will flash 3 times to show the position
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 50
Model Explorer
To find the object in the model, select the object in the tree with a right mouse click and select Display in the graphic. The explorer will show the right hierarchy layer and the object will slowly flash 3 times. Just the other way round: Right mouse click on the object in the picture and the object is highlighted in the tree.
Flashing!
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 51
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer > Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 52
Right mouse button, select Insert measurement signal The DLL can be used in the online mode as mentioned before.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 53
Alternative 1:
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 54
Alternative 2:
By inserting the DLL as a signal, the result of the Simulink DLL is displayed
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 55
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 56
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 57
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 58
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement > Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 59
Right mouse button into the window Select Insert virtual file channel or press Shift+F7
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 60
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 61
The disc symbol shows that the source of the signal is a file. Select the signals from the file and map them to the In-/ Outputs of the model or link them automatically Select a time raster. Normally the fastest time raster of one of the input signals fits best. Select time range of the calculation. You can either use an explicit time range.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 62
Now an additional signal is integrated. The signal is calculated through the Simulink DLL.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 63
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 64
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool > Use Case 3: Bypassing with XCP Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 65
Bypassing can be realized by making use of Synchronous Data Acquisition and Synchronous Data Stimulation simultaneously.
1.
2.
ECU
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 66
ECU.A2L Model.A2L
6.
2. 3.
Simulink DLL
5.
1.
4.
ECU
Signal path 1. Receiving signals from the ECU (DAQ) 2. Sending the signals as an input into the DLL 3. Sending the results back to CANape 4. Sending the results back to the ECU (STIM) Calibration path 5. Calibration of the ECU (XCP) 6. Calibration of the DLL like an ECU with XCP
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 67
XCP
This event channel cannot be used for bypassing therefore: Use events channels with STIM capability only!
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 68
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 69
ECU XCPsim
limit
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 70
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 71
Using bypassing, the normal standard PC is the platform for the running model. In the example, the measurement was running 6 h!
PC ECU.A2L Model.A2L
6.
2. 3.
Simulink DLL
5.
1.
XCP
t =
Time Delay 450000 400000 350000 300000 250000
n1
4.
ECU
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector.
Ti m
on ##
slave
E T H Ethernet U S B C A N L I N F L X
FlexRay
LIN
ETH SxI
on SxI
ETH
DPRAM
on USB
on CAN
on LIN
on FlexRay
slave
slave
slave
slave
slave
slave
slave
slave
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 73
Agenda
Version / Software Information Installation of CANape Realtime Target Configuration of Matlab Create a Simulink model Create a Simulink DLL from a Simulink Model Defining Signals and Parameters Integrate Simulink DLL into CANape Model Explorer Use Case 1: Simulink DLL during Online Measurement Use Case 2: Simulink DLL as an Offline Analyzing Tool Use Case 3: Bypassing with XCP > Use Case 4: Generate CAN Messages with Simulink DLL
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 74
u u u
Integrate a new Device Select CAN as the driver type Select a matching DBC file as the database
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 75
Map the output value of the DLL to the signal in the DBC
Start measurement in CANape. By changing the value of the selected signal Kanal1, CANape will generate a new message and send it to the bus.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 76
This message was generated by CANape, cause the DLL changed the value of the signal Kanal1
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 77
Thank you for your attention. For detailed information about Vector and our products please have a look at: www.vector-informatik.com Author: [email protected] [email protected] Vector Informatik GmbH Ingersheimerstr. 24 70499 Stuttgart
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, Embedded MATLAB, and PolySpace are trademarks of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders.
2007. Vector Informatik GmbH. All rights reserved. Any distribution or copying is subject to prior written approval by Vector. Slide: 78