From 655483182c2ba1b0b88d7a4409f94447c6400523 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Fri, 12 May 2017 23:38:20 +0100 Subject: [PATCH 01/12] daving work --- .../controllers/src/controllers/InputDevice.cpp | 2 ++ .../controllers/src/controllers/InputDevice.h | 2 ++ plugins/openvr/src/.#ViveControllerManager.cpp | Bin 0 -> 76 bytes plugins/openvr/src/ViveControllerManager.cpp | 11 +++++++++++ plugins/openvr/src/ViveControllerManager.h | 3 ++- 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 plugins/openvr/src/.#ViveControllerManager.cpp diff --git a/libraries/controllers/src/controllers/InputDevice.cpp b/libraries/controllers/src/controllers/InputDevice.cpp index d5044a219f..12d8b676eb 100644 --- a/libraries/controllers/src/controllers/InputDevice.cpp +++ b/libraries/controllers/src/controllers/InputDevice.cpp @@ -16,6 +16,8 @@ namespace controller { bool InputDevice::_lowVelocityFilter = false; + float InputDevice::_translationFilterConstant = 0.1f; + float InputDevice::_rotationFilterConstant = 0.1f; const float DEFAULT_HAND_RETICLE_MOVE_SPEED = 37.5f; float InputDevice::_reticleMoveSpeed = DEFAULT_HAND_RETICLE_MOVE_SPEED; diff --git a/libraries/controllers/src/controllers/InputDevice.h b/libraries/controllers/src/controllers/InputDevice.h index 10e1a104f4..aad1f235ec 100644 --- a/libraries/controllers/src/controllers/InputDevice.h +++ b/libraries/controllers/src/controllers/InputDevice.h @@ -105,6 +105,8 @@ protected: PoseStateMap _poseStateMap; static bool _lowVelocityFilter; + static float _translationFilterConstant; + static float _rotationFilterConstant; private: static float _reticleMoveSpeed; diff --git a/plugins/openvr/src/.#ViveControllerManager.cpp b/plugins/openvr/src/.#ViveControllerManager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f036319c61274919fb416be94769422ca7946d0 GIT binary patch literal 76 zcmY$iDXz@T$;`{P`~S~{A(0`Ep@booL4hHNp_Cz$p^CwQ!G*zaddPreference(preference); } + + { + auto getter = [this]()->float { return _translationFilterConstant; }; + auto setter = [this](const float& value) { _translationFilterConstant; }; + } + } controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const { diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index c2ebdc6144..2fe386593c 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -50,7 +50,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; @@ -121,6 +121,7 @@ private: float _leftHapticDuration { 0.0f }; float _rightHapticStrength { 0.0f }; float _rightHapticDuration { 0.0f }; + bool _enableFiltering { false }; bool _triggersPressedHandled { false }; bool _calibrated { false }; bool _timeTilCalibrationSet { false }; From e41406458604bec8cd95c0923dd9c2156c01738a Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 15 May 2017 20:05:34 +0100 Subject: [PATCH 02/12] removing trash files --- plugins/openvr/src/.#ViveControllerManager.cpp | Bin 76 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 plugins/openvr/src/.#ViveControllerManager.cpp diff --git a/plugins/openvr/src/.#ViveControllerManager.cpp b/plugins/openvr/src/.#ViveControllerManager.cpp deleted file mode 100644 index 5f036319c61274919fb416be94769422ca7946d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 76 zcmY$iDXz@T$;`{P`~S~{A(0`Ep@booL4hHNp_Cz$p^CwQ!G*z Date: Tue, 16 May 2017 00:15:06 +0100 Subject: [PATCH 03/12] moved low velocity filter in the input system --- interface/src/Application.cpp | 4 -- interface/src/Application.h | 1 - interface/src/Menu.cpp | 2 - interface/src/avatar/MyAvatar.cpp | 51 +++---------------- .../src/controllers/InputDevice.cpp | 4 -- .../controllers/src/controllers/InputDevice.h | 10 +--- .../src/controllers/impl/Filter.cpp | 4 +- .../controllers/impl/RouteBuilderProxy.cpp | 6 +++ .../src/controllers/impl/RouteBuilderProxy.h | 1 + .../impl/filters/LowVelocityFilter.cpp | 46 +++++++++++++++++ .../impl/filters/LowVelocityFilter.h | 36 +++++++++++++ plugins/openvr/src/ViveControllerManager.cpp | 6 --- 12 files changed, 100 insertions(+), 71 deletions(-) create mode 100644 libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp create mode 100644 libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f4699009ac..d36bfdc606 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3622,10 +3622,6 @@ void Application::idle(float nsecsElapsed) { _overlayConductor.update(secondsSinceLastUpdate); } -void Application::setLowVelocityFilter(bool lowVelocityFilter) { - controller::InputDevice::setLowVelocityFilter(lowVelocityFilter); -} - ivec2 Application::getMouse() const { return getApplicationCompositor().getReticlePosition(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 5027c58349..37660e0a88 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -324,7 +324,6 @@ public slots: void updateThreadPoolCount() const; void updateSystemTabletMode(); - static void setLowVelocityFilter(bool lowVelocityFilter); Q_INVOKABLE void loadDialog(); Q_INVOKABLE void loadScriptURLDialog() const; void toggleLogDialog(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index f5f248602d..089385085b 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -538,8 +538,6 @@ Menu::Menu() { MenuWrapper* handOptionsMenu = developerMenu->addMenu("Hands"); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false, avatar.get(), SLOT(setEnableDebugDrawHandControllers(bool))); - addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::LowVelocityFilter, 0, true, - qApp, SLOT(setLowVelocityFilter(bool))); MenuWrapper* leapOptionsMenu = handOptionsMenu->addMenu("Leap Motion"); addCheckableActionToQMenuAndActionHash(leapOptionsMenu, MenuOption::LeapMotionOnHMD, 0, false); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index fd547e39e0..414fb64e4c 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1301,28 +1301,10 @@ void MyAvatar::rebuildCollisionShape() { _characterController.setLocalBoundingBox(corner, diagonal); } -static controller::Pose applyLowVelocityFilter(const controller::Pose& oldPose, const controller::Pose& newPose) { - controller::Pose finalPose = newPose; - if (newPose.isValid()) { - // Use a velocity sensitive filter to damp small motions and preserve large ones with - // no latency. - float velocityFilter = glm::clamp(1.0f - glm::length(oldPose.getVelocity()), 0.0f, 1.0f); - finalPose.translation = oldPose.getTranslation() * velocityFilter + newPose.getTranslation() * (1.0f - velocityFilter); - finalPose.rotation = safeMix(oldPose.getRotation(), newPose.getRotation(), 1.0f - velocityFilter); - } - return finalPose; -} void MyAvatar::setHandControllerPosesInSensorFrame(const controller::Pose& left, const controller::Pose& right) { - if (controller::InputDevice::getLowVelocityFilter()) { - auto oldLeftPose = getLeftHandControllerPoseInSensorFrame(); - auto oldRightPose = getRightHandControllerPoseInSensorFrame(); - _leftHandControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldLeftPose, left)); - _rightHandControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldRightPose, right)); - } else { - _leftHandControllerPoseInSensorFrameCache.set(left); - _rightHandControllerPoseInSensorFrameCache.set(right); - } + _leftHandControllerPoseInSensorFrameCache.set(left); + _rightHandControllerPoseInSensorFrameCache.set(right); } controller::Pose MyAvatar::getLeftHandControllerPoseInSensorFrame() const { @@ -1352,15 +1334,8 @@ controller::Pose MyAvatar::getRightHandControllerPoseInAvatarFrame() const { } void MyAvatar::setFootControllerPosesInSensorFrame(const controller::Pose& left, const controller::Pose& right) { - if (controller::InputDevice::getLowVelocityFilter()) { - auto oldLeftPose = getLeftFootControllerPoseInSensorFrame(); - auto oldRightPose = getRightFootControllerPoseInSensorFrame(); - _leftFootControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldLeftPose, left)); - _rightFootControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldRightPose, right)); - } else { - _leftFootControllerPoseInSensorFrameCache.set(left); - _rightFootControllerPoseInSensorFrameCache.set(right); - } + _leftFootControllerPoseInSensorFrameCache.set(left); + _rightFootControllerPoseInSensorFrameCache.set(right); } controller::Pose MyAvatar::getLeftFootControllerPoseInSensorFrame() const { @@ -1390,15 +1365,8 @@ controller::Pose MyAvatar::getRightFootControllerPoseInAvatarFrame() const { } void MyAvatar::setSpineControllerPosesInSensorFrame(const controller::Pose& hips, const controller::Pose& spine2) { - if (controller::InputDevice::getLowVelocityFilter()) { - auto oldHipsPose = getHipsControllerPoseInSensorFrame(); - auto oldSpine2Pose = getSpine2ControllerPoseInSensorFrame(); - _hipsControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldHipsPose, hips)); - _spine2ControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldSpine2Pose, spine2)); - } else { - _hipsControllerPoseInSensorFrameCache.set(hips); - _spine2ControllerPoseInSensorFrameCache.set(spine2); - } + _hipsControllerPoseInSensorFrameCache.set(hips); + _spine2ControllerPoseInSensorFrameCache.set(spine2); } controller::Pose MyAvatar::getHipsControllerPoseInSensorFrame() const { @@ -1428,12 +1396,7 @@ controller::Pose MyAvatar::getSpine2ControllerPoseInAvatarFrame() const { } void MyAvatar::setHeadControllerPoseInSensorFrame(const controller::Pose& head) { - if (controller::InputDevice::getLowVelocityFilter()) { - auto oldHeadPose = getHeadControllerPoseInSensorFrame(); - _headControllerPoseInSensorFrameCache.set(applyLowVelocityFilter(oldHeadPose, head)); - } else { - _headControllerPoseInSensorFrameCache.set(head); - } + _headControllerPoseInSensorFrameCache.set(head); } controller::Pose MyAvatar::getHeadControllerPoseInSensorFrame() const { diff --git a/libraries/controllers/src/controllers/InputDevice.cpp b/libraries/controllers/src/controllers/InputDevice.cpp index 12d8b676eb..dd27726a55 100644 --- a/libraries/controllers/src/controllers/InputDevice.cpp +++ b/libraries/controllers/src/controllers/InputDevice.cpp @@ -15,10 +15,6 @@ namespace controller { - bool InputDevice::_lowVelocityFilter = false; - float InputDevice::_translationFilterConstant = 0.1f; - float InputDevice::_rotationFilterConstant = 0.1f; - const float DEFAULT_HAND_RETICLE_MOVE_SPEED = 37.5f; float InputDevice::_reticleMoveSpeed = DEFAULT_HAND_RETICLE_MOVE_SPEED; diff --git a/libraries/controllers/src/controllers/InputDevice.h b/libraries/controllers/src/controllers/InputDevice.h index aad1f235ec..9d46930104 100644 --- a/libraries/controllers/src/controllers/InputDevice.h +++ b/libraries/controllers/src/controllers/InputDevice.h @@ -77,17 +77,13 @@ public: static float getReticleMoveSpeed() { return _reticleMoveSpeed; } static void setReticleMoveSpeed(float reticleMoveSpeed) { _reticleMoveSpeed = reticleMoveSpeed; } - static bool getLowVelocityFilter() { return _lowVelocityFilter; }; - Input makeInput(StandardButtonChannel button) const; Input makeInput(StandardAxisChannel axis) const; Input makeInput(StandardPoseChannel pose) const; Input::NamedPair makePair(StandardButtonChannel button, const QString& name) const; Input::NamedPair makePair(StandardAxisChannel button, const QString& name) const; Input::NamedPair makePair(StandardPoseChannel button, const QString& name) const; -public slots: - static void setLowVelocityFilter(bool newLowVelocityFilter) { _lowVelocityFilter = newLowVelocityFilter; }; - + protected: friend class UserInputMapper; @@ -104,10 +100,6 @@ protected: AxisStateMap _axisStateMap; PoseStateMap _poseStateMap; - static bool _lowVelocityFilter; - static float _translationFilterConstant; - static float _rotationFilterConstant; - private: static float _reticleMoveSpeed; }; diff --git a/libraries/controllers/src/controllers/impl/Filter.cpp b/libraries/controllers/src/controllers/impl/Filter.cpp index 2cb35d85ce..e75465f007 100644 --- a/libraries/controllers/src/controllers/impl/Filter.cpp +++ b/libraries/controllers/src/controllers/impl/Filter.cpp @@ -28,6 +28,7 @@ #include "filters/TransformFilter.h" #include "filters/PostTransformFilter.h" #include "filters/RotateFilter.h" +#include "filters/LowVelocityFilter.h" using namespace controller; @@ -45,6 +46,7 @@ REGISTER_FILTER_CLASS_INSTANCE(TranslateFilter, "translate") REGISTER_FILTER_CLASS_INSTANCE(TransformFilter, "transform") REGISTER_FILTER_CLASS_INSTANCE(PostTransformFilter, "postTransform") REGISTER_FILTER_CLASS_INSTANCE(RotateFilter, "rotate") +REGISTER_FILTER_CLASS_INSTANCE(LowVelocityFilter, "lowVelocity") const QString JSON_FILTER_TYPE = QStringLiteral("type"); const QString JSON_FILTER_PARAMS = QStringLiteral("params"); @@ -286,4 +288,4 @@ namespace controller { // const float _max; //}; } -#endif \ No newline at end of file +#endif diff --git a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp index f3c447238a..581d51ea61 100644 --- a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp +++ b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp @@ -30,6 +30,7 @@ #include "filters/TransformFilter.h" #include "filters/PostTransformFilter.h" #include "filters/RotateFilter.h" +#include "filters/LowVelocityFilter.h" #include "conditionals/AndConditional.h" using namespace controller; @@ -127,6 +128,11 @@ QObject* RouteBuilderProxy::rotate(glm::quat rotation) { return this; } +QObject* RouteBuilderProxy::lowVelocity(float rotationConstant, float translationConstant) { + addFilter(std::make_shared(rotationConstant, translationConstant)); + return this; +} + QObject* RouteBuilderProxy::constrainToInteger() { addFilter(std::make_shared()); return this; diff --git a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h index de9c23d2cd..102e72b3ad 100644 --- a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h +++ b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h @@ -52,6 +52,7 @@ class RouteBuilderProxy : public QObject { Q_INVOKABLE QObject* transform(glm::mat4 transform); Q_INVOKABLE QObject* postTransform(glm::mat4 transform); Q_INVOKABLE QObject* rotate(glm::quat rotation); + Q_INVOKABLE QObject* lowVelocity(float rotationConstant, float translationConstant); private: void to(const Endpoint::Pointer& destination); diff --git a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp new file mode 100644 index 0000000000..b47a78c133 --- /dev/null +++ b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp @@ -0,0 +1,46 @@ +// +// Created by Dante Ruiz 2017/05/15 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include "LowVelocityFilter.h" + +#include +#include + +static const QString JSON_ROTATION = QStringLiteral("rotation"); +static const QString JSON_TRANSLATION = QStringLiteral("translation"); +namespace controller { + + Pose LowVelocityFilter::apply(Pose newPose) const { + Pose finalPose = newPose; + if (finalPose.isValid()) { + float rotationFilter = glm::clamp(1.0f - (glm::length(_oldPose.getVelocity() / _rotationConstant)), 0.0f, 1.0f); + float translationFilter = glm::clamp(1.0f - (glm::length(_oldPose.getVelocity() / _translationConstant)), 0.0f, 1.0f); + finalPose.translation = _oldPose.getTranslation() * translationFilter + newPose.getTranslation() * (1.0f - translationFilter); + finalPose.rotation = safeMix(_oldPose.getRotation(), newPose.getRotation(), 1.0f - rotationFilter); + } + _oldPose = finalPose; + return finalPose; + } + + bool LowVelocityFilter::parseParameters(const QJsonValue& parameters) { + + if (parameters.isObject()) { + auto obj = parameters.toObject(); + if (obj.contains(JSON_ROTATION) && obj.contains(JSON_TRANSLATION)) { + _rotationConstant = obj[JSON_ROTATION].toDouble(); + _translationConstant = obj[JSON_TRANSLATION].toDouble(); + qDebug() << "--------->Successfully parsed low velocity filter"; + return true; + } + } + qDebug() << "--------->failed parsed low velocity filter"; + return false; + } + +} diff --git a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.h b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.h new file mode 100644 index 0000000000..d870a5c551 --- /dev/null +++ b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.h @@ -0,0 +1,36 @@ +// +// Created by Dante Ruiz 2017/05/15 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_Controllers_Filters_Low_Velocity_h +#define hifi_Controllers_Filters_Low_Velocity_h + +#include "../Filter.h" + +namespace controller { + + class LowVelocityFilter : public Filter { + REGISTER_FILTER_CLASS(LowVelocityFilter); + + public: + LowVelocityFilter() {} + LowVelocityFilter(float rotationConstant, float translationConstant) : + _translationConstant(translationConstant), _rotationConstant(rotationConstant) {} + + virtual float apply(float value) const override { return value; } + virtual Pose apply(Pose newPose) const; + virtual bool parseParameters(const QJsonValue& parameters) override; + + private: + float _translationConstant { 0.1f }; + float _rotationConstant { 0.1f }; + mutable Pose _oldPose { Pose() }; + }; + +} + +#endif diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index c27dc8010f..581cf970a1 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -169,7 +169,6 @@ ViveControllerManager::InputDevice::InputDevice(vr::IVRSystem*& system) : contro _configStringMap[Config::Feet] = QString("Feet"); _configStringMap[Config::FeetAndHips] = QString("FeetAndHips"); _configStringMap[Config::FeetHipsAndChest] = QString("FeetHipsAndChest"); - _lowVelocityFilter = false; } void ViveControllerManager::InputDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { @@ -661,11 +660,6 @@ void ViveControllerManager::InputDevice::createPreferences() { preferences->addPreference(preference); } - - { - auto getter = [this]()->float { return _translationFilterConstant; }; - auto setter = [this](const float& value) { _translationFilterConstant; }; - } } From 52f82191f13b57045cbcec7f3c85f21e122d3b62 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 16 May 2017 00:19:08 +0100 Subject: [PATCH 04/12] minimize diff --- plugins/openvr/src/ViveControllerManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 581cf970a1..3d5f36490c 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -659,8 +659,7 @@ void ViveControllerManager::InputDevice::createPreferences() { preference->setItems(list); preferences->addPreference(preference); - } - + } } controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const { From e90fdae889fd7c1b946114602bffb45a5d1f8346 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 16 May 2017 00:20:02 +0100 Subject: [PATCH 05/12] minimize diff 2 --- plugins/openvr/src/ViveControllerManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 3d5f36490c..5e22272dd6 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -659,7 +659,7 @@ void ViveControllerManager::InputDevice::createPreferences() { preference->setItems(list); preferences->addPreference(preference); - } + } } controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const { From 6b12e17cfc491ec30beb369a479444ce5fe04215 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 16 May 2017 00:20:52 +0100 Subject: [PATCH 06/12] minimize diff 3 --- plugins/openvr/src/ViveControllerManager.h | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 02c3ebe81b..fa2566da45 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -125,7 +125,6 @@ private: float _leftHapticDuration { 0.0f }; float _rightHapticStrength { 0.0f }; float _rightHapticDuration { 0.0f }; - bool _enableFiltering { false }; bool _triggersPressedHandled { false }; bool _calibrated { false }; bool _timeTilCalibrationSet { false }; From b0fa26e39038bac544dd97468f7e932c0c4f6d0a Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 16 May 2017 16:38:01 +0100 Subject: [PATCH 07/12] fix wierd calibration effect due to low velocity filter --- .../src/controllers/impl/filters/LowVelocityFilter.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp index b47a78c133..594f538369 100644 --- a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp +++ b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp @@ -18,7 +18,7 @@ namespace controller { Pose LowVelocityFilter::apply(Pose newPose) const { Pose finalPose = newPose; - if (finalPose.isValid()) { + if (finalPose.isValid() && _oldPose.isValid()) { float rotationFilter = glm::clamp(1.0f - (glm::length(_oldPose.getVelocity() / _rotationConstant)), 0.0f, 1.0f); float translationFilter = glm::clamp(1.0f - (glm::length(_oldPose.getVelocity() / _translationConstant)), 0.0f, 1.0f); finalPose.translation = _oldPose.getTranslation() * translationFilter + newPose.getTranslation() * (1.0f - translationFilter); @@ -35,11 +35,9 @@ namespace controller { if (obj.contains(JSON_ROTATION) && obj.contains(JSON_TRANSLATION)) { _rotationConstant = obj[JSON_ROTATION].toDouble(); _translationConstant = obj[JSON_TRANSLATION].toDouble(); - qDebug() << "--------->Successfully parsed low velocity filter"; return true; } } - qDebug() << "--------->failed parsed low velocity filter"; return false; } From 25b1bb0633d3144c77b03ed2fc4bcacfab77df41 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 16 May 2017 23:34:46 +0100 Subject: [PATCH 08/12] adjusted values --- interface/resources/controllers/vive.json | 31 +++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 4491507a9c..1757c30ae3 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -34,12 +34,33 @@ { "from": "Vive.RSCenter", "to": "Standard.RightPrimaryThumb" }, { "from": "Vive.RightApplicationMenu", "to": "Standard.RightSecondaryThumb" }, - { "from": "Vive.LeftHand", "to": "Standard.LeftHand", "when": [ "Application.InHMD" ] }, + { "from": "Vive.LeftHand", "to": "Standard.LeftHand", "when": [ "Application.InHMD" ] }, { "from": "Vive.RightHand", "to": "Standard.RightHand", "when": [ "Application.InHMD" ] }, - { "from": "Vive.LeftFoot", "to" : "Standard.LeftFoot", "when": [ "Application.InHMD"] }, - { "from": "Vive.RightFoot", "to" : "Standard.RightFoot", "when": [ "Application.InHMD"] }, - { "from": "Vive.Hips", "to" : "Standard.Hips", "when": [ "Application.InHMD"] }, - { "from": "Vive.Spine2", "to" : "Standard.Spine2", "when": [ "Application.InHMD"] }, + + { + "from": "Vive.LeftFoot", "to" : "Standard.LeftFoot", + "filters" : [{"type" : "lowVelocity", "rotation" : 9.0, "translation": 9.0 }], + "when": [ "Application.InHMD"] + }, + + { + "from": "Vive.RightFoot", "to" : "Standard.RightFoot", + "filters" : [{"type" : "lowVelocity", "rotation" : 9.0, "translation": 9.0}] + ,"when": [ "Application.InHMD"] + }, + + { + "from": "Vive.Hips", "to" : "Standard.Hips", + "filters" : [{"type" : "lowVelocity", "rotation" : 10.0, "translation": 10.0}], + "when": [ "Application.InHMD"] + }, + + { + "from": "Vive.Spine2", "to" : "Standard.Spine2", + "filters" : [{"type" : "lowVelocity", "rotation" : 10.0, "translation": 10.0}], + "when": [ "Application.InHMD"] + }, + { "from": "Vive.Head", "to" : "Standard.Head", "when" : [ "Application.InHMD"] } ] } From 90ddc16d09d44af03074777cc8158f477c8ebfe3 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 18 May 2017 17:07:28 +0100 Subject: [PATCH 09/12] add calibration data to filters --- interface/resources/controllers/vive.json | 6 ++---- interface/src/Application.cpp | 1 + .../src/controllers/UserInputMapper.h | 5 +++++ .../impl/filters/LowVelocityFilter.cpp | 19 +++++++++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 1757c30ae3..9ad7969217 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -39,25 +39,23 @@ { "from": "Vive.LeftFoot", "to" : "Standard.LeftFoot", - "filters" : [{"type" : "lowVelocity", "rotation" : 9.0, "translation": 9.0 }], + "filters" : [{"type" : "lowVelocity", "rotation" : 1.0, "translation": 1.0}], "when": [ "Application.InHMD"] }, { "from": "Vive.RightFoot", "to" : "Standard.RightFoot", - "filters" : [{"type" : "lowVelocity", "rotation" : 9.0, "translation": 9.0}] + "filters" : [{"type" : "lowVelocity", "rotation" : 1.0, "translation": 1.0}] ,"when": [ "Application.InHMD"] }, { "from": "Vive.Hips", "to" : "Standard.Hips", - "filters" : [{"type" : "lowVelocity", "rotation" : 10.0, "translation": 10.0}], "when": [ "Application.InHMD"] }, { "from": "Vive.Spine2", "to" : "Standard.Spine2", - "filters" : [{"type" : "lowVelocity", "rotation" : 10.0, "translation": 10.0}], "when": [ "Application.InHMD"] }, diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7904447db0..ba962cef76 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4376,6 +4376,7 @@ void Application::update(float deltaTime) { } } + userInputMapper->setInputCalibrationData(calibrationData); userInputMapper->update(deltaTime); if (keyboardMousePlugin && keyboardMousePlugin->isActive()) { diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index baa05f2f9f..05a286cc10 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -114,6 +114,9 @@ namespace controller { void loadDefaultMapping(uint16 deviceID); void enableMapping(const QString& mappingName, bool enable = true); + void setInputCalibrationData(const InputCalibrationData& data) { inputCalibrationData = data; } + const InputCalibrationData& getInputCalibrationData() { return inputCalibrationData; } + void unloadMappings(const QStringList& jsonFiles); void unloadMapping(const QString& jsonFile); @@ -187,6 +190,8 @@ namespace controller { QSet _loadedRouteJsonFiles; + InputCalibrationData inputCalibrationData; + mutable std::recursive_mutex _lock; }; diff --git a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp index 594f538369..edb706482c 100644 --- a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp +++ b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp @@ -11,18 +11,29 @@ #include #include +#include "../../UserInputMapper.h" +#include "../../Input.h" +#include static const QString JSON_ROTATION = QStringLiteral("rotation"); static const QString JSON_TRANSLATION = QStringLiteral("translation"); namespace controller { Pose LowVelocityFilter::apply(Pose newPose) const { + auto userInputMapper = DependencyManager::get(); + const InputCalibrationData calibrationData = userInputMapper->getInputCalibrationData(); Pose finalPose = newPose; if (finalPose.isValid() && _oldPose.isValid()) { - float rotationFilter = glm::clamp(1.0f - (glm::length(_oldPose.getVelocity() / _rotationConstant)), 0.0f, 1.0f); - float translationFilter = glm::clamp(1.0f - (glm::length(_oldPose.getVelocity() / _translationConstant)), 0.0f, 1.0f); - finalPose.translation = _oldPose.getTranslation() * translationFilter + newPose.getTranslation() * (1.0f - translationFilter); - finalPose.rotation = safeMix(_oldPose.getRotation(), newPose.getRotation(), 1.0f - rotationFilter); + Pose sensorPose = finalPose.transform(calibrationData.avatarMat); + Pose lastPose = _oldPose.transform(calibrationData.avatarMat); + + float rotationFilter = glm::clamp(1.0f - (glm::length(lastPose.getVelocity() / _rotationConstant)), 0.0f, 1.0f); + float translationFilter = glm::clamp(1.0f - (glm::length(lastPose.getVelocity() / _translationConstant)), 0.0f, 1.0f); + sensorPose.translation = lastPose.getTranslation() * translationFilter + sensorPose.getTranslation() * (1.0f - translationFilter); + sensorPose.rotation = safeMix(lastPose.getRotation(), sensorPose.getRotation(), 1.0f - rotationFilter); + + finalPose = sensorPose.transform(glm::inverse(calibrationData.avatarMat)); + finalPose.valid = true; } _oldPose = finalPose; return finalPose; From 78f6d2e850e18415534eded1780b733960ee6f5a Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 18 May 2017 21:22:42 +0100 Subject: [PATCH 10/12] fix low velocity filter --- interface/resources/controllers/vive.json | 6 ++++-- .../impl/filters/LowVelocityFilter.cpp | 15 ++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 9ad7969217..07c4047e0e 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -45,17 +45,19 @@ { "from": "Vive.RightFoot", "to" : "Standard.RightFoot", - "filters" : [{"type" : "lowVelocity", "rotation" : 1.0, "translation": 1.0}] - ,"when": [ "Application.InHMD"] + "filters" : [{"type" : "lowVelocity", "rotation" : 1.0, "translation": 1.0}], + "when": [ "Application.InHMD"] }, { "from": "Vive.Hips", "to" : "Standard.Hips", + "filters" : [{"type" : "lowVelocity", "rotation" : 0.01, "translation": 0.01}], "when": [ "Application.InHMD"] }, { "from": "Vive.Spine2", "to" : "Standard.Spine2", + "filters" : [{"type" : "lowVelocity", "rotation" : 0.01, "translation": 0.01}], "when": [ "Application.InHMD"] }, diff --git a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp index edb706482c..22db24274e 100644 --- a/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp +++ b/libraries/controllers/src/controllers/impl/filters/LowVelocityFilter.cpp @@ -22,20 +22,21 @@ namespace controller { Pose LowVelocityFilter::apply(Pose newPose) const { auto userInputMapper = DependencyManager::get(); const InputCalibrationData calibrationData = userInputMapper->getInputCalibrationData(); + glm::mat4 sensorToAvatarMat = glm::inverse(calibrationData.avatarMat) * calibrationData.sensorToWorldMat; + glm::mat4 avatarToSensorMat = glm::inverse(calibrationData.sensorToWorldMat) * calibrationData.avatarMat; Pose finalPose = newPose; if (finalPose.isValid() && _oldPose.isValid()) { - Pose sensorPose = finalPose.transform(calibrationData.avatarMat); - Pose lastPose = _oldPose.transform(calibrationData.avatarMat); - + Pose sensorPose = finalPose.transform(avatarToSensorMat); + Pose lastPose = _oldPose; + float rotationFilter = glm::clamp(1.0f - (glm::length(lastPose.getVelocity() / _rotationConstant)), 0.0f, 1.0f); float translationFilter = glm::clamp(1.0f - (glm::length(lastPose.getVelocity() / _translationConstant)), 0.0f, 1.0f); sensorPose.translation = lastPose.getTranslation() * translationFilter + sensorPose.getTranslation() * (1.0f - translationFilter); sensorPose.rotation = safeMix(lastPose.getRotation(), sensorPose.getRotation(), 1.0f - rotationFilter); - finalPose = sensorPose.transform(glm::inverse(calibrationData.avatarMat)); - finalPose.valid = true; + finalPose = sensorPose.transform(sensorToAvatarMat); } - _oldPose = finalPose; + _oldPose = finalPose.transform(avatarToSensorMat); return finalPose; } @@ -51,5 +52,5 @@ namespace controller { } return false; } - + } From e4c79926c0f206c670f8a1a5cfcd3084c8e53fa6 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 18 May 2017 22:46:25 +0100 Subject: [PATCH 11/12] trying to improve puck lost --- plugins/openvr/src/ViveControllerManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 3bda481243..96d27af992 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -248,7 +248,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_OK) { mat = _nextSimPoseData.poses[deviceIndex]; linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex]; From ffcc3c8df9ccab8b8f99c5ab0d068b8abbc09ad1 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Sat, 20 May 2017 00:06:54 +0100 Subject: [PATCH 12/12] going back to old lost tracking method --- plugins/openvr/src/ViveControllerManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 96d27af992..3bda481243 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -248,7 +248,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_OK) { + if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != vr::TrackingResult_Running_OutOfRange) { mat = _nextSimPoseData.poses[deviceIndex]; linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex];