openvr icon indicating copy to clipboard operation
openvr copied to clipboard

OpenVR c++ SDK: Receive assigned Tracker Roles from SteamVR

Open dano2595 opened this issue 4 years ago • 3 comments

Hello everyone,

I am developing a c++ background application with the OpenVR SDK and I think that I am missing something.

You can assign Roles for Trackers inside SteamVR under Settings > Controllers > MANAGE VIVE TRACKERS: Steam VR Tracker

How can you receive the assigned Roles inside the c++ OpenVR SDK? I tried to get my head around it, but could not find a enum inside openvr.h or a related function. I figured out, that you can receive a VREvent_TrackersSectionSettingChanged VREvent after changig the Roles inside the settings, but I could not figure out how to react to it and read the changes.

Can you give me a hint, please?

Thank you.

dano2595 avatar May 03 '21 09:05 dano2595

I don't think it's possible to get the role directly from OpenVR. The intended usage seems to be to use SteamVR Input to define pose actions for all the tracker poses you need, and then add bindings to the specific tracker types you want to control each pose. Each of the tracker roles seem to be setup as a different type of controller, so you'd need to setup separate binding files for each tracker role.

HTC also has some kind of input management plugin for Unity that seems to be able to access tracker roles. I have no idea how it does that though, but reverse engineering it might be an alternative if you don't like the SteamVR Input method. https://github.com/ViveSoftware/ViveInputUtility-Unity

Rectus avatar May 09 '21 14:05 Rectus

I don't have Vive trackers, but generally you should be able to use the IVRSettings interface to read settings value from the k_pch_Trackers_Section section. There doesn't seem to be a direct API for this from what I can tell.

Can't find any default definitions for that section on my system, so I can't tell you how it should look like, but I suppose that's not hard to figure out if you have trackers at hand.

elvissteinjr avatar May 26 '21 13:05 elvissteinjr

To those who found this issue through Google, here is how you manage to get tracker roles:

  • Listen for VREvent_TrackersSectionSettingChanged event
    • This event, however, does not tell you which tracker was reassigned with a new role. The trackedDeviceIndex is always 0xffffffff
  • When the event is fired, call vr::VRSettings()->GetString(vr::k_pch_Trackers_Section, trackeDeviceName, buffer, sizeof(buffer)/sizeof(*buffer), &err) to get the role settings from SteamVR
    • trackerDeviceName is either /devices/htc/vive_tracker${serial} for Vive Trackers or /devices/lighthouse/${serial} for TundraLab Trackers. There might be more exotic types but we don't have any method for enumerating all possible devices. (We can know all the serial numbers, but the /devices/... stuff is not documented anywhere to my knowledge.)
    • Perhaps we have to parse the settings file of SteamVR directly for this. The file is at X:\Program Files (x86)\Steam\config\steamvr.vrsettings where X is the drive letter you installed Steam (not SteamVR).
    • You will need a method to enumerate all possible devices. If you are writing an app then vr::VRSystem()->GetSortedTrackedDeviceIndicesOfClass(...) is enough. But if you are writing a driver, then you may have to hook into the internals of SteamVR (or parse the steamvr.vrsettings).
    • The format of the settings string is TrackerRole_${role}. The role part is usually something like LeftShoulder. However, if the tracker was set as handheld, it will be either TrackerRole_Handed,TrackerRole_${hand} where hand is either Invalid, LeftHand or RightHand. There is, as you may have guessed, no document about all possible names of tracker roles.

A reference implementation.

dousha avatar Feb 01 '24 01:02 dousha