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:
- Install pre-commit
- Install the Git hooks by running
pre-commit installor, alternatively, run `pre-commit run --all-files manually.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e348c440b34716815186392686e7fa594cfc1a74d7050d92793b8ebb09e0aec5
|
|
| MD5 |
87c896cf4b30c502811e472dc3ce0db3
|
|
| BLAKE2b-256 |
ac3eb29f2ed94d12355695639410b18f9bb12a1f17e030d7d82c1ac5a2585669
|
Provenance
The following attestation bundles were made for natnet-0.2.0.tar.gz:
Publisher:
publish.yml on TimSchneider42/python-natnet-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
natnet-0.2.0.tar.gz -
Subject digest:
e348c440b34716815186392686e7fa594cfc1a74d7050d92793b8ebb09e0aec5 - Sigstore transparency entry: 488517608
- Sigstore integration time:
-
Permalink:
TimSchneider42/python-natnet-client@50a9907603f6345f1daff46d0d49f486e5c18414 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/TimSchneider42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50a9907603f6345f1daff46d0d49f486e5c18414 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
babeba88c41df3b001658b5994bf1c15c3b12fa1110f7fb9a86e393444efb14e
|
|
| MD5 |
d15ce11c99b8b8e8c9093b4ead4bcf90
|
|
| BLAKE2b-256 |
f02b14e6995b3d05c25039acb31178816370079665e7aeb59d83e5fb783b870c
|
Provenance
The following attestation bundles were made for natnet-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on TimSchneider42/python-natnet-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
natnet-0.2.0-py3-none-any.whl -
Subject digest:
babeba88c41df3b001658b5994bf1c15c3b12fa1110f7fb9a86e393444efb14e - Sigstore transparency entry: 488517620
- Sigstore integration time:
-
Permalink:
TimSchneider42/python-natnet-client@50a9907603f6345f1daff46d0d49f486e5c18414 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/TimSchneider42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50a9907603f6345f1daff46d0d49f486e5c18414 -
Trigger Event:
push
-
Statement type: