Search Unity

Mixed reality controllers won't give position

Discussion in 'Windows Mixed Reality' started by TheRaider, Oct 19, 2017.

  1. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I have been using the interaction manager to connect the controllers (which are tricky as it appears I have to push windows button, go to mixed reality portal and then back to unity for it to connect, any clues how to make it connect are appreciated) and it doesn't seem to matter what I have the SourcePos never returns a position.

    Can anyone get this work and if so what is the trick?
     
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    Can you give us more information on your script please?
     
  3. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I can get the control to detetect and detect button presses (but only if I press windows button on controller, go to mixed reality portal and then back to unity which doesn't seem right)

    I can't get any position information.

    Code (csharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.XR;
    7. using UnityEngine.XR.WSA.Input;
    8.  
    9. public class ControllerInput : MonoBehaviour {
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.      
    14.         InteractionManager.InteractionSourceDetected += InteractionManager_SourceDetected;
    15.         InteractionManager.InteractionSourceUpdated += InteractionManager_SourceUpdated;
    16.         InteractionManager.InteractionSourceLost += InteractionManager_SourceLost;
    17.         InteractionManager.InteractionSourcePressed += InteractionManager_SourcePressed;
    18.         InteractionManager.InteractionSourceReleased += InteractionManager_SourceReleased;
    19.     }
    20.  
    21.     void OnDestroy()
    22.     {
    23.      
    24.         InteractionManager.InteractionSourceDetected -= InteractionManager_SourceDetected;
    25.         InteractionManager.InteractionSourceUpdated -= InteractionManager_SourceUpdated;
    26.         InteractionManager.InteractionSourceLost -= InteractionManager_SourceLost;
    27.         InteractionManager.InteractionSourcePressed -= InteractionManager_SourcePressed;
    28.         InteractionManager.InteractionSourceReleased -= InteractionManager_SourceReleased;
    29.     }
    30.         // Update is called once per frame
    31.     void Update ()
    32.     {
    33.         //Vector3 leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
    34.  
    35.         //Debug.Log("LP" + leftPosition);
    36.  
    37.  
    38.         var interactionSourceStates = InteractionManager.GetCurrentReading();
    39.         Debug.Log("Num Interaction Source States: " + interactionSourceStates.Length);
    40.         /*
    41.         if (interactionSourceStates.selectPressed)
    42.         {
    43.             Debug.Log("Press" + Time.time);
    44.         }
    45.         */
    46.         if (Input.GetButton("Fire1"))
    47.         {
    48.             Debug.Log("Fire1");
    49.         }
    50.      
    51.     }
    52.  
    53.     void InteractionManager_SourcePressed(InteractionSourcePressedEventArgs args)
    54.     {
    55.  
    56.         Debug.Log("Source pressed");
    57.     }
    58.     void InteractionManager_SourceDetected(InteractionSourceDetectedEventArgs args)
    59.     {
    60.  
    61.         Debug.Log("Source detected");
    62.     }
    63.     void InteractionManager_SourceUpdated(InteractionSourceUpdatedEventArgs args)
    64.     {
    65.         Vector3 p;
    66.         //float a;
    67.         args.state.sourcePose.TryGetPosition(out p);
    68.         //a = args.state.sourcePose.positionAccuracy;
    69.  
    70.         //Debug.Log("Source updated " + p);
    71.     }
    72.     void InteractionManager_SourceLost(InteractionSourceLostEventArgs args)
    73.     {
    74.  
    75.         Debug.Log("Source lost");
    76.     }
    77.     void InteractionManager_SourceReleased(InteractionSourceReleasedEventArgs args)
    78.     {
    79.  
    80.         Debug.Log("Source released");
    81.     }
    82.  
    83. }
    84.  
    85.  
     
  4. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    Should I have the mixed reality portal open? I wondered if that was the issue but I am not sure how to start the headset without it.
     
  5. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I seem to be able to get all the button presses etc. I am just struggling to get the position of the controller :(

    Also args.state.sourcePose.positionAccuracy returns "none" so I assume that means it isn't getting any data. Is there something i need to do to enable it?

    I tried

    Code (csharp):
    1.  
    2.  
    3. Vector3 leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
    4.  
    5.             Debug.Log("LP" + leftPosition);
    6.  
    7.             Vector3 rightPosition = InputTracking.GetLocalPosition(XRNode.RightHand);
    8.  
    9.             Debug.Log("RP" + rightPosition);
    10.  
    and still no luck.

    Interesting once I tried starting before it had run the setup and it seemed to actually read positions in, however I tried to replicate and can't.
     
    Last edited: Oct 23, 2017
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    What build of unity are you using? Are you using the MRTP builds?
     
  7. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    Current release build 2017.2.0f3
     
    Last edited: Oct 24, 2017
  8. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I don't have access to MRTP builds

    edit: I figured how to access those builds and it now works fine. Guess it is just 2017.2 that is broken.

    edit2: new Problem. The controllers track but are signifcantly offset. Is that normal?
     
    Last edited: Oct 24, 2017
  9. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    147
    Controllers should track correctly. What exactly do you mean by "significantly offset"?
     
  10. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    If I use the position reported to place a 3D object (a sphere) at the point it reports by simple assignment it appears off in the distance. However when I move the controller right the ball in the distance moves right. So it appears to be tracking but it is nowhere near where my hand actually is (and it is reporting high accuracy).
     
  11. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    147
    That sounds like a bug, haven't seen that myself. Would you mind filing a bug for us?
     
  12. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I will do that as soon as I get back from work.

    Can I confirm I should just be able to poll the position and apply to an object and it appear where the controller is?

    Also can I confirm the main camera should start at 0,0,0?

    There isn't a whole lot of examples(do you have a working example?) so I wanted to check I am not doing anything wrong.
     
  13. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    147
    Yes, you should just be able to apply the position to an object and have it appear where the controller is, regardless of tracking space type.

    The main camera should start at (0,0,0) if your tracking space type is stationary (or if you're running on a HoloLens), which we fall back to if the floor can't be found at start-up. Normally, though, the default tracking space type is room-scale, which places the floor at y=0, so your camera would have a y-value of however many meters up in the air it is.

    But like I said, the controller positions should be reporting in the right space regardless of tracking space type, so having your controllers appear way out in the distance in either case is definitely wrong.

    I don't know of any example of displaying controller objects in the scene, I'll add that to my to-do list.
     
  14. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    Okay thanks.

    If I am trying to do roomscale where should the camera be?
     
  15. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    147
    The exact position depends on how far the headset is from where it was when the user ran setup in Mixed Reality Portal and clicked the "Center" button. If the HMD is exactly where it was during the setup's "Center" button-click, you should get a position of (0,y,0), where y is how many meters above the floor the HMD is. The x and z coordinates should be the number of meters away from that starting position in either direction.

    The default orientation should have the HMD facing towards your monitor(s) when "Center" was clicked, so your main camera's rotation should be based on that, regardless of where it's looking at app startup. For example, if you place a cube 5 meters down the z-axis and you look way to the left of your monitor(s) (or wherever you clicked the "Center" button during setup), you would need to look to the right a bit (towards your monitor) to see the cube.
     
  16. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    So basically I should have to do nothing special and Unity will handle that?

    Is there a way get the boundaries?

    Thank you for your time replying, it is great get some info rather than guessing.
     
  17. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    147
    Correct, everything I mentioned above should be taken care of automatically by Unity.

    You can in fact get boundaries - we still haven't moved that API out of the Experimental namespace, and to my knowledge, it hasn't been documented... we really should take care of both of those. But the API you want is:
    Code (CSharp):
    1. using UnityEngine.Experimental.XR;
    2. // ...
    3. List<Vector3> listOfPointsYouWantPopulated = new List<Vector3>();
    4. Boundary.TryGetGeometry(listOfPointsYouWantPopulated, Boundary.Type.TrackedArea);
    Let me know if you need anything else!
     
  18. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    well I finally got it working. Thought I would include the code for anyone in the future.

    It is still not overly reliable but at least it tracks. Also it actually shows the mesh for my roomscale no matter if I want to or not.

    Code (csharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.XR;
    7. using UnityEngine.XR.WSA.Input;
    8.  
    9. public class ControllerInput : MonoBehaviour {
    10.  
    11.     public GameObject leftHand;
    12.     public GameObject rightHand;
    13.  
    14.  
    15.     // Use this for initialization
    16.     void Start () {
    17.        
    18.         InteractionManager.InteractionSourceDetected += InteractionManager_SourceDetected;
    19.         InteractionManager.InteractionSourceUpdated += InteractionManager_SourceUpdated;
    20.         InteractionManager.InteractionSourceLost += InteractionManager_SourceLost;
    21.         InteractionManager.InteractionSourcePressed += InteractionManager_SourcePressed;
    22.         InteractionManager.InteractionSourceReleased += InteractionManager_SourceReleased;
    23.     }
    24.  
    25.     void OnDestroy()
    26.     {
    27.        
    28.         InteractionManager.InteractionSourceDetected -= InteractionManager_SourceDetected;
    29.         InteractionManager.InteractionSourceUpdated -= InteractionManager_SourceUpdated;
    30.         InteractionManager.InteractionSourceLost -= InteractionManager_SourceLost;
    31.         InteractionManager.InteractionSourcePressed -= InteractionManager_SourcePressed;
    32.         InteractionManager.InteractionSourceReleased -= InteractionManager_SourceReleased;
    33.     }
    34.         // Update is called once per frame
    35.     void Update ()
    36.     {
    37.  
    38.        
    39.     }
    40.  
    41.     void InteractionManager_SourcePressed(InteractionSourcePressedEventArgs args)
    42.     {
    43.  
    44.         Debug.Log("Source pressed");
    45.     }
    46.     void InteractionManager_SourceDetected(InteractionSourceDetectedEventArgs args)
    47.     {
    48.  
    49.         Debug.Log("Source detected");
    50.     }
    51.     void InteractionManager_SourceUpdated(InteractionSourceUpdatedEventArgs args)
    52.     {
    53.         Vector3 p;
    54.        
    55.         args.state.sourcePose.TryGetPosition(out p);
    56.        // string acc = args.state.sourcePose.positionAccuracy.ToString();
    57.  
    58.         Debug.Log("Hand " + args.state.source.handedness.ToString());
    59.  
    60.         if (args.state.source.handedness.ToString() == "Left")
    61.             leftHand.transform.position = p;
    62.         else if (args.state.source.handedness.ToString() == "Right")
    63.             rightHand.transform.position = p;
    64.  
    65.         Debug.Log("Source updated " + p);
    66.     }
    67.     void InteractionManager_SourceLost(InteractionSourceLostEventArgs args)
    68.     {
    69.  
    70.         Debug.Log("Source lost");
    71.     }
    72.     void InteractionManager_SourceReleased(InteractionSourceReleasedEventArgs args)
    73.     {
    74.  
    75.         Debug.Log("Source released");
    76.     }
    77.  
    78. }
    79.  
    80.  
    81.  
     
  19. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    Actually still buggy. But I think I have figured the cause. If the mixed reality headset hasn't loaded the tracking once it does the controllers are off. If I restart a few times eventually one of the times it will track correctly. It is like I need to reset the controllers on load, but not sure how to do that.

    I did use the report a bug (962382).
     
    Last edited: Oct 25, 2017
  20. charleswcpalmer

    charleswcpalmer

    Joined:
    Feb 16, 2014
    Posts:
    2
    Yup, I've noticed similar, basically getting the controller position through the interaction manager using TryGetPosition on an InteractionSourcePose stops returning positions in the Editor despite everything else working correctly. Tracking is correct in the home space and in the Editor when it does actually return positions.
     
  21. charleswcpalmer

    charleswcpalmer

    Joined:
    Feb 16, 2014
    Posts:
    2
    Further investigation actually turns up that when the controllers aren't being tracked in the Editor the InteractionManager is not returning any results to me.

    I can get things to work if whilst in play mode, I press the windows button on the controller to go to the home space and then re-enter the application from the home space.
     
  22. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    That is how I have to get it working each time, however if it has to rescan the world I need to do a second time.

    Interestingly it still detects the source and button pressing just not the tracking.
     
  23. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    356
    @TheRaider
    I moved your bug report over to one of our testers to see what's going on and check that we're not already tracking that bug somewhere else. If we don't have it on record already, we will get your bug to our developers. You will also get an email from me with a similar reply as this. :)
     
  24. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    Thanks. I am going to make a video tutorial of what I have learnt so far since there aren't that many resources currently.
     
  25. tolosaoldfan

    tolosaoldfan

    Joined:
    Sep 14, 2012
    Posts:
    65
    I've got the same behavior.
    Also, I get the controller "normal" behavior when I enable a breakpoint in VStudio, debug with Unity, the breakpoint occurs, and then , when I go back to Unity Editor, the controller works normally. So, it seems to be a problem with the management of the focus in the Unity Editor + controllers
     
  26. tolosaoldfan

    tolosaoldfan

    Joined:
    Sep 14, 2012
    Posts:
    65
    It works now with the MRP4 version.
     
  27. HypothicEntropy

    HypothicEntropy

    Joined:
    Mar 24, 2014
    Posts:
    19
    Hi, I am having the problem from the original post, is it because I am using the newest Unity build, Unity 2017.2.1f1? This is the build recommended by MRTK (for MR headsets, should I be using the newest MRP build?).

    upload_2017-12-20_17-2-3.png
     
unityunity