Skip to content

Commit

Permalink
Made physics optional, removed 'prediction' filters
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 7, 2022
1 parent 44af41f commit 84c4786
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 42 deletions.
2 changes: 0 additions & 2 deletions Amethyst/JointExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,6 @@ namespace winrt::Microsoft::UI::Xaml::Controls
L"SettingsPage", L"Filters/Position/LowPass")));
_kalman.Content(box_value(k2app::interfacing::LocalizedResourceWString(
L"SettingsPage", L"Filters/Position/Kalman")));
_predict.Content(box_value(k2app::interfacing::LocalizedResourceWString(
L"SettingsPage", L"Filters/Position/Prediction")));
_pos_off.Content(box_value(k2app::interfacing::LocalizedResourceWString(
L"SettingsPage", L"Filters/Position/Off")));

Expand Down
41 changes: 5 additions & 36 deletions Amethyst/K2AppTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ namespace k2app
k2_PositionTrackingFilter_Lowpass,
// Extended Kalman
k2_PositionTrackingFilter_Kalman,
// Hekky^ pose prediction
k2_PositionTrackingFilter_Prediction,
// Filter Off
k2_NoPositionTrackingFilter
};
Expand Down Expand Up @@ -271,13 +269,6 @@ namespace k2app

/* Update the pose prediction filter */
predictedPosition = pose_position;

/* Notes for `k2_PositionTrackingFilter_Prediction\\predictedPosition` impl:
*
* - if you need timestamps, you're gonna need to manage them manually (sorry)
* - you may want to create your own filter class and put it in `[repo]/external/vendor/`, like lowpass and kalman filters
* - the tracker class will auto-manage your filter, just output the final position to the `predictedPosition` variable
*/
}

// Update orientation filters
Expand All @@ -294,31 +285,6 @@ namespace k2app
lastSLERPSlowOrientation = pose_orientation.normalized(); // Backup the orientation
}

// Update the internal physics components,
// not called if the managing device overrides physics
void updateInternalPhysics()
{
// Timestamps
//pose_poseTimestamp;
//pose_previousPoseTimestamp;

// Pose components
//pose_position
//pose_previousPosition
//pose_orientation
//pose_previousOrientation

// Physics components to update
//pose_velocity;
//pose_angularVelocity;
//pose_acceleration;
//pose_angularAcceleration;

// Called after all orientation&pose composes,
// MUST YIELD UNCALIBRATED-SPACE COMPONENTS
// (which get calibrated at getTrackerBase())
}

// Get filtered data
// By default, the saved filter is selected,
// and to select it, the filter number must be < 0
Expand All @@ -341,8 +307,6 @@ namespace k2app
return lowPassPosition;
case k2_PositionTrackingFilter_Kalman:
return kalmanPosition;
case k2_PositionTrackingFilter_Prediction:
return predictedPosition;
case k2_NoPositionTrackingFilter:
return pose_position;
}
Expand Down Expand Up @@ -510,6 +474,7 @@ namespace k2app
tracker_base.mutable_pose()->mutable_position()->set_z(_full_position.z());

