Play a haptic touch
Python 3.8+ · Teslasuit v4.5+ (XR5 recommended) · SDK 2.5.1+
A complete, runnable walkthrough: initialize the API, 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.
import time
from teslasuit_sdk import ts_api
import teslasuit_sdk.subsystems.ts_haptic
from teslasuit_sdk.ts_mapper import TsBone2dIndex
PERIOD_US = 10000 # period in µs; 10000 µs = 100 Hz (1000000 / frequency_hz)
AMPLITUDE_PERCENT = 40
PULSE_WIDTH_US = 120
TOUCH_DURATION_MS = 3000
def main():
# Initialize the API and wait for a device to connect
api = ts_api.TsApi()
device = api.get_device_manager().get_or_wait_last_device_attached()
player = device.haptic
mapper = api.mapper
# Resolve the haptic channel layout and get channels for the right upper arm
layout = mapper.get_haptic_electric_channel_layout(device.get_mapping())
bones = mapper.get_layout_bones(layout)
channels = mapper.get_bone_contents(bones[TsBone2dIndex.RightUpperArm.value])
# Create touch parameters
params = player.create_touch_parameters(
PERIOD_US, AMPLITUDE_PERCENT, PULSE_WIDTH_US
)
# Create a touch playable and start it
playable_id = player.create_touch(params, channels, TOUCH_DURATION_MS)
try:
player.play_playable(playable_id)
# Wait for playback to finish
time.sleep(TOUCH_DURATION_MS / 1000)
print("Finished")
except (KeyboardInterrupt, SystemExit):
print("\n! Received keyboard interrupt, quitting haptic touch play\n")
if __name__ == "__main__":
main()Expected output#
Device connected: a1b2c3d4-e5f6-7890-abcd-ef1234567890
FinishedWhat 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 Subsystem API Reference: Full reference for the
TsHapticPlayerclass used in this example. - API: Core Mapper: How to resolve the channel layout and bones used to target a touch.
- Core Data Structures — 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: Visualize which suit channels map to which areas of the body.
- Teslasuit Main Concepts: Fundamental articles covering Teslasuit's core technology and how its subsystems interact.
