Page 1 of 1

Stream Arena to Matlab using NatNetML.dll

Posted: Thu Aug 23, 2012 7:01 am
by heath789
Hello,

I am trying to convert the WinFormsSample code to Matlab to be able to use the functions in the libraries. I am not quite sure of the order of steps to take, and also how to access the data in Matlab. I don't have much experience with object-oriented programming, so even the NatNet User's Guide is a little over my head at times. My sample code and output are shown below. Thanks!

Code: Select all

Test1 = NET.addAssembly('E:\OPTITRACK\DOCUMENTATION\NatNetSDK2.2\NatNetSDK\lib\x64\NatNetML.dll');

m_NatNet = NatNetML.NatNetClientML(1);
m_FrameOfData = NatNetML.FrameOfMocapData;

m_NatNet.Initialize('CurentIP','CurrentIP')

ver = zeros(1,4,'int32');
ver = m_NatNet.NatNetVersion()

rb = NatNetML.RigidBodyData;
rb = m_FrameOfData.RigidBodies

m_NatNet.Uninitialize()

Output:

ans =

0


ver =

System.Int32[] handle
Package: System

Properties:
Length: 4
LongLength: 4
Rank: 1
SyncRoot: [1x1 System.Int32[]]
IsReadOnly: 0
IsFixedSize: 1
IsSynchronized: 0

Methods, Events, Superclasses


rb =

NatNetML.RigidBodyData[] handle
Package: NatNetML

Properties:
Length: 1000
LongLength: 1000
Rank: 1
SyncRoot: [1x1 NatNetML.RigidBodyData[]]
IsReadOnly: 0
IsFixedSize: 1
IsSynchronized: 0

Methods, Events, Superclasses


ans =

0

Re: Stream Arena to Matlab using NatNetML.dll

Posted: Fri Aug 24, 2012 5:26 pm
by morgan
you'll need to add a callback handler for when data is delivered:

Code: Select all

            // [NatNet] set a "Frame Ready" callback function (event handler) handler that will be
            // called by NatNet when NatNet receives a frame of data from the server application
            m_NatNet.OnFrameReady += new NatNetML.FrameReadyEventHandler(m_NatNet_OnFrameReady);
In gneeral you will follow the steps in the WinForms example:
- Connect
- Set Callback
- Get Data in Callback

Not sure exactly how to do events though in MatLab - anyone?

Re: Stream Arena to Matlab using NatNetML.dll

Posted: Mon Aug 27, 2012 8:43 am
by heath789
After I initialize, I try to run the following code:

Code: Select all

descs = NatNetML.DataDescriptor

m_NatNet.GetDataDescriptions()
I get the following output:

descs =

NatNetML.DataDescriptor handle
Package: NatNetML

Properties:
type: 0

Methods, Events, Superclasses

Error using StreamTestA (line 30)
Message: Object reference not set to an instance of an object.
Source: NatNetML


Are you saying that you can't do anything with the stream until you set up some sort of event listener? Inside the Delegates section of the assembly, I see 'NatNetML.FrameReadyEventHandler', is this what I want?

Re: Stream Arena to Matlab using NatNetML.dll

Posted: Mon Aug 27, 2012 10:38 am
by heath789
I've tried various methods to implement the listener:

h = NatNetML.FrameReadyEventHandler(@greenbeans);
h1 = m_NatNet.addlistener('OnFrameReady',@greenbeans);
h2 = h.addlistener('OnFrameReady',@greenbeans);

I don't get errors but I'm not sure how to make sure it is working, in the data descriptions it says there is nothing.

Re: Stream Arena to Matlab using NatNetML.dll

Posted: Tue Sep 04, 2012 6:39 am
by heath789
Still trying to figure this out.

I am trying to connect to the server and get the server description, but it always returns a zero for Host Present in the server description properties.

m_NatNet = NatNetML.NatNetClientML
desc = NatNetML.ServerDescription
ReturnCode = GetServerDescription(m_NatNet)

This signature is what Matlab says to use, but the signature in the NatNet user's guide is different.

Any ideas?

Re: Stream Arena to Matlab using NatNetML.dll

Posted: Thu Nov 29, 2012 8:57 pm
by gerard
hi heath789, I tried to used your code to connect NatNet version 2.2 with Matlab in a computer of 64-bit, but i don't have succed, did you can solve your problem? could you give me some ideas for resolve this problem?. thank you.