Stream motion data
C# 7.3+ · Teslasuit XR5+ · SDK 2.5.1+
A complete, runnable walkthrough: create a TsRoot, 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#
using System;
using System.Linq;
using System.Threading;
using TsSDK;
using TsAPI;
using TsAPI.Types;
internal static class Program
{
// Change these to explore other bones and joints.
private const TsHumanBoneIndex TargetBone = TsHumanBoneIndex.RightUpperArm;
private const TsBiomechanicalIndex TargetJoint = TsBiomechanicalIndex.PelvisTilt;
private static void Main()
{
// Resolve the native library and create the single root instance.
TsRoot.InitSDKInstallation();
using var tsRoot = new TsRoot();
// Poll until a device is attached (Control Center owns the connection).
IDevice device = null;
while (device == null)
{
Console.WriteLine("Waiting for a device...");
device = tsRoot.DeviceManager.Devices.FirstOrDefault();
Thread.Sleep(100);
}
Console.WriteLine($"Using device: {device.ProductType}");
IMocap mocap = device.Mocap;
mocap.Start();
Console.WriteLine("Press Enter to end");
// Mocap data is read on demand. Poll until the user ends the program.
while (!Console.KeyAvailable)
{
// Raw IMU data for the target bone.
if (mocap.ImuData != null &&
mocap.ImuData.GetSensorData(TargetBone, out TsImuSensorData imu))
{
Console.WriteLine($"Gyro: ({imu.gyro.x:F2}, {imu.gyro.y:F2}, {imu.gyro.z:F2})");
}
// Processed biomechanical joint angle, in degrees.
if (mocap.Skeleton != null &&
mocap.Skeleton.GetBiomechanicalAngle(TargetJoint, out float angle))
{
Console.WriteLine($"Biomechanical angle: {angle:F2}");
}
Thread.Sleep(100);
}
mocap.Stop();
}
}Expected output#
Waiting for a device...
Using device: Suit
Press Enter to end
Gyro: (0.12, -0.03, 0.45)
Biomechanical angle: 15.00
...What to read next#
Explore these references and guides to build on this example and get the most out of Teslasuit Mocap features:
Essential API references#
- Mocap reference: Full reference for the skeleton and IMU accessors used in this example.
- Common types — Mocap: Reference for the raw sensor and biomechanical data types.
Practical guides & examples#
- Examples overview: Browse the full set of runnable 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.
