RuntimeError: no event resources available

I get an error on line 181 (controller_1.buttonR1.pressed(user_intake)) that says there is no event resources available

def user_control():
    brain.screen.clear_screen()
    # place driver control in this while loop
    while True:
        leftPos = controller_1.axis3.position()
        rightPos = controller_1.axis2.position()
        left1.set_velocity(leftPos, PERCENT)
        left2.set_velocity(leftPos, PERCENT)
        right1.set_velocity(rightPos, PERCENT)
        right2.set_velocity(rightPos, PERCENT)
        left1.spin(FORWARD)
        left2.spin(FORWARD)
        right1.spin(FORWARD)
        right2.spin(FORWARD)
        
        controller_1.buttonR1.pressed(user_intake)
        controller_1.buttonL1.pressed(user_flywheel_100)
        controller_1.buttonL2.pressed(user_flywheel_65)
        controller_1.buttonR2.pressed(user_pusher)

Don’t register event handlers in a while loop. (this line and all the other “pressed” calls)

4 Likes

I assumed this was the problem but where do I register them then? If I take them out the while loop they are never updated.

Not sure what you mean by

If I take them out the while loop they are never updated.

They should be called once only, you could, for example, do this (I don’t have the benefit of seeing all your other code, so this may be incorrect).

controller_1.buttonR1.pressed(user_intake)
controller_1.buttonL1.pressed(user_flywheel_100)
controller_1.buttonL2.pressed(user_flywheel_65)
controller_1.buttonR2.pressed(user_pusher)

def user_control():
    brain.screen.clear_screen()
    # place driver control in this while loop
    while True:
        leftPos = controller_1.axis3.position()
        rightPos = controller_1.axis2.position()
        left1.set_velocity(leftPos, PERCENT)
        left2.set_velocity(leftPos, PERCENT)
        right1.set_velocity(rightPos, PERCENT)
        right2.set_velocity(rightPos, PERCENT)
        left1.spin(FORWARD)
        left2.spin(FORWARD)
        right1.spin(FORWARD)
        right2.spin(FORWARD)
6 Likes