Tutorials
Each tutorial is a standalone program that demonstrates one capability of the Inverse Service. Three language variants ship side-by-side so you can compare idioms and pick the stack that fits your project:
- Python — the shortest, easiest entry point (
websockets+json) - C++ (nlohmann/json) — portable C++11, runtime-parsed JSON
- C++ (Glaze) — modern C++20 with compile-time reflection and zero-allocation parsing, recommended for real-time haptic loops
Source code is published in two public sample repositories:
- haply-inverse-cpp-samples — one directory per tutorial with both nlohmann/json (C++11) and Glaze (C++20) variants. Build targets have a
-glzsuffix for the Glaze variant. - haply-inverse-python-samples — one directory per tutorial.
Each release of the Inverse Service pins a matching tag on both repos: follow the release/<version> branch to stay on the version that matches this documentation.
Prerequisites
- The Inverse Service is running (either via the Haply Hub or the standalone installer) on port
10001. - At least one Haply device is detected. The tutorials each target a specific device family — see the table below.
- Python tutorials:
pip install websockets(tutorials 04, 05, 06, 07 additionally needkeyboard, which requires elevated privileges on Linux). - C++ tutorials: CMake 3.15+ and a C++11 compiler for the nlohmann variants, C++20 for the Glaze (
-glz) variants. The sample repo's top-levelCMakeLists.txtfetcheslibhv,nlohmann/json, andglazevia FetchContent — no manual dependency setup.
Tutorial list
| # | Name | Devices | Variants | What you'll learn |
|---|---|---|---|---|
| 00 | Device List | Any | Py · C++ · C++ Glaze | HTTP device discovery, session-scoped queries |
| 01 | Print Inverse3 | Inverse3 | Py · C++ · C++ Glaze | WebSocket state streaming, zero-force keepalive, first-message handshake |
| 02 | Print VerseGrip | Wired VG | Py · C++ · C++ Glaze | Orientation streaming, probe_orientation keepalive, quaternion → Euler |
| 03 | Print Wireless VG | WVG | Py · C++ · C++ Glaze | Buttons, battery, hall sensor |
| 04 | Hello Floor | Inverse3 | Py · C++ · C++ Glaze | First haptic effect — set_cursor_force penalty spring |
| 05 | Position Control | Inverse3 | Py · C++ · C++ Glaze | set_cursor_position control, random targets (C++) or WASD hold-to-move (Python) |
| 06 | Combined | Inverse3 + WVG | Py · C++ · C++ Glaze | Multi-device loop, quaternion-to-direction cursor drive |
| 07 | Basis & Mount | Inverse3 | Py · C++ · C++ Glaze | configure.basis, configure.preset, and runtime configure.mount overrides; mutual exclusion between preset and mount |
| 08 | Remote Config (coming soon) | Any | Py | Remote device configuration over HTTP; session discovery by profile |
| 10 | Events | — | Py · C++ · C++ Glaze | Event stream listener on port 10020, level/name filtering |
Tip — benchmark the haptic loop
Tutorial 10 (Events) is designed to be run alongside any other tutorial. With --no-hide-rate enabled, it prints the service's system-rate-report event, which includes the effective device tick rate. Compare the rate across the Python / C++ (nlohmann) / C++ (Glaze) variants of the same tutorial to observe the serialization overhead impact on a ~4 kHz control loop.
# Terminal 1 — pick a tutorial variant
./04-haply-inverse-hello-floor # C++ nlohmann
./04-haply-inverse-hello-floor-glz # C++ Glaze
python 04-haply-inverse-hello-floor.py # Python
# Terminal 2 — watch the rate
./10-haply-inverse-events --no-hide-rate