Skip to content
Get SDK Access

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

Start the driver with --auto-stream-usb so it streams the gloves (see Streaming data):

Terminal window
rokoko-sdk --auto-stream-usb

Then, from $ROKOKO_SDK_HOME/examples/python:

Terminal window
uv run rgmp_pinch_detector.py # or: python3 rgmp_pinch_detector.py

It 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.

Pinch left thumb_index fired #2 ...I|....
Pinch right thumb_ring fired #1 ...I|..R.
Pinch left thumb_index released #2 ....|..R.
  • fired when the fingers meet, released when the pinch ends. Every fired is closed by exactly one released, 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.
  • released means the hand stopped looking like that pinch, not the moment the fingertips parted — expect it a few hundred milliseconds after the fingers separate.
FlagDefaultPurpose
--host127.0.0.1Driver host.
--port12276Driver RGMP port.
--threshold-scale1.0Scales all four collision thresholds; above 1 is stricter, below 1 looser. Reach for it first when pinches under- or over-fire.
--orientationsfingers_up,edge_downHand 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.

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.