PDA

View Full Version : Another Joystick Question


Plasma
01-31-2004, 08:06 AM
I'm trying to get Vizard to print the user's yaw and positional information when the joystick trigger is pulled. I've used the sid.get() command to determine that the trigger is button number 1.

However, when I to call on that button using something like this:

if data[2] == viz.BUTTON_1:
print yaw,pos

it returns the following message:

AttributeError: 'module' object has no attribute 'BUTTON_1'

How does Vizard call on joystick buttons?

Thanks!

farshizzo
02-02-2004, 09:46 AM
Hi,

To test whether joystick button 1 is down use the following code:buttons = sid.buttons()
if buttons & 1:
print 'button 1 is down'
Accessing joystick information is somewhat cryptic right now, in the next version we will make it a lot easier to use.

Plasma
02-03-2004, 08:15 AM
Perfect.

I have it set up to give the user's yaw and positional data on the trigger press, but because it is within the joystick control loop, when the trigger is pressed, I get about 10 sets of information.

Is there a way to make it so that, no matter how long the trigger is held down, it only prints the information once?

Thanks!

farshizzo
02-03-2004, 11:16 AM
Hi,

The upcoming version of Vizard will allow you to create callbacks for joystick buttons, but for now you'll have to manually check when a button is first pressed. Here's a simple example:
import viz
import sid

viz.go()

laststate = sid.buttons()

def mytimer(num):
global laststate
state = sid.buttons()
if state & 1 and not laststate & 1:
print 'button pressed down'
laststate = state

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.001,viz.FOREVER)