Can someone take a look at the code for the bumper switch? It is towards the bottom. I’m trying to get the robot to stop moving when the switch is pressed.
Thanks so much for showing us your code, it makes it way easier to help!
When you check the bumper switch’s value, you need to do that inside a while loop that essentially waits until the switch is pressing. Otherwise, the switch is only checked once and if it is not pressed at that moment then the code will exit your autonomous function. The DSP on the brain is fast enough that you can easily poll the bumper switch at 200HZ without issues (5msec wait time, anything more starts to become kinda pointless because the motors have 100HZ components).
TL;DR: Use a while loop to keep checking the switch value
Ok thank i will check it out
The while loop did not work
Did you make sure to add a wait inside the loop? If it’s still not working an updated screenshot could be helpful.
Sorry for the late response on the screenshot.
Yeah, that isn’t how while loops work. You need to enclose the loop in brackets like this:
void autonomous(void) {
Drivetrain.drive(forward);
while(true) {
if (Bumper.pressing()) {
Drivetrain.stop();
}
wait(20, msec);
}
}
Do note that I changed the wait from 0.5 seconds to 0.02; there isn’t a reason to have such a long wait time.