question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trigger axis value is always 0

See original GitHub issue

As far as I understood trigger position should be inside of pControllerState as one of the axis.

But when I run this program:

import openvr

openvr.init(openvr.VRApplication_Background)

while True:
    print()

    result, pControllerState, pTrackedDevicePose = openvr.VRSystem().getControllerStateWithPose(1,
                                                                                          openvr.TrackingUniverseSeated,
                                                                                            )
    for i in pControllerState.rAxis:
        print(i.x, i.y)

I get only zeroes, am I doing something wrong? (Edit - I had init inside loop)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
mdovgialocommented, Jul 7, 2017

I had function arguments mixed up. As you can see:

def getControllerStateWithPose(self, eOrigin, unControllerDeviceIndex, unControllerStateSize=sizeof(VRControllerState_t)):

the first one is the tracking universe id, the seconds is the device index and I did it vice versa.

But this function introduced a little lag in posing information, so I don’t use it. You can see minimal example to get axis: https://github.com/mdovgialo/steam-vr-wheel/blob/master/steam_vr_wheel/test.py

I’ve found, that it’s better to get poses like that:

vrsystem = openvr.VRSystem()
poses_t = openvr.TrackedDevicePose_t * openvr.k_unMaxTrackedDeviceCount
poses = poses_t()
vrsystem.getDeviceToAbsoluteTrackingPose(openvr.TrackingUniverseSeated, 0, len(poses), poses)

And then get controller state for a controller:

vrsys = openvr.VRSystem()
result, pControllerState = vrsys.getControllerState(controller_id)
trigger = pControllerState.rAxis[1].x
trackpadX = pControllerState.rAxis[0].x
trackpadY = pControllerState.rAxis[0].y

Controller_id can be any number from 0 to 15, so you have to identify controllers using something like this:

def get_controller_ids():
    vrsys = openvr.VRSystem()
    for i in range(openvr.k_unMaxTrackedDeviceCount):
        device_class = vrsys.getTrackedDeviceClass(i)
        if device_class == openvr.TrackedDeviceClass_Controller:
            role = vrsys.getControllerRoleForTrackedDeviceIndex(i)
            if role == openvr.TrackedControllerRole_RightHand:
                 right = i
            if role == openvr.TrackedControllerRole_LeftHand:
                 left = i
return left, right
0reactions
matEhickeycommented, Mar 8, 2018
vr_system = openvr.init(openvr.VRApplication_Background)
result, pControllerState = openvr.VRSystem().getControllerState(openvr.TrackedControllerRole_LeftHand)
trigger = pControllerState.rAxis[1].x
trackpadX = pControllerState.rAxis[0].x
trackpadY = pControllerState.rAxis[0].y
print("ok : "+str(result))
print("trigger : "+str(trigger))
print("trackpadX : "+str(trackpadX))
print("trackpadY : "+str(trackpadY))

These value always remain at 0.0, except for result, that always stay at one, even if the controller is shutdown.

(Windows 10, openvr 1.0.1201)

Read more comments on GitHub >

github_iconTop Results From Across the Web

changing axis values to become from 0 to 1 instead of [-1,1]
hello everyone I'm using a PS4 controller in my project and i want to use one of the triggers value as an accelerator...
Read more >
Input Axis Value ALWAYS 0 - Unreal Engine Forums
Hello, I have a big problem I set up a test to enter a function with a axis map that is set to...
Read more >
unity - Input.GetAxis() always returns 0
Here are the fields and properties of my Hand class, in which I am invoking the Input. GetAxis(trigger) method:
Read more >
Trigger Button Potential Bug · Issue #155 · ros-drivers ... - GitHub
The trigger buttons seem to map to values between -1 and 1, and after pressing the releasing the trigger button(s) once, the axes...
Read more >
Xbox One Right Trigger Not Working - Stack Overflow
It looks like the Left and Right triggers now both use the 3rd axis (Joystick) with the Left generating positive (0 to +1)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found