Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine whether a SteamVR_TrackedObject is a Vive Controller or a Vive Tracker

What is the best way to determine whether a SteamVR_TrackedObject is a Vive Controller and a Vive Tracker?


When 0 Controllers and 1 Tacker is paired:

The Tracker is taken as Controller (right) of the CameraRig.

When 1 Controller and 1 Tacker is paired:

The Tracker is set to Device 2.

When 2 Controllers and 1 Tacker is paired:

Creating a third SteamVR_TrackedObject and placing it in the CameraRig's objects array. Also when a controller looses tracking so does the tracker.


In each scenario the Tracker ends up being a different SteamVR_TrackedObject.index. What is the best way to check if a SteamVR_TrackedObject is a Tracker, or to find which index the Tracker is?

like image 995
Liam Ferris Avatar asked Apr 03 '17 12:04

Liam Ferris


2 Answers

The only method of checking a SteamVR_TrackedObject that I have found yet is to check the ETrackedDevicePoperty.Prop_RenderModelName_String:

uint index = 0;
var error = ETrackedPropertyError.TrackedProp_Success;
for (uint i = 0; i < 16; i++)
{
    var result = new System.Text.StringBuilder((int)64);
    OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error);
    if (result.ToString().Contains("tracker"))
    {
        index = i;
        break;
    }
}

Then you can set SteamVR_TrackedObject.index to index:

GetComponent<SteamVR_TrackedObject>().index = (SteamVR_TrackedObject.EIndex)index;

Finding any documentation on this has been pretty difficult so far but here's some sources:

  • OpenVR wiki
  • List of ETrackedDeviceProperty values
like image 112
Liam Ferris Avatar answered Nov 14 '22 23:11

Liam Ferris


Just stumbled upon this old question and I guess accepted answer was strictly correct when it was asked - there's a direct way to do it now, though: you can use GetTrackedDeviceClass.

It will return value of an enum ETrackedDeviceClass. Possible values are:

  • Invalid - if there's no tracked device under this index,
  • HMD - if the device is a headset,
  • Controller - if the device is, well, controller - this is one of your cases,
  • GenericTracker - this is another one of your cases
  • TrackingReference - for base stations, supporting cameras etc,
  • DisplayRedirect - by documentation - "Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices"
  • Max - this one is undocumented and I haven't stumbled upon it yet
like image 38
Pindwin Avatar answered Nov 14 '22 21:11

Pindwin