• No se han encontrado resultados

The CarMaker interface blockset contains blocks that serve the purpose of directly connect-ing a Simulink model with CarMaker. The blocks may be used as an alternative or in addi-tion to the Simulink’s standard Inport and Outport blocks at a model’s top level.

You may find the blockset in the Simulink library browser, under Blocksets and Toolboxes.

Double click on Matlab Support for CarMaker, or simply type

>> CarMaker

in Matlab’s command window.

5.3.1 Accessing the CarMaker dictionary

The CarMaker interface blockset contains two blocks, From CM Dict and To CM Dict, for read and write access of CarMaker dictionary variables. The variable to be accessed is sim-ply specified by its name.

When a non existent dictionary variable is given as a parameter of a From CM Dict or To CM Dict block, CarMaker will report the following error at the start of a simulation:

Model ‘abcde’: Missing quantity in data dict: ‘xyz’

Figure 5.6: Simulink library browser (Unix): CarMaker interface blockset

Figure 5.7: Simulink library browser (Unix): CarMaker interface blockset

66 Integrating Simulink models

The CarMaker interface blockset

From CM Dict

The From CM Dict block reads a variable in the CarMaker dictionary and provides its current value on the block’s output port. The variable needs not to be defined with a Def CM Dict block in the model; any existing dictionary variable may be read.

Enter the name of the variable in the block parameters dialog of the block. In the model, the name will be displayed inside the block’s symbol.

To CM Dict

The To CM Dict block writes the current value at the block’s input port to a variable in the CarMaker dictionary. The variable needs not to be defined with a Def CM Dict block in the model; any existing dictionary variable may be written to.

Enter the name of the variable in the block parameters dialog of the block. In the model, the name will be displayed inside the block’s symbol.

5.3.2 Defining CarMaker dictionary variables

A Simulink model can define its own variables in the CarMaker dictionary, because there may be signals that are to be monitored with IPG-CONTROL. Also, before a signal can be saved as part of the simulation results file, it must be put into the CarMaker dictionary.

When you define a dictionary variable in Simulink model, it is recommended to prefix its name with the model’s name or with a convenient abbreviation. This makes it easier for you to identify the model’s variables in the dictionary with tools like the CarMaker GUI or IPG-CONTROL. Example: A dictionary variable xyz defined in a Simulink model called MyModel should be given the name MyModel.xyz.

Figure 5.8: From CM Dict block parameters dialog

Figure 5.9: To CM Dict block parameters dialog

67 Integrating Simulink models

The CarMaker interface blockset

A convenient shortcut exists for this purpose: The character $ in a variable’s name will be automatically expanded to the model’s name. In the example above, instead of MyMod-el.xyz you may also type the shorter form $.xyz.

The shortcut works for all blocks accessing the CarMaker dictionary. It saves you some key-strokes, reduces the probability of typing errors, and proves to be really valuable once the model is saved under a different name.

When defining a dictionary (using the Def CM Dict block) that is already defined somewhere else, CarMaker will report the following error at the start of a simulation:

Model ‘abcde’: Error defining quantity ‘xyz’

If you need to access the dictionary variable in other parts of CarMaker, you may want to consider defining it in the wrapper module, defining a C variable for it and declaring it in the wrapper’s header file.

Def CM Dict

The Def CM Dict block defines a variable in the CarMaker dictionary.

Enter the name of the variable in the block parameters dialog of the block. In the model, the name will be displayed inside the block’s symbol.

The variable may also be given a unit, this is recommended but optional. See IPG-CON-TROL for units used with CarMaker. Specifying a unit serves as some kind of documenta-tion about the variable, but also allows IPG-CONTROL to display it on the same axis with other dictionary variables of the same unit.

If the variable’s values are strictly monotonic increasing over time, you should check the Stricly monotonecheckbox. Again, this is an information that tools like IPG-CONTROL need for proper display of the variable’s values.

Choose the variable’s type according to your needs and the range of values of the variable.

You may choose between two floating point types and six integer types. When in doubt use Double.

Figure 5.10: Def CM Dict block parameters dialog

68 Integrating Simulink models

The CarMaker interface blockset

For discrete variables (any of the integer types), if the range of values starts at 0 and has an reasonably small upper limit (e.g. an indicator light that is either on or off), it may make sense to specify the number of discrete states of the variable. For the indicator light there would be 2 discrete values (0=off, 1=on). Again this is information is provided mainly for IPG-CONTROL which displays variables with a limited number of states in a special, space saving way. Specifying a value of 0 in this field means that no special state info is available.

For the Double and Float type, the value of this field is ignored.

5.3.3 Accessing C variables

Use of a From CM Var or To CM Var block is intended for accessing a C variable that is not defined in the dictionary. You have to make sure that the variable exists and is declared properly in all C code modules where the variable is used.

RTW’s custom code library blocks might be handy for adding a #include of the proper head-er file for the refhead-erenced variable at the top of your model source file. An althead-ernative place for this is the wrapper header file of your model, which gets #include’d automatically by the generated model source code.

If a non existent C variable is specified as a parameter of a From CM Var or To CM Var block, you will very likely get warnings from the compiler about not knowing the type of the vari-able, and an error like

unresolved external reference: ‘xyz’

reported by the linker.

From CM Var

The From CM Var block reads a C variable and provides its current value on the block’s out-put port. The variable’s name will be out-put without change into the model’s C code.

Enter the name of the variable in the block parameters dialog of the block. In the model, the name will be displayed inside the block’s symbol.

Figure 5.11: From CM Var block parameters dialog

69 Integrating Simulink models

The CarMaker interface blockset

To CM Var

The To CM Var block writes the current value at the block’s input port to a C variable. The variable’s name will be put without change into the model’s C code.

Enter the name of the variable in the block parameters dialog of the block. In the model, the name will be displayed inside the block’s symbol.

Figure 5.12: To CM Var block parameters dialog

70 Integrating Simulink models

The CarMaker target for Real-Time Workshop

Documento similar