MoveTo function only running latest instance

In python, I have the following piece of code in Vex VR:

PMX = PMY = 1
def P(v: float): return 24*v

# gps.set_location(PMX * P(-2.5), PMY * P(-1.5), INCHES)
def MoveTo(x, y, reverse=False):
    [yDif, xDif] = [P(y*PMY)-gps.y_position(INCHES), P(x*PMX)-gps.x_position(INCHES)]
    
    K1 = math.atan2(yDif, xDif)*180/math.pi
    K2 = (math.pi - math.atan2(yDif, abs(xDif)))*180/math.pi
    
    angle = K1 if xDif >= 0 else K2
    drivetrain.turn_to_heading(-angle, DEGREES)
    drivetrain.drive_for(REVERSE if reverse else FORWARD, math.sqrt(xDif**2 + yDif**2), INCHES)

MoveTo(0,-2,0,0)
# MoveTo(-2.5,-0.5,0,0)

This code allows you to go to any location on the V5 High Stakes Field by tile-coordinates (1 tile coord per 24 inches), where (0,0) is the center of the field.
The line MoveTo(0,-2,0,0) allows you to go to the spot directly beneath the ladder (you can run the code yourself and see)

However, if you uncomment the last line,

MoveTo(-2.5,-0.5,0,0)

It will go directly to (-2.5,-0.5) instead of (0,-2), then (-2.5,-0.5).

Can you please help me fix this issue?
Thanks.

Oops, it’s in the Rapid Relay Category. Can a moderator move it to High Stakes? Thanks.

I tried out your code and got the same thing, moving the function calls inside the main function like this fixed it for me:

def main():
    MoveTo(0,-2)
    MoveTo(-2.5,-0.5)

vr_thread(main)

Also side note it looks like you have too many parameters when you call MoveTo

2 Likes

Those are for my original code, where those extra parameters are relative coordinates if the quality is < 60.