Play a haptic touch
C# 7.3+ · Teslasuit XR5+ · SDK 2.5.1+
A complete, runnable walkthrough: create a TsRoot, connect to a device, access the Haptic subsystem, and play a haptic touch on the right upper arm.
Code for haptic touch#
⚠️ Safety. Make sure the device is connected and calibrated before running. Start with conservative touch settings (low amplitude, short duration), check electrode placement, and stop if anything feels wrong.
using System;
using System.Linq;
using System.Threading;
using TsSDK;
using TsAPI;
using TsAPI.Types;
internal static class Program
{
// Change these to play with the touch: which bone gets it, and how it feels.
private const TsHumanBoneIndex TargetBone = TsHumanBoneIndex.RightUpperArm;
private const ulong TouchPeriodUs = 21600;
private const ulong TouchAmplitudePercent = 40;
private const ulong TouchPulseWidthUs = 240;
private const ulong TouchDurationMs = 3000;
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}");
// Resolve the target bone to its electric channel handles.
IntPtr[] channels = device.Mapping2d.ElectricChannels
.Where(channel => channel.BoneIndex == TargetBone)
.Select(channel => channel.Handle)
.ToArray();
if (channels.Length == 0)
{
Console.WriteLine("Error: no channels found for the target bone");
return;
}
// Describe the touch: period, amplitude (percent of calibrated range), pulse width.
var parameters = new[]
{
new TsHapticParam(TsHapticParamType.Period, TouchPeriodUs),
new TsHapticParam(TsHapticParamType.Amplitude, TouchAmplitudePercent),
new TsHapticParam(TsHapticParamType.PulseWidth, TouchPulseWidthUs),
};
// Create the touch and play it for its duration.
IHapticPlayable touch = device.HapticPlayer.CreateTouch(parameters, channels, TouchDurationMs);
device.HapticPlayer.Play(touch);
Thread.Sleep((int)TouchDurationMs);
device.HapticPlayer.Stop(touch);
// Release the playable once finished.
device.HapticPlayer.Remove(touch);
}
}Expected output#
Waiting for a device...
Using device: SuitWhat to read next#
Explore these references and guides to build on this example and get the most out of Teslasuit haptic and EMS features:
Essential API references#
- Haptic reference: Full reference for
CreateTouchand the playback methods used in this example. - Mapping: How to resolve bones to the electric channels used to target a touch.
- Common types — Haptic: Reference for the haptic parameter and playable types.
Practical guides & examples#
- Examples overview: Browse the full set of runnable examples.
Deeper dives & broader concepts#
- Haptics & EMS main concept: The conceptual background behind haptic feedback and EMS.
- Body & channel map: A Python-first tool to visualize which suit channels map to which areas of the body. Conceptually useful here too.
- Teslasuit Main Concepts: Fundamental articles covering Teslasuit's core technology and how its subsystems interact.
