meta-bridge-irsl 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- meta_bridge_irsl-0.1.0/LICENSE +21 -0
- meta_bridge_irsl-0.1.0/PKG-INFO +342 -0
- meta_bridge_irsl-0.1.0/README.md +313 -0
- meta_bridge_irsl-0.1.0/pyproject.toml +52 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/__init__.py +65 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/__main__.py +6 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/_bridge.py +169 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/_convert.py +333 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/_frame.py +193 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/_hub.py +327 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/_subscriber.py +147 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/cli.py +36 -0
- meta_bridge_irsl-0.1.0/src/meta_bridge/py.typed +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 meta-bridge contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meta-bridge-irsl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Bridge Meta Quest VR ZeroMQ JSON into typed robot_msg messages, over ZeroMQ or in-process
|
|
5
|
+
Keywords: meta-quest,vr,teleoperation,robotics,zeromq,robot-msg
|
|
6
|
+
Author: SeoWook Han
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering
|
|
20
|
+
Classifier: Topic :: System :: Networking
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: pyzmq>=26,<28
|
|
23
|
+
Requires-Dist: robot-msg-irsl==0.5.4
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Project-URL: Homepage, https://github.com/SeoWookHan/meta_bridge
|
|
26
|
+
Project-URL: Issues, https://github.com/SeoWookHan/meta_bridge/issues
|
|
27
|
+
Project-URL: Repository, https://github.com/SeoWookHan/meta_bridge
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# ๐ก Meta Bridge
|
|
31
|
+
|
|
32
|
+
A **Meta VR message bridge** that converts incoming **ZeroMQ JSON** into typed `robot_msg` controller, tracking, and SMPL messages. Each input is published as a **single binary `MessageBatch` frame** using `robot-msg-irsl==0.5.4` (protocol 2).
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## โจ Features
|
|
37
|
+
|
|
38
|
+
- ๐ฆพ **Typed conversion** โ preserve controller inputs, tracked poses, and optional SMPL-X parameters.
|
|
39
|
+
- ๐ฆ **Complete snapshots** โ send related messages together in one binary envelope, without a topic frame.
|
|
40
|
+
- **Latest-frame processing** โ keep the newest input and output rather than accumulating old frames.
|
|
41
|
+
- **Input validation** โ reject malformed packets and continue processing subsequent valid input.
|
|
42
|
+
- ๐ก **Verbose monitoring** โ display complete received values and the actual input rate.
|
|
43
|
+
- ๐ **In-process API** โ typed `MetaFrame`s via callbacks, `latest()` or iterators, from an embedded `MetaBridge` or a `MetaSubscriber` of a running bridge.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## ๐ฆ Installation
|
|
48
|
+
|
|
49
|
+
Requires **Python 3.11+**. The distribution name is **`meta-bridge-irsl`**, the import is **`meta_bridge`**, and the command is **`meta-bridge`**.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install meta-bridge-irsl # or: uv add meta-bridge-irsl
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Read a frame from an existing bridge** (no CLI or sockets to manage in your application):
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from meta_bridge import MetaSubscriber
|
|
59
|
+
|
|
60
|
+
with MetaSubscriber("tcp://127.0.0.1:28420") as source:
|
|
61
|
+
frame = source.next_frame(timeout=2.0)
|
|
62
|
+
if frame is not None:
|
|
63
|
+
print(frame.btn_a, frame.right_controller.position)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Your application hasโฆ | Use |
|
|
67
|
+
|---|---|
|
|
68
|
+
| A running bridge that publishes binary frames | `MetaSubscriber(endpoint)` |
|
|
69
|
+
| The headset's JSON endpoint, no separate bridge process | `MetaBridge(input_endpoint, output_endpoint=None)` |
|
|
70
|
+
| Its own ZeroMQ receiver or stored binary batches | `decode_frame(batch_bytes)` |
|
|
71
|
+
| An input JSON packet to validate and convert | `convert_packet(raw_json_bytes, timestamp)` |
|
|
72
|
+
|
|
73
|
+
The only runtime dependencies are PyZMQ and `robot-msg-irsl==0.5.4`. No headset SDK, collector, or Git checkout is required. To develop from source, clone the repository and run `uv sync`.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## ๐ Usage
|
|
78
|
+
|
|
79
|
+
### Run the bridge
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv run meta-bridge
|
|
83
|
+
# equivalent:
|
|
84
|
+
uv run python -m meta_bridge
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Options
|
|
88
|
+
|
|
89
|
+
| Option | Default | Description |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `--input` | `tcp://192.168.50.215:4999` | Meta JSON endpoint; the bridge connects as a subscriber |
|
|
92
|
+
| `--output` | `tcp://*:28420` | Protocol-2 output endpoint; the bridge binds as a publisher |
|
|
93
|
+
| `--verbose` | Off | Print complete received values and input rate |
|
|
94
|
+
| `--version` | | Print the version and exit |
|
|
95
|
+
|
|
96
|
+
#### Examples
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv run meta-bridge --input tcp://192.168.50.215:4999 --output 'tcp://*:28420'
|
|
100
|
+
uv run meta-bridge --verbose
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The output port is `robot_msg.ports.META`. Input is a single JSON frame; output is
|
|
104
|
+
`robot_msg.encode(MessageBatch(...))`, with no topic frame.
|
|
105
|
+
|
|
106
|
+
Every valid input is published regardless of either hand's trigger values. No
|
|
107
|
+
messages are published while Meta input is absent. If Meta continues sending
|
|
108
|
+
frames with trigger values of `0.0`, those frames are still converted and sent.
|
|
109
|
+
|
|
110
|
+
Verbose mode prints each received Meta JSON frame in aligned `SMPL / INPUT / POSE`
|
|
111
|
+
columns. Long arrays wrap without truncation. The actual received frame rate is
|
|
112
|
+
reported once per second, including `0.0 Hz` when no frames arrive.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## ๐๏ธ Message Types
|
|
117
|
+
|
|
118
|
+
| Message type (Python class) | Source Meta JSON fields |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `smpl.smpl_state` (`SmplState`) | `smpl.root_orient[3]`, `pose_body[21][3]`, `left_hand_pose[15][3]`, `right_hand_pose[15][3]`, `trans[3]`, optional `betas[10]` and `gender` |
|
|
121
|
+
| `meta.controller_input` (`MetaControllerInput`) | `btnA/B/X/Y`, left/right `HandTrigger`, `IndexTrigger`, `TriggerForce`, `Thumbstick[2]`, and `ThumbstickClick` |
|
|
122
|
+
| `meta.tracking_pose` (`MetaTrackingPose`) | Head and left/right controller `Position[3]` and `Rotation[4]` (XYZW) |
|
|
123
|
+
|
|
124
|
+
### Input mapping and geometry
|
|
125
|
+
|
|
126
|
+
CamelCase input keys map to snake_case output fields. Controller input also
|
|
127
|
+
accepts snake_case keys. Existing vector objects (`{x,y,z,w}` and `{x,y}`), flat
|
|
128
|
+
`pose_body[63]`, and `pose_hand[90]` (45 left-hand values followed by 45 right-hand
|
|
129
|
+
values) remain supported.
|
|
130
|
+
|
|
131
|
+
`encode_payload(payload, timestamp=None)` accepts either a flat Quest frame or a
|
|
132
|
+
dictionary with `controller`, `tracking`, and `smpl` sections. Coordinates,
|
|
133
|
+
rotations, SMPL parameters, and analog trigger values are preserved. Protocol-2
|
|
134
|
+
`HandTrigger` / `IndexTrigger` values are floats, not booleans.
|
|
135
|
+
|
|
136
|
+
Tracking becomes `Pose(Vec3, Quaternion)`; SMPL rotations become `RotationVector`.
|
|
137
|
+
Default frame IDs are `meta_tracking` and `meta_smpl`, respectively: the bridge
|
|
138
|
+
does **not** assume a shared world frame. The default SMPL `hand_pose_convention`
|
|
139
|
+
is `mean_offset`; `root_orientation_valid` and `translation_valid` default to
|
|
140
|
+
`True`. Explicit frame, convention, and validity values are preserved. Missing
|
|
141
|
+
`betas` or `gender` are not invented.
|
|
142
|
+
|
|
143
|
+
If `smpl` is absent, the batch contains only controller input and tracking poses.
|
|
144
|
+
|
|
145
|
+
### Metadata and validation
|
|
146
|
+
|
|
147
|
+
All messages from one input, including the outer batch, use the same host receipt
|
|
148
|
+
time in `metadata.receive_time = Timestamp(seconds=..., clock_kind="unix")`.
|
|
149
|
+
The outer batch's `metadata.send_time` is set to that same time.
|
|
150
|
+
|
|
151
|
+
Packets with unknown fields, duplicate JSON keys, missing required fields,
|
|
152
|
+
invalid types or array lengths, or nonfinite numbers are skipped in full and
|
|
153
|
+
logged.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## ๐ก Receiving Messages
|
|
158
|
+
|
|
159
|
+
ZeroMQ PUB/SUB may lose frames before subscriptions connect or when consumers are
|
|
160
|
+
slow. The bridge retains the newest single input and output frame. Subscribers
|
|
161
|
+
should also set `ZMQ_CONFLATE=1` to skip older queued batches.
|
|
162
|
+
|
|
163
|
+
If Meta stops publishing, even the last batch can be stale. Consumers should
|
|
164
|
+
check data age using `message.metadata.receive_time.seconds`.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
import zmq
|
|
168
|
+
from robot_msg import MessageBatch, decode, ports
|
|
169
|
+
|
|
170
|
+
context = zmq.Context()
|
|
171
|
+
subscriber = context.socket(zmq.SUB)
|
|
172
|
+
subscriber.setsockopt(zmq.SUBSCRIBE, b"")
|
|
173
|
+
subscriber.setsockopt(zmq.CONFLATE, 1)
|
|
174
|
+
subscriber.connect(f"tcp://127.0.0.1:{ports.META}")
|
|
175
|
+
try:
|
|
176
|
+
while True:
|
|
177
|
+
batch = decode(subscriber.recv())
|
|
178
|
+
assert isinstance(batch, MessageBatch)
|
|
179
|
+
for data in batch.encoded_messages:
|
|
180
|
+
message = decode(bytes(data))
|
|
181
|
+
print(message.MSG_TYPE, message.metadata.receive_time.seconds)
|
|
182
|
+
finally:
|
|
183
|
+
subscriber.close(linger=0)
|
|
184
|
+
context.term()
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## ๐ Use from Python
|
|
190
|
+
|
|
191
|
+
`MetaFrame` is a typed, frozen view of a received batch. Its nested `robot_msg` objects are shared; treat them as read-only.
|
|
192
|
+
|
|
193
|
+
| Attribute | Contents |
|
|
194
|
+
|---|---|
|
|
195
|
+
| `frame.btn_a`, `btn_b`, `btn_x`, `btn_y`, `left/right_thumbstick_click` | Button **levels** (`True` while held) |
|
|
196
|
+
| `frame.left/right_index_trigger`, `left/right_hand_trigger`, `left/right_trigger_force` | Analog values |
|
|
197
|
+
| `frame.left_thumbstick`, `frame.right_thumbstick` | `(x, y)` tuples |
|
|
198
|
+
| `frame.head`, `frame.left_controller`, `frame.right_controller` | `Pose(position, orientation)` |
|
|
199
|
+
| `frame.smpl` | `SmplState` or `None` |
|
|
200
|
+
| `frame.receive_time` | Host receive time, unix seconds; `frame.age()` gives seconds since then |
|
|
201
|
+
| `frame.buttons()`, `frame.triggers()`, `frame.thumbsticks()` | Fresh `dict`s of the above |
|
|
202
|
+
| `frame.controller`, `frame.tracking` | The underlying `robot_msg` messages (treat them as read-only) |
|
|
203
|
+
|
|
204
|
+
There are two ways to get frames. Both are context managers that run a background thread and
|
|
205
|
+
offer the same consumer API: `on_frame=` / `.on_frame(cb)` callbacks, `.latest(max_age=None)`,
|
|
206
|
+
`.next_frame(timeout)`, and `.frames(buffer=32, timeout=None)` (or `iter(...)`), which yields
|
|
207
|
+
new frames from a bounded buffer that drops the oldest frame first.
|
|
208
|
+
|
|
209
|
+
* **`MetaSubscriber(endpoint="tcp://127.0.0.1:28420")`** consumes the output of a `meta-bridge`
|
|
210
|
+
process that is already running. It reconnects automatically when the bridge restarts. By
|
|
211
|
+
default (`conflate=True`) it keeps only the newest batch. `.connected` and `.reconnects`
|
|
212
|
+
report the link state.
|
|
213
|
+
* **`MetaBridge(input_endpoint, output_endpoint=DEFAULT_OUTPUT)`** makes your process *the*
|
|
214
|
+
bridge. Pass `output_endpoint=None` to keep frames in-process with no PUB socket and no port.
|
|
215
|
+
Keep the default if other processes, such as `robot_data_collector`, should still receive
|
|
216
|
+
port 28420.
|
|
217
|
+
|
|
218
|
+
The example below starts and stops something on A and B:
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
import time
|
|
222
|
+
|
|
223
|
+
from meta_bridge import MetaFrame, MetaSubscriber
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class StartStopButtons:
|
|
227
|
+
"""Rising-edge detector for A and B. It re-baselines after a gap, so no phantom press fires."""
|
|
228
|
+
|
|
229
|
+
def __init__(self, stale_after: float = 0.5) -> None:
|
|
230
|
+
self.previous: dict[str, bool] = {}
|
|
231
|
+
self.last_time = float("-inf")
|
|
232
|
+
self.stale_after = stale_after
|
|
233
|
+
|
|
234
|
+
def __call__(self, frame: MetaFrame) -> None:
|
|
235
|
+
buttons = frame.buttons()
|
|
236
|
+
if frame.receive_time - self.last_time > self.stale_after:
|
|
237
|
+
self.previous = buttons # first frame, or the headset came back
|
|
238
|
+
self.last_time = frame.receive_time
|
|
239
|
+
if buttons["btn_a"] and not self.previous["btn_a"]:
|
|
240
|
+
print("A pressed: start recording")
|
|
241
|
+
if buttons["btn_b"] and not self.previous["btn_b"]:
|
|
242
|
+
print("B pressed: stop recording")
|
|
243
|
+
self.previous = buttons
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
with MetaSubscriber("tcp://127.0.0.1:28420", on_frame=StartStopButtons()) as meta:
|
|
247
|
+
while True: # your teleoperation loop
|
|
248
|
+
frame = meta.latest(max_age=0.2) # None while the headset or the bridge is silent
|
|
249
|
+
if frame is not None:
|
|
250
|
+
pass # e.g. follow frame.right_controller
|
|
251
|
+
time.sleep(0.01)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
To embed the bridge instead of running `meta-bridge` separately, replace the `with` line:
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
from meta_bridge import MetaBridge
|
|
258
|
+
|
|
259
|
+
with MetaBridge("tcp://192.168.50.215:4999", output_endpoint=None, on_frame=StartStopButtons()) as meta:
|
|
260
|
+
...
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`decode_frame(data)` turns one raw batch from port 28420 into a `MetaFrame` if you manage your
|
|
264
|
+
own socket. `run_bridge(..., on_frame=cb, output_endpoint=None)` is the blocking equivalent of
|
|
265
|
+
`MetaBridge`.
|
|
266
|
+
|
|
267
|
+
**Callbacks** run on the bridge or subscriber thread, in registration order, after the batch
|
|
268
|
+
has been published. Keep them short and hand slow work to another thread or a non-blocking API.
|
|
269
|
+
An exception from a callback is logged (rate-limited) and counted in `callback_errors`. It never
|
|
270
|
+
stops the bridge, and the other callbacks still run. `close()` is idempotent and may be called from inside a callback. Slow callbacks delay shutdown and subsequent input, so use a queue or an async command for longer work. Use `with source.frames(...) as frames:` if you stop iterating early. `latest(max_age=...)` and `next_frame(timeout=...)` return `None` when no qualifying frame is available.
|
|
271
|
+
|
|
272
|
+
**Buttons are levels, not events.** A press spans many frames at 72-90 Hz. Packets simply stop
|
|
273
|
+
when the headset disconnects, so no "released" frame arrives. Edge detection, debouncing,
|
|
274
|
+
chords and holds are therefore the consumer's job, and so is re-baselining after a gap.
|
|
275
|
+
|
|
276
|
+
### With robot_data_collector
|
|
277
|
+
|
|
278
|
+
Install the [collector](https://pypi.org/project/robot-data-collector-irsl/) only if you want to record episodes:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
pip install meta-bridge-irsl robot-data-collector-irsl==0.1.0
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
With the bridge and the configured recording sources running, this program uses A to start, B to save, and X+Y held for 0.5 s to discard. `RecordingButtons` handles edges and debouncing and queues commands without blocking the subscriber thread. Keep the `__main__` guard: the collector spawns its capture service.
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from threading import Event
|
|
288
|
+
|
|
289
|
+
from meta_bridge import MetaSubscriber
|
|
290
|
+
from robot_data_collector import Collector, CollectorConfig
|
|
291
|
+
from robot_data_collector.triggers import RecordingButtons
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def main():
|
|
295
|
+
with Collector(CollectorConfig.from_toml("teleop.toml"), on_exit="discard") as rec:
|
|
296
|
+
rec.wait_ready(timeout=10)
|
|
297
|
+
buttons = RecordingButtons(rec, task="pick_cube")
|
|
298
|
+
with MetaSubscriber(on_frame=buttons.update):
|
|
299
|
+
Event().wait() # or run your teleoperation loop here
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
if __name__ == "__main__":
|
|
303
|
+
try:
|
|
304
|
+
main()
|
|
305
|
+
except KeyboardInterrupt:
|
|
306
|
+
pass # the Collector already applied its exit policy
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## ๐งช Testing
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
uv sync
|
|
315
|
+
uv run pytest
|
|
316
|
+
# Alternatively, the same suite uses the standard-library test runner:
|
|
317
|
+
uv run python -m unittest discover -s tests -v
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Tests use the public types and codecs from the installed `robot-msg-irsl==0.5.4`
|
|
321
|
+
package. The default `dev` dependency group includes pytest. Coverage includes
|
|
322
|
+
binary round trips using that package's own decoder, receipt metadata, default
|
|
323
|
+
ports, preserved frame IDs and SMPL enums, invalid-packet rejection, and real
|
|
324
|
+
ZeroMQ delivery and recovery. `tests/test_api.py` covers the in-process API
|
|
325
|
+
(`decode_frame`, callback isolation, `MetaBridge`, `MetaSubscriber` reconnects,
|
|
326
|
+
no-PUB mode) and both CLI entry points. Live ZeroMQ tests use loopback ports
|
|
327
|
+
22700-22799.
|
|
328
|
+
|
|
329
|
+
To run against another interpreter without touching `.venv`:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
UV_PROJECT_ENVIRONMENT=/tmp/meta-bridge-py311 uv run --python 3.11 pytest
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## ๐ ๏ธ Dependencies
|
|
338
|
+
|
|
339
|
+
| Package | Purpose |
|
|
340
|
+
|---|---|
|
|
341
|
+
| `pyzmq>=26,<28` | ZeroMQ input and output transport |
|
|
342
|
+
| `robot-msg-irsl==0.5.4` | Protocol-2 message definitions and codecs (`import robot_msg`) |
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# ๐ก Meta Bridge
|
|
2
|
+
|
|
3
|
+
A **Meta VR message bridge** that converts incoming **ZeroMQ JSON** into typed `robot_msg` controller, tracking, and SMPL messages. Each input is published as a **single binary `MessageBatch` frame** using `robot-msg-irsl==0.5.4` (protocol 2).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## โจ Features
|
|
8
|
+
|
|
9
|
+
- ๐ฆพ **Typed conversion** โ preserve controller inputs, tracked poses, and optional SMPL-X parameters.
|
|
10
|
+
- ๐ฆ **Complete snapshots** โ send related messages together in one binary envelope, without a topic frame.
|
|
11
|
+
- **Latest-frame processing** โ keep the newest input and output rather than accumulating old frames.
|
|
12
|
+
- **Input validation** โ reject malformed packets and continue processing subsequent valid input.
|
|
13
|
+
- ๐ก **Verbose monitoring** โ display complete received values and the actual input rate.
|
|
14
|
+
- ๐ **In-process API** โ typed `MetaFrame`s via callbacks, `latest()` or iterators, from an embedded `MetaBridge` or a `MetaSubscriber` of a running bridge.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## ๐ฆ Installation
|
|
19
|
+
|
|
20
|
+
Requires **Python 3.11+**. The distribution name is **`meta-bridge-irsl`**, the import is **`meta_bridge`**, and the command is **`meta-bridge`**.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install meta-bridge-irsl # or: uv add meta-bridge-irsl
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Read a frame from an existing bridge** (no CLI or sockets to manage in your application):
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from meta_bridge import MetaSubscriber
|
|
30
|
+
|
|
31
|
+
with MetaSubscriber("tcp://127.0.0.1:28420") as source:
|
|
32
|
+
frame = source.next_frame(timeout=2.0)
|
|
33
|
+
if frame is not None:
|
|
34
|
+
print(frame.btn_a, frame.right_controller.position)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
| Your application hasโฆ | Use |
|
|
38
|
+
|---|---|
|
|
39
|
+
| A running bridge that publishes binary frames | `MetaSubscriber(endpoint)` |
|
|
40
|
+
| The headset's JSON endpoint, no separate bridge process | `MetaBridge(input_endpoint, output_endpoint=None)` |
|
|
41
|
+
| Its own ZeroMQ receiver or stored binary batches | `decode_frame(batch_bytes)` |
|
|
42
|
+
| An input JSON packet to validate and convert | `convert_packet(raw_json_bytes, timestamp)` |
|
|
43
|
+
|
|
44
|
+
The only runtime dependencies are PyZMQ and `robot-msg-irsl==0.5.4`. No headset SDK, collector, or Git checkout is required. To develop from source, clone the repository and run `uv sync`.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ๐ Usage
|
|
49
|
+
|
|
50
|
+
### Run the bridge
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
uv run meta-bridge
|
|
54
|
+
# equivalent:
|
|
55
|
+
uv run python -m meta_bridge
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Options
|
|
59
|
+
|
|
60
|
+
| Option | Default | Description |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `--input` | `tcp://192.168.50.215:4999` | Meta JSON endpoint; the bridge connects as a subscriber |
|
|
63
|
+
| `--output` | `tcp://*:28420` | Protocol-2 output endpoint; the bridge binds as a publisher |
|
|
64
|
+
| `--verbose` | Off | Print complete received values and input rate |
|
|
65
|
+
| `--version` | | Print the version and exit |
|
|
66
|
+
|
|
67
|
+
#### Examples
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uv run meta-bridge --input tcp://192.168.50.215:4999 --output 'tcp://*:28420'
|
|
71
|
+
uv run meta-bridge --verbose
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The output port is `robot_msg.ports.META`. Input is a single JSON frame; output is
|
|
75
|
+
`robot_msg.encode(MessageBatch(...))`, with no topic frame.
|
|
76
|
+
|
|
77
|
+
Every valid input is published regardless of either hand's trigger values. No
|
|
78
|
+
messages are published while Meta input is absent. If Meta continues sending
|
|
79
|
+
frames with trigger values of `0.0`, those frames are still converted and sent.
|
|
80
|
+
|
|
81
|
+
Verbose mode prints each received Meta JSON frame in aligned `SMPL / INPUT / POSE`
|
|
82
|
+
columns. Long arrays wrap without truncation. The actual received frame rate is
|
|
83
|
+
reported once per second, including `0.0 Hz` when no frames arrive.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## ๐๏ธ Message Types
|
|
88
|
+
|
|
89
|
+
| Message type (Python class) | Source Meta JSON fields |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `smpl.smpl_state` (`SmplState`) | `smpl.root_orient[3]`, `pose_body[21][3]`, `left_hand_pose[15][3]`, `right_hand_pose[15][3]`, `trans[3]`, optional `betas[10]` and `gender` |
|
|
92
|
+
| `meta.controller_input` (`MetaControllerInput`) | `btnA/B/X/Y`, left/right `HandTrigger`, `IndexTrigger`, `TriggerForce`, `Thumbstick[2]`, and `ThumbstickClick` |
|
|
93
|
+
| `meta.tracking_pose` (`MetaTrackingPose`) | Head and left/right controller `Position[3]` and `Rotation[4]` (XYZW) |
|
|
94
|
+
|
|
95
|
+
### Input mapping and geometry
|
|
96
|
+
|
|
97
|
+
CamelCase input keys map to snake_case output fields. Controller input also
|
|
98
|
+
accepts snake_case keys. Existing vector objects (`{x,y,z,w}` and `{x,y}`), flat
|
|
99
|
+
`pose_body[63]`, and `pose_hand[90]` (45 left-hand values followed by 45 right-hand
|
|
100
|
+
values) remain supported.
|
|
101
|
+
|
|
102
|
+
`encode_payload(payload, timestamp=None)` accepts either a flat Quest frame or a
|
|
103
|
+
dictionary with `controller`, `tracking`, and `smpl` sections. Coordinates,
|
|
104
|
+
rotations, SMPL parameters, and analog trigger values are preserved. Protocol-2
|
|
105
|
+
`HandTrigger` / `IndexTrigger` values are floats, not booleans.
|
|
106
|
+
|
|
107
|
+
Tracking becomes `Pose(Vec3, Quaternion)`; SMPL rotations become `RotationVector`.
|
|
108
|
+
Default frame IDs are `meta_tracking` and `meta_smpl`, respectively: the bridge
|
|
109
|
+
does **not** assume a shared world frame. The default SMPL `hand_pose_convention`
|
|
110
|
+
is `mean_offset`; `root_orientation_valid` and `translation_valid` default to
|
|
111
|
+
`True`. Explicit frame, convention, and validity values are preserved. Missing
|
|
112
|
+
`betas` or `gender` are not invented.
|
|
113
|
+
|
|
114
|
+
If `smpl` is absent, the batch contains only controller input and tracking poses.
|
|
115
|
+
|
|
116
|
+
### Metadata and validation
|
|
117
|
+
|
|
118
|
+
All messages from one input, including the outer batch, use the same host receipt
|
|
119
|
+
time in `metadata.receive_time = Timestamp(seconds=..., clock_kind="unix")`.
|
|
120
|
+
The outer batch's `metadata.send_time` is set to that same time.
|
|
121
|
+
|
|
122
|
+
Packets with unknown fields, duplicate JSON keys, missing required fields,
|
|
123
|
+
invalid types or array lengths, or nonfinite numbers are skipped in full and
|
|
124
|
+
logged.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## ๐ก Receiving Messages
|
|
129
|
+
|
|
130
|
+
ZeroMQ PUB/SUB may lose frames before subscriptions connect or when consumers are
|
|
131
|
+
slow. The bridge retains the newest single input and output frame. Subscribers
|
|
132
|
+
should also set `ZMQ_CONFLATE=1` to skip older queued batches.
|
|
133
|
+
|
|
134
|
+
If Meta stops publishing, even the last batch can be stale. Consumers should
|
|
135
|
+
check data age using `message.metadata.receive_time.seconds`.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
import zmq
|
|
139
|
+
from robot_msg import MessageBatch, decode, ports
|
|
140
|
+
|
|
141
|
+
context = zmq.Context()
|
|
142
|
+
subscriber = context.socket(zmq.SUB)
|
|
143
|
+
subscriber.setsockopt(zmq.SUBSCRIBE, b"")
|
|
144
|
+
subscriber.setsockopt(zmq.CONFLATE, 1)
|
|
145
|
+
subscriber.connect(f"tcp://127.0.0.1:{ports.META}")
|
|
146
|
+
try:
|
|
147
|
+
while True:
|
|
148
|
+
batch = decode(subscriber.recv())
|
|
149
|
+
assert isinstance(batch, MessageBatch)
|
|
150
|
+
for data in batch.encoded_messages:
|
|
151
|
+
message = decode(bytes(data))
|
|
152
|
+
print(message.MSG_TYPE, message.metadata.receive_time.seconds)
|
|
153
|
+
finally:
|
|
154
|
+
subscriber.close(linger=0)
|
|
155
|
+
context.term()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## ๐ Use from Python
|
|
161
|
+
|
|
162
|
+
`MetaFrame` is a typed, frozen view of a received batch. Its nested `robot_msg` objects are shared; treat them as read-only.
|
|
163
|
+
|
|
164
|
+
| Attribute | Contents |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `frame.btn_a`, `btn_b`, `btn_x`, `btn_y`, `left/right_thumbstick_click` | Button **levels** (`True` while held) |
|
|
167
|
+
| `frame.left/right_index_trigger`, `left/right_hand_trigger`, `left/right_trigger_force` | Analog values |
|
|
168
|
+
| `frame.left_thumbstick`, `frame.right_thumbstick` | `(x, y)` tuples |
|
|
169
|
+
| `frame.head`, `frame.left_controller`, `frame.right_controller` | `Pose(position, orientation)` |
|
|
170
|
+
| `frame.smpl` | `SmplState` or `None` |
|
|
171
|
+
| `frame.receive_time` | Host receive time, unix seconds; `frame.age()` gives seconds since then |
|
|
172
|
+
| `frame.buttons()`, `frame.triggers()`, `frame.thumbsticks()` | Fresh `dict`s of the above |
|
|
173
|
+
| `frame.controller`, `frame.tracking` | The underlying `robot_msg` messages (treat them as read-only) |
|
|
174
|
+
|
|
175
|
+
There are two ways to get frames. Both are context managers that run a background thread and
|
|
176
|
+
offer the same consumer API: `on_frame=` / `.on_frame(cb)` callbacks, `.latest(max_age=None)`,
|
|
177
|
+
`.next_frame(timeout)`, and `.frames(buffer=32, timeout=None)` (or `iter(...)`), which yields
|
|
178
|
+
new frames from a bounded buffer that drops the oldest frame first.
|
|
179
|
+
|
|
180
|
+
* **`MetaSubscriber(endpoint="tcp://127.0.0.1:28420")`** consumes the output of a `meta-bridge`
|
|
181
|
+
process that is already running. It reconnects automatically when the bridge restarts. By
|
|
182
|
+
default (`conflate=True`) it keeps only the newest batch. `.connected` and `.reconnects`
|
|
183
|
+
report the link state.
|
|
184
|
+
* **`MetaBridge(input_endpoint, output_endpoint=DEFAULT_OUTPUT)`** makes your process *the*
|
|
185
|
+
bridge. Pass `output_endpoint=None` to keep frames in-process with no PUB socket and no port.
|
|
186
|
+
Keep the default if other processes, such as `robot_data_collector`, should still receive
|
|
187
|
+
port 28420.
|
|
188
|
+
|
|
189
|
+
The example below starts and stops something on A and B:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
import time
|
|
193
|
+
|
|
194
|
+
from meta_bridge import MetaFrame, MetaSubscriber
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class StartStopButtons:
|
|
198
|
+
"""Rising-edge detector for A and B. It re-baselines after a gap, so no phantom press fires."""
|
|
199
|
+
|
|
200
|
+
def __init__(self, stale_after: float = 0.5) -> None:
|
|
201
|
+
self.previous: dict[str, bool] = {}
|
|
202
|
+
self.last_time = float("-inf")
|
|
203
|
+
self.stale_after = stale_after
|
|
204
|
+
|
|
205
|
+
def __call__(self, frame: MetaFrame) -> None:
|
|
206
|
+
buttons = frame.buttons()
|
|
207
|
+
if frame.receive_time - self.last_time > self.stale_after:
|
|
208
|
+
self.previous = buttons # first frame, or the headset came back
|
|
209
|
+
self.last_time = frame.receive_time
|
|
210
|
+
if buttons["btn_a"] and not self.previous["btn_a"]:
|
|
211
|
+
print("A pressed: start recording")
|
|
212
|
+
if buttons["btn_b"] and not self.previous["btn_b"]:
|
|
213
|
+
print("B pressed: stop recording")
|
|
214
|
+
self.previous = buttons
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
with MetaSubscriber("tcp://127.0.0.1:28420", on_frame=StartStopButtons()) as meta:
|
|
218
|
+
while True: # your teleoperation loop
|
|
219
|
+
frame = meta.latest(max_age=0.2) # None while the headset or the bridge is silent
|
|
220
|
+
if frame is not None:
|
|
221
|
+
pass # e.g. follow frame.right_controller
|
|
222
|
+
time.sleep(0.01)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
To embed the bridge instead of running `meta-bridge` separately, replace the `with` line:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from meta_bridge import MetaBridge
|
|
229
|
+
|
|
230
|
+
with MetaBridge("tcp://192.168.50.215:4999", output_endpoint=None, on_frame=StartStopButtons()) as meta:
|
|
231
|
+
...
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`decode_frame(data)` turns one raw batch from port 28420 into a `MetaFrame` if you manage your
|
|
235
|
+
own socket. `run_bridge(..., on_frame=cb, output_endpoint=None)` is the blocking equivalent of
|
|
236
|
+
`MetaBridge`.
|
|
237
|
+
|
|
238
|
+
**Callbacks** run on the bridge or subscriber thread, in registration order, after the batch
|
|
239
|
+
has been published. Keep them short and hand slow work to another thread or a non-blocking API.
|
|
240
|
+
An exception from a callback is logged (rate-limited) and counted in `callback_errors`. It never
|
|
241
|
+
stops the bridge, and the other callbacks still run. `close()` is idempotent and may be called from inside a callback. Slow callbacks delay shutdown and subsequent input, so use a queue or an async command for longer work. Use `with source.frames(...) as frames:` if you stop iterating early. `latest(max_age=...)` and `next_frame(timeout=...)` return `None` when no qualifying frame is available.
|
|
242
|
+
|
|
243
|
+
**Buttons are levels, not events.** A press spans many frames at 72-90 Hz. Packets simply stop
|
|
244
|
+
when the headset disconnects, so no "released" frame arrives. Edge detection, debouncing,
|
|
245
|
+
chords and holds are therefore the consumer's job, and so is re-baselining after a gap.
|
|
246
|
+
|
|
247
|
+
### With robot_data_collector
|
|
248
|
+
|
|
249
|
+
Install the [collector](https://pypi.org/project/robot-data-collector-irsl/) only if you want to record episodes:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
pip install meta-bridge-irsl robot-data-collector-irsl==0.1.0
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
With the bridge and the configured recording sources running, this program uses A to start, B to save, and X+Y held for 0.5 s to discard. `RecordingButtons` handles edges and debouncing and queues commands without blocking the subscriber thread. Keep the `__main__` guard: the collector spawns its capture service.
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from threading import Event
|
|
259
|
+
|
|
260
|
+
from meta_bridge import MetaSubscriber
|
|
261
|
+
from robot_data_collector import Collector, CollectorConfig
|
|
262
|
+
from robot_data_collector.triggers import RecordingButtons
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def main():
|
|
266
|
+
with Collector(CollectorConfig.from_toml("teleop.toml"), on_exit="discard") as rec:
|
|
267
|
+
rec.wait_ready(timeout=10)
|
|
268
|
+
buttons = RecordingButtons(rec, task="pick_cube")
|
|
269
|
+
with MetaSubscriber(on_frame=buttons.update):
|
|
270
|
+
Event().wait() # or run your teleoperation loop here
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
if __name__ == "__main__":
|
|
274
|
+
try:
|
|
275
|
+
main()
|
|
276
|
+
except KeyboardInterrupt:
|
|
277
|
+
pass # the Collector already applied its exit policy
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## ๐งช Testing
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
uv sync
|
|
286
|
+
uv run pytest
|
|
287
|
+
# Alternatively, the same suite uses the standard-library test runner:
|
|
288
|
+
uv run python -m unittest discover -s tests -v
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Tests use the public types and codecs from the installed `robot-msg-irsl==0.5.4`
|
|
292
|
+
package. The default `dev` dependency group includes pytest. Coverage includes
|
|
293
|
+
binary round trips using that package's own decoder, receipt metadata, default
|
|
294
|
+
ports, preserved frame IDs and SMPL enums, invalid-packet rejection, and real
|
|
295
|
+
ZeroMQ delivery and recovery. `tests/test_api.py` covers the in-process API
|
|
296
|
+
(`decode_frame`, callback isolation, `MetaBridge`, `MetaSubscriber` reconnects,
|
|
297
|
+
no-PUB mode) and both CLI entry points. Live ZeroMQ tests use loopback ports
|
|
298
|
+
22700-22799.
|
|
299
|
+
|
|
300
|
+
To run against another interpreter without touching `.venv`:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
UV_PROJECT_ENVIRONMENT=/tmp/meta-bridge-py311 uv run --python 3.11 pytest
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## ๐ ๏ธ Dependencies
|
|
309
|
+
|
|
310
|
+
| Package | Purpose |
|
|
311
|
+
|---|---|
|
|
312
|
+
| `pyzmq>=26,<28` | ZeroMQ input and output transport |
|
|
313
|
+
| `robot-msg-irsl==0.5.4` | Protocol-2 message definitions and codecs (`import robot_msg`) |
|