How to clear the buffer of the NatNet Python Client? I only want to query the latest data point?

NatNet, VRPN, TrackD, and Plugins
Post Reply
AhmadAB
Posts: 1
Joined: Wed Mar 03, 2021 1:39 pm

How to clear the buffer of the NatNet Python Client? I only want to query the latest data point?

Post by AhmadAB »

Hello there,

I have two questions:
1) How can I clear the buffer of the NatNetClient object in Python?
2) This might be a Python question. When I use the threading.Lock() object in one of my threads to block other threads to avoid race conditions, the thread in the NatNetClient object still runs, i.e., the NatNetClient will still be called even though the Lock() is acquired in a different thread?

My application is the following:

I am using the Python NatNetClient to stream the position and orientation of a single rigid body attached to a quadcopter for real-time feedback control experimentation. When some of my threads take more execution time, the NatNetClient will buffer receiving data, and then it will execute its callback function several times to clear the buffer. This is causing issues in my code, especially with my code architecture. Is there a way for the NatNetClient object to only send back the most recent position data and discard the buffered data?

Kind regards,

Ahmad
steven.andrews
NaturalPoint Employee
NaturalPoint Employee
Posts: 738
Joined: Mon Jan 19, 2015 11:52 am

Re: How to clear the buffer of the NatNet Python Client? I only want to query the latest data point?

Post by steven.andrews »

Hello Ahmad,


Thank you for reaching out to the community regarding the Python Client. The Python implementation is not the best sample we have, so if you are not too far along to consider a more complete method you could try the C++ examples included in our Ubuntu and Fedora versions of the SDK.


1. Unfortunately, It does not look like there is a way to clear the buffer in the sample. You can either empty the buffer one by one when it is the NatNet sample's turn to process the data, like what you are doing, or you could add a method to "class NatNetClient" that clears the buffer for you, then call that before you are ready to receive data.


2. The lock function needs to be seen and used by both threads. We cannot speak to your specific code, but our best guess is that the lock is not declared correctly, so our data threads are not respecting it.
https://stackoverflow.com/questions/251 ... le-example



We hope this helps to give you some guidance as you continue to develop your streaming client.



Best,
Steven
--
Steven Andrews
OptiTrack | Senior Customer Support Engineer
help.naturalpoint.com
wiki.optitrack.com
support@optitrack.com
Post Reply