Need help with emergency stop. Vex v5 python

motor_2.set_velocity(20, PERCENT)
motor_3.set_velocity(20, PERCENT)

def emergency_stop():
    motor_2.stop()
    motor_3.stop()

while True:
    motor_2.spin(FORWARD)
    motor_3.spin(FORWARD)
    if distance_11.object_distance(INCHES) < 8.5:
        motor_2.stop()
        motor_3.stop()
        wait(.5, SECONDS)
        motor_2.spin_for(FORWARD, 510, DEGREES)
        wait(.5, SECONDS)
        break

motor_2.spin(FORWARD)
motor_3.spin(FORWARD)

while True:
    motor_2.spin(FORWARD)
    motor_3.spin(FORWARD)
    if distance_11.object_distance(INCHES) < 8.5:
        motor_2.stop()
        motor_3.stop()
        wait(.5, SECONDS)
        motor_3.spin_for(FORWARD, 510, DEGREES)
        wait(.5, SECONDS)
        break

motor_2.spin(FORWARD)
motor_3.spin(FORWARD)
while True:
    motor_2.spin(FORWARD)
    motor_3.spin(FORWARD)
    if distance_11.object_distance(INCHES) < 9:
        motor_2.stop()
        motor_3.stop()
        wait(.5, SECONDS)
        motor_3.spin_for(FORWARD, 510, DEGREES)
        wait(.5, SECONDS)
        break

motor_2.spin(FORWARD)
motor_3.spin(FORWARD)

while True:
    motor_2.spin(FORWARD)
    motor_3.spin(FORWARD)
    if distance_11.object_distance(INCHES) < 8:
        motor_2.stop()
        motor_3.stop()



if bumper_b.pressed(emergency_stop) == 1:
    motor_2.stop()
    motor_3.stop()

What isn’t working? What do you need help with? Just posting your code won’t get you help…

2 Likes

Your problem seems to be that your emergency stop only stops the motors once, however it does not deactivate your other parts of the code which continuously reactivate the motors. You may look into the stop project command or consider other ways you could tie the emergency stop into effecting the rest of your code.

You could also add 2 lines of code inside the emergency stop to set the motor velocities to zero

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