It is currently Tue Nov 21, 2017 9:48 am



Reply to topic  [ 18 posts ] 
 Simulate Vive controller trackpad from WASD/joystick. 
Author Message
One Eyed Hopeful

Joined: Sat Jan 18, 2014 1:29 pm
Posts: 7
Reply with quote
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.


Mon Dec 05, 2016 7:09 pm
Profile
One Eyed Hopeful

Joined: Thu Dec 01, 2016 7:36 pm
Posts: 14
Reply with quote
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.

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:
keypress = keyboard.getPressed(Key.PageDown)
if keypress:
      #do something


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


Mon Dec 05, 2016 10:31 pm
Profile
One Eyed Hopeful

Joined: Sat Jan 18, 2014 1:29 pm
Posts: 7
Reply with quote
Cheers for the link!

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


Wed Dec 07, 2016 5:31 am
Profile
Cross Eyed!
User avatar

Joined: Thu Apr 09, 2015 4:27 am
Posts: 133
Reply with quote
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.


Wed Dec 07, 2016 7:55 am
Profile
One Eyed Hopeful

Joined: Sun Jun 25, 2017 11:51 am
Posts: 1
Reply with quote
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?


Sun Jun 25, 2017 12:49 pm
Profile
One Eyed Hopeful

Joined: Tue Oct 10, 2017 5:27 am
Posts: 1
Reply with quote
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!


Tue Oct 10, 2017 5:30 am
Profile
Cross Eyed!
User avatar

Joined: Thu Apr 09, 2015 4:27 am
Posts: 133
Reply with quote
NobleBrutus, mmorselli and AgentMilkshake1

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


Thu Oct 12, 2017 5:49 am
Profile
One Eyed Hopeful

Joined: Tue Nov 07, 2017 7:48 pm
Posts: 9
Reply with quote
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:
xbox360[i].leftStickX
xbox360[i].leftStickY

with
Code:
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:
## 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?


Last edited by EVOL on Wed Nov 15, 2017 4:57 am, edited 1 time in total.



Wed Nov 08, 2017 12:23 pm
Profile
Cross Eyed!
User avatar

Joined: Thu Apr 09, 2015 4:27 am
Posts: 133
Reply with quote
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:
## 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


Wed Nov 08, 2017 12:59 pm
Profile
One Eyed Hopeful

Joined: Tue Nov 07, 2017 7:48 pm
Posts: 9
Reply with quote
Thank you! I'm getting somewhere now I think...


Last edited by EVOL on Wed Nov 15, 2017 5:28 am, edited 3 times in total.



Wed Nov 08, 2017 1:20 pm
Profile
Cross Eyed!
User avatar

Joined: Thu Apr 09, 2015 4:27 am
Posts: 133
Reply with quote
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:
## 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


Wed Nov 08, 2017 1:43 pm
Profile
One Eyed Hopeful

Joined: Tue Nov 07, 2017 7:48 pm
Posts: 9
Reply with quote
Yeah I figured that out right before your post... Sorry

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


Wed Nov 08, 2017 1:47 pm
Profile
One Eyed Hopeful

Joined: Tue Nov 07, 2017 7:48 pm
Posts: 9
Reply with quote
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!!!


Wed Nov 08, 2017 2:16 pm
Profile
One Eyed Hopeful

Joined: Tue Nov 07, 2017 7:48 pm
Posts: 9
Reply with quote
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:
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)


Sun Nov 12, 2017 8:24 pm
Profile
Cross Eyed!
User avatar

Joined: Thu Apr 09, 2015 4:27 am
Posts: 133
Reply with quote
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:
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()


Mon Nov 13, 2017 2:57 am
Profile
One Eyed Hopeful

Joined: Tue Dec 22, 2015 12:52 pm
Posts: 34
Reply with quote
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:
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:
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


Mon Nov 13, 2017 4:46 am
Profile
One Eyed Hopeful

Joined: Tue Nov 07, 2017 7:48 pm
Posts: 9
Reply with quote
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.


Mon Nov 13, 2017 11:31 am
Profile
Two Eyed Hopeful

Joined: Mon Mar 02, 2015 3:58 pm
Posts: 55
Reply with quote
Button spamming/tapping and sequences have been discussed in this topic, have you seen it?

https://www.mtbs3d.com/phpbb/viewtopic.php?f=139&t=22533


Mon Nov 13, 2017 12:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.