From 5d457eaa3951b9b19fa9762506f85fb9c3850756 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 11 May 2017 20:44:08 +0100 Subject: [PATCH 1/3] better handling of when lost tracking of pucks --- plugins/openvr/src/ViveControllerManager.cpp | 30 ++++++++++++++++---- plugins/openvr/src/ViveControllerManager.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 6e5697730b..411cac3d2b 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -32,8 +32,6 @@ #include -#include "OpenVrHelpers.h" - extern PoseData _nextSimPoseData; vr::IVRSystem* acquireOpenVrSystem(); @@ -207,6 +205,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle } updateCalibratedLimbs(); + _lastSimPoseData = _nextSimPoseData; } void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) { @@ -217,11 +216,30 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde _nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid && poseIndex <= controller::TRACKED_OBJECT_15) { - // process pose - const mat4& mat = _nextSimPoseData.poses[deviceIndex]; - const vec3 linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; - const vec3 angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex]; + mat4& mat = mat4(); + vec3 linearVelocity = vec3(); + vec3 angularVelocity = vec3(); + // check if the device is tracking out of range, then process the correct pose depending on the result. + if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != vr::TrackingResult_Running_OutOfRange) { + mat = _nextSimPoseData.poses[deviceIndex]; + linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; + angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex]; + } else { + mat = _lastSimPoseData.poses[deviceIndex]; + linearVelocity = _lastSimPoseData.linearVelocities[deviceIndex]; + angularVelocity = _lastSimPoseData.angularVelocities[deviceIndex]; + // make sure that we do not overwrite the pose in the _lastSimPose with incorrect data. + _nextSimPoseData.poses[deviceIndex] = _lastSimPoseData.poses[deviceIndex]; + _nextSimPoseData.linearVelocities[deviceIndex] = _lastSimPoseData.linearVelocities[deviceIndex]; + _nextSimPoseData.angularVelocities[deviceIndex] = _lastSimPoseData.angularVelocities[deviceIndex]; + + } + +/* const mat4& mat; + const vec3 linearVelocity; + const vec3 angularVelocity;*/ + controller::Pose pose(extractTranslation(mat), glmExtractRotation(mat), linearVelocity, angularVelocity); // transform into avatar frame diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 4e8b2b3a04..ca78fd0b37 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -25,6 +25,7 @@ #include #include #include +#include "OpenVrHelpers.h" namespace vr { class IVRSystem; @@ -108,6 +109,7 @@ private: std::vector> _validTrackedObjects; std::map _pucksOffset; std::map _jointToPuckMap; + PoseData _lastSimPoseData; // perform an action when the InputDevice mutex is acquired. using Locker = std::unique_lock; template From 5042d4d3129b667992769f5dbd62699a608241d4 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Fri, 12 May 2017 00:28:31 +0100 Subject: [PATCH 2/3] add print when device changes tracking result --- plugins/openvr/src/ViveControllerManager.cpp | 41 ++++++++++++++++---- plugins/openvr/src/ViveControllerManager.h | 1 + 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 606cc38da2..a5b742c32c 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -29,7 +29,6 @@ #include #include - #include #include @@ -67,6 +66,28 @@ static bool sortPucksYPosition(std::pair firstPuck, return (firstPuck.second.translation.y < firstPuck.second.translation.y); } +static QString deviceTrackingResultToString(vr::ETrackingResult trackingResult) { + QString result; + switch (trackingResult) { + case vr::TrackingResult_Uninitialized: + result = "vr::TrackingResult_Uninitialized"; + break; + case vr::TrackingResult_Calibrating_InProgress: + result = "vr::TrackingResult_Calibrating_InProgess"; + break; + case vr::TrackingResult_Calibrating_OutOfRange: + result = "vr::TrackingResult_Calibrating_OutOfRange"; + break; + case vr::TrackingResult_Running_OK: + result = "vr::TrackingResult_Running_OK"; + break; + case vr::TrackingResult_Running_OutOfRange: + result = "vr::TrackingResult_Running_OutOfRange"; + break; + } + return result; +} + bool ViveControllerManager::isSupported() const { return openVrSupported(); } @@ -212,7 +233,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) { uint32_t poseIndex = controller::TRACKED_OBJECT_00 + deviceIndex; - + printDeviceTrackingResultChange(deviceIndex); if (_system->IsTrackedDeviceConnected(deviceIndex) && _system->GetTrackedDeviceClass(deviceIndex) == vr::TrackedDeviceClass_GenericTracker && _nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid && @@ -222,7 +243,7 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde vec3 linearVelocity = vec3(); vec3 angularVelocity = vec3(); // check if the device is tracking out of range, then process the correct pose depending on the result. - if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != vr::TrackingResult_Running_OutOfRange) { + if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != vr::TrackingResult_Running_OutOfRange) { mat = _nextSimPoseData.poses[deviceIndex]; linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex]; @@ -235,13 +256,9 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde _nextSimPoseData.poses[deviceIndex] = _lastSimPoseData.poses[deviceIndex]; _nextSimPoseData.linearVelocities[deviceIndex] = _lastSimPoseData.linearVelocities[deviceIndex]; _nextSimPoseData.angularVelocities[deviceIndex] = _lastSimPoseData.angularVelocities[deviceIndex]; - + } -/* const mat4& mat; - const vec3 linearVelocity; - const vec3 angularVelocity;*/ - controller::Pose pose(extractTranslation(mat), glmExtractRotation(mat), linearVelocity, angularVelocity); // transform into avatar frame @@ -466,6 +483,14 @@ enum ViveButtonChannel { RIGHT_APP_MENU }; +void ViveControllerManager::InputDevice::printDeviceTrackingResultChange(uint32_t deviceIndex) { + if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != _lastSimPoseData.vrPoses[deviceIndex].eTrackingResult) { + qDebug() << "OpenVR: Device" << deviceIndex << "Tracking Result changed from" << + deviceTrackingResultToString(_lastSimPoseData.vrPoses[deviceIndex].eTrackingResult) + << "to" << deviceTrackingResultToString(_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult); + } +} + bool ViveControllerManager::InputDevice::checkForCalibrationEvent() { auto& endOfMap = _buttonPressedMap.end(); auto& leftTrigger = _buttonPressedMap.find(controller::LT); diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 30680ec264..c815506770 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -77,6 +77,7 @@ private: void handleHeadPoseEvent(const controller::InputCalibrationData& inputCalibrationData, const mat4& mat, const vec3& linearVelocity, const vec3& angularVelocity); void partitionTouchpad(int sButton, int xAxis, int yAxis, int centerPsuedoButton, int xPseudoButton, int yPseudoButton); + void printDeviceTrackingResultChange(uint32_t deviceIndex); class FilteredStick { public: From e6020e0137ae2e9abd0d1b88c235efc62002b498 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Sat, 13 May 2017 00:40:07 +0100 Subject: [PATCH 3/3] added lookup table for tracking result and configs --- plugins/openvr/src/ViveControllerManager.cpp | 59 ++++++++------------ plugins/openvr/src/ViveControllerManager.h | 3 +- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index ccc843b5cc..5e22272dd6 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -56,6 +56,14 @@ static const int CHEST = 3; const char* ViveControllerManager::NAME { "OpenVR" }; +const std::map TRACKING_RESULT_TO_STRING = { + {vr::TrackingResult_Uninitialized, QString("vr::TrackingResult_Uninitialized")}, + {vr::TrackingResult_Calibrating_InProgress, QString("vr::TrackingResult_Calibrating_InProgess")}, + {vr::TrackingResult_Calibrating_OutOfRange, QString("TrackingResult_Calibrating_OutOfRange")}, + {vr::TrackingResult_Running_OK, QString("TrackingResult_Running_Ok")}, + {vr::TrackingResult_Running_OutOfRange, QString("TrackingResult_Running_OutOfRange")} +}; + static glm::mat4 computeOffset(glm::mat4 defaultToReferenceMat, glm::mat4 defaultJointMat, controller::Pose puckPose) { glm::mat4 poseMat = createMatFromQuatAndPos(puckPose.rotation, puckPose.translation); glm::mat4 referenceJointMat = defaultToReferenceMat * defaultJointMat; @@ -68,22 +76,10 @@ static bool sortPucksYPosition(std::pair firstPuck, static QString deviceTrackingResultToString(vr::ETrackingResult trackingResult) { QString result; - switch (trackingResult) { - case vr::TrackingResult_Uninitialized: - result = "vr::TrackingResult_Uninitialized"; - break; - case vr::TrackingResult_Calibrating_InProgress: - result = "vr::TrackingResult_Calibrating_InProgess"; - break; - case vr::TrackingResult_Calibrating_OutOfRange: - result = "vr::TrackingResult_Calibrating_OutOfRange"; - break; - case vr::TrackingResult_Running_OK: - result = "vr::TrackingResult_Running_OK"; - break; - case vr::TrackingResult_Running_OutOfRange: - result = "vr::TrackingResult_Running_OutOfRange"; - break; + auto iterator = TRACKING_RESULT_TO_STRING.find(trackingResult); + + if (iterator != TRACKING_RESULT_TO_STRING.end()) { + return iterator->second; } return result; } @@ -166,6 +162,15 @@ void ViveControllerManager::pluginUpdate(float deltaTime, const controller::Inpu } } +ViveControllerManager::InputDevice::InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) { + createPreferences(); + + _configStringMap[Config::Auto] = QString("Auto"); + _configStringMap[Config::Feet] = QString("Feet"); + _configStringMap[Config::FeetAndHips] = QString("FeetAndHips"); + _configStringMap[Config::FeetHipsAndChest] = QString("FeetHipsAndChest"); +} + void ViveControllerManager::InputDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { _poseStateMap.clear(); _buttonPressedMap.clear(); @@ -626,25 +631,7 @@ void ViveControllerManager::InputDevice::saveSettings() const { } QString ViveControllerManager::InputDevice::configToString(Config config) { - QString currentConfig; - switch (config) { - case Config::Auto: - currentConfig = "Auto"; - break; - - case Config::Feet: - currentConfig = "Feet"; - break; - - case Config::FeetAndHips: - currentConfig = "FeetAndHips"; - break; - - case Config::FeetHipsAndChest: - currentConfig = "FeetHipsAndChest"; - break; - } - return currentConfig; + return _configStringMap[config]; } void ViveControllerManager::InputDevice::setConfigFromString(const QString& value) { @@ -665,7 +652,7 @@ void ViveControllerManager::InputDevice::createPreferences() { static const QString VIVE_PUCKS_CONFIG = "Vive Pucks Configuration"; { - auto getter = [this]()->QString { return configToString(_preferedConfig); }; + auto getter = [this]()->QString { return _configStringMap[_preferedConfig]; }; auto setter = [this](const QString& value) { setConfigFromString(value); saveSettings(); }; auto preference = new ComboBoxPreference(VIVE_PUCKS_CONFIG, "Configuration", getter, setter); QStringList list = (QStringList() << "Auto" << "Feet" << "FeetAndHips" << "FeetHipsAndChest"); diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index d7ab77ddbc..fa2566da45 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -51,7 +51,7 @@ public: private: class InputDevice : public controller::InputDevice { public: - InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) { createPreferences(); } + InputDevice(vr::IVRSystem*& system); private: // Device functions controller::Input::NamedVector getAvailableInputs() const override; @@ -111,6 +111,7 @@ private: std::vector> _validTrackedObjects; std::map _pucksOffset; std::map _jointToPuckMap; + std::map _configStringMap; PoseData _lastSimPoseData; // perform an action when the InputDevice mutex is acquired. using Locker = std::unique_lock;