vr: add VrSessionControlComponent button-to-session bridge#263
vr: add VrSessionControlComponent button-to-session bridge#263abhichothani42 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new VR hardware component that converts VR controller button presses into SessionControlCapable events, intended to let VR input drive SessionManager session/episode transitions.
Changes:
- Introduces
VrSessionControlComponent(header + implementation) with JSON-configurable bindings and a polling reader thread. - Adds VR connection/timeout configuration and basic disconnect detection.
- Wires the new component into the shared library build via
CMakeLists.txt.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/hw/vr/vr_session_control_component.cpp |
Implements button→session-control event mapping, configuration parsing, VR input claiming, and the reader thread loop. |
include/trossen_sdk/hw/vr/vr_session_control_component.hpp |
Declares the new hardware component and its JSON configuration surface. |
CMakeLists.txt |
Adds the new .cpp file to the trossen_sdk library target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b202244 to
b6e47c5
Compare
217b9c1 to
42eab09
Compare
b6e47c5 to
d1dd2e0
Compare
42eab09 to
065673b
Compare
shantanuparab-tr
left a comment
There was a problem hiding this comment.
"Tests pass" and "tested on hardware" do not hold with no tests and a disconnect path that cannot run. The button detection and validation are easy to test with fake frames.
| void VrSessionControlComponent::reader_loop() { | ||
| auto& session = VrSession::instance(); | ||
|
|
||
| // Connection staleness tracking: monitor when we last saw a valid frame. |
There was a problem hiding this comment.
The disconnect check only runs when the latest-frame call comes back empty, but that call never comes back empty once the first frame arrives, so the disconnect notice can never fire. The PR says it fires after a timeout, and right now it cannot. Switching to the "is it connected?" check (the one you already use elsewhere in this file) fixes it.
There was a problem hiding this comment.
Fixed, the loop uses is_vr_connected() now instead of waiting for latest_frame() to go empty. Disconnect fires reliably.
| {"vr_port", vr_port_}, | ||
| {"poll_interval_ms", poll_interval_.count()}, | ||
| {"binding_count", bindings_.size()}, | ||
| {"connected", VrSession::instance().is_vr_connected()}, |
There was a problem hiding this comment.
This spot uses the proper "is it connected?" check. Reusing it in the worker loop above makes the disconnect detection work.
There was a problem hiding this comment.
Done, reused it in the reader loop.
| } | ||
| } | ||
|
|
||
| void VrSessionControlComponent::configure(const nlohmann::json& config) { |
There was a problem hiding this comment.
Each configure() says "I am using the connection," but the cleanup only says "I am done" once. If configure() runs twice, the count never reaches zero and the connection never closes. Can we release before re-taking it, or block a second configure?
There was a problem hiding this comment.
Fixed via the RAII lease: acquire() releases the previous reference before taking a new one, so a second configure() can't leak.
| reader_thread_ = std::thread(&VrSessionControlComponent::reader_loop, this); | ||
| } | ||
|
|
||
| void VrSessionControlComponent::stop() { |
There was a problem hiding this comment.
A couple of small timing notes: callbacks should be set before start() and not swapped while running, and a callback should not call stop() on this same component (it would make the worker wait for itself). Worth saying so in the header.
There was a problem hiding this comment.
Added to set_callbacks, set before start(), don't swap while running, and a callback must not call this component's own stop()
065673b to
69e790f
Compare
d1dd2e0 to
7eb8d37
Compare
|
Added test_vr_session_control_component.cpp: button detection, config/binding validation, and disconnect firing once + re-arming. Updated the tests/hardware boxes in description. |
Add VrSessionControlComponent, which turns VR controller button presses into SessionControlCapable events. Registered as hardware type "vr_session_control". - A background reader thread polls the shared VR frame stream, detects rising edges on bound buttons, and fires the event callback once per press. Frames stalling past disconnect_timeout_s fire the one-shot disconnect callback. - Configurable bindings map buttons to events: button_a/button_x -> primary, button_b/button_y -> secondary; events start, stop_early, rerecord, stop_session. Default is A=start, B=rerecord. - Claims its bound buttons on the configured controller_type via VrSession, so two controls fighting for the same button fail at configure() time. Implements SessionControlCapable and builds on VrSession. Adds src/hw/vr/vr_session_control_component.cpp to the library; this completes the VR hardware layer.
69e790f to
bc60d48
Compare
7eb8d37 to
1c42bfa
Compare

Summary
Adds
VrSessionControlComponent, which turns VR controller button presses intoSessionControlCapableevents (hardware typevr_session_control). Completes the VR hardware layer.Changes
disconnect_timeout_sfire the one-shot disconnect callback.button_a/button_x→ primary,button_b/button_y→ secondary; eventsstart,stop_early,rerecord,stop_session. Default is A=start, B=rerecord.button_aandbutton_x), which would otherwise fire the event twice per press.controller_typeviaVrSession.Test Plan
make build)make test)pre-commit run --all-files)Breaking Changes
None.
Related Issues
N/A — part of the VR teleoperation feature stack.