NatNet User's Guide Nat Net Users

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 22

DownloadNatNet User's Guide Nat Net Users
Open PDF In BrowserView PDF
NatNet API
User’s Guide
Version 2.8.0
April 2015

Technical support
help.naturalpoint.com
1-888-965-0435

TABLE OF CONTENTS
NatNet Overview ....................................................................................................................................................................................... 3
SDK Contents ............................................................................................................................................................................................. 4
Folder Contents...................................................................................................................................................................................... 4
Running the Samples ................................................................................................................................................................................. 5
Running the Simple Client-Server Sample ............................................................................................................................................. 6
Running the rigid body sample (SampleClient3D) ................................................................................................................................. 7
Running the .NET sample ....................................................................................................................................................................... 9
Using the NatNet SDK .............................................................................................................................................................................. 11
Building a Native Client to Receive NatNet Data ................................................................................................................................. 11
Building a Native Server to Send NatNet Data ..................................................................................................................................... 11
Building a Managed .NET Client to Receive NatNet Data .................................................................................................................... 11
API Reference........................................................................................................................................................................................... 12
NatNet Data Types ............................................................................................................................................................................... 12
NatNetClient Class ............................................................................................................................................................................... 13
Description ....................................................................................................................................................................................... 13
Constructor & Destructor Documentation ...................................................................................................................................... 17
Member Function Documentation .................................................................................................................................................. 17
Appendix A : Bitstream Syntax ................................................................................................................................................................. 21
Building a Direct Depacketization Client (Without NatNet)................................................................................................................. 21
Technical Support .................................................................................................................................................................................... 22

NatNet User's Guide

2

NATNET OVERVIEW
The NatNet SDK is a Client/Server networking SDK for sending and receiving NaturalPoint data across networks. NatNet uses the
UDP protocol in conjunction with either Point-To-Point Unicast or IP Multicasting for sending data.
The following diagram outlines the major component communication of a typical NetNet setup.

Figure 1 – NatNet Component Overview

NatNet Server App
(Motive, Arena,
TrackingTools)

Multicast Address
(224.0.0.1:1001)
OR
Unicast Address
(app defined ip/port) UDP Packets

NatNet .NET
Assembly
(NatNetML.dll)

NatNet Managed
Client (e.g. VB.Net,
MatLab)

NatNet SDK
(NatNet.lib)

NatNet Native
Client

Direct
Depacketization
Client (e.g. Unix
clients)

A NatNet Server has 2 threads and 2 sockets, one for sending data, and one for receiving/sending commands. A NatNet Client has 2
threads and 2 sockets, one for receiving data, and one for receiving/sending commands.
NatNet servers and clients can exist on the same or separate machines. Additionally, multiple NatNet clients can connect to a single
NatNet server. When a NatNet server is configured to use IP Multicast, the data is only sent once, to the Multicast group.

NatNet User's Guide

3

SDK CONTENTS
The NatNet SDK consists of:
NatNet Library
NatNet Assembly
NatNet Samples

Native C++ networking library (headers, static library (.lib) and dynamic import library (.lib/.dll))
Managed .NET assembly (NatNetML.dll) for use in .Net compatible clients.
Sample projects and executables designed to be quickly integrated into your own code.

FOLDER CONTENTS

Folder

Contents

\include

NatNet SDK header files. Client applications should include these.

\lib

Static and dynamic library files for the NatNet SDK.

\lib\x64

64-bit versions of the library files.

\Samples

VisualStudio 2005 samples. Use the solution file here to open all sample
projects.

\Samples\bin

Precompiled samples with sample data files.

\Samples\SampleClient

Sample NatNet console app that connects to a NatNet server, receives a
data stream, and writes that data stream to an ascii file

\Samples\SampleClient3D

Sample NatNet console app that connects to a NatNet server, receives a
data stream, and displays that data in an OpenGL 3D window.

\Samples\SimpleServer

Sample NatNet console app that creates and starts a NatNet server, creates
simple Marker, RigidBody, and Skeleton data, and streams that data onto
the network.

\Samples\PacketClient

