Data Streaming to MATLAB - NatNetPollingSample.m

NatNet, VRPN, TrackD, and Plugins
Post Reply
Bjamdtcgd
Posts: 1
Joined: Thu Jul 01, 2021 5:01 am

Data Streaming to MATLAB - NatNetPollingSample.m

Post by Bjamdtcgd »

Hi everyone! I've tried to sort this out, but I cannot get it to work for the life of me. I got the data streaming from Motive to MATLAB to work a couple days ago, but it isn't working now that I'm trying to use it today. I am able to connect to the server, but I'm getting the following message:
Packet is empty/stale
Make sure the server is in Live mode or playing in playback
Here's the code:

Code: Select all

function NatNetPollingSample
	fprintf( 'NatNet Polling Sample Start\n' )

	% create an instance of the natnet client class
	fprintf( 'Creating natnet class object\n' )
	natnetclient = natnet;

	% connect the client to the server (multicast over local loopback) -
	% modify for your network
	fprintf( 'Connecting to the server\n' )
	natnetclient.HostIP = '192.168.1.98';
	natnetclient.ClientIP = '192.168.1.98';
	natnetclient.ConnectionType = 'Multicast';
	natnetclient.connect;
	if ( natnetclient.IsConnected == 0 )
		fprintf( 'Client failed to connect\n' )
		fprintf( '\tMake sure the host is connected to the network\n' )
		fprintf( '\tand that the host and client IP addresses are correct\n\n' ) 
		return
	end

	% get the asset descriptions for the asset names
	model = natnetclient.getModelDescription;
	if ( model.RigidBodyCount < 1 )
        fprintf('No Rigid Bodies Detected\n')
        fprintf('Closing...\n')
		return
	end

	% Poll for the rigid body data a regular intervals (~1 sec) for 10 sec.
	fprintf( '\nPrinting rigid body frame data approximately every second for 10 seconds...\n\n' )
	for idx = 1 : 10  
		java.lang.Thread.sleep( 996 );
		data = natnetclient.getFrame; % method to get current frame
		
		if (isempty(data.RigidBody(1)))
			fprintf( '\tPacket is empty/stale\n' )
			fprintf( '\tMake sure the server is in Live mode or playing in playback\n\n')
			return
		end
		fprintf( 'Frame:%6d  ' , data.Frame )
		fprintf( 'Time:%0.2f\n' , data.Timestamp )
		for i = 1:model.RigidBodyCount
			fprintf( 'Name:"%s"  ', model.RigidBody( i ).Name )
			fprintf( 'X:%0.1fmm  ', data.RigidBody( i ).x * 1000 )
			fprintf( 'Y:%0.1fmm  ', data.RigidBody( i ).y * 1000 )
			fprintf( 'Z:%0.1fmm\n', data.RigidBody( i ).z * 1000 )			
		end
	end 
	disp('NatNet Polling Sample End' )
end
And here's a screenshot of the data streaming pane:

Image

Any help would be greatly appreciated!
David123
Posts: 1
Joined: Thu Aug 05, 2021 1:20 am

Re: Data Streaming to MATLAB - NatNetPollingSample.m

Post by David123 »

I'm having the same problem with the demo script using NatNetSDK4.0 and MATLAB 2021.
ghuneke
Posts: 1
Joined: Fri Nov 15, 2024 3:57 pm

Re: Data Streaming to MATLAB - NatNetPollingSample.m

Post by ghuneke »

I realize this is an old thread but I was having the same problem, I had to give MATLAB permissions to communicate through windows firewall on public networks and was then able to receive data correctly.
kubark42
Posts: 1
Joined: Wed Mar 21, 2012 1:09 pm

Re: Data Streaming to MATLAB - NatNetPollingSample.m

Post by kubark42 »

We had identical symptoms on two computers. After some sleuthing, we discovered that the problem is the Windows Firewall. It was configured not to allow Matlab to access public networks, but the mocap network was running on an internal "public" LAN.
Post Reply