Graphics.SimulinkToEDGELibrary - lordmundi/wikidoctest GitHub Wiki

Simulink to EDGE Library

On this page… (hide)

  1. 1. Simulink to EDGE Library
    1. 1.1 About
    2. 1.2 Downloads
    3. 1.3 Limitations (aka, planned bugs)
    4. 1.4 Usage
    5. 1.5 Files

1.  Simulink to EDGE Library

Written by Richard Joyce, Jun 2013 [email protected]

1.1  About

This simple library provides a connection from Simulink to EDGE.

Before you use it you must compile the 'S-Function' code in Matlab. To compile, you need to run:

>> mex sf_dcomm.c -L${PWD}/lib64/ -ld_comm_tc -ldsp -ldl

For a 32bit machine, I imagine this would work though I haven't tested (the -m32 flag is probably superfluous).

>> mex sf_dcomm.c -m32 -L${PWD}/lib/ -ld_comm_tc -ldsp -ldl

Mac and Windows machines will need to copy over the correct library files too.

A simple example is included that will drive the default EDGE scene. It requires the Aerospace Blockset in order to run in realtime. Make sure you're running an EDGE manager instance if you want to try it!

1.2  Downloads

1.3  Limitations (aka, planned bugs)

  • I've had much more luck using the default multicast settings instead of the config file. Running the model a second time with the config file seems to sometimes fail to read the file.
  • Convert units in Simulink before you input to this block. Nothing gets converted.
    • Position should be in inches
    • Angles should be in degrees
  • There is currently no way to set rotation order, it assumes EDGE default PYR — DCOMM has the function calls for this so I may implement this as some point, if it's important to you it wouldn't be too hard to either hard code in what you need or convert in Simulink to PYR rotation.
  • The API file parser is _incredibly_ unrobust.
    1. List nodes in the same order as your Simulink data vector
    2. It ignores lines whose first character is whitespace
    3. It only reads in the first word and the first two characters of the third word, i.e. the node name, and which dof you want to drive.
    4. It cares not about what units you say to use. See above.
  • For best consistent results, please start the EDGE manager before you run your model.
  • Reconnection logic does not always work as expected. I'm not sure if this is a bug with simulink or DCOMM or my code, but sometimes when it tries to reconnect right away it doesn't use the right multicast config and will cause simulink to hang.
  • The maximum number of characters in an api file line is 512. It won't fail gracefully if you exceed this, it will fail spectacularly. You can change this in the source `#define MAXLINE`
  • The maximum number of nodes it can drive is 512. Again, changeable in the source `#define MAXNODES`
  • The sample time is hardcoded as 1/30 of second, but can be changed in the source `#define SAMPLETIME`

1.4  Usage

It's probably best to copy all the files in this library into your project root.

Then you can just copy the DCOMM client block from `dcomm_library.mdl into your model. Create an api file similar to the example (see EDGE user's guide for full format) for the nodes you want to drive. Set the filename of the API file in the block parameters. Create a simulink vector (using the Mux, for example) of all the nodes you want to drive, _in the order_ of the API file. Connect that to the DCOMM client block. Start the EDGE manager and then run your model.

It is strongly recommended you use a Set Pace block from the Aerospace Blockset or something similar to make the simulation run in real time.

1.5  Files

dcomm_library.mdl : Simulink Library file containing the Simulink to EDGE block

example.mdl : An example simulink model that drives the default EDGE setup

cev_graphics.api : An example api file used by the example model

multicast.cfg : An example multicast setting file, not used by the example

includes/ : EDGE header files

lib{,64}/ : EDGE shared lib files