Skip to main content
Up and Coming
March 10, 2016

angular velocity

I'm inspecting the angular velocity in OVRDisplay and I'm somewhat confused by the output. With my DK2 lying still on a desk I'm getting many values at or near zero as I'd expect but I'm also getting some values in the 359-360 range. They appear randomly in the x, y and z components. The values might make sense to me if I was accessing an orientation but this is angular velocity. The documentation (https://developer.oculus.com/doc/0.1.3.0-unity/class_o_v_r_display.html#a96be90faeb312e8fcd2c9f389083ae19) doesn't provide any insight as to what the units are supposed to be but I'm guessing it should be degrees per second.

I'm outputting the values as follows:
Debug.Log(OVRManager.display.angularVelocity);


I'm using Unity 5.3.3f1 with Oculus Utilities 1.3.0 beta and the 0.8 runtime.

I've attached angularVelocity.txt which has some sample output.
angularVelocity.txt
    This topic has been closed for replies.

    11 replies

    Inspiring
    March 10, 2016
    Last I heard this was broke, but I don't know when the fix is coming.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    March 10, 2016
    Do you know at what level it might be broken? I'm wondering if I could use VRDevice.GetNativePtr to in order to use a angular velocity accessor at the OVR SDK level. If the problem is in the Oculus Utilities for Unity wrapper this approach might work but if the problem is down at the OVR SDK / runtime level I guess I'm out of luck. If you have any more information it would be greatly appreciated!
    Inspiring
    March 11, 2016
    OK, so I confirmed that it's not working in 0.8, but is fixed in a later SDK that will become public shortly.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Inspiring
    March 11, 2016
    "JeffBail" wrote:
    I'm wondering if I could use VRDevice.GetNativePtr to in order to use a angular velocity accessor at the OVR SDK level.
    Yes, that kind of fix should work. The bug is in OVRPlugin.
    Up and Coming
    March 11, 2016
    Thanks for the quick responses but I'm confused; is the issue in the SDK or the plugin (or maybe both)?

    Does GetNativePtr return an ovrSession? Are there any examples of how to use it? I'm totally new to p/invoke but from what I've read it seems to assume you have a DLL so I'm wondering if the right thing to do is modify the LibOVR SDK project to build a .dll instead of a .lib.
    Inspiring
    March 11, 2016
    Yes, it's an ovrSession. To use it, you would have to write a native plugin that uses LibOVR and pass the session down to it as an IntPtr or (advanced) DLLImport ovr_GetTrackingState from LibOVRRT64_0_8.dll (see https://developer.oculus.com/doc/0.8.0. ... 0720677a3b) and marshal the necessary structs. Please send me a PM if you need help with this. It will be tricky and we already have a fix due out within the next few weeks.
    Up and Coming
    March 15, 2016
    Thanks for your help! I got it working as a native plugin and my code is below. I'm actually interested in the raw sensor data (as opposed to the predicted angular velocity reported by ovr_GetTrackingState) so others may want to adjust the implementation. Along the way I found that I had to call ovr_Initialize for my plugin because the call already made by Unity did not apply to my plugin (probably due to some static initialization or something). Please note however that you should not call ovr_Shutdown from the plugin as this will cause Unity to crash upon application exit.

    Plugin code:

    #include "OVR_CAPI.h"
    #define _USE_MATH_DEFINES // for C++
    #include <cmath>

    #if _MSC_VER // this is defined when compiling with Visual Studio
    #define EXPORT_API __declspec(dllexport) // Visual Studio needs annotating exported functions with this
    #else
    #define EXPORT_API // XCode does not need annotating exported functions, so define is empty
    #endif

    extern "C" {
    // Although Unity may have already called ovr_Initialize the plug-in also needs to call
    // it otherwise the accessors will return zero values.
    bool EXPORT_API InitializeOVR()
    {
    ovrResult result = ovr_Initialize(NULL);
    if (OVR_FAILURE(result))
    {
    return false;
    }
    return true;
    }

    /*
    Leaving this commented out for future reference; premature shutdown will crash Unity!
    void EXPORT_API ShutdownOVR()
    {
    ovr_Shutdown();
    }
    */

    // Gets the raw sensor data for yaw, pitch and roll from ovr_GetTrackingState in degrees.
    void EXPORT_API GetOVRAngularVelocity(void* sessionPtr, float& yaw, float& pitch, float& roll)
    {
    if (!sessionPtr)
    {
    return;
    }
    ovrSession session = (ovrSession)sessionPtr;
    ovrTrackingState state = ovr_GetTrackingState(session, 0, false);

    if (state.StatusFlags & ovrStatus_OrientationTracked)
    {
    // OVR seems to have yaw & pitch switched
    yaw = (float)(state.RawSensorData.Gyro.y * (180.0 / M_PI));
    pitch = (float)(state.RawSensorData.Gyro.x * (180.0 / M_PI));
    roll = (float)(state.RawSensorData.Gyro.z * (180.0 / M_PI));
    // yaw needs to be reversed to get a right turn to be positive to match unity
    yaw *= -1;
    // pitch needs to be reversed to get pitch up to be negative to match unity
    pitch *= -1;
    }
    else
    {
    yaw = 0.0f;
    pitch = 0.0f;
    roll = 0.0f;
    }
    }
    }


    Mono Code:

    //
    // Oculus (LibOVR) functions wrapped in UnityOVRPlugin to allow access to the raw sensor data
    //
    [DllImport("UnityOVRPlugin")]
    private static extern bool InitializeOVR();

    [DllImport("UnityOVRPlugin")]
    private static extern void GetOVRAngularVelocity(IntPtr ovrSessionPtr, out float yaw, out float pitch, out float roll);

    void Start ()
    {
    // OVR initialization
    if (!InitializeOVR())
    {
    Debug.Log("OVR initialization failed!");
    }
    }

    void FixedUpdate ()
    {
    // Test code for reading raw YPR directly from the Oculus sensor
    float yaw = 0.0f;
    float pitch = 0.0f;
    float roll = 0.0f;
    GetOVRAngularVelocity(UnityEngine.VR.VRDevice.GetNativePtr(), out yaw, out pitch, out roll);
    }
    Inspiring
    March 15, 2016
    Thanks for sharing.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    April 5, 2016
    I'm in the process of upgrading to 1.3 runtime, OVRPlugin and utilities. Has the bug been fixed in this release? If not I'll also have to rebuild my native plugin wrapper against the 1.3 SDK. Not a big deal but I'd prefer to get rid of it completely if possible.
    Up and Coming
    April 6, 2016
    Unfortunately I can't simply just rebuild my plugin; it looks like ovrTrackingState.RawSensorData was removed in SDK 1.3. Is there any way to still access this data? I couldn't find any occurrence of "raw" anywhere in the API.