Skip to main content

Python client for Optitrack NatNet streams.

Project description

Python NatNet Client

Python client for Optitrack NatNet streams.

Installation

Install this package via pip:

pip install git+https://github.com/TimSchneider42/python-natnet-client

Usage

The following example highlights the basic usage of this package:

import time

from natnet import DataDescriptions, DataFrame, NatNetClient


def receive_new_frame(data_frame: DataFrame):
    global num_frames
    num_frames += 1


def receive_new_desc(desc: DataDescriptions):
    print("Received data descriptions.")


num_frames = 0
if __name__ == "__main__":
    streaming_client = NatNetClient(server_ip_address="127.0.0.1", local_ip_address="127.0.0.1", use_multicast=False)
    streaming_client.on_data_description_received_event.handlers.append(receive_new_desc)
    streaming_client.on_data_frame_received_event.handlers.append(receive_new_frame)

    with streaming_client:
        streaming_client.request_modeldef()

        for i in range(10):
            time.sleep(1)
            streaming_client.update_sync()
            print(f"Received {num_frames} frames in {i + 1}s")

In this example, we first instantiate NatNetClient with the connection parameters and attach one callback function to each of its events. The streaming_client.on_data_description_received_event event is triggered whenever a new data description packet arrives, while the streaming_client.on_data_frame_received_event event is triggered on each incoming data frame. For the configuration of the NatNet server, please refer to the official documentation.

You can process data synchronously, as in this example, by calling streaming_client.update_sync() in your run loop. Alternatively, you can call streaming_client.run_async() once after connecting, which will handle data asynchronously in two additional threads.

We then use the streaming_client instance as a context manager, which is equivalent to calling streaming_client.connect() (and streaming_client.shutdown() afterwards). After the client has been connected, we request the model definitions from the server, which causes it to send a data description packet. Note that data frames do not have to be explicitly requested, but are continuously streamed once a connection has been established.

Apart from requesting model definitions, the NatNetClient class allows sending arbitrary commands to the NatNet server via the send_command and send_request functions. For a list of different commands and requests, please refer to the official documentations.

Notes

As of Motive version 2.3, the marker positions of rigid bodies are only transmitted correctly if "Y-up" is selected in the streaming pane. If "Z-up" is selected, the frame of the rigid bodies is rotated but the marker positions are not, resulting in wrong positions of the markers relative to the rigid body.

License

The project is licensed under the MIT license.

Contributing

If you wish to contribute to this project, you are welcome to create a pull request. Please run the pre-commit hooks before submitting your pull request. To install the pre-commit hooks, run:

  1. Install pre-commit
  2. Install the Git hooks by running pre-commit install or, alternatively, run `pre-commit run --all-files manually.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

natnet-0.2.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

natnet-0.2.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file natnet-0.2.0.tar.gz.

File metadata

  • Download URL: natnet-0.2.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for natnet-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e348c440b34716815186392686e7fa594cfc1a74d7050d92793b8ebb09e0aec5
MD5 87c896cf4b30c502811e472dc3ce0db3
BLAKE2b-256 ac3eb29f2ed94d12355695639410b18f9bb12a1f17e030d7d82c1ac5a2585669

See more details on using hashes here.

Provenance

The following attestation bundles were made for natnet-0.2.0.tar.gz:

Publisher: publish.yml on TimSchneider42/python-natnet-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file natnet-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: natnet-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for natnet-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 babeba88c41df3b001658b5994bf1c15c3b12fa1110f7fb9a86e393444efb14e
MD5 d15ce11c99b8b8e8c9093b4ead4bcf90
BLAKE2b-256 f02b14e6995b3d05c25039acb31178816370079665e7aeb59d83e5fb783b870c

See more details on using hashes here.

Provenance

The following attestation bundles were made for natnet-0.2.0-py3-none-any.whl:

Publisher: publish.yml on TimSchneider42/python-natnet-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page