Skip to content

Commit

Permalink
Return the rate at which the pose is changing
Browse files Browse the repository at this point in the history
This will allow us to feed a rough guesstimate of the velocity to
SteamVR which should reduce the jitteriness.
  • Loading branch information
bobsayshilol committed Dec 18, 2022
1 parent 0ab2110 commit 551095f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions driver_files/src/Driver/TrackerDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void ExampleDriver::TrackerDevice::Update()
double previous_position[3] = { 0 };
std::copy(std::begin(pose.vecPosition), std::end(pose.vecPosition), std::begin(previous_position));

PoseInfo next_pose;
if (get_next_pose(Seconds(0), next_pose) != 0)
PoseInfo next_pose, pose_rate;
if (get_next_pose(Seconds(0), next_pose, &pose_rate) != 0)
return;

normalizeQuat(next_pose);
Expand Down Expand Up @@ -118,6 +118,10 @@ void ExampleDriver::TrackerDevice::Update()

pose.poseTimeOffset = 0;

pose.vecVelocity[0] = pose_rate[0];
pose.vecVelocity[1] = pose_rate[1];
pose.vecVelocity[2] = pose_rate[2];

//pose.vecVelocity[0] = (pose.vecPosition[0] - previous_position[0]) / pose_time_delta_seconds;
//pose.vecVelocity[1] = (pose.vecPosition[1] - previous_position[1]) / pose_time_delta_seconds;
//pose.vecVelocity[2] = (pose.vecPosition[2] - previous_position[2]) / pose_time_delta_seconds;
Expand All @@ -133,12 +137,16 @@ void ExampleDriver::TrackerDevice::Log(std::string message)
vr::VRDriverLog()->Log(message_endl.c_str());
}

int ExampleDriver::TrackerDevice::get_next_pose(Seconds time_offset, PoseInfo& next_pose) const
int ExampleDriver::TrackerDevice::get_next_pose(Seconds time_offset, PoseInfo& next_pose, PoseInfo* pose_rate_) const
{
std::lock_guard guard(pose_mutex);

int statuscode = 0;

PoseInfo dummy_rate;
PoseInfo& pose_rate = pose_rate_ ? *pose_rate_ : dummy_rate;
pose_rate.fill(0);

const auto time_now = std::chrono::system_clock::now();
const auto req_time = time_now - time_offset;
double new_time = std::chrono::duration_cast<Seconds>(last_update - req_time).count();
Expand Down Expand Up @@ -193,6 +201,7 @@ int ExampleDriver::TrackerDevice::get_next_pose(Seconds time_offset, PoseInfo& n
const double y = avg_val + m * (new_time - avg_time);

next_pose[i] = y;
pose_rate[i] = -m; // -ve since |new_time| and |PrevPose::time| increase into the past
}

return statuscode;
Expand Down
2 changes: 1 addition & 1 deletion driver_files/src/Driver/TrackerDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ExampleDriver {

void reinit(int msaved, double mtime, double msmooth);
void save_current_pose(double a, double b, double c, double qw, double qx, double qy, double qz, Seconds time_offset);
int get_next_pose(Seconds time_offset, PoseInfo& pred) const;
int get_next_pose(Seconds time_offset, PoseInfo& next_pose, PoseInfo* pose_rate = nullptr) const;

private:
vr::TrackedDeviceIndex_t device_index_ = vr::k_unTrackedDeviceIndexInvalid;
Expand Down

0 comments on commit 551095f

Please sign in to comment.