Page 1 of 1

Simulate Vive controller trackpad from WASD/joystick.

Posted: Mon Dec 05, 2016 7:09 pm
by NobleBrutus
I'm new to freepie but am studying programming and electronics.

Here's the deal.

1) I have a Vive.

2) I have a virtual reality treadmill which can either emulate a keyboard or a joystick input.

3) Increasingly many Vive games are using a Vive trackpad to control movement.

I want to be able to emulate pressing the trackpad on my Vive controller while still using my Vive controllers for the rest of the functions.

Does anyone have an idea how this could be achieved?

Is it possible to emulate a Vive controller with a Vive controller? If so extra input data could be added prior to SteamVR seeing it which would be a big boon.

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Mon Dec 05, 2016 10:31 pm
by flo2
I have followed this example to emulate the Vive controllers. It works by emulating the Razer Hydra controllers and having user install the Steam VR Razer Hydra drivers. It's pretty tricky if you don't read everything carefully first (don't do what I did), but really straightforward when you wrap your head around it.

http://www.mtbs3d.com/phpbb/viewtopic.php?f=139&t=22033

Once you get it to work, try replacing the xbox inputs with equivalent the keyboard keys or joystick values. For example:

Code: Select all

keypress = keyboard.getPressed(Key.PageDown) 
if keypress:
   	#do something
or

Code: Select all

xAxis = joystick[0].x
hydra[1].x = xAxis *1000

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Dec 07, 2016 5:31 am
by NobleBrutus
Cheers for the link!

However is it possible to use both a Razer Hydra and a Vive controller at the same time?

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Dec 07, 2016 7:55 am
by zelmon64
NobleBrutus wrote:However is it possible to use both a Razer Hydra and a Vive controller at the same time?
I is possible to use multiple types of controllers simultaneously (such as PSMove controllers and a Leap Motion) but they are all recognised as separate controllers. To do this you must have the multiple drivers setting enabled. I don't know if you will get the desired effect by using the treadmill as a third controller.

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Sun Jun 25, 2017 12:49 pm
by mmorselli
NobleBrutus wrote:2) I have a virtual reality treadmill which can either emulate a keyboard or a joystick input.
I'm very interested 'cause I'm expecting my treadmill (ROVR) next week. Have you found a working solution?

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Tue Oct 10, 2017 5:30 am
by AgentMilkshake1
Hi there,

I'm currently trying to get my device working that emulates a thumbstick, and pass it into OpenVR.

Were you able to achieve this with the FreePIE API?

If so how?

Cheers!

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Thu Oct 12, 2017 5:49 am
by zelmon64
NobleBrutus, mmorselli and AgentMilkshake1

I'm not certain but OpenVR-InputEmulator is probably the way to go.

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Nov 08, 2017 12:23 pm
by EVOL
I'm trying to do this also but sadly I have terrible coding skills. I have got as far as getting an xbox 360 controller to emulate a Razor Hydra with zelmon64's script. Using OpenVR-InputEmulator I've got the xbox 360 controlling the vive trackpad. The treadmill is directinput so I've tried replacing in zelmon64's script:

Code: Select all

xbox360[i].leftStickX
xbox360[i].leftStickY
with

Code: Select all

joystick[i].x
joystick[i].y
When I do this the Y axis is backwards I don't know how to fix this (Walking forward is backwards, Backwards is forwards)
Also it moves on it's own with little input. Although it does register movements sometimes also it seems to ignore input at other times. I've spent many hours now editing zelmon64's script and even attempting to write completely new scripts. I have looked at every example and tried everything I could think of but I'm just not good at this....

Basically I just need something like this but with the ability to tweak Deadzone, Sensitivity, and Axis direction.

Code: Select all

## Start
	hydra[0].start = keyboard.getKeyDown(Key.Space)
	hydra[1].start = keyboard.getKeyDown(Key.Space)

	

## joystick
	hydra[0].joyx = joystick[i].x
	hydra[0].joyy = joystick[i].y
	hydra[1].joyx = joystick[i].x
	hydra[1].joyy = joystick[i].y
Can anyone help me, please?

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Nov 08, 2017 12:59 pm
by zelmon64
EVOL wrote:Basically I just need something like this but with the ability to tweak Deadzone, Sensitivity, and Axis direction.
Hi EVOL,

Try this (with appropriate settings):

Code: Select all

## Start
   hydra[0].start = keyboard.getKeyDown(Key.Space)
   hydra[1].start = keyboard.getKeyDown(Key.Space)

## Settings
   Deadzone = 0.1
   Sensitivity = 1
   Axis_direction_X = 1
   Axis_direction_Y = -1
   i = 0

