Having a While Loop function in the preauton

I am having trouble with having the preauton allow the program move onto driver and autonomous, and I have it in a while loop set to true because I don;t know the proper condition I would use. SOS

As a basic rule of thumb, in anything supposed to end prior to power being cut or similar, you should never use while(true).

If you want the equivalent in preauton, you should do something more like this:

bool performingSetup = true;

while(performingSetup){
// put all your code here
// include a way to tell the code you’re done.
if(thatCondition) {
performingSetup = false;
}
}

Honestly, even in driver control stuff, I don’t love while(true). I would rather have a similar thing with a button selected as an off button on the controller. You hit that and the program ends. It’s a much safer way to program driver control. But that’s really, really risky in competition, especially since it won’t run forever because the field control sets a time limit.

If you want a while loop to run in your pre-autonomous until the field controller enables your robot for either autonomous or driver mode, use this condition in the while loop:


// stay in this loop until the robot is enabled
while (bIfiRobotDisabled)
{
    // stuff you want to keep doing, like flashing an LED indicator
    // reading the LCD buttons, 
    // or displaying something interesting on the LCD
}

“bIfiRobotDisabled” is a boolean variable managed by the framework such that it is true when the field controller has the robot disabled, and becomes false when the robot is enabled.

I understand this is an opinion, but I think it shows an incorrect point of view. This does, of course, go against some teacher’s stand that infinite loops are a bad thing. However, embedded systems (which is what a robotic control system is) have almost no reason to stop. Heart pacemakers, for instance, probably shouldn’t stop. So an infinite loop is a good idea there. Under what conditions would you like the robot to stop responding to your commands while driving? I can’t think of any. Given that, an infinite loop is a very reasonable construct.

How about this one: you go to handle the robot and someone moves it, slicing your finger. Yup, that has happened to me.

Think about this in a different context. What do you do when changing the blade on a circular saw? You only have to let it stop. But this attitude results in lost fingers, while unplugging it makes you safe.

If you cannot remotely disable the robot, you cannot really make it safe to handle unless you wait for the battery to die every time. Yes, it’s an opinion, but it’s also the opinion of someone who has worked with power tools, including in a machine shop, for decades and has a number of people he knows who have cut off or into their arms, legs, and fingers.

We’re not talking about a pacemaker here. We’re talking about something that can be safely disabled and should be for handling purposes. Is there any responsible reason to purposely not make the robot safe to handle?