+ All Categories
Home > Documents > Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time...

Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time...

Date post: 19-Feb-2018
Category:
Upload: lykhue
View: 235 times
Download: 2 times
Share this document with a friend
10
Generating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time software for the QNX operating system using Matlab/Real-Time Workshop, you need both the Simulink and Real-Time Workshop toolboxes. You can check your Matlab installation by typing ver to the Matlab command line. You should have the following toolboxes: Simulink Version 7.1 Fixed-Point Toolbox Version 2.2 Real-Time Workshop Version 7.1 Real-Time Workshop Embedded Coder Version 5.1 Simulink Fixed Point Version 5.6 The version numbers may vary, but this tutorial was written with the above installation. As versions change, it is possible that some of the generated code may break. This generally occurs when minor C functions are added and can be easily fixed with a little debugging. On a fresh installation, you must download some files from: http://www.du.edu/~rvoyles/software.puma.html Follow the README file for instructions. If the QNX files have already been installed, all you have to do is make sure you have the following directories in your path. To check the path, type path to the Matlab command line. To modify your Matlab path, click on File/Set Path… The following directories must be in your path: C:\Program Files\MATLAB\R2008a\toolbox\pumatrc C:\Program Files\MATLAB\R2008a\rtw\c\qnx_trc C:\Program Files\MATLAB\R2008a\toolbox\pumastg C:\Program Files\MATLAB\R2008a\rtw\c\qnx_stg If you click on SAVE before you close the Set Path… dialog, your path will be permanently saved on this particular machine. Start Simulink by clicking on the Simulink icon, shown below (or typing simulink).
Transcript
Page 1: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Generating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A

To create real-time software for the QNX operating system using Matlab/Real-Time Workshop, you need both the Simulink and Real-Time Workshop toolboxes. You can check your Matlab installation by typing

ver to the Matlab command line. You should have the following toolboxes:

Simulink Version 7.1 Fixed-Point Toolbox Version 2.2 Real-Time Workshop Version 7.1 Real-Time Workshop Embedded Coder Version 5.1 Simulink Fixed Point Version 5.6

The version numbers may vary, but this tutorial was written with the above installation. As versions change, it is possible that some of the generated code may break. This generally occurs when minor C functions are added and can be easily fixed with a little debugging. On a fresh installation, you must download some files from:

http://www.du.edu/~rvoyles/software.puma.html Follow the README file for instructions. If the QNX files have already been installed, all you have to do is make sure you have the following directories in your path. To check the path, type path to the Matlab command line. To modify your Matlab path, click on File/Set Path… The following directories must be in your path: C:\Program Files\MATLAB\R2008a\toolbox\pumatrc C:\Program Files\MATLAB\R2008a\rtw\c\qnx_trc C:\Program Files\MATLAB\R2008a\toolbox\pumastg C:\Program Files\MATLAB\R2008a\rtw\c\qnx_stg If you click on SAVE before you close the Set Path… dialog, your path will be permanently saved on this particular machine. Start Simulink by clicking on the Simulink icon, shown below (or typing simulink ).

Page 2: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Upon starting Simulink, the Simulink Library Browser should appear. Under the Library Browser should appear two special libraries:

PUMA w/STG Board PUMA w/TRC Board

These are the interface libraries to the hardware. Click on the PUMA w/STG Board , as shown below.

Page 3: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Open a new model canvas by clicking on the NEW icon in the Simulink Library Browser. You can click on objects in the library and drag them onto the canvas. Once on the model canvas, you can right click the objects to modify their parameters, as shown below, with the Mask Parameters… option. The Sample Time parameter determines the periodic update of each object on the canvas.

Page 4: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time
Page 5: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time
Page 6: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

On the model canvas, the menu item Tools/Real-Time Workshop/Options… must be set up for QNX. Set the System Target File to qnx_stg.tlc and click the Generate Code Only checkbox.

Page 7: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Select Solver on the left-hand side and then set the Solver Options Type to Fixed-Step . Choose an appropriate Solver and Start and Stop times. Set the Fixed Step Size to the fundamental frequency you desire for your system. (This is the “heartbeat” period and must be as fast or faster than all objects on your canvas.)

Page 8: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Click menu item Tools/Real-Time Workshop/Build Model to generate the real-time code for your model.

Page 9: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Matlab/RTW will generate code in a special directory within the current working directory. The current working directory is highlighted in the figure above. The name of the new directory is <model_name>_qnx_stg_rtw , where “<model_name>” is the name you gave your model when you created it. In the example above, the new directory is pot6_qnx_stg_rtw . Copy all the files in this directory into a new directory on a DOS-formatted floppy disk in drive “A:”. These files must be compiled on the target system. Insert the floppy disk into the target QNX system and if you have not used the floppy drive since logging in, you must mount the drive. In QNX, to mount the floppy, you must open a terminal window and type: mount –t dos /dev/fd0 /fs/floppy Once the floppy drive has been mounted, you can use the File Manager to look at /fs/floppy . From here, you can copy files or the entire directory from one location to another. To copy your files onto the QNX system, a special directory has been set up at /usr/ENGR3730 . Create a new folder with your own name under this directory and then copy the directory from the floppy into this new directory.

Page 10: Generating Real-Time Code with Matlab/RTW and QNX This ... · PDF fileGenerating Real-Time Code with Matlab/RTW and QNX This document is under construction. Rev A To create real-time

Now you are ready to make you executable on the target QNX system. In the terminal window, change directories, using the cd command, to the directory you just copied from the floppy drive. For example:

cd /usr/ENGR3730/voyles/pot6 From within this directory, type:

make –f pot6.mk The make file will have the same name as your model in Matlab/RTW with a .mk file extension. The QNX executable file will have the same name as your model with no file extension. In this example, the executable is named pot6 and it appears one directory up the tree. (In this case, in /usr/ENGR3730/voyles .) You can run your executable my moving up to the proper directory and typing:

./pot6


Recommended