Simple example showing how to connect to a NatNet multicast stream and
decode NatNet packets directly without using the NatNet SDK.

\Samples\WinFormsSample

Simple C# .NET sample showing how to use the NatNet managed assembly
(NatNETML.dll).

NatNet User's Guide

4

\Samples\Matlab

Sample MATLAB code file (.m) for using MATLAB with the NatNet managed
assembly (NatNETML.dll).

\Samples\NatCap

Sample Capture start/stop broadcast app.

NatNet User's Guide

5

RUNNING THE SAMPLES
Pre-compiled versions of the NatNet samples have been provided in the \Samples\bin folder. These versions can be used to quickly
test your application. Please refer to the instructions in this section for information on running specific samples.

Note! The Visual C++ runtime libraries are required to run the samples. If you encounter an error message when attempting to
run the samples, especially on machines without Visual C++ installed, please install the VC runtime redistributable package located in
Samples\VCRedist. If the problem persists, please try rebuilding the samples using Visual C++, or contact support.

RUNNING THE SIMPLE CLIENT-SERVER SAMPLE
1. Start the server:
SimpleServer.exe
2. Start the client:
SampleClient.exe [IPAddress] [OutputFilename.txt]
3. Start streaming by pressing 's' in the SimpleServer console window.
You should begin to see data streaming in the client window or to text file.
Note



[parameters] are optional.
If no IP address is specified, the client will assume the server is on the same machine (local machine).

NatNet User's Guide

6

RUNNING THE RIGID BODY SAMPLE (SAMPLECLIENT3D)
The Rigid Body sample (SampleClient3D) illustrates how to decode NatNet 6DOF Rigid Body and Skeleton Segment data from
OptiTrack quaternion format to euler angles and display them in a simple OpenGL 3D viewer. This sample also illustrates how to
associate RigidBody/Skeleton Segment names and IDs from the data descriptions with the IDs streamed in the FrameOfMocapData
packet.
SampleClient3D - Decoding and drawing labeled rigid body position and orientation (6DOF) data

With Client/Server on same machine:
1. [Motive] Load a dataset with rigid body or skeleton definitions
2. [Motive] Enable network streaming ( Data Streaming Pane -> Check Broadcast Frame Data )
3. [Motive] Enable streaming rigid body data (check Stream Options -> Stream Rigid Bodies = True)
4. [Sample3D] File -> Connect
With Client/Server on separate machines:
1. [Motive] Load a dataset with rigid body or skeleton definitions
2. [Motive] Set IP address to stream from (Network Interface Selection -> Local Interface)
3. [Motive] Enable network streaming ( Data Streaming Pane -> Check Broadcast Frame Data )
4. [Motive] Enable streaming rigid body data (check Stream Options -> Stream Rigid Bodies = True)
5. [Sample3D] Set Client and Server IP addresses
6. [Sample3D] File -> Connect
Note


IP Address

NatNet User's Guide

IP Address of client NIC card you wish to use.
7



Server IP Address

NatNet User's Guide

IP Address of server entered in step 2 above.

8

RUNNING THE .NET SAMPLE
1. Start a NatNet server application (e.g. Motive).
2. Enable NatNet streaming from the Server application.
3. Start the WinForms sample application from the NatNet Samples folder.
4. Update the “Local” and “Server” IP Addresses as necessary.
5. Press the “Connect” button to connect to the server.
6. Press the “GetDataDesc” button to request and display a detailed description of the Server’s currently streamed objects.
7. Select a Row in the DataGrid to display that value in the graph.
Receiving NatNet data in a .NET Environment

NatNet User's Guide

9

RUNNING THE MATLAB SAMPLE
1. Motive
2. Motive
3. Matlab
4. Matlab
5. Matlab

Start a NatNet server application (e.g. Motive).
Enable NatNet streaming from the Server application.
Start Matlab
Open the NatNetMatlabSample.m file.
From the editor window, press Run
Real-Time Streaming Mocap data from Motive into MATLAB

NatNet User's Guide

10

USING THE NATNET SDK
The code samples are the quickest path towards getting NatNet data into your application. We typically recommend you:
1.

Identify your application’s development/interface requirements (managed, native, etc).

