-
Notifications
You must be signed in to change notification settings - Fork 14
refactor: replace HandInjector with SchemaPusher pipeline for Haply device #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vickybot911
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
vickybot911:haply-schema-rework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dbe0aa1
feat: add Haply Robotics hand tracking plugin
vickybot911 b00417e
fix: address CodeRabbit review comments
vickybot911 645f7ac
fix: align env var names and add printer timeout
vickybot911 14238cc
refactor: replace HandInjector with SchemaPusher pipeline for Haply d…
vickybot911 fb9ad96
cleanup: remove old HandInjector-based Haply plugin files
vickybot911 9bfbe1f
test: add mock Haply SDK server and align env var names
vickybot911 6391941
fix: address CodeRabbit review feedback
vickybot911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "inc/deviceio/haply_device_tracker.hpp" | ||
|
|
||
| #include "inc/deviceio/deviceio_session.hpp" | ||
|
|
||
| #include <flatbuffers/flatbuffers.h> | ||
| #include <oxr_utils/oxr_time.hpp> | ||
| #include <schema/haply_device_bfbs_generated.h> | ||
|
|
||
| #include <vector> | ||
|
|
||
| namespace core | ||
| { | ||
|
|
||
| // ============================================================================ | ||
| // HaplyDeviceTracker::Impl | ||
| // ============================================================================ | ||
|
|
||
| class HaplyDeviceTracker::Impl : public ITrackerImpl | ||
| { | ||
| public: | ||
| Impl(const OpenXRSessionHandles& handles, SchemaTrackerConfig config); | ||
|
|
||
| bool update(XrTime time) override; | ||
| void serialize_all(size_t channel_index, const RecordCallback& callback) const override; | ||
|
|
||
| const HaplyDeviceOutputTrackedT& get_data() const; | ||
|
|
||
| private: | ||
| SchemaTracker m_schema_reader; | ||
| XrTimeConverter m_time_converter_; | ||
| XrTime m_last_update_time_ = 0; | ||
| bool m_collection_present = false; | ||
| HaplyDeviceOutputTrackedT m_tracked; | ||
| std::vector<SchemaTracker::SampleResult> m_pending_records; | ||
| }; | ||
|
|
||
| HaplyDeviceTracker::Impl::Impl(const OpenXRSessionHandles& handles, SchemaTrackerConfig config) | ||
| : m_schema_reader(handles, std::move(config)), m_time_converter_(handles) | ||
| { | ||
| } | ||
|
|
||
| bool HaplyDeviceTracker::Impl::update(XrTime time) | ||
| { | ||
| m_last_update_time_ = time; | ||
| m_pending_records.clear(); | ||
| m_collection_present = m_schema_reader.read_all_samples(m_pending_records); | ||
|
|
||
| if (!m_collection_present) | ||
| { | ||
| // Device disappeared: clear tracked data so get_data() reflects absence. | ||
| m_tracked.data.reset(); | ||
| return true; | ||
| } | ||
|
|
||
| // Deserialize only the last sample to keep m_tracked current for get_data(). | ||
| // Full per-sample deserialization is deferred to serialize_all(). | ||
| if (!m_pending_records.empty()) | ||
| { | ||
| auto fb = flatbuffers::GetRoot<HaplyDeviceOutput>(m_pending_records.back().buffer.data()); | ||
| if (fb) | ||
| { | ||
| if (!m_tracked.data) | ||
| { | ||
| m_tracked.data = std::make_shared<HaplyDeviceOutputT>(); | ||
| } | ||
| fb->UnPackTo(m_tracked.data.get()); | ||
| } | ||
| } | ||
| // When no samples arrive but the collection is present, m_tracked retains | ||
| // the last seen value so get_data() reflects the most recently received state. | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void HaplyDeviceTracker::Impl::serialize_all(size_t channel_index, const RecordCallback& callback) const | ||
| { | ||
| if (channel_index != 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| int64_t update_ns = m_time_converter_.convert_xrtime_to_monotonic_ns(m_last_update_time_); | ||
|
|
||
| if (m_pending_records.empty()) | ||
| { | ||
| if (!m_collection_present) | ||
| { | ||
| // Device disappeared: emit one empty record to mark the absence in the MCAP stream. | ||
| DeviceDataTimestamp update_timestamp(update_ns, 0, 0); | ||
| flatbuffers::FlatBufferBuilder builder(64); | ||
| HaplyDeviceOutputRecordBuilder record_builder(builder); | ||
| record_builder.add_timestamp(&update_timestamp); | ||
| builder.Finish(record_builder.Finish()); | ||
| callback(update_ns, builder.GetBufferPointer(), builder.GetSize()); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| for (const auto& sample : m_pending_records) | ||
| { | ||
| auto fb = flatbuffers::GetRoot<HaplyDeviceOutput>(sample.buffer.data()); | ||
| if (!fb) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| HaplyDeviceOutputT parsed; | ||
| fb->UnPackTo(&parsed); | ||
|
|
||
| flatbuffers::FlatBufferBuilder builder(256); | ||
| auto data_offset = HaplyDeviceOutput::Pack(builder, &parsed); | ||
| HaplyDeviceOutputRecordBuilder record_builder(builder); | ||
| record_builder.add_data(data_offset); | ||
| record_builder.add_timestamp(&sample.timestamp); | ||
| builder.Finish(record_builder.Finish()); | ||
| callback(update_ns, builder.GetBufferPointer(), builder.GetSize()); | ||
| } | ||
| } | ||
|
|
||
| const HaplyDeviceOutputTrackedT& HaplyDeviceTracker::Impl::get_data() const | ||
| { | ||
| return m_tracked; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // HaplyDeviceTracker | ||
| // ============================================================================ | ||
|
|
||
| HaplyDeviceTracker::HaplyDeviceTracker(const std::string& collection_id, size_t max_flatbuffer_size) | ||
| : m_config{.collection_id = collection_id, | ||
| .max_flatbuffer_size = max_flatbuffer_size, | ||
| .tensor_identifier = "haply_device", | ||
| .localized_name = "HaplyDeviceTracker"} | ||
| { | ||
| } | ||
|
|
||
| std::vector<std::string> HaplyDeviceTracker::get_required_extensions() const | ||
| { | ||
| return SchemaTracker::get_required_extensions(); | ||
| } | ||
|
|
||
| std::string_view HaplyDeviceTracker::get_name() const | ||
| { | ||
| return "HaplyDeviceTracker"; | ||
| } | ||
|
|
||
| std::string_view HaplyDeviceTracker::get_schema_name() const | ||
| { | ||
| return "core.HaplyDeviceOutputRecord"; | ||
| } | ||
|
|
||
| std::string_view HaplyDeviceTracker::get_schema_text() const | ||
| { | ||
| return std::string_view(reinterpret_cast<const char*>(HaplyDeviceOutputRecordBinarySchema::data()), | ||
| HaplyDeviceOutputRecordBinarySchema::size()); | ||
| } | ||
|
|
||
| const SchemaTrackerConfig& HaplyDeviceTracker::get_config() const | ||
| { | ||
| return m_config; | ||
| } | ||
|
|
||
| const HaplyDeviceOutputTrackedT& HaplyDeviceTracker::get_data(const DeviceIOSession& session) const | ||
| { | ||
| return static_cast<const Impl&>(session.get_tracker_impl(*this)).get_data(); | ||
| } | ||
|
|
||
| std::shared_ptr<ITrackerImpl> HaplyDeviceTracker::create_tracker(const OpenXRSessionHandles& handles) const | ||
| { | ||
| return std::make_shared<Impl>(handles, get_config()); | ||
| } | ||
|
|
||
| } // namespace core |
77 changes: 77 additions & 0 deletions
77
src/core/deviceio/cpp/inc/deviceio/haply_device_tracker.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "schema_tracker.hpp" | ||
| #include "tracker.hpp" | ||
|
|
||
| #include <schema/haply_device_generated.h> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace core | ||
| { | ||
|
|
||
| /*! | ||
| * @brief Tracker for reading HaplyDeviceOutput FlatBuffer messages via OpenXR tensor extensions. | ||
| * | ||
| * This tracker reads Haply Inverse3 + VerseGrip device state (cursor position, | ||
| * velocity, orientation, buttons) pushed by the Haply plugin using the | ||
| * SchemaTracker utility. Both pusher and reader must agree on the collection_id | ||
| * and use the HaplyDeviceOutput schema. | ||
| * | ||
| * Usage: | ||
| * @code | ||
| * auto tracker = std::make_shared<HaplyDeviceTracker>("haply_device"); | ||
| * // ... create DeviceIOSession with tracker ... | ||
| * session->update(); | ||
| * const auto& data = tracker->get_data(*session); | ||
| * @endcode | ||
| */ | ||
| class HaplyDeviceTracker : public ITracker | ||
| { | ||
| public: | ||
| //! Default maximum FlatBuffer size for HaplyDeviceOutput messages. | ||
| static constexpr size_t DEFAULT_MAX_FLATBUFFER_SIZE = 256; | ||
|
|
||
| /*! | ||
| * @brief Constructs a HaplyDeviceTracker. | ||
| * @param collection_id Tensor collection identifier for discovery. | ||
| * @param max_flatbuffer_size Maximum serialized FlatBuffer size (default: 256 bytes). | ||
| */ | ||
| explicit HaplyDeviceTracker(const std::string& collection_id = "haply_device", | ||
| size_t max_flatbuffer_size = DEFAULT_MAX_FLATBUFFER_SIZE); | ||
|
|
||
| // ITracker interface | ||
| std::vector<std::string> get_required_extensions() const override; | ||
| std::string_view get_name() const override; | ||
| std::string_view get_schema_name() const override; | ||
| std::string_view get_schema_text() const override; | ||
|
|
||
| std::vector<std::string> get_record_channels() const override | ||
| { | ||
| return {"haply_device"}; | ||
| } | ||
|
|
||
| /*! | ||
| * @brief Get the current Haply device data (tracked.data is null when no data available). | ||
| */ | ||
| const HaplyDeviceOutputTrackedT& get_data(const DeviceIOSession& session) const; | ||
|
|
||
| protected: | ||
| /*! | ||
| * @brief Access the configuration for subclass use. | ||
| */ | ||
| const SchemaTrackerConfig& get_config() const; | ||
|
|
||
| private: | ||
| std::shared_ptr<ITrackerImpl> create_tracker(const OpenXRSessionHandles& handles) const override; | ||
|
|
||
| SchemaTrackerConfig m_config; | ||
|
|
||
| class Impl; | ||
| }; | ||
|
|
||
| } // namespace core |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.