TeslasuitDocumentation
APIs

Stream motion data

Python 3.8+ · Teslasuit v4.5+ (XR5 recommended) · SDK 2.5.1+

A complete, runnable walkthrough: initialize the Teslasuit API, connect to a device, and use the Mocap subsystem to stream both raw IMU gyroscope data and a biomechanical joint angle.

Code for Mocap data#

from teslasuit_sdk import ts_api
import teslasuit_sdk.subsystems.ts_mocap
from teslasuit_sdk.ts_mapper import TsBone2dIndex, TsBiomechanicalIndex

# Number of data frames to capture before stopping
FRAMES_TO_CAPTURE = 100


def main():
    print("Initializing Teslasuit API...")
    api = ts_api.TsApi()  # create the central API object

    print("Waiting for a Teslasuit device to connect...")
    device = api.get_device_manager().get_or_wait_last_device_attached()

    print("Accessing the Mocap subsystem...")
    mocap = device.mocap  # mocap subsystem streams IMU and skeleton data

    print("Starting Mocap data streaming...")
    mocap.start_streaming()

    try:
        frames_remaining = FRAMES_TO_CAPTURE
        while frames_remaining > 0:
            # Raw sensor data: returns a dict keyed by TsBone2dIndex
            # Each value is a TsMocapSensor with gyro, accel, quaternions, etc.
            raw_data = mocap.get_raw_data_on_ready()
            print("Bone data:", raw_data[TsBone2dIndex.RightUpperArm])

            # Biomechanical angles: returns a dict keyed by TsBiomechanicalIndex
            # Each value is a float representing the joint angle in degrees
            biomech_data = mocap.get_biomechanical_angles_on_ready()
            print(
                "Biomech Pelvis Tilt: ", biomech_data[TsBiomechanicalIndex.PelvisTilt]
            )

            frames_remaining -= 1

        print("Finished")

    except (KeyboardInterrupt, SystemExit):
        print("\n! Received keyboard interrupt, quitting mocap streaming\n")

    finally:
        mocap.stop_streaming()
        print("Mocap streaming was stopped")


if __name__ == "__main__":
    main()

Expected output#

Initializing Teslasuit API...
Device connected: a1b2c3d4-e5f6-7890-abcd-ef1234567890
Waiting for a Teslasuit device to connect...
Accessing the Mocap subsystem...
Starting Mocap data streaming...
Bone data: [0.5, 0.2, 0.1]
Biomech Pelvis Tilt: 15.0
...
Finished
Mocap streaming was stopped

Explore these references and guides to build on this example and get the most out of Teslasuit Mocap features:

Essential API references#

Practical guides & examples#

Deeper dives & broader concepts#

  • Mocap Main Concept: The conceptual background behind the motion capture subsystem.
  • Teslasuit Main Concepts: Fundamental articles explaining Teslasuit technology and how mocap works alongside haptics and EMS.