WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   changing the gain of a joystick during a program (https://forum.worldviz.com/showthread.php?t=2105)

Saz 06-22-2009 04:22 AM

changing the gain of a joystick during a program
 
Hi,

I want to change the gain of the joystick by altering the scalar constant (in this case MOVE_SPEED)- so effectively the speed will alter - at a certain point in my program (22secs in). Here's what I have so far:
Code:

def UpdateJoystick1():
    #Get the joystick position
    x,y,z = joy.getPosition()
   
    #Move the viewpoint forward/backward based on y-axis value
    if abs(y) > 0.0001: #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.RELATIVE_WORLD)


#UpdateJoystick every frame
vizact.ontimer(0,UpdateJoystick1)


def UpdateJoystick2():
    #Get the joystick position
    x,y,z = joy.getPosition()
   
    #Move the viewpoint forward/backward based on y-axis value
    if abs(y) > 0.0001: #Make sure value is above a certain threshold
        viz.MainView.move(0,0,-y*MOVE_SPEED2,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.RELATIVE_WORLD)


#UpdateJoystick every frame
vizact.ontimer2(22,0,UpdateJoystick2)

but it doesn't seem to make a difference at all - is it because it just comes on at the 22 sec point and then reverts back to the original joystick code? Would I need to insert starttimer and killtimer statements to initiate the two sections?
Any help - as usual - will be greatly appreciated!

Jeff 06-22-2009 11:21 AM

UpdateJoystick1 is being called every frame. UpdateJoystick2 is only called once after 22 seconds. I don't think you need two different functions here. You could just change the value of MOVE_SPEED after 22 seconds.

Saz 06-24-2009 06:31 AM

I tried using this code
Code:

def UpdateJoystick1():
    #Get the joystick position
    x,y,z = joy.getPosition()
   
    #Move the viewpoint forward/backward based on y-axis value
    if abs(y) > 0.0001: #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.RELATIVE_WORLD)


#UpdateJoystick every frame
vizact.ontimer(0,UpdateJoystick1)

def MOVE_SPEEDCH():
        MOVE_SPEED=0
vizact.ontimer(22,MOVE_SPEEDCH)

but it still made no difference - I'm sorry I must be coming across as really dense - it's been a long week and it's only Wednesday!

farshizzo 06-24-2009 10:56 AM

You need to declare the MOVE_SPEED variable as global in your MOVE_SPEEDCH function.
Code:

def MOVE_SPEEDCH():
        global MOVE_SPEED
        MOVE_SPEED=0
vizact.ontimer(22,MOVE_SPEEDCH)

The Python Tips page in the docs explains when you need to use the global keyword.

Saz 06-25-2009 03:49 AM

Thank you poppet - you're a star - works beautifully!


All times are GMT -7. The time now is 06:46 PM.

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