5.6.1 Upgrading to a new CarMaker version
When upgrading to a new CarMaker version, always be sure to update yourcmenv.mscript as well:
• Either replace it with its successor, to be found inExamples/Car_Generic/mdl/
cmenv.m in the installation directory of the new CarMaker version (recommended).
• Or change the setting of the cminstdir variable in the first few lines of yourcmenv.m script and make it point to the new version.
There might be other files, too, that may need to be updated. Check the wrapper source code and regenerate you model C code. The Release Notes document coming with CarMaker will provide you with the necessary information.
5.6.2 Integration of more than one model
Integration of more than one Simulink model into CarMaker should be possible without problems, if the following conditions are met:
• The C code for all Simulink models was generated using the same version of Matlab.
• The C code for all Simulink models was generated using the same version of CarMaker’s Matlab Support Package.
Failure to meet these conditions may lead to errors while linking the CarMaker executable or to subtle problems during simulation.
5.6.3 Using blocks from the CarMaker for Simulink blockset
...
5.6.4 CarMaker and Matlab installed on different computers
If CarMaker and Matlab are not available on the same computer, two problems arise:
• C code generation with Real-Time Workshop is not possible because the CarMaker tar-get is not available on the Matlab host.
• Compiling the model library of a Simulink model is not possible because the necessary Matlab *.h include files are not available on the CarMaker host.
A solution exists for both problems.
Making the CarMaker target available on the Matlab host
The text below describes the steps for a CarMaker host running Linux and a Matlab host running MS Windows, but operating systems used don’t really play an important role here.
The same technique also applies to scenarios with a different “operating system mix”; of course OS specific file and directory names need to be adapted accordingly.
Copying the CarMaker target directory
Copy the directory containing the CarMaker target /opt/ipg/hil/<version>/Matlab
(i.e. the one in the installation directory of the CarMaker version you use) from the CarMaker host to the Matlab host. Be sure that the copy is complete and includes all subdirectories.
88 Integrating Simulink models
Miscellaneous
All S-functions coming with the CarMaker target need to be recompiled for the Matlab ver-sion installed on the Matlab host. For this reason the source code of all S-functions is part of the package.
Start Matlab and change to the directory of the CarMaker target that matches your Matlab version (here version 6.5.1 is assumed):
>> cd <location_of_the_copy_you_made>/Matlab/v6.5.1-r13
Invoke the m-file script that recompiles all S-functions:
>> mksfun
The compilation process should proceed without any warnings or errors.
After compilation is done, check that the following files exist in your current working direc-tory:
If all files exist, you’re done. The CarMaker target for Real-Time Workshop is ready for use.
Generating C code
In order to use the CarMaker target on the Matlab system, it’s directory must be added to Matlab’s search path. This was described in detail at the beginning of this manual. But since the Matlab system is without a proper CarMaker installation, thecmenv.mscript will very likely not work. That means before you can use the package you have to issue the the nec-essary command in Matlab manually (or put it into a small m-file script). In our case, the command looks like:
>> addpath <location_of_the_copy_you_made>/Matlab/v6.5.1-r13)
After that everything should work as described in the other chapters of this manual. C code generation with Real-Time Workshop and the CarMaker target should be possible without any problems.
Make sure that theGenerate code onlycheckbox in the Real-Time Workshop tab of the Simulation parameters dialog is checked, since compilation can only be done on the CarMaker system. Thus, after code generation is complete, all generated files must be transfered to the CarMaker system.
Important note When transfering files between the CarMaker host and the Matlab host, make absolutely sure that you use 100% identical file names on both sides. Beware of subtle differences in terms of upper/lower case of characters.
Differing filenames may lead to compilation errors on the CarMaker system. Both the gen-erated C code and the gengen-erated Makefile contain the original file names and identifiers derived from them and are very sensitive to changes in the naming of files.
“File not found”, “No such file or directory” oder “Don’t know how to make XXX” when com-piling a model are typical indications of unexpectedly renamed files.
Making the Matlab include files available on the CarMaker host
A supplemental CarMaker package (CarMaker-matinc-XX.tgz) containing the Matlab include files is available on request. Simply add the package to your CarMaker installation using the IPG installer.
89 Integrating Simulink models
Miscellaneous
In order to make use of the newly installed include files, Real-Time Workshop must be informed that the include files can be found somewhere in the CarMaker installation direc-tory. Open theSimulation / Simulation Parameters...dialog of your model. On the Real-Time Workshoptab, the code generation options for the CarMaker target must be changed as follows:
• Category: CarMaker code generation options
• Matlab include path: $(MATSUPP_DIR)/matlab Now regenerate the C code of your model.
If regeneration of the C code is not an option, an alternative would be to edit the generated XXX.mkMakefile of your model C code and change the value of the CM_MATINCPATH vari-able to the above mentioned value:
CM_MATINCPATH = "$(MATSUPP_DIR)/matlab"
After the changes are made, you should be able to compile the model library without a Mat-lab installation avaiMat-lable on the CarMaker host.
5.6.5 Troubleshooting
Real-Time Workshop automatically deletes files
Since Matlab version 6.0, Real-Time Workshop places the C code files generated from a Simulink model in a subdirectory <ModelName>_<TargetName>_rtw. Since Matlab version 6.5, Real-Time Workshop, before generating new code, automatically does a cleanup in this subdirectory and deletes files it considers to be “old” or “temporary”.
This behaviour may collide with the common practice of keeping additional user code need-ed to compile the model in this directory. C code files, as well as e.g. customizneed-ed Makefiles are affected.
Closer observation shows that files containing the text “target specific file” in the very first line will not be touched or deleted by Real-Time Workshop, so this might be a workaround to the problem. Nevertheless it seems to be safer to keep user code files in a different place and not in the subdirectory obviously under Real-Time Workshop’s control.
Integration of multiple models leads to link error
The C code generated by Real-Time Workshop contains a function rt_CallSys(). This func-tion has global scope, which makes the linker issue a “duplicate definifunc-tion error” when link-ing two ore more Simulink models into CarMaker.
Since rt_CallSys() doesn’t seem to be used anywhere in the code or in the runtime library, a possible workaround is commenting out the function completely in the generated source code. The drawback of this method is, that each time you generate code from one of the Simulink models, you’ll have to repeat this step.
90 Integrating Simulink models
Demonstration examples