Updated 17 Aug 2015
My project is to interface between Natural Point Motive (Optitrack) to Simulink (Matlab 64bit) in Real-Time Windows Target, My testing OS is Win7 64bit but i belive it would work for other OS.
Or Hirshfeld (2021). Natural Point Motive (Optitrack) API interface to Matlab and Simulink 64bit by Or Hirshfeld (https://github.com/orhirshfeld/Motive-API-interface-to-Matlab-and-simulink-in-Real-time), GitHub. Retrieved .
I am trying to connect Natural Point Motive (Optitrack) to Matlab.
I have been experiencing an issue running the Sample 3D Client on Skeletons using Motive: Body 2.1.1. Our goal is to connect MATLAB and Motive and plot the mocap angle in real-time.
This section of the code is where the program pauses at:
% approach 3 : get data by event handler (no polling)
% Add NatNet FrameReady event handler
ls = addlistener(theClient,'OnFrameReady2',@(src,event)FrameReadyCallback(src,event));
display('[NatNet] FrameReady Listener added.');
I appreciate your efforts. But I am getting errors listed below after running the set up and Simulink file provided by you at the location: https://www.mathworks.com/matlabcentral/fileexchange/51326-orhirshfeld-simulink_motive_api_v3?s_tid=prof_contriblnk&s_tid=mwa_osa_a
Model Load 1 Clear
11:57 AM Elapsed: 0.26 sec
The model 'Optitrack_Simulink_TrackableLocation' was saved in a previous release. The Simulation range checking setting for Stateflow and MATLAB Function blocks is now set to 'none'. To change Simulation range checking diagnostic, set Simulation range checking. For more information, see documentation.
Simulation 2 2 Clear
11:58 AM Elapsed: 2 sec
Output port 1 of 'Optitrack_Simulink_TrackableLocation/initilaze optittrack' is not connected.
Component:Simulink | Category:Block warning
Warning: Simulink Desktop Real-Time kernel is not installed. The Simulink Desktop Real-Time blocks will not perform I/O operations and will not be synchronized to real time.
Error evaluating 'StartFcn' callback of Constant block (mask) 'Optitrack_Simulink_TrackableLocation/initilaze optittrack'.
Callback string is 'if ~exist('inc_location')
inc_location =[pwd '\inc']; % change if necessary
lib_location =[pwd '\inc']; % change if necessary
% load the NPTrackingTools library if it is not already loaded
addpath(inc_location); % change if necessary
addpath(lib_location); % change if necessary
% to see all function write the code: libfunctionsview NPTrackingTools
% libfunctionsview NPTrackingTools --> use this to see available functions
% initialise cameras
calllib('NPTrackingTools', 'TT_Initialize') %you should see red leds on the camera turns on
% load the project file which sets up cameras correctly
project_file =[pwd '\Motive_1_5_Project.ttp']; % change if necessary
calllib('NPTrackingTools', 'TT_LoadProject', project_file)'
No supported compiler or SDK was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler. For more options, visit http://www.mathworks.com/support/compilers.
Component:Simulink | Category:Block error
Error evaluating 'StopFcn' callback of Constant block (mask) 'Optitrack_Simulink_TrackableLocation/initilaze optittrack'.
Callback string is 'calllib('NPTrackingTools', 'TT_Shutdown') % exit tracking tools
Library was not found
You could try my latest version for Simulink which is
it's run in real-time but it's the min loop time is 1ms
a researcher that substitute me in the lab actually succeed to make it compiled for Real-Time External in Simulink
I'm contacting him now to see if he can share his solution
Has anyone got progress in migrating optitrack motive data from matlab to simulink on real-time basis? Please let me know. Thanks for your time.
Hi, thanks for your different approaches.
When I try to run Optitrack_Simulink_TrackableLocation.slx I also get the error:
"Library not found", I think this problem might come from the fact this library was compiled for 32bits. Is there anyway to get it compiled for 64bits OS?
I'd also be glad to know if you managed to connect motive to simulink RT by UDP @Rushikesh
@Rushikesh where you able to use UDP to connect motive with optitrack???
I'm currently trying your interface, I've changed the path of the inc and lib (both in init file and in the startup callback function) and of the motive project to match my setup.
But once I run the model nothing happens, it keeps browsing (mouse logo with the blue circle).
I'm running Matlab 2016b and Motive 1.10.3 ith Flex3 cameras, do you have any clue?
I am new to matlab, motive and NatNet. Could you please give me some info on how to use NatNet stream from Matlab?
I am a Matlab and Simulink noob and dont have much help from people at the school so if I ask really dumb questions please forgive me.
I have been unable to get this simulink or matlab in this zip to run.
If I run the simulink all I get is "
An error occurred while running the simulation and the simulation was terminated
Library was not found" error messages. I have make sure that the lib and inc files are added to the path but it still will not run.
If I try to run the Matlab "Motive_API_test_init" I get all sorts of syuntax and fatal errors. And it seems to reference "NPTrackingTools.h"
Please Help! I am working on this for my Senior Project and need desperately to get rigid body location and Euler angles into simulink from Motive so I can use that to control and AR. Drone.
Rushikesh thank you for your kind words
you can use NatNet to connect to connect from different computer just by putting the right IP address and set the stream in Motive for the right Network card.
but if you want to use depacketization there is examples available on NatNet SDK folder.
I never tried this method but if you succeed I would love to hear about it.
the Real-Time in Matlab with NatNet dll might not be an option as the support of Matlab told me that because it's use .NET libaries.
UDP depacketization can be an option
I didn't get into it but they have examples in NATNET libary and a bit Documation in NATNET guide
But if you don't need to run it Real-Time you can use NatNet and there is many examples
but if you want Real-Time without Network you can use the normal DLL API (not NatNet) than probally you need to work with TLC files that define blocks
a good example for NATNET in matlab is
example for using it in simulink using s-function is
another fourm thread about making a block to work in Real Time is
I'm still trying to figure out a way to make it fully integrted in Real-Time in Simulink so if you find a way i would glad to hear about it
Hi nice work! I am looking for a way to do this over network using NatNet or direct UDP depacketization in simulink real time. Do you have any ideas there?
Inspired by: Tracking Tools (Optitrack), NatNet (Motive/Arena) simple sample for location data by Or Hirshfeld, Trackable Location (Mocap) from Optitrack Tracking Tools to Simulink by Or Hirshfeld in Technion, MotiveExample
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!