Saz
01-05-2009, 03:38 AM
Hi,
hope you all had a good Christmas and New Year. I am trying to get the joystick position to update on the screen, however instead of updating it merely writes over the previous value resulting in a huge jumbled mess. Would I need to define this process as a separate function?
file = open( 'speed_.txt' + str(subject),'w' )
#Open file in path
#file = open( path + 'speed.txt', 'w' )
def mytimer (num):
joy_pos = str(joy.getPosition())
#speed = joy_pos*[0.0,5.0,0.0]
out = str(joy_pos + '\n')
file.write(out)
file.flush()
print out
#Add text to the screen.
speed = viz.addText(joy_pos, viz.SCREEN)
speed.setPosition(.05, .9 )
speed.fontSize (30)
speed.message(str(joy_pos))
viz.callback( viz.TIMER_EVENT, mytimer )
viz.starttimer( 0, 0.25, viz.FOREVER )
Also as its the joystick position it comes up as an [x, y, z] co-ordinate system whereas I'm only really interested in the y-axis, is there a way around this? Its coded as follows:
def UpdateJoystick():
#Get the joystick position
x,y,z = joy.getPosition()
#Get the twist of the joystick
twist = joy.getTwist()
#Move the viewpoint forward/backward based on y-axis value
if abs(y) > 0.001: #Make sure value is above a certain threshold
viz.MainView.move(0,0,-y*MOVE_SPEED,viz.BODY_ORI)
#Move the viewpoint left/right based on x-axis value
if abs(x) > 0.001: #Make sure value is above a certain threshold
viz.MainView.move(x*0.1,0,0,viz.BODY_ORI)
#Turn the viewpoint left/right based on twist value
if abs(twist) > 0.001: #Make sure value is above a certain threshold
viz.MainView.rotate(0,1,0,twist,viz.BODY_ORI,viz.R ELATIVE_WORLD)
The y position would also need to be multiplied by a value in order to make sense but I'm guessing that's a simple math function?
Any help - as usual will be greatly appreciated!!!
hope you all had a good Christmas and New Year. I am trying to get the joystick position to update on the screen, however instead of updating it merely writes over the previous value resulting in a huge jumbled mess. Would I need to define this process as a separate function?
file = open( 'speed_.txt' + str(subject),'w' )
#Open file in path
#file = open( path + 'speed.txt', 'w' )
def mytimer (num):
joy_pos = str(joy.getPosition())
#speed = joy_pos*[0.0,5.0,0.0]
out = str(joy_pos + '\n')
file.write(out)
file.flush()
print out
#Add text to the screen.
speed = viz.addText(joy_pos, viz.SCREEN)
speed.setPosition(.05, .9 )
speed.fontSize (30)
speed.message(str(joy_pos))
viz.callback( viz.TIMER_EVENT, mytimer )
viz.starttimer( 0, 0.25, viz.FOREVER )
Also as its the joystick position it comes up as an [x, y, z] co-ordinate system whereas I'm only really interested in the y-axis, is there a way around this? Its coded as follows:
def UpdateJoystick():
#Get the joystick position
x,y,z = joy.getPosition()
#Get the twist of the joystick
twist = joy.getTwist()
#Move the viewpoint forward/backward based on y-axis value
if abs(y) > 0.001: #Make sure value is above a certain threshold
viz.MainView.move(0,0,-y*MOVE_SPEED,viz.BODY_ORI)
#Move the viewpoint left/right based on x-axis value
if abs(x) > 0.001: #Make sure value is above a certain threshold
viz.MainView.move(x*0.1,0,0,viz.BODY_ORI)
#Turn the viewpoint left/right based on twist value
if abs(twist) > 0.001: #Make sure value is above a certain threshold
viz.MainView.rotate(0,1,0,twist,viz.BODY_ORI,viz.R ELATIVE_WORLD)
The y position would also need to be multiplied by a value in order to make sense but I'm guessing that's a simple math function?
Any help - as usual will be greatly appreciated!!!