API Documentation

Optitrack Client

A python module to connect to Optitrack optical tracking system and receive data from it.

class opti_ssr.opti_client.OptiTrackClient(unicast_ip=None, multicast_ip='239.255.42.99', port=1511, natnet_version=(3, 0, 0, 0))[source]

Connect to Optitrack systems and Motive software and receive data, including rigid body position and orientation, from it. By default, it connects to Optitrack software Motive on the same machine.

unicast_ip

str, optional – IP of the Motive software to establish a unicast connection to. By default, no unicast connection is established.

multicast_ip

str, optional – Multicast address to connect to.

port

int, optional – Port of the Motive network interface.

natnet_version

tuple, optional – Version number of the NatNetSDK to use.

get_packet_data(packet_types=[<class 'opti_ssr.optirx.SenderData'>, <class 'opti_ssr.optirx.ModelDefs'>, <class 'opti_ssr.optirx.FrameOfData'>])[source]

Receive desired packet data.

based on optirx-demo.py source: https://bitbucket.org/astanin/python-optirx

Parameters:packet_types (list, optional) – Types of the packets to be returned.
Returns:packet (list) – Received packets of desired type.
get_rigid_body(rb_id=0)[source]

Receive rigid body position, orientation and time data.

Parameters:rb_id (int, optional) – ID of the rigid body to receive data from.
Returns:
  • position (numpy array) – Rigid body position packet data of the desired rigid body. Consists of x, y, z coordinates of Motive’s coordinate system.
  • orientation (list) – List of rigid body orientation data in quaternion representation.
  • time_data (list) – List of time data consisting of frame mumber, timestamp and latency packet data.

SSR Client

A python module for controlling the SoundScape Renderer.

class opti_ssr.ssr_client.SSRClient(ip='localhost', port=4711, end_message='x00')[source]

Establish a TCP/IP4 network connection and send XML messages to communicate with a specific instance of the SoundScape Renderer.

ip

str, optional – IP of the server running thr SSR. By default, it connects to localhost.

port

int, optional – Port of SSR Network Interface. By default, port = 4711.

end_message

str, optional – Symbol to terminate the XML messages send to SSR. By default, a binary zero.

load_scene(path)[source]

Load a scene from a specified location on the machine running the SSR.

recv_ssr_returns()[source]

Receive messages returned by the SSR.

set_ref_offset_orientation(alpha)[source]

Set reference offset orientation in degrees (zero in positive x-direction).

set_ref_offset_position(x, y)[source]

Set reference offset position in meters.

set_ref_orientation(alpha)[source]

Set reference orientation in degrees (zero in positive x-direction).

set_ref_position(x, y)[source]

Set reference position in meters.

set_src_orientation(src_id, alpha)[source]

Change orientation of an existing source in degrees (zero in positive x-direction).

set_src_position(src_id, x, y)[source]

Change name and position of an existing source.

set_transport_state(state)[source]

Set a specific transport state, namely start, stop or rewind to play, pause or rewind all audio tracks of the loaded scene respectively.

src_creation(src_id)[source]

Define a new source.

Bridges Module

A python module that provides tools for position and orientation tracking inside the SoundScape Renderer (SSR) using the OptiTrack optical tracking system.

This module contains the abstract class _Bridge and its subclasses. _Bridge is a thread class that includes the actual sequence, whereas the subclasses implement different applications of a connection between the SSR and a tracking system. In any subclass of _Bridge the functions to receive and send data need to be defined according to the desired application.

class opti_ssr.bridges.HeadTracker(optitrack, ssr, rb_id=0, angle=1, *args, **kwargs)[source]

Bases: opti_ssr.bridges._Bridge

A class for using the OptiTrack system as a head tracker for the SSR.

optitrack

class object – Object of class OptiTrackClient.

ssr

class object – Object of class SSRClient.

rb_id

int, optional – ID of the rigid body to receive data from.

angle

int, optional – angle which is used for head rotation

  • +1 - positive yaw
  • -1 - negative yaw
  • +2 - positive pitch
  • -2 - negative pitch
  • +3 - positive roll
  • -3 - negative roll
calibrate()[source]

Use current position and orientation of head tracker to set the origin and orientation of the world coordinate system.

class opti_ssr.bridges.LocalWFS(optitrack, ssr, ssr_virt_repr, rb_id=0, *args, **kwargs)[source]

Bases: opti_ssr.bridges._Bridge

A class for using the OptiTrack system to track the listener position in the SSR for local sound field synthesis.

The first SSR instance (ssr) shifts the reference position and the reference offset position of the real reproduction setup, such that it emulates the movement a virtual source array placed around the listener.

The second SSR instance (ssr_virt_repr) shifts the reference position of aforementioned point sources as the virtual reproduction setup in relation to the real sources based on audio files.

optitrack

class object – Object of the class OptiTrackClient.

ssr

class object – First SSR instance as object of class SSRClient.

ssr_virt_repr

class object – Second SSR instance as object of the class SSRClient.

rb_id

int, optional – ID of the rigid body to receive data from.

_create_virtual_sources()[source]

Create a specified amount of new sources via network connection to the SSR.

_receive()[source]

Get position data of rigid body from OptiTrack system

Returns:center (list) – Rigid body position data. Consists of x, y, z coordinates of Motive`s coordinate system.
_send(center)[source]

Send reference position data to both SSR instance.

class opti_ssr.bridges._Bridge(optitrack, ssr, data_limit=500, timeout=0.01, *args, **kwargs)[source]

Bases: threading.Thread

An abstract class which implements a threading approach to receive and send data. To implement the functionality to send and receive the desired data, subclasses need to define the functions _receive and _send.

Note

The returns of _receive have to be the input of _send.

clear_data()[source]

Clears buffer

get_last_data(num=None)[source]

Returns a list of data received from the OptiTrack system.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

Optirx Module

A pure Python library to receive motion capture data from OptiTrack. The version 1.10 of this optirx library is included here with only minor changes from the original source.

See original source: https://bitbucket.org/astanin/python-optirx