diff --git a/src/tabcontrollers/FixFloorTabController.cpp b/src/tabcontrollers/FixFloorTabController.cpp index 57edbce..e8c8fd5 100644 --- a/src/tabcontrollers/FixFloorTabController.cpp +++ b/src/tabcontrollers/FixFloorTabController.cpp @@ -74,6 +74,7 @@ void FixFloorTabController::eventLoopTick( { // The controller with the lowest y-pos is the floor fix // reference + if ( leftPose->mDeviceToAbsoluteTracking.m[1][3] < rightPose->mDeviceToAbsoluteTracking.m[1][3] ) { @@ -89,6 +90,7 @@ void FixFloorTabController::eventLoopTick( tempOffsetX = static_cast( m[0][3] ); tempOffsetY = static_cast( m[1][3] ); tempOffsetZ = static_cast( m[2][3] ); + /* | Intrinsic y-x'-z" rotation matrix: | cr*cy+sp*sr*sy | cr*sp*sy-cy*sr | cp*sy | @@ -133,15 +135,60 @@ void FixFloorTabController::eventLoopTick( if ( measurementCount >= 25 ) { + int type = 0; if ( std::abs( tempRoll ) <= M_PI_2 ) { - floorOffsetY = static_cast( tempOffsetY ) - - controllerUpOffsetCorrection; + type = getControllerType( referenceController ); + if ( type == Controller_Wand ) + { + floorOffsetY = static_cast( tempOffsetY ) + - controllerUpOffsetCorrection; + } + else if ( type == Controller_Knuckles ) + { + // Production + + floorOffsetY = static_cast( tempOffsetY ) + - knucklesUpOffsetCorrection; + + // Generate Offset + // Comment out production and un-comment this. + // Only if Floor is known to be good (zero with wand) + + /* + floorOffsetY = static_cast(tempOffsetY); + LOG(INFO) << "Offset For Knuckles up is: " << + floorOffsetY; + */ + } + floorOffsetY = static_cast( tempOffsetY ); } else { - floorOffsetY = static_cast( tempOffsetY ) - - controllerDownOffsetCorrection; + type = getControllerType( referenceController ); + if ( type == Controller_Wand ) + { + floorOffsetY = static_cast( tempOffsetY ) + - controllerDownOffsetCorrection; + } + else if ( type == Controller_Knuckles ) + { + // Production + + floorOffsetY = static_cast( tempOffsetY ) + - knucklesDownOffsetCorrection; + + // Generate Offset + // Comment out production and un-comment this. + // Only if Floor is known to be good (zero with wand) + + /* + floorOffsetY = static_cast(tempOffsetY); + LOG(INFO) << "Offset For Knuckles up is: " << + floorOffsetY; + */ + } + floorOffsetY = static_cast( tempOffsetY ); } floorOffsetX = static_cast( tempOffsetX ); @@ -172,6 +219,47 @@ void FixFloorTabController::eventLoopTick( } } +int FixFloorTabController::getControllerType( + vr::TrackedDeviceIndex_t controllerRole ) +{ + int maxLength = 64; + /* + vr::k_unMaxPropertyStringSize is Theoretical Max Size, however it is + 1024*32, and its pretty unrealistic to expect a controller name to be that + big. We are just going to set 64 as an arbitrary size, and print error to + log if too small + */ + char* controllerTypeString = new char[maxLength]; + vr::ETrackedPropertyError error; + auto stringLength = vr::VRSystem()->GetStringTrackedDeviceProperty( + controllerRole, + vr::Prop_ControllerType_String, + controllerTypeString, + maxLength, + &error ); + if ( error != vr::TrackedProp_Success ) + { + LOG( ERROR ) << "Error With Controller Type: " + << vr::VRSystem()->GetPropErrorNameFromEnum( error ); + } + else if ( stringLength == 0 ) + { + LOG( ERROR ) << "Device Index not valid"; + } + else if ( strcmp( controllerTypeString, "knuckles" ) == 0 ) + { + delete[] controllerTypeString; + return Controller_Knuckles; + } + else if ( strcmp( controllerTypeString, "vive_controller" ) == 0 ) + { + delete[] controllerTypeString; + return Controller_Wand; + } + delete[] controllerTypeString; + return Controller_Unknown; +} + QString FixFloorTabController::currentStatusMessage() { return statusMessage; diff --git a/src/tabcontrollers/FixFloorTabController.h b/src/tabcontrollers/FixFloorTabController.h index 7178edf..688f6c0 100644 --- a/src/tabcontrollers/FixFloorTabController.h +++ b/src/tabcontrollers/FixFloorTabController.h @@ -25,6 +25,8 @@ private: = 0.062f; // Controller touchpad facing upwards float controllerDownOffsetCorrection = 0.006f; // Controller touchpad facing downwards + float knucklesUpOffsetCorrection = 0.0285f; // touchpad facing up PRELIM + float knucklesDownOffsetCorrection = 0.031f; // touchpad facing down PRELIM int state = 0; // 0 .. idle, 1 .. floor fix in progress, 2 .. recenter in progress @@ -42,6 +44,15 @@ private: float statusMessageTimeout = 0.0f; bool m_canUndo = false; + enum ControllerType : int + { + Controller_Unknown = 0, + Controller_Wand = 1, + Controller_Knuckles = 2, + }; + + int getControllerType( vr::TrackedDeviceIndex_t controllerRole ); + public: void initStage1(); void initStage2( OverlayController* parent, QQuickWindow* widget );