Making my robot move in a spiral with only right <s

I want my robot to move in a spiral can anyone send me a sample code of it I don’t know how to attach my code like I took a screenshot but don’t know how to attach it onto here could anyone help me with that too?

ty

Hey, welcome to the forum! Could you be a little clearer on what you mean by spiral? Do you mean turning while driving, or following a curved path?

Also, regarding posting screenshots, there should be a little hardrive-looking button on the bottom of the text window when you make a post where you can upload files (I’m on mobile right now, not sure if it’s the same on a PC.) :slight_smile:

1 Like

If you’re looking to attach your code (written in Python or C++) try using the characters ``` around your copy-pasted code in your post. If you want to send an image you should be able to drag it into the forum post and it will upload it for you.

Making your robot go in a spiral could depend on how your robot is structured and how you’re programming the robot (with a drivetrain class, two motor groups, motors individually; I’m assuming you’re coding some sort of tank drive). It’ll be helpful if you can provide us with your current code and more information on how your robot is constructed with a picture or more description.

Here is my current code

vexcode_brain_precision = 0
vexcode_console_precision = 0
message1 = Event()
FWD = Event()
TR = Event()
TL = Event()
DEBUG = False
DEBUGY = False
myVariable = 0
FORWARD_MOVE = 0
TURN_RIGHT = 0
TURN_LEFT = 0
iteration_step = 0
iteration = 0
forward_length = 0

def when_started1():
    global message1, FWD, TR, TL, DEBUG, DEBUGY, myVariable, FORWARD_MOVE, TURN_RIGHT, TURN_LEFT, iteration_step, iteration, forward_length, vexcode_brain_precision, vexcode_console_precision
    # Spiral path
    brain.screen.clear_screen()
    DEBUG = False
    iteration_step = 0
    forward_length = 400
    for repeat_count in range(4):
        while iteration_step == 0:
            FWD.broadcast_and_wait()
            iteration_step = iteration_step + 1
            TR.broadcast_and_wait()
            FWD.broadcast_and_wait()
            forward_length = forward_length + 400
            iteration_step = 0
            wait(5, MSEC)
        wait(5, MSEC)

def when_started2():
    global message1, FWD, TR, TL, DEBUG, DEBUGY, myVariable, FORWARD_MOVE, TURN_RIGHT, TURN_LEFT, iteration_step, iteration, forward_length, vexcode_brain_precision, vexcode_console_precision
    # Spiral path
    brain.screen.clear_screen()
    DEBUG = False
    iteration_step = 0
    forward_length = 400
    for repeat_count2 in range(4):
        while iteration_step == 0:
            FWD.broadcast_and_wait()
            iteration_step = iteration_step + 1
            TR.broadcast_and_wait()
            FWD.broadcast_and_wait()
            forward_length = forward_length + 400
            iteration_step = 0
            wait(5, MSEC)
        wait(5, MSEC)

def onevent_FWD_0():
    global message1, FWD, TR, TL, DEBUG, DEBUGY, myVariable, FORWARD_MOVE, TURN_RIGHT, TURN_LEFT, iteration_step, iteration, forward_length, vexcode_brain_precision, vexcode_console_precision
    if DEBUG:
        brain.screen.next_row()
        brain.screen.print("FORWARD")
    else:
        motor_1.spin_for(FORWARD, forward_length, DEGREES, wait=False)
        motor_2.spin_for(FORWARD, forward_length, DEGREES)

def onevent_TL_0():
    global message1, FWD, TR, TL, DEBUG, DEBUGY, myVariable, FORWARD_MOVE, TURN_RIGHT, TURN_LEFT, iteration_step, iteration, forward_length, vexcode_brain_precision, vexcode_console_precision
    if DEBUG:
        brain.screen.next_row()
        brain.screen.print("LEFT")
    else:
        motor_1.spin_for(REVERSE, 214, DEGREES, wait=False)
        motor_2.spin_for(FORWARD, 214, DEGREES)

def onevent_TR_0():
    global message1, FWD, TR, TL, DEBUG, DEBUGY, myVariable, FORWARD_MOVE, TURN_RIGHT, TURN_LEFT, iteration_step, iteration, forward_length, vexcode_brain_precision, vexcode_console_precision
    if DEBUG:
        brain.screen.next_row()
        brain.screen.print("RIGHT")
    else:
        motor_1.spin_for(FORWARD, 214, DEGREES, wait=False)
        motor_2.spin_for(REVERSE, 214, DEGREES)

# system event handlers
FWD(onevent_FWD_0)
TL(onevent_TL_0)
TR(onevent_TR_0)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)

ws2 = Thread( when_started2 )
when_started1()

Im trying to make a spiral that goes forward and then turns right 90 degrees and then moves forward the same distance then turns 90 degrees but increases the distance and this goes on for 4 loops

1 Like

It seems that your program started off at one point as a blocks project looking at the formatting it’s presented in. Do you still have a copy of your project in this format? You seem to have utilized parallel programming in a way that I’ve only seen exported blocks code done, so it could be easier to tell things if you show your code in its original format.

Have you tested your code yet? Logically your code seems to make sense to me but there might be some small mistakes that would’ve affected how it performs. If you have information on hits end behavior that could be helpful too (I don’t have much coding experience with VEX, so I’m trying to figure out this along with you!)

Something that I see right now is in the functions where you tell the motors to move. In the function for right turns, you tell the motors to spin for 214 degrees. Is there a reason why? Also in your main loop, you could potentially see if changing the ordering of turns and movement might help since, from my own logic, it seems to be a bit off.

turning while driving

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.