// Physics
if (overridePhysics)
{
const auto _full_velocity =
not_calibrated
Expand Down Expand Up @@ -598,6 +563,7 @@ namespace k2app
tracker_base.mutable_pose()->mutable_position()->set_z(_full_position.z());

// Physics
if (overridePhysics)
{
// Velocity
tracker_base.mutable_pose()->mutable_physics()->mutable_velocity()->set_x(pose_velocity.x());
Expand Down Expand Up @@ -667,6 +633,7 @@ namespace k2app

// Is this tracker enabled?
bool data_isActive = false;
bool overridePhysics = false;

// Does the managing device request no pos filtering?
bool m_no_position_filtering_requested = false;
Expand Down Expand Up @@ -696,6 +663,8 @@ namespace k2app
CEREAL_NVP(overrideJointID),
CEREAL_NVP(overrideGUID),

CEREAL_NVP(overridePhysics),

CEREAL_NVP(pose_position),
CEREAL_NVP(pose_orientation),
CEREAL_NVP(pose_previousPosition),
Expand Down
12 changes: 8 additions & 4 deletions Amethyst/K2Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ namespace k2app::main
// If the device overrides physics
if (_kinect->isPhysicsOverrideEnabled())
{
tracker.overridePhysics = true; // Mark as requested
tracker.pose_velocity = _joint.getJointVelocity();
tracker.pose_acceleration = _joint.getJointAcceleration();
tracker.pose_angularVelocity = _joint.getJointAngularVelocity();
Expand All @@ -849,7 +850,7 @@ namespace k2app::main
// If not and the tracker is not overriden
else if (!tracker.isPositionOverridden ||
!K2Settings.overrideDeviceGUIDsMap.contains(tracker.overrideGUID))
tracker.updateInternalPhysics();
tracker.overridePhysics = false;
}
}
else if (_device.index() == 1)
Expand All @@ -874,6 +875,7 @@ namespace k2app::main
// If the device overrides physics
if (_joints->isPhysicsOverrideEnabled())
{
tracker.overridePhysics = true; // Mark as requested
tracker.pose_velocity = _joint.getJointVelocity();
tracker.pose_acceleration = _joint.getJointAcceleration();
tracker.pose_angularVelocity = _joint.getJointAngularVelocity();
Expand All @@ -882,7 +884,7 @@ namespace k2app::main
// If not and the tracker is not overriden
else if (!tracker.isPositionOverridden ||
!K2Settings.overrideDeviceGUIDsMap.contains(tracker.overrideGUID))
tracker.updateInternalPhysics();
tracker.overridePhysics = false;
}
}
}
Expand Down Expand Up @@ -1145,12 +1147,13 @@ namespace k2app::main
// If the device overrides physics
if (_kinect->isPhysicsOverrideEnabled())
{
tracker.overridePhysics = true; // Mark as requested
tracker.pose_velocity = _joint.getJointVelocity();
tracker.pose_acceleration = _joint.getJointAcceleration();
tracker.pose_angularVelocity = _joint.getJointAngularVelocity();
tracker.pose_angularAcceleration = _joint.getJointAngularAcceleration();
}
else tracker.updateInternalPhysics();
else tracker.overridePhysics = false;
}
}
else if (_device.index() == 1)
Expand All @@ -1177,12 +1180,13 @@ namespace k2app::main
// If the device overrides physics
if (_joints->isPhysicsOverrideEnabled())
{
tracker.overridePhysics = true; // Mark as requested
tracker.pose_velocity = _joint.getJointVelocity();
tracker.pose_acceleration = _joint.getJointAcceleration();
tracker.pose_angularVelocity = _joint.getJointAngularVelocity();
tracker.pose_angularAcceleration = _joint.getJointAngularAcceleration();
}
else tracker.updateInternalPhysics();
else tracker.overridePhysics = false;
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions driver_Amethyst/K2Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ void K2Tracker::set_pose(const ktvr::K2TrackerPose& pose)
_pose.vecAngularAcceleration[2] = pose.physics().angularacceleration().z();
}

else
{
// Velocity
_pose.vecVelocity[0] = 0.;
_pose.vecVelocity[1] = 0.;
_pose.vecVelocity[2] = 0.;

// Acceleration
_pose.vecAcceleration[0] = 0.;
_pose.vecAcceleration[1] = 0.;
_pose.vecAcceleration[2] = 0.;

// Angular Velocity
_pose.vecAngularVelocity[0] = 0.;
_pose.vecAngularVelocity[1] = 0.;
_pose.vecAngularVelocity[2] = 0.;

// Angular Acceleration
_pose.vecAngularAcceleration[0] = 0.;
_pose.vecAngularAcceleration[1] = 0.;
_pose.vecAngularAcceleration[2] = 0.;
}

// Automatically update the tracker when finished
update(); // called from this
}
Expand Down

0 comments on commit 84c4786

Please sign in to comment.