Robot not turning unless using drivetimeout

So In my case my robot wont turn unless I use drive time out. Ive had this issue for the past 2 weeks. It takes time from my autonomous. Anyone can help me program this without using drive time out and get the robot turning with using drive timeout.
Here my code. Python

myVariable = 0

def onevent_controller_1buttonB_pressed_0():
    global myVariable
    Lock.set(False)

def onauton_autonomous_0():
    global myVariable
    Lock.set(True)
    wait(0.5, SECONDS)
    drivetrain.set_drive_velocity(50, PERCENT)
    drivetrain.set_turn_velocity(50, PERCENT)
    drivetrain.set_timeout(1, SECONDS)
    drivetrain.drive_for(FORWARD, 5, INCHES)
    drivetrain.turn_for(LEFT, 90, DEGREES)

def onevent_controller_1buttonRight_pressed_0():
    global myVariable
    backwing.set(True)

def when_started1():
    global myVariable
    Kicker.set_max_torque(100, PERCENT)
    forebar.set_max_torque(100, PERCENT)
    Intake.set_max_torque(100, PERCENT)
    Kicker.set_velocity(63, PERCENT)
    forebar.set_velocity(100, PERCENT)
    Intake.set_velocity(100, PERCENT)
    drivetrain.set_drive_velocity(100, PERCENT)
    drivetrain.set_turn_velocity(100, PERCENT)
    forebar.set_stopping(HOLD)
    Lock.set(True)

def onevent_controller_1buttonRight_released_0():
    global myVariable
    backwing.set(False)

def onevent_controller_1buttonY_pressed_0():
    global myVariable
    Wings.set(True)

def onevent_controller_1buttonY_released_0():
    global myVariable
    Wings.set(False)

def onevent_controller_1buttonL2_pressed_0():
    global myVariable
    Intake.spin(FORWARD)

def onevent_controller_1buttonDown_pressed_0():
    global myVariable
    Kicker.spin(FORWARD)

def onevent_controller_1buttonL2_released_0():
    global myVariable
    Intake.stop()

def onevent_controller_1buttonDown_released_0():
    global myVariable
    Kicker.stop()

def onevent_controller_1buttonL1_pressed_0():
    global myVariable
    Intake.spin(REVERSE)

def onevent_controller_1buttonL1_released_0():
    global myVariable
    Intake.stop()

def onevent_controller_1buttonR2_pressed_0():
    global myVariable
    forebar.spin(FORWARD)

def onevent_controller_1buttonR2_released_0():
    global myVariable
    forebar.stop()

def onevent_controller_1buttonR1_pressed_0():
    global myVariable
    forebar.spin(REVERSE)

def onevent_controller_1buttonR1_released_0():
    global myVariable
    forebar.stop()

# create a function for handling the starting and stopping of all autonomous tasks
def vexcode_auton_function():
    # Start the autonomous control tasks
    auton_task_0 = Thread( onauton_autonomous_0 )
    # wait for the driver control period to end
    while( competition.is_autonomous() and competition.is_enabled() ):
        # wait 10 milliseconds before checking again
        wait( 10, MSEC )
    # Stop the autonomous control tasks
    auton_task_0.stop()

def vexcode_driver_function():
    # Start the driver control tasks

    # wait for the driver control period to end
    while( competition.is_driver_control() and competition.is_enabled() ):
        # wait 10 milliseconds before checking again
        wait( 10, MSEC )
    # Stop the driver control tasks


# register the competition functions
competition = Competition( vexcode_driver_function, vexcode_auton_function )

# system event handlers
controller_1.buttonB.pressed(onevent_controller_1buttonB_pressed_0)
controller_1.buttonRight.pressed(onevent_controller_1buttonRight_pressed_0)
controller_1.buttonRight.released(onevent_controller_1buttonRight_released_0)
controller_1.buttonY.pressed(onevent_controller_1buttonY_pressed_0)
controller_1.buttonY.released(onevent_controller_1buttonY_released_0)
controller_1.buttonL2.pressed(onevent_controller_1buttonL2_pressed_0)
controller_1.buttonDown.pressed(onevent_controller_1buttonDown_pressed_0)
controller_1.buttonL2.released(onevent_controller_1buttonL2_released_0)
controller_1.buttonDown.released(onevent_controller_1buttonDown_released_0)
controller_1.buttonL1.pressed(onevent_controller_1buttonL1_pressed_0)
controller_1.buttonL1.released(onevent_controller_1buttonL1_released_0)
controller_1.buttonR2.pressed(onevent_controller_1buttonR2_pressed_0)
controller_1.buttonR2.released(onevent_controller_1buttonR2_released_0)
controller_1.buttonR1.pressed(onevent_controller_1buttonR1_pressed_0)
controller_1.buttonR1.released(onevent_controller_1buttonR1_released_0)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)

when_started1()

edit: code tags added by mods, please remember to use them as code, especially python, is almost unreadable without them.

While I’m not familiar with Python for VEX (I use c++), here’s what I think is happening.

The drivetrain.set_timeout() function will abort autonomous movement of the drivetrain if the drivetrain cannot complete the given movement within the passed parameter (1 second). Based on the fact that you’re saying that the turn function is not being called if the set_timeout() function is not present, it seems like the drive_for() function is getting stuck and is unable to complete and thus the code only proceeds when the set_timeout() function aborts it.

How far does the robot actually drive when the drive_for() function is called? Does it actually drive 5 inches or does it only drive 2 inches and then gets stuck.

What I would assume is happening, is that there is some mechanical issue that is preventing the robot from moving the full amount and thus it’ll keep trying either forever (without a timeout and never move on to the turn code) or keep trying for 1 second (with timeout and then move on but never complete the movement).

Please provide more details on what the robot is or is not doing (you can increase the movement amount of the drive_for() function to have an easier time measuring distance). You can also provide a picture of the robot and its drivetrain so I can try to help you with mechanical issues.

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