## joystick
   hydra[0].joyx = filters.deadband(joystick[i].x, Deadzone) * Sensitivity * Axis_direction_X
   hydra[0].joyy = filters.deadband(joystick[i].y, Deadzone) * Sensitivity * Axis_direction_Y
   hydra[1].joyx = filters.deadband(joystick[i].x, Deadzone) * Sensitivity * Axis_direction_X
   hydra[1].joyy = filters.deadband(joystick[i].y, Deadzone) * Sensitivity * Axis_direction_Y

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Nov 08, 2017 1:20 pm
by EVOL
Thank you! I'm getting somewhere now I think...

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Nov 08, 2017 1:43 pm
by zelmon64
EVOL wrote:Sorry, but should I be putting anything more in the script than what you provided?

I get an error with just that code
That says remove all the indentations:

Code: Select all

## Start
hydra[0].start = keyboard.getKeyDown(Key.Space)
hydra[1].start = keyboard.getKeyDown(Key.Space)

## Settings
Deadzone = 0.1
Sensitivity = 1
Axis_direction_X = 1
Axis_direction_Y = -1
i = 0

## joystick
hydra[0].joyx = filters.deadband(joystick[i].x, Deadzone) * Sensitivity * Axis_direction_X
hydra[0].joyy = filters.deadband(joystick[i].y, Deadzone) * Sensitivity * Axis_direction_Y
hydra[1].joyx = filters.deadband(joystick[i].x, Deadzone) * Sensitivity * Axis_direction_X
hydra[1].joyy = filters.deadband(joystick[i].y, Deadzone) * Sensitivity * Axis_direction_Y

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Nov 08, 2017 1:47 pm
by EVOL
Yeah I figured that out right before your post... Sorry

Thank you so much I think with this I can get it working!!

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Wed Nov 08, 2017 2:16 pm
by EVOL
This is awesome it's gonna take some fine tuning but I think it will work great. Could you possibly give me some code that would allow clicking the thumbpad button when the Y axis is a set distance from center? This would enable running at full speed.

I cant thank you enough!!!

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Sun Nov 12, 2017 8:24 pm
by EVOL
How can a make this code keep tapping hydra[0].joybutton while running?
I tried adding another press with a pause between using time.sleep but got error saying time wasn't defined.

Code: Select all

def Run_Action(Running):
    hydra[0].joybutton = Running
    hydra[1].joybutton = Running

if (abs(joystick[i].y) > Run_Threshold):
    Run_Action(True)
else:
    Run_Action(False)

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Mon Nov 13, 2017 2:57 am
by zelmon64
EVOL wrote:How can a make this code keep tapping hydra[0].joybutton while running?
I tried adding another press with a pause between using time.sleep but got error saying time wasn't defined.
Are you sure it needs to be tapped instead of held down? That just seems a bit odd to me.

Code: Select all

if starting:
    # system.setThreadTiming(TimingTypes.HighresSystemTimer) # uncomment to use use a iteration interval less than 16 ms
    # system.threadExecutionInterval = 2 # uncomment to set a non-default iteration interval 
    from time import sleep

def Run_Action():
    hydra[0].joybutton = True
    hydra[1].joybutton = True
    sleep(0.1)
    hydra[0].joybutton = False
    hydra[1].joybutton = False

if (abs(joystick[i].y) > Run_Threshold):
    Run_Action()

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Mon Nov 13, 2017 4:46 am
by MarijnS95
Be careful though, this'll freeze your entire script for 100ms, including all the other positional updates that are (probably) in your script. Instead, it's better to store the state and the time since the last change (or the time at the last change). This can be implemented using either system.threadExecutionInterval, or by taking the difference between the current time and some previous time, as acquired by time.time().

Code: Select all

if starting:
    tap_time = 0
    tap_state = False

# In milliseconds:
if tap_time >= 100 and abs(joystick[i].y) > Run_Threshold: 
    tap_time = 0
    tap_state = not tap_state
    hydra[1].joybutton = hydra[0].joybutton = tap_state

tap_time += system.threadExecutionInterval
The time variant is probably a little more accurate, because the script won't execute at exactly the rate of system.threadExecutionInterval.

Code: Select all

if starting:
    import time
    last_tap_time = time.time()
    tap_state = False

current_time = time.time()

# In seconds:
if current_time - last_tap_time >= .1 and abs(joystick[i].y) > Run_Threshold: 
    last_tap_time = current_time
    tap_state = not tap_state
    hydra[1].joybutton = hydra[0].joybutton = tap_state

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Mon Nov 13, 2017 11:31 am
by EVOL
Thank you both! I'll give it a go tonight. Holding down the button works great in most games. However I tried out a game that uses dashes. Instead of just being held down it needs to be tapped to perform the dash multiple times.

Re: Simulate Vive controller trackpad from WASD/joystick.

Posted: Mon Nov 13, 2017 12:14 pm
by Jabberwock
Button spamming/tapping and sequences have been discussed in this topic, have you seen it?

https://www.mtbs3d.com/phpbb/viewtopic. ... 39&t=22533