Limit switches during autonomous on V5

Our team uses a limit switch to detect when a ball is in the intake. During user control the pressed feature is used:
Limit1.pressed(stop_intake);
This method works reliably during user control but does not work during autonomous. Our guess is the callback feature used to service the buttons during user control are all disabled during autonomous.

Is there another way to achieve a blocking read of the limit switch during autonomous? We have tried starting another task to poll the switch but sometimes miss the change as the ball goes by?

1 Like

If you want something to be blocking, using an asynchronous callback scheme (pressed) would not be the way to do it. Use the synchronous state check instead, and wait for it to be pressed by delaying while it is not being pressed:

while (!Limit1.pressing()) {
    //do stuff while waiting
}

There is going to be some limitations on how fast sensor data actually comes back to the user processor, but unless your switch is making contact for <10ms that shouldn’t crop up. Given that you’re in VCS, you may have run afoul of its cooperative scheduler by not yielding in some thread, starving all your other tasks. We’d have to see more of your code to tell you for sure, though.