Motive (NatNet) interface to Simulink using Optitrack Camera

NatNet, VRPN, TrackD, and Plugins
Post Reply
orhirshfeld
Posts: 16
Joined: Tue Jun 17, 2014 9:42 am

Motive (NatNet) interface to Simulink using Optitrack Camera

Post by orhirshfeld »

I need to create interface between Simulink to Motive I already succeed to interface between Matlab and Motive through NatNet, I reviewed the sample available with NatNet SDK to do so but I'm having trouble to migrate it to Simulink, I tried using Matlab function block unsuccessfully, it's have problem to use the dll command.

the error i got from Simulink is : Undefined function or variable 'NatNetML.NatNetClientML'.

I want to thanks Glen Lichtwark sample that helped me writing interface to matlab http://www.mathworks.com/matlabcentral/ ... optitrack-

the code i tried is the follwing:

Code: Select all

function [x,y,z,yaw,pitch,roll] = Location_Orinteation_Motive_64bit(RigidBody_ID) %#codegen
coder.extrinsic('–sync:on','quaternion','fullfile','NET.addAssembly','addpath')
dllPath = fullfile('c:','NatNetSDK2.5','lib','x64','NatNetML.dll');
assemblyInfo = NET.addAssembly(dllPath);
addpath('E:\Motive')
dllPath = fullfile('c:','NatNetSDK2.5','lib','x64','NatNetML.dll');
assemblyInfo = NET.addAssembly(dllPath);
theClient = NatNetML.NatNetClientML(0); % Input = iConnectionType: 0 = Multicast, 1 = Unicast
% Connect to an OptiTrack server (e.g. Motive)
HostIP = char('127.0.0.1');
theClient.Initialize(HostIP, HostIP); % Flg = returnCode: 0 = Success
% data
 frameOfData = theClient.GetLastFrameOfData()
 rigidBodyData = frameOfData.RigidBodies(RigidBody_ID)
 x=rigidBodyData.x
 y=rigidBodyData.y
 z=rigidBodyData.y
% angle 
q = quaternion( rigidBodyData.qx, rigidBodyData.qy, rigidBodyData.qz, rigidBodyData.qw ); % extrnal file quaternion.m
qRot = quaternion( 0, 0, 0, 1);     % rotate pitch 180 to avoid 180/-180 flip for nicer graphing
q = mtimes(q, qRot);
angles = EulerAngles(q,'zyx');
yaw = angles(2) * 180.0 / pi;
pitch = -angles(1) * 180.0 / pi;   % must invert due to 180 flip above
roll = -angles(3) * 180.0 / pi;   % must invert due to 180 flip above 
thanks
Or Hirshfeld

http://il.linkedin.com/pub/or-hirshfeld/4b/79/577/
morgan
NaturalPoint Employee
NaturalPoint Employee
Posts: 199
Joined: Tue Jun 24, 2008 2:01 pm
Location: Corvallis, OR, USA
Contact:

Re: Motive (NatNet) interface to Simulink using Optitrack Ca

Post by morgan »

the error i got from Simulink is : Undefined function or variable 'NatNetML.NatNetClientML'.
This usually means MATLAB cannot find the NatNetML.dll or one of its dependencies.

You might try confirming the NatNetML.dll is at the path specified in the code (i.e. dllPath = fullfile('c:','NatNetSDK2.5','lib','x64','NatNetML.dll' )

and that the other NatNet samples are able to load/run with it (e.g. the Winforms sample sues the NatNetML.dll).

Morgan
orhirshfeld
Posts: 16
Joined: Tue Jun 17, 2014 9:42 am

Re: Motive (NatNet) interface to Simulink using Optitrack Ca

Post by orhirshfeld »

Thank you for your respone
But i double check the location
And also when i run the code in Matlab workspace and not simulink it's works fine.

Or Hirshfeld
אור הירשפלד
morgan
NaturalPoint Employee
NaturalPoint Employee
Posts: 199
Joined: Tue Jun 24, 2008 2:01 pm
Location: Corvallis, OR, USA
Contact:

Re: Motive (NatNet) interface to Simulink using Optitrack Ca

Post by morgan »

I'm afraid I'm not too familiar with how Simulink consumes MATLAB / .NET assemblies.

[UPDATE]

One suggestion was to put the .NET assembly in the MATLAB working directory.

[/UPDATE]

A completely separate approach would be to consume NatNet UDP packets directly in Simulink. This approach does not require using the NatNETML assembly at all. The disadvantage is you would need to parse the UDP packet directly from Simulink/MATLAB code.

The NatNet SDK ships with a PacketClient sample that shows how to do this in C++. You would need to port this over to MATLAB.

We'll contact MathWorks to see if they have any proposed solution for the .NET assembly pathway.

Morgan
orhirshfeld
Posts: 16
Joined: Tue Jun 17, 2014 9:42 am

Re: Motive (NatNet) interface to Simulink using Optitrack Ca

Post by orhirshfeld »

I found a solution that work well by Raphael Cherfan
http://www.mathworks.com/matlabcentral/ ... iveexample

but it still not working in external mode so i'm trying now to get it done with C-Mex S-function
https://github.com/orhirshfeld/Motive-S-function
minkow38
Posts: 1
Joined: Mon Oct 16, 2017 12:31 am

Re: Motive (NatNet) interface to Simulink using Optitrack Ca

Post by minkow38 »

orhirshfeld wrote:I found a solution that work well by Raphael Cherfan
http://www.mathworks.com/matlabcentral/ ... iveexample

but it still not working in external mode so i'm trying now to get it done with C-Mex S-function
https://github.com/orhirshfeld/Motive-S-function
Hi, could you find a way to make it receive data when running the simulink in external mode?
I've tried several ways with no luck!
Post Reply