Pinch Detection Example (Python)
rgmp_pinch_detector.py reads the driver’s RGMP stream and
prints one line each time a thumb pinch starts or ends — thumb to index, middle,
ring or pinky, on either hand. What you do with a pinch is up to you; the example
prints and stops there.
flowchart LR
Driver["SDK Driver<br/>rokoko-sdk"]
Detector["rgmp_pinch_detector.py"]
Out["One line per event<br/>on stdout"]
Driver -->|"TCP :12276 (RGMP)"| Detector
Detector --> Out
Running it
Section titled “Running it”Start the driver with --auto-stream-usb so it streams the gloves (see
Streaming data):
rokoko-sdk --auto-stream-usbThen, from $ROKOKO_SDK_HOME/examples/python:
uv run rgmp_pinch_detector.py # or: python3 rgmp_pinch_detector.pyIt reads both gloves, left and right, at the same time, and each event names the hand that made it. Other devices on the same driver are named on stderr and ignored.
What it prints
Section titled “What it prints”Pinch left thumb_index fired #2 ...I|....Pinch right thumb_ring fired #1 ...I|..R.Pinch left thumb_index released #2 ....|..R.firedwhen the fingers meet,releasedwhen the pinch ends. Everyfiredis closed by exactly onereleased, so you can pair them directly.- The lanes on the right show all eight pinches at once, left hand then right, a letter for each one held.
releasedmeans the hand stopped looking like that pinch, not the moment the fingertips parted — expect it a few hundred milliseconds after the fingers separate.
| Flag | Default | Purpose |
|---|---|---|
--host | 127.0.0.1 | Driver host. |
--port | 12276 | Driver RGMP port. |
--threshold-scale | 1.0 | Scales all four collision thresholds; above 1 is stricter, below 1 looser. Reach for it first when pinches under- or over-fire. |
--orientations | fingers_up,edge_down | Hand attitudes a pinch is accepted in, comma separated, or any. |
--verbose | — | Also print each event’s sensor clock. The clock is per glove and not comparable between gloves. |
How the source is laid out
Section titled “How the source is laid out”The detector is a small package, pinch_detection/, driven by
rgmp_pinch_detector.py, so it isn’t reproduced here — read it in
$ROKOKO_SDK_HOME/examples/python. It reuses rgmp_core for the RGMP client and
solver_core for which sensor a stream belongs to, the same packages as the
Hand Solver example.
Where to go next
Section titled “Where to go next”- Hand Solver (Python) — the same glove stream, solved into 26-joint hands.
- RGMP specification — the wire format the detector reads.