OptiTrack MATLAB Plugin
An overview of the samples available in the OptiTrack MATLAB plugin.
Last updated
Was this helpful?
An overview of the samples available in the OptiTrack MATLAB plugin.
Last updated
Was this helpful?
OptiTrack provides a wrapper class (natnet.m) for using real-time streamed NatNet data in MATLAB applications. Using this class, you can easily connect/disconnect to the server, receive the tracking data, and parse each component.
The Matlab-NatNet wrapper class is a wrapper for the NatNet assembly and provides a simplified interface for managing the native members in MATLAB. The class definition and supporting code should be placed within the MATLAB PATH. The implementation automatically disposes running connections when ending a streaming session, along with basic object management. In order to use the Matlab wrapper class, the NatNetML assembly must be loaded into the MATLAB session. This is handled automatically and the first time the class is used the user is prompted to find the NatNetML.dll file in the Windows file browser. A reference to this location is used in future MATLAB sessions.
The MATLAB Plugin provides Samples of Code for MATLAB users to connect to Motive via NatNet streaming. It provides support for streaming in all assets by iteration. It additionally provides examples of listeners, graphing, and data via streaming ID.
The first time you run any of the samples the system will prompt for a DLL. This is the NatNetML.dll that comes packaged with the product.
Load the NatNetML.dll file into MATLAB when prompted, then press play.
MATLAB samples included in the OptiTrack MATLAB plugin have the prefix OptiSample_ in their file names.
The OptiTrack Sample for Rigid Body Graphing supports streaming rigid body asset data from Motive into MATLAB and graphing the results.
This sample demonstrates how to use real time graphing from MATLAB with Motive software.
The NatNet wrapper class interface uses the getFrame method to poll mocap data and return the data structure of the streamed data packet. Polling is supported but not recommended due to access errors.
The function, poll.m, provides a simple example of how to poll the frames of mocap data. Connect the NatNet object to the host server then run the polling script to acquire the data packets in the main workspace.
The OptiTrack Sample for All Asset Types Polling supports streaming from Motive for each asset or device, including rigid bodies, NIDAQ, trained markersets, skeleton data, marker data, force plate data, and camera data. This provides sample code for polling each of the various types of data out of Motive.
The OptiTrack Sample for Rigid Body Marker Data uses the streaming ID of a Rigid Body in Motive to obtain all the marker data for that Rigid Body. This sample demonstrates how to poll individual marker data from an asset into MATLAB.
The OptiTrack Sample for Rigid Body Pose Data uses the streaming ID of a Rigid Body in Motive to poll for associated Rigid Body data including its position and orientation within Motive. This is the twin streaming ID example for MATLAB.
To create an instance of the NatNet wrapper class, call the class with no input arguments and store it in a variable.
Class Properties: To see the available properties to the class, use the following command:
Class Methods Available:
Three types of callback functions are included with the NatNet class. If they are added to the NatNet listener list and enabled, they will execute each time the host sends a frame of data. The setup.m file contains an example of how to operate the class.
The NatNet method, addlistener, requires two input arguments. The first input indicates which listener slot to use, and the second is the name of the m-function file to be attached to the listener. Once the function is attached using the addlistener method, it will be called each time a frame is received. When the callback function is first created, the listener is turned off by default to ensure the user has control of the execution of the event callback function.
Multiple functions can be attached to the listener.
Call the enable method to begin receiving streamed data.
The input of the enable method indicates the index value of the listener to enable. To enable a specific listener enter its index value. Enter 0 to enable all listeners.
To stop streaming, use the disable method. To disable all listeners, enter a value of 0. To disable a specific listener enter its index value.