How to determine whether a SteamVR_TrackedObject is a Vive Controller or a Vive Tracker
Asked Answered
N

2

6

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?

Needham answered 3/4, 2017 at 12:24 Comment(5)
Have you considered using triggers?Roldan
@Roldan Can you expand? I'm not sure what you mean? If you are meaning to check if the object has a trigger button, then it wouldn't work. As the tracker has pins (to connect something as a trigger) and uses the same protocols as the controller.Needham
Omg, I'm sorry I meant to say tagsRoldan
As in tag certain gameObjects before starting? The issue is that each SteamVR_TrackedObject is dynamically set to a device, and I can't predict how it will be assigned. Looking for the best method for talking to the SteamVR and OpenVR APIs.Needham
Yeah, you could assign different tags to different GameObjects, that's how you can differentiate them. At least from what I understand from your title. QUOTE: "is a Vive Controller or a Vive Tracker".Roldan
N
10

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:

Needham answered 3/4, 2017 at 12:24 Comment(1)
Love it. Also note the Oculus touch controller names will contain "controller_left" and "controller_right".Brigade
A
4

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
Asteroid answered 6/9, 2019 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.