2.

Adapt the NatNet sample code from the corresponding NatNet sample application in the samples folder into your
application.

3.

Use the API reference for additional information.

The Visual Studio solution file \Samples\NatNetSamples.sln will open and build all of the NatNet sample projects.
If you are creating an application from scratch, please refer to the following sections for application specific requirements.

BUILDING A NATIVE CLIENT TO RECEIVE NATNET DATA
Steps for building a NatNet client application/library to receive data from a NatNet server application such as Motive:
1. Adapt the SampleClient sample (SampleClient.cpp) to your application's code.
2. Include NatNetClient.h and NatNetTypes.h
3. Link to NatNetLib.lib (dynamic) OR NatNetLibStatic.lib (static)
4. [OPTIONAL] If linking dynamically, define NATNETLIB_IMPORTS and distribute NatNetLib.dll with your application
Note : Be sure to link to ws2_32.lib if linking to NatLetLib statically.

BUILDING A NATIVE SERVER TO SEND NATNET DATA
Steps for building a NatNet server application/library to send/forward NatNet formatted data to a NatNet client application:
1. Adapt SimpleServer (SampleServer.cpp) to your application's code.
2. Include NatNetServer.h and NatNetTypes.h
3. Link to NatNetLib.lib (dynamic) OR NatNetLibStatic.lib (static)
4. [OPTIONAL] if linking dynamically, define NATNETLIB_IMPORTS and distribute NatNetLib.dll with your application
Note : Be sure to link to ws2_32.lib if linking to NatLetLib statically.

BUILDING A MANAGED .NET CLIENT TO RECEIVE NATNET DATA
Steps for building a managed NatNet client application.
1. Add the NatNetML.dll .NET assembly as a reference to your VB.NET/C# project.
2. The NatNetML namespace is now available to your code, in addition to intellisense library comments.
Note : When distributing your .NET application, be sure to distribute the NatNetML.dll as well.

NatNet User's Guide

11

API REFERENCE
The NatNET API consist of the following objects:
NatNetClient

The class for communicating with a NatNet Server such as Motive.

NatNetServer

The class for implementing a NatNet server and sending NatNet formatted data packets.

NatNet Data Types

Structures encapsulating data encoded in NatNet packets.

NatNet Assembly

