Page 1 of 1

Data Streaming to MATLAB - NatNetPollingSample.m

Posted: Thu Jul 01, 2021 5:11 am
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!

Re: Data Streaming to MATLAB - NatNetPollingSample.m

Posted: Thu Aug 05, 2021 1:26 am
by David123
I'm having the same problem with the demo script using NatNetSDK4.0 and MATLAB 2021.

Re: Data Streaming to MATLAB - NatNetPollingSample.m

Posted: Fri Nov 15, 2024 4:00 pm
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.

Re: Data Streaming to MATLAB - NatNetPollingSample.m

Posted: Mon Nov 18, 2024 7:34 pm
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.