natnet

NatNet client library.

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.

class natnet.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 DiscoveryError if 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
run_once(timeout=None)[source]

Receive and process one message.

set_callback(callback)[source]

Set the frame callback.

It will be called with a list of RigidBody, a list of LabelledMarker, and a TimestampAndLatency.

set_model_callback(callback)[source]

Set the model definition callback.

It will be called with a list of RigidBodyDescription, a list of SkeletonDescription, and a list of MarkersetDescription, immediately and whenever the tracked models change.

spin(timeout=None)[source]

Continuously receive and process messages.

exception natnet.DiscoveryError[source]
class natnet.MessageId[source]

Message IDs for each NatNet message (as in NatNetTypes.h).

Variables:
  • Connect – Request for server info
  • ServerInfo – Motive version, NatNet version, clock frequency, data port, and multicast address
  • RequestModelDef – Request for model definitions
  • ModelDef – List of definitions of rigid bodies, markersets, skeletons etc
  • FrameOfData – Frame of motion capture data
  • EchoRequest – Request server to immediately respond with its current time (used for clock sync)
  • EchoResponse – Current server time (and time contained in EchoRequest message)
Connect = 0
Disconnect = 9
DisconnectByTimeout = 11
Discovery = 14
EchoRequest = 12
EchoResponse = 13
FrameOfData = 7
KeepAlive = 10
MessageString = 8
ModelDef = 5
Request = 2
RequestFrameOfData = 6
RequestModelDef = 4
Response = 3
ServerInfo = 1
UnrecognizedRequest = 256
class natnet.Version[source]

NatNet version, with correct comparison operator.

Believe it or not, this is performance-critical.

Variables:
  • major (int) –
  • minor (int) –
  • build (int) –
  • revision (int) –
classmethod deserialize(data, version=None)[source]

Deserialize a Version from a ParseBuffer.

serialize()[source]

Serialize a Version to bytes.

class natnet.Logger[source]

Dummy logger implementation that just calls print.

debug(msg, *args)

Print msg % args.

error(msg, *args)

Print msg % args.

fatal(msg, *args)

Print msg % args.

info(msg, *args)

Print msg % args.

warning(msg, *args)

Print msg % args.

class natnet.Server[source]

Fake server which implements just enough of the protocol for integration tests.

run(rate=1)[source]

Run the server.

Parameters:rate (int) – Rate at which to send mocap frames, in Hz