Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/plugins/sharpa_avatar/core/avatar_hand_tracking_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>

Expand All @@ -35,7 +36,7 @@ namespace
{

constexpr size_t kJointFlatbufferSize = 4096;
constexpr auto kAvatarDataTimeout = std::chrono::seconds(10);
constexpr auto kAvatarDataTimeout = std::chrono::seconds(3);
constexpr auto kGloveRetryInterval = std::chrono::seconds(2);
constexpr auto kGloveWaitLogInterval = std::chrono::seconds(10);
constexpr auto kHapticCommandTimeout = std::chrono::milliseconds(200);
Expand Down Expand Up @@ -256,6 +257,7 @@ void GloveState::reset() noexcept
robot_frame = {};
device.reset();
last_successful_fetch.reset();
last_sample_stamp = {};
}

AvatarTracker::AvatarTracker(AvatarPluginConfig config) : m_config(std::move(config)), m_sdk(m_config.sdk_config_path)
Expand Down Expand Up @@ -428,15 +430,26 @@ void AvatarTracker::refresh_data()
}

const bool expects_data = m_config.human || m_config.raw || m_config.robot;
// fetch_data() keeps returning a silent glove's last sample, so only a newer
// sample stamp counts as data for the timeout below.
bool fetched_any = false;
const auto note_stamp = [&state, &fetched_any](const ::avatar::Stamp& stamp)
{
if (std::tie(stamp.sec, stamp.nanosec) >
std::tie(state.last_sample_stamp.sec, state.last_sample_stamp.nanosec))
{
state.last_sample_stamp = stamp;
fetched_any = true;
}
};
if (m_config.human)
{
::avatar::AvatarDataFrame frame;
const bool fetched =
state.device->fetch_data(frame, ::avatar::DeviceDataCategory::HUMAN) == ::avatar::ErrorCode::SUCCESS;
fetched_any = fetched_any || fetched;
if (fetched)
{
note_stamp(frame.skeleton.header.stamp);
state.landmarks = std::move(frame.skeleton.landmark);
}
else
Expand All @@ -452,10 +465,10 @@ void AvatarTracker::refresh_data()
}
::avatar::AvatarDataFrame frame;
const bool fetched = state.device->fetch_data(frame, category) == ::avatar::ErrorCode::SUCCESS;
fetched_any = fetched_any || fetched;
::avatar::AvatarDataFrame& cached = cached_joint_frame(state, category);
if (fetched)
{
note_stamp(hand_payload(frame, category).header.stamp);
cached = std::move(frame);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ struct GloveState
::avatar::AvatarDataFrame robot_frame;
// Empty until start() or a successful fetch; drives the data-timeout window.
std::optional<std::chrono::steady_clock::time_point> last_successful_fetch;
// Newest sample stamp seen; a fetch only counts as data when it advances this.
::avatar::Stamp last_sample_stamp;
};

class __attribute__((visibility("default"))) AvatarTracker
Expand Down
Loading