Search Unity

[SteamVR 2] Detect if tracking was lost

Discussion in 'VR' started by Wattosan, Mar 6, 2019.

  1. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Hey,

    Is there any built-in mechanism for figuring out if a device has lost tracking? (meaning the device usually jumps to 0,0,0). Any events perhaps?

    Thank you!
     
  2. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Bump.

    If there isn't a built-in solution for this then perhaps other developers could share their custom solutions to this problem. Maybe we can find a reliable solution together.
     
  3. CedricWelty

    CedricWelty

    Joined:
    Apr 9, 2019
    Posts:
    1
    Hey, I don't know if you still need it, but there are a few ways to achieve this.

    If you need tracking lost information on controllers, you have it on the Steamvr_Behaviour_Pose, you have an event OnTrackingChanged containing an enum ETrackingResult.
    This enum will return if the controller is Uninitialized, Calibrating, OutOfRange, ...

    But this doesn't work for the head, to my knowledge. If you want data on the head, you have statics Boolean in SteamVR class. SteamVR.outOfRange, SteamVR.calibrating, etc. If you go deeper in SteamVR classes, you see that theses Boolean are just result of listening event in SteamVR_Events (SteamVR_Events.Calibrating and SteamVR_Events.OutOfRange).

    Hope it helps
     
    Henri-J-Norden likes this.
  4. benjaminoutram

    benjaminoutram

    Joined:
    Nov 10, 2014
    Posts:
    20
    Can you give an example of this being implemented? I can't for the life of me figure out how to subscribe to the event you mention and get the enum result back.
     
  5. AmberElferink

    AmberElferink

    Joined:
    Jan 28, 2019
    Posts:
    4
    For anyone still looking for this:
    You can see it where the tracking data actually comes in, which is in the SteamVR_TrackedObject script.
    You can change it like so (see line 18 & 19):


    Code (CSharp):
    1.     private void OnNewPoses(TrackedDevicePose_t[] poses)
    2.     {
    3.         if (index == EIndex.None)
    4.             return;
    5.  
    6.         var i = (int)index;
    7.  
    8.         isValid = false;
    9.         if (poses.Length <= i)
    10.             return;
    11.  
    12.         if (!poses[i].bDeviceIsConnected)
    13.             return;
    14.  
    15.         if (!poses[i].bPoseIsValid)
    16.             return;
    17.  
    18.         if (poses[i].eTrackingResult != ETrackingResult.Running_OK)
    19.             Debug.Log("tracking issue");
    20.  
    21.         isValid = true;
    22.  
    23.         var pose = new SteamVR_Utils.RigidTransform(poses[i].mDeviceToAbsoluteTracking);
    24.  
    25.         if (origin != null)
    26.         {
    27.             transform.position = origin.transform.TransformPoint(pose.pos);
    28.             transform.rotation = origin.rotation * pose.rot;
    29.         }
    30.         else
    31.         {
    32.             transform.localPosition = pose.pos;
    33.             transform.localRotation = pose.rot;
    34.         }
    35.  
    36.         //Debug.Log("Trackers: dt " + (Time.time - prevTime) + "position delta " + (transform.position - prevPos) * 100);
    37.         //prevTime = Time.time;
    38.         //prevPos = transform.position;
    39.  
    40.  
    41.     }
    42.