natnet.comms¶
Communications.
Copyright (c) 2017, Matthew Edwards. This file is subject to the 3-clause BSD license, as found in the LICENSE file in the top-level directory of this distribution and at https://github.com/mje-nz/python_natnet/blob/master/LICENSE. No part of python_natnet, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
Note that all local timestamps (e.g. packet reception time) are from timeit.default_timer().
-
class
natnet.comms.Client(conn, clock_synchronizer, log, model_definitions=NOTHING, expected_markers=NOTHING, model_names=NOTHING, callback=None, model_callback=None)[source]¶ NatNet client.
This class connects to a NatNet server and calls a callback whenever a frame of mocap data arrives.
-
classmethod
connect(server=None, logger=<natnet.logging.Logger object>, timeout=1)[source]¶ Connect to a NatNet server.
Raises
DiscoveryErrorif server is not provided and discovery fails.Parameters: - server (str) – IPv4 address of server (hostname probably works too), or None to autodiscover
- logger (
Logger) - timeout (int) – How long to wait for server(s) to respond
-
set_callback(callback)[source]¶ Set the frame callback.
It will be called with a list of
RigidBody, a list ofLabelledMarker, and aTimestampAndLatency.
-
set_model_callback(callback)[source]¶ Set the model definition callback.
It will be called with a list of
RigidBodyDescription, a list ofSkeletonDescription, and a list ofMarkersetDescription, immediately and whenever the tracked models change.
-
classmethod
-
class
natnet.comms.Connection(command_socket, data_socket, command_address, last_sender_address=None)[source]¶ Connection to NatNet server.
Variables: last_sender_address (tuple[str, int]) – Sending IP and port of last packet received. -
bind_data_socket(multicast_addr, data_port)[source]¶ Bind data socket and begin receiving mocap frames.
Parameters: - multicast_addr (str) – Server’s IPv4 multicast address
- data_port (int) – Server’s data port
-
classmethod
open(server, command_port=1510, multicast_addr=None, data_port=None)[source]¶ Open a connection to a NatNet server.
If you don’t know the multicast address and data port, you can get them from a ServerInfo message (by sending a Connect message and waiting) then open the data socket later with
bind_data_socket().Parameters: - server (str) – IPv4 address of server (hostname probably works too)
- command_port (int) – Server’s command port
- multicast_addr (str) – Server’s IPv4 multicast address
- data_port (int) – Server’s data port
-
wait_for_message(timeout=None)[source]¶ Return the next message to arrive on either socket, or None if a timeout occurred.
-
wait_for_message_with_id(id_, timeout=None)[source]¶ Return the next message received of the given type, discarding any others.
-
-
class
natnet.comms.TimestampAndLatency(timestamp, system_latency, transit_latency, processing_latency)[source]¶ Timing information for a received mocap frame.
Variables: - timestamp (float) – Camera mid-exposure timestamp (according to local clock)
- system_latency (float) – Time from camera mid-exposure to Motive transmitting frame
- transit_latency (float) – Time from transmitting frame to receiving frame
- processing_latency (float) – Time from receiving frame to calling callback
-
latency¶ Time from camera mid-exposure to calling callback.