Changes between Version 2 and Version 3 of Packages/Matlab


Ignore:
Timestamp:
Dec 11, 2014, 2:42:02 AM (5 years ago)
Author:
Chris Johns
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Packages/Matlab

    v2 v3  
    2626
    2727
    28 RTW is part of the MathWorks libraries comming with usual MATLAB package versions. During MATLAB installation, choose "manual installation" and tick the following options, besides Simulink and MATLAB itself:
     28RTW is part of the !MathWorks libraries coming with usual MATLAB package versions. During MATLAB installation, choose "manual installation" and tick the following options, besides Simulink and MATLAB itself:
    2929
    30 - MATLAB Real-Time WorkShop;
     30- MATLAB Real-Time !WorkShop;
    3131
    3232- MATLAB Compilers <- This will install LCC, which is a GNU C compiler used to build the C S-Functions.
     
    3636
    3737
    38 After building the Simulink model, it is necessary to specify the I/O interface ports. These will be implemented as arrays of type and dimention specified in ExternalInputs_ModelName and ExternalOutputs_ModelName structs once the code is generated.
     38After building the Simulink model, it is necessary to specify the I/O interface ports. These will be implemented as arrays of type and dimension specified in ExternalInputs_ModelName and ExternalOutputs_ModelName structs once the code is generated.
    3939
    40 This is done by double clicking the inputs and outputs of the simulink model (inPort and outPort blocks respectively) and setting the "Port Dimentions", "Sample Time" and "Data Type" fields in the Signal Attributes tab.
     40This is done by double clicking the inputs and outputs of the simulink model (inPort and outPort blocks respectively) and setting the "Port Dimensions", "Sample Time" and "Data Type" fields in the Signal Attributes tab.
    4141
    4242'''Example:'''
    4343
    44 If, for instance, we have a 6 doubles packet to be injected in the model at 10Hz, the following shoud be set in the inPort Simulink block:
     44If, for instance, we have a 6 doubles packet to be injected in the model at 10Hz, the following should be set in the inPort Simulink block:
    4545
    4646- Port Dimentions: 6
     
    5050- Data Type: double
    5151
    52 At this point, the simulink model is a black box with an inPort configured as above. If we are dealing with a feedback system, where the Simulink block is the feedback control block, it shoud have an outPort block configured as above but with the correct output type and dimentions.
     52At this point, the simulink model is a black box with an inPort configured as above. If we are dealing with a feedback system, where the Simulink block is the feedback control block, it should have an outPort block configured as above but with the correct output type and dimensions.
    5353=  Configure RTW  =
    5454
     
    6464- '''Generate Makefile''': This option should be ticked in order to generate the makefile template of our simulink block objects library. In "Make Command", one should put make_rtw and the template makefile name can be grt_RTEMS.tmf.
    6565
    66 - '''Tasking Mode''': In the Solver tab, one should choose the tasking mode (Single/Multitasking) according to the wrapper template. For instance, if the Execution function in the wrapper model uses SingleTasking timing functions such as rt_SimGetNextSampleHit and rt_SimUpdateDiscreteTaskSampleHits, as in the following example:
     66- '''Tasking Mode''': In the Solver tab, one should choose the tasking mode (!Single/Multitasking) according to the wrapper template. For instance, if the Execution function in the wrapper model uses !SingleTasking timing functions such as rt_SimGetNextSampleHit and rt_SimUpdateDiscreteTaskSampleHits, as in the following example:
    6767
    6868    int Execute_%<Model_Name>(void){
     
    8989    }
    9090
    91 this option should be left as SingleTasking. In practice, if working with slow-rate applications, this option does not impose problems.
     91this option should be left as !SingleTasking. In practice, if working with slow-rate applications, this option does not impose problems.
    9292
    9393- '''Step Size''': This should correspond to the "continuous" discrete approximation of your model, i.e., the base rate. The solver must be set as "Discrete" with Type "Fixed Step".
     
    101101Before building the model it is advised to run the "MATLAB Model Advisor Tool". This can be done from the Simulink model window Tools-> Model Advisor. The tool will run a series of tests on your model and warn about potential problems it might have once built.
    102102
    103 Then, for this step a build.m scipt can be made with the following content:
     103Then, for this step a build.m script can be made with the following content:
    104104
    105105'''rtwbuild('modelName')'''
     
    112112=  Tune the generated Makefile  =
    113113
    114 Inside the generated code folder, there is an auto-generated MakeFile. This file can have missing sources or libraries, so it's important to check its correctness. It is then important to add the make process of this library to your main RTEMS application makefile:
     114Inside the generated code folder, there is an auto-generated !MakeFile. This file can have missing sources or libraries, so it's important to check its correctness. It is then important to add the make process of this library to your main RTEMS application makefile:
    115115
    116116model_lib:
    117         make -C generatedCodePath -f ModelName.mk all
     117        make -C generatedCodePath -f !ModelName.mk all
    118118
    119 This will include the compilation of all the autocoded files and creation of the model.a library which also needs to be incuded at the linking process with "-lModelName" in the makefile.
     119This will include the compilation of all the autocoded files and creation of the model.a library which also needs to be included at the linking process with "-lModelName" in the makefile.
    120120=  Integrate the code under the RTEMS Project  =
    121121
    122122This should be very straightforward. As said above, the wrapper includes Init and Exec functions. The Init should be used to initialize the model at an initial state of the application. Then, every time the model should be run to produce results, this is done with the Exec function. This function should run under a RTEMS task activated with the fundamental sample period set in the solver options as said above.
    123123
    124 Before executing the model with the Exec function, one has to make sure that its inputs are filled with data. Again as said above, the I/O variables of the model are within structs ExternalInputs_ModelName and ExternalOutputs_ModelName in the ModelName.h header within the generated code.
     124Before executing the model with the Exec function, one has to make sure that its inputs are filled with data. Again as said above, the I/O variables of the model are within structs ExternalInputs_ModelName and ExternalOutputs_ModelName in the !ModelName.h header within the generated code.
    125125
    126126Summarizing, the model execution task should first fill the ExternalInputs_ModelName variables, then execute the model using the Exec wrapper function and then read its outputs from the ExternalOutputs_ModelName struct variables. The names of the variables within this struc will be equal to the inPort and outPort names in the simulink model.