EZPhysics

Robotic simulation made easy

  • Increase font size
  • Default font size
  • Decrease font size

Blog

Debian Lenny Roboard interaction with Windows Matlab 2010b

E-mail Print PDF

Matlab 2010b’s Simulink as a component that allows for insertion of custom code blocks, code generation and allows building real-time applications with Real-Time Workshop (RTW) (http://www.mathworks.com/help/toolbox/rtw/ug/f1133672.html).

This Matlab component is essential for generating code to run on Unix/Linux systems. This tool has lots of customization options and uses, the most relevant of which is the deployment of a Simulink model to an external device and also the External Mode feature that allows for in Simulink to activate and receive logs and stats feedback from the controler running on the remote device.

There are several examples on how to export/compile code for devices supported by Matlab, however we had to look a bit deeper to code generation feature to parameterize it to the right format in order to compile for Roboard Linux. The most important resource in this endeavor was the previous work developed by Dan Bhanderi (http://bhanderi.dk/downloads/) which made a customized soft real-time Linux target, this was updated last for Matlab 2006b hence it required some tunning to be used in 2010b.

Dan Bhanderi adds a System Target to the RTW options menu that opens new options in the interface and when asked to generate code it does so with a makefile for Unix and the lnx_main.c develop by himself to provide the soft real-time solution. This process of creating a new target uses mainly the Target Language Compiler (TLC) and the Template MakeFile (TMF) files that determine the options in the menus and the format of the makefile respectively. If you want to learn more about it I recommend this pdf (http://www.mathworks.com/support/solutions/attachment.html?resid=1-CAFIKO&solution=1-BHU00D) which is taken from Matlab’s website (http://www.mathworks.com/support/solutions/en/data/1-BHU00D/index.html?solution=1-BHU00D), although a bit off-topic I found it very clear and alot easier to read than the main user guides provided.

Dan Bhanderi’s instructions are somewhat outdated, so instead of following this steps exactly we found an utility that upon generating code for a model saves all of it’s code and dependencies to a zip file, the packNGo utility. This utility is very useful to discover the necessary source files to run Simulink engine in the current Matlab instalation be it 2010b or any other. In this way, you always know the smallest amount of code needed to run your code on the device. i.e.: set_param(bdroot, ‘PostCodeGenCommand’, ‘packNGo(buildInfo, {”packType” ”hierarchical” ”fileName” ”BioloidControl”});’); (http://blogs.mathworks.com/seth/2008/11/26/wheres-the-code/)

Since we are not using Dan Bhanderi’s TLC or TMF (just using the generic real-time target) we now need to update the makefile and the main to work in the Unix environment. this process involves updating the makefile with the correct filepaths, included libraries (from code used in possible the s-functions in the model), host and make command, and updating the main file with Bhanderi’s soft real-time code (that uses the POSIX timer).

Warning: When transferring files from other operating systems to Unix be careful to update the newline symbols accordingly. (google dos2unix)

After this process we have the Simulink running on the Roboard, however we whant to see what is happening so we need to activate the External Mode. To do this you access the RTW options under Interface and select External Mode instead of None in the data exchance group. In the mex-file arguments you need to supply the target’s location (so Matlab knows where to get the data) (http://www.mathworks.com/help/techdoc/matlab_external/bp_kqh7.html)

Now if you run the executable in the device with the “-w” parameter it will wait for a connection from Matlab/simulink, upon doing so it will update the scopes data with the values present in your device  (you might have to adjust some settings under the menu Tools->External Mode Control Panel).

 

Last Updated on Thursday, 21 April 2011 16:54