A managed (.NET) class library that can be called by .NET components. The NatNet assembly wraps the
underlying native NatNet library, exposing the NatNetClient and NatNet Data Types for use in .NET
compatible environments (e.g. VB.NET, C#, LabView, MatLab).

NATNET DATA TYPES
NatNet server applications stream the following types of motion capture data.
NatNet Data Types
Data Type

Description

MarkerSet Data

A named collection of identified markers and the marker positions (X,Y,Z). This list is ordered, padded,
point cloud solved, model filled (where occluded). This list also contains special MarkerSet named "all"
which is a list of all labeled markers.

RigidBody Data

A named segment with a unique ID, position, and orientation data, and the collection of identified
markers used to define it. Marker data is model-solved positions.

Skeleton Data

A named, hierarchical collection of RigidBodies. Marker data is model-solved positions.

Labeled Markers

Ordered, padded, point cloud solved, model filled (where occluded) labeled Marker data (labeled
markers not associated with a "MarkerSet").

Unlabeled Markers
(Other markers)

List of point cloud solved 3D positions for all markers in the frame that were unlabeled by either the
skeleton or the rigid body solver.

Timestamp data

Timing information for the frame, including:
Frame ID
Frame Timestamp
SMPTE Timecode (If timecode is present)

NatNet User's Guide

12

NatNet clients can discover what data objects a server application is currently streaming out of band or ahead of time using the
DataSetDescriptions structure. NatNet clients receive actual data from a server using the FrameOfMocapData structure. Both of
these packets are delivered to the client via the DataHandler callback.
Dataset Descriptions This packet contains a description of the motion capture data sets (MarkerSets, Skeletons,
RigidBody) for which a frame of motion capture data will be generated.
Frame of Mocap Data This packet contains a single frame of motion capture data for all the data sets described in the
Dataset Descriptions.
In addition to the formal data sets described above, FrameOfMocapData also contains additional per-frame tracking data. This
additional data is not described in the DataSetDescriptions structure as it is typically not known ahead of time or out of band, but on
a frame by frame basis:
Labeled Markers Labeled Markers not associated with a pre-defined MarkerSet or RigidBody. This data type is used when
MarkerSets and/or RigidBodies are not explicitly defined in the Tracking Application but labeled markers are still generated.
Other Markers All 3D points that were triangulated but not labeled for the given frame.
It is possible for data to be duplicated between structures. For example, a given FrameOfMocapData may contain the same marker
in LabeledMarkers as well as within the RigidBody data structure. In those cases, marker id can be used in the client code to
correlate if necessary.
The SampleClient sample illustrates how to retrieve data descriptions and data and interpret this data.
Please refer to the NatNetTypes.h header file or the NatNetML.dll assembly for the most up to date descriptions of the types.

COORDINATE SYSTEM CO NVENTIONS
In the NatNet data stream, orientation data is represented as a quaternion. Quaternion orientations are order independent,
however they do indicated a handedness. When decomposing quaternions into Euler angles, it is important to consider the
coordinate system conventions you want to convert into. An Euler angle convention must account for:
 Rotation order
 Left handed or Right handed
 Static (Global) or Relative (Local) Axes
As an example, the OptiTrack Motive software uses the following "Motive" coordinate system convention:

X (Pitch), Y (Yaw), Z (Roll), Right-Handed (RHS), Relative Axes (aka 'local')

The NatNet SDK includes quaternion to Euler conversion routines. Please refer to the WinForms sample or the SampleClient3D for
specific implementation details and usage examples.

NatNet User's Guide

13

REMOTE COMMAND AND CONTROL
NatNet provides a command / request mechanism for passing commands and request between NatNet server’s (Motive) and NatNet
Client’s (your application). Examples of commands / requests are starting/stopping record, setting the current take name, or
querying the server for the current framerate.
Motive Supported Command/Request
Command

Description

Parameters

Returns

UnitsToMillimeters

Request current system’s units, in
terms of millimeters

none

float

FrameRate

Request current system’s tracking
framerate

none

float

StartRecording

Start recording

none

none

StopRecording

Stop recording

none

none

LiveMode

Switch to Live mode

none

none

EditMode

Switch to Edit mode

none

none

TimelinePlay

Start take playback

none

none

TimelineStop

Stop take playback

none

none

TakeName

Set the current take name

Take name

none

Refer to the SendMessage(…) and SendMessageAndWait(…) functions in the API reference for more details.

NatNet User's Guide

14

TIMECODE
On supported systems, all frames of NatNet data will contain an OptiTrack timecode stamp, which is an extended form of the typical
studio SMPTE timecode stamp.
Note: SMPTE Timecode support requires an OptiTrack eSync hub.
Because motion capture frame rates typically exceed standard SMPTE timecode frame rates, an additional “subframe” value is
added to the end of the timecode stamp. This “subframe” value is the 0-based, nth “in-between” frame:
Typical OptiTrack Timecode Representation
( 120 fps mocap data, 30-fps no-drop SMPTE timecode source )

In the above representation, for a typical 120 fps motion capture session synched to a 30 fps no-drop SMPTE timecode studio-sync
source, there is a 4 : 1 ratio of motion capture frames to studio frames. The extra motion capture frames are represented by the
OptiTrack SubFrame field in the OptiTrack timecode.
The generic form for OptiTrack timecode is:

HH:MM:SS:FF.Y

hours:minutes:seconds:frames.subframe

OptiTrack timecode is sent to NatNet clients in the form of 2 unsigned integers.
unsigned int Timecode

OptiTrack encoded SMPTE timecode

unsigned int TimecodeSubframe

OptiTrack encoded sub-frame data

Note : The FrameOfMocapData structure contains two entries for timecode information for a given frame of timecode data.
The Timecode parameter is interpreted differently when streaming Live or from File Playback (Edit).
In Live mode, the Timecode parameter is only valid when SMPTE timecode is present in your Mocap hardware setup, typically when
using the eSync and a timecode generator. When present, the Timecode parameter will be a correctly formatted SMPTE timecode
value.
In Edit Mode, the Timecode parameter is the current frame number converted to SMPTE Timecode format.

NatNet User's Guide

15

The NatNet SDK provides helper routines to decode the Timecode parameter into a string friendly format as well as the subframe of
mocap data that may exist between whole timecode frames.

Latency is the capture computer's hardware timestamp for the given frame, which is also displayed in Motive in the Camera Preview
viewport when camera info is enabled. This is the same whether live or playback from file.
Timecode values should not be used directly, but decoded using the NatNet timecode utility functions:
bool DecodeTimecode(unsigned int inTimecode,
unsigned int inTimecodeSubframe, int* hour,
int* minute, int* second, int* frame, int*
subframe);

Helper function to decode IOptiTrack timecode data into
individual timecode values

bool TimecodeStringify(unsigned int inTimecode,
unsigned int inTimecodeSubframe, char *Buffer,
int BufferSize);

Helper function to decode OptiTrack timecode into a user
friendly string in the form “hh:mm:ss:ff:yy”

The following is an example of how to decode timecode using the NatNet helper functions (from the SampleClient.cpp example):
// decode timecode to values
int hour, minute, second, frame, subframe;
bool bValid = pClient->DecodeTimecode(data->Timecode, data->TimecodeSubframe, &hour, &minute,
&second, &frame, &subframe);
// decode timecode to friendly string
char szTimecode[128] = "";
pClient->TimecodeStringify(data->Timecode, data->TimecodeSubframe, szTimecode, 128);
printf("Timecode : %s\n", szTimecode);

NatNet User's Guide

16

NATNETCLIENT CLASS
DESCRIPTION
NatNetClient is a complete C++ class for connecting to NatNet server applications, such as Motive.

CONSTRUCTOR & DESTRU CTOR DOCUMENTATION
NatNetClient::NatNetClient ()
Creates a new (multicast) instance of a NatNet Client.
NatNetClient::NatNetClient (int iConnectionType)
Creates a new instance of a NatNet Client using the specified connection protocol.
Parameters:
iConnectionType Type of connection (0 = Multicast, 1 = Unicast).
NatNetClient::~NatNetClient ()
Destructor.
NatNetClient::Uninitialize()
Disconnects from server.

MEMBER FUNCTION DOCUMENTATION
int NatNetClient::GetDataDescriptions (sDataDescriptions ** pDataDescriptions)
Requests a description of the current streamed data objects from the server app. This call blocks until request is responded to
or times out.
Parameters:
pDataDescriptions Array of Data Descriptions.
Returns:
On success, number of data objects. 0 otherwise.

NatNet User's Guide

17

sFrameOfMocapData * NatNetClient::GetLastFrameOfData ()
Retrieves the most recently received frame of mocap data.
Returns:
Frame of Mocap Data
int NatNetClient::GetServerDescription (sServerDescription * pServerDescription)
Requests a description of the current NatNet server the client is connected to. This call blocks until request is responded to or
times out.
Parameters:
pServerDescription Description of the NatNet server.
Returns:
On success, number of data objects. 0 otherwise.
int NatNetClient::Initialize (char * szLocalAddress, char * szServerAddress)
int NatNetClient::Initialize (char * szLocalAddress, char * sz ServerAddress, int HostCommandPort)
int NatNetClient::Initialize (char * szLocalAddress, char * sz ServerAddress, int HostCommandPort, int
HostDataPort)
Initializes client socket and attempts to connect to a NatNet server at the specified address.
Parameters:
szLocalAddress IP address of client
szServerAddress IP address of server
HostCommandPort server command port (default = 1510)
HostDataPort server data port (default = 1511)
Returns:
0 if successful, error code otherwise
void NatNetClient::SetMulticastAddress (char * szMulticast)
Sets the NatNet server multicast group/address to connect to. SetMulticastAddress() must be called before calling Initialize(...).
Parameters:
szCommand application defined Message string
void NatNetClient::NatNetVersion (unsigned char Version[4])
Retrieves the version of the NatNet library the client is using.
Parameters:
Version version array (form: major.minor.build.revision)

NatNet User's Guide

18

void NatNetClient::SendMessage (char * szCommand)
Sends a message to the server and returns. Response will be delivered in-band.
Parameters:
szCommand application defined Message string
int NatNetClient::SendMessageAndWait (char * szCommand, int tries, int timeout, void ** Response, int *
pnBytes)
Sends an application-defined message to the NatNet server and waits for a response.
Parameters:
szCommand Application defined message.
tries Number of times to try and send the message
timeout time to wait for response (in milliseconds) before timing out
Response Application defined response.
pnBytes Number of bytes in response
Returns:
0 if succssful, error code otherwise.
int NatNetClient::SendMessageAndWait (char * szCommand, void ** Response, int * pnBytes)
Sends an application-defined message to the NatNet server and waits for a response.
Parameters:
szCommand Application defined message.
Response Application defined response.
pnBytes Number of bytes in response.
Returns:
0 if successful, error code otherwise.
int NatNetClient:: SetDataCallback(void (*CallbackFunction)(sFrameOfMocapData *FrameOfData, void* pUserData),
void* pUserData /*=NULL*/)
Sets the data callback function for NatNet frame delivery. This function will be called whenever NatNet receives an in-band data
(e.g. frame of data).
Parameters:
CallbackFunction Callback Function
pUserData User-Definable data
Returns:
0 if successful, error code otherwise.

NatNet User's Guide

19

void NatNetClient::SetVerbosityLevel (int iLevel)
Sets the message reporting level for internal NatNet messages.
Parameters:
iLevel Verbosity level (see Verbosity level in NatNetTypes.h)
int NatNetClient::Uninitialize ()
Disconnects from the current NatNet Server.
Returns:
0 if successful, error code otherwise.

NatNet User's Guide

20

APPENDIX A : BITSTREAM SYNTAX
In order to provide the most current bitstream syntax, the NatNet SDK includes a testable working depacketization sample that
decodes NatNet Packets directly without using the NatNet client library.
Note: Decoding packets directly is not recommended. The bitstream packet syntax is subject to change, requiring an application
to rebuild against the latest NatNet library. NatNet packets should only be decoded directly where use of the NatNet library is not
possible.
Using the NatNet client library protects client applications from future bistream syntax changes.

BUILDING A DIRECT DEPACKETIZATI ON CLIENT (WITHOUT N ATNET)
For situtions where you would like to receive a NatNet data stream but it is not possible to use the NatNet client library (e.g. on an
unsupported platform such as Unix), you can use the PacketClient sample as a template for depacketizing NatNet packets directly.
1. Adapt the PacketClient sample (PacketClient.cpp) to your application's code.
2. Regularly update your code with each revision to the NatNet bitstream syntax.

NatNet User's Guide

21

TECHNICAL SUPPORT
NaturalPoint is committed to providing best-in-class technical support.
In order to provide you with the most up to date information as quickly as possible, we recommend the following procedure:
1.

Update to the latest software. For the latest versions of OptiTrack software, drivers, and SDK samples, please visit our
downloads section:
http://www.naturalpoint.com/optitrack/support/downloads.html

2.

Check out the OptiTrack FAQs:
http://www.naturalpoint.com/optitrack/support/opti-faq.html

3.

Check the forums. Very often a similar issue has been reported and solved in the forums:
http://forum.naturalpoint.com/

4.

Contact technical support:
Phone: 541-753-6645
Fax: 541-753-6689
Email Form: http://www.naturalpoint.com/optitrack/support/contact/
Mail:

NatNet User's Guide

NaturalPoint, Inc.
P.O. Box 2317
Corvallis, OR 97339

22



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Page Count                      : 22
Language                        : en-US
Tagged PDF                      : Yes
Title                           : NatNet User's Guide
Author                          : NaturalPoint
Creator                         : Microsoft® Word 2013
Create Date                     : 2015:05:04 12:14:38-07:00
Modify Date                     : 2015:05:04 12:14:38-07:00
Producer                        : Microsoft® Word 2013
EXIF Metadata provided by EXIF.tools

Navigation menu