WorldViz User Forum MainView velocity depending on joystick deflection
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 Thread Tools Rate Thread Display Modes
#1
01-16-2014, 07:06 AM
 4711 Member Join Date: Jan 2010 Posts: 15
MainView velocity depending on joystick deflection

Hi all,

how can I move the viz.MainView with a certain velocity (in virtual meters per second) independent of the controlling device (i.e. joystick, gamepad, ...) and the machine on which I'm running the script (i.e., old laptop, new desktop, ...)?

Currently I'm using:

Code:
```# add joystick
joy = vizjoy.add()

# define joystick parameters
thresh = 0.2
stepWidth = 0.01

# timer function, called every 0.05 seconds
def updateJoystick(self):

# get joystick position
joy_x, joy_y, joy_z = joy.getPosition()

# move viewpoint forward/backward based on y-axis value
if abs(joy_y) > thresh:
viz.MainView.move([0, 0, -joy_y*stepWidth], viz.VIEW_ORI)

# move viewpoint left/right based on x-axis value
if abs(joy_x) > thresh:
viz.MainView.move([joy_x*stepWidth, 0, 0], viz.VIEW_ORI)

# schedule timer
vizact.ontimer(0.05, updateJoystick)```
This works nice in principle, but the actual speed, that is, the distance moved within the 0.05 seconds, seems to depend on both the input device (i.e.., one joystick seems to generate faster movement than another), and the machine (i.e., on faster computers the distance is larger than on older machines). That means I have to determine the stepWidth manually for each machine and device, based on trial and error.

So, is there a way around this? Is it possible to set the MainView's velocity in m/s, depending on the joystick's current deflection (via joy.getPosition())?

Any help is appreciated!
#2
01-16-2014, 11:09 AM
 Jeff WorldViz Team Member Join Date: Aug 2008 Posts: 2,462
Try setting the timer expiration time to 0 so it expires every frame. Then use viz.getFrameElapsed to get the elapsed time since the previous frame and multiply that against the speed in m/s and joystick position:
Code:
`viz.MainView.move([0, 0, -joy_y * SPEED * viz.getFrameElapsed()])`
#3
01-17-2014, 08:57 AM
 4711 Member Join Date: Jan 2010 Posts: 15
Thanks a lot, Jeff, that was exactly what I was looking for!

And a follow-up question: Any suggestions how to achieve the same for rotating (not translating) the viewpoint, depending on the joystick's X deflection? Probably using viewpoint.moveTo()?
#4
01-17-2014, 12:50 PM
 Jeff WorldViz Team Member Join Date: Aug 2008 Posts: 2,462
You could use viewpoint.setEuler and update the yaw value every frame:
Code:
`viz.MainView.setEuler([ joy_x * TURN_SPEED * viz.getFrameElapsed(), 0, 0 ], viz.REL_PARENT)`

 Tags joystick, velocity

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

 Similar Threads Thread Thread Starter Forum Replies Last Post jacky Vizard 1 06-04-2013 04:22 AM nmohandes Vizard 2 01-16-2012 10:03 AM jvacare1 Vizard 2 02-18-2010 10:25 AM Vinicius Lima Vizard 7 10-23-2007 10:42 AM Vygreif Vizard 1 01-25-2006 10:56 AM

All times are GMT -7. The time now is 02:18 AM.

 Contact Us - WorldViz Home - Archive - Top

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC