If you are working in an environment that supports the use of the Vicon DataStream SDK (where TCP/IP is supported), you can use the SDK from within a Simulink block (S-function) to access data streamed from Vicon Tracker.

In addition, Vicon Tracker 3 includes a UDP stream that contains object translation and rotation data. If you are working in an environment that supports only UDP and therefore cannot use the Vicon DataStream SDK to access Tracker object data from Simulink, you can access Tracker positional data from the UDP stream.

The UDP stream contains only a small subset of the data that is available via the Vicon DataStream SDK, so if possible, use the Vicon DataStream SDK in preference to the UDP stream.

To help you access Tracker data from Simulink, examples of both types of access are installed with Tracker. They can be found in the following default location:

C:\Program Files\Vicon\Tracker3.#\Simulink

For more information, see:

Prerequisites for using Simulink with Vicon Tracker

To use Simulink with Tracker, ensure the following requirements are met:


About the UDP stream

The UDP stream outputs translation and rotation information for active objects in Vicon Tracker.

To access data from this stream you must write a 'client' to access the stream and parse the data block to access its contents. The example clients provided with Tracker illustrate the block parsing and some possible configurations for block outputs. 

For each frame in Tracker, one or more data blocks are sent. The number of blocks per frame sent is dependent on:

The UDP Stream parameters are stored in the .system file:

Example UDP Packet contents table

The following UDP Packet contents table provides more technical detail about the layout and content of the UDP stream. You may find this useful if, for example, you want to use the UDP stream, but do not want to use it with Simulink. It is taken from DataBlock.h, which is one of the Simulink example files:


Byte offset

Content

Comment

0-3

Frame Number

nnnn

4

ItemsInBlock

2

5

ItemHeader:ItemID

0 (0 for object data. Other object types not currently supported.)

6-7

ItemHeader:ItemDataSize

72

8-31

TrackerObject:ItemName

'O''b''j''e''c''t''1'00000000000000000

32-39

TrackerObject:TransX


40-47

TrackerObject:TransY


48-55

TrackerObject:TransZ


56-63

TrackerObject:RotX


64-71

TrackerObject:RotY

72-79

TrackerObject:RotZ


80

ItemHeader:ItemID

0 (0 for object data. Other object types not currently supported.)

81-82

ItemHeader:ItemDataSize

72

83-106

TrackerObject:ItemName

'O''b''j''e''c''t''2'00000000000000000

107-114

TrackerObject:TransX


115-122

TrackerObject:TransY


123-130

TrackerObject:TransZ


131-138

TrackerObject:RotX


139-146

TrackerObject:RotY


147-154

TrackerObject:RotZ


Object data output by the UDP stream

Data that is output matches the Vicon DataStream SDK values for the same frame. The UDP stream contains no axis mapping options.
For each object six values are output:


About the Simulink examples provided with Vicon Tracker

All of the examples consist of an S-function along with a Simulink model showing a block using the custom S-function in a simulation. Note the following points:

Single block parameter:

Multiple block parameters:

How to run the Simulink examples

The following steps described how to run one of the Simulink examples provided with Vicon Tracker, which demonstrate how to obtain Vicon Tracker data from Simulink.

When you compile the code for the custom blocks, files are created in the same folder as your source file. It is recommended that you copy the example files to a folder other than the Tracker installation folder before compiling, running, or modifying the example files.  

To run an example:

  1. Ensure Tracker is running and streaming data.
  2. The examples reference objects named Object1 and/or Object2. If you need to change the objects that are displayed, modify the block parameters to reference the desired object(s).
  3. Open MATLAB.
    A MATLAB window similar to the following is displayed:
  4. Change your current folder to one containing the example you want to run.
  5. Compile the example file. For more information, see the specific compile information below. Vicon DataStream SDK examples need to link in the proper Vicon DataStream SDK file as well.
  6. Load the model by dragging the desired .mdl file from the file listing to the command window.
     

    This issues a uiopen command passing in the file you are dragging and opens the model window.
  7. In the model window click the Play button to run the simulation.

     If the model contains a scope block to draw a graph of the data, you must double-click on the scope to open it – it does not open automatically.

Vicon DataStream SDK examples

Before you use any of the Vicon DataStream SDK examples, they must be compiled and linked with the Vicon DataStream SDK.

To compile and link the Vicon DataStream SDK examples:

  1. Copy the CPP files from the Vicon DataStream SDK installation folder to the folder containing the example files.
    Your file names might be slightly different from those in the following illustration, depending on the version of the Vicon DataStream SDK you are using.
  2. To compile and link C++ code, use the mex command. You need to compile the .cpp file and then link it with the Vicon DataStream SDK .lib file. You can do this in a single step that looks like this

    Successful compilation results in the creation of a file with a .mexw64 extension.

Vicon DataStream SDK SingleObject example

This example displays the positional information for an object (object name specified as block parameter). Each of the translation and rotation values is on a separate output.

Vicon DataStream SDK MultipleObjects example

This example displays the positional information for two objects (names specified as block parameters). Three values are provided for each of the four defined outputs.

UDP stream examples

All examples use the Instrument Control Toolbox receiving UDP packets. This toolbox is licensed separately (i.e. it is not part of the Simulink license).

All of the example S-functions have been written in C. Before using any of these examples, they must be compiled. 

To compile the examples:

ObjectPerPort folder

This folder contains two models:
TrackerSingleObject.mdl
and TrackerMultipleObjects.mdl

Both models use the same custom S-function, TrackerSingleObjectParser. The object parsing function looks for the object name passed in as a block parameter and displays the positional information for the object. Each of the translation and rotation values is on a separate output.

You must configure the UDP Receive blocks in the models to match Tracker output with regard to data block size and port numbers.

UDP stream TrackerSingleObject example

This example displays the positional information for an object (object name specified as block parameter). Each of the translation and rotation values is on a separate output.

UDP stream TrackerMultipleObjects example

This model has two UDP receive blocks to receive data from Tracker, using the Object Per Port option.

UDP stream MultipleObjectsSamePort example

This example displays the positional information for two objects (object names specified as block parameters). Three values are provided for each of the four defined outputs.