Logical Auto?

Anyone know if you can safely do logic in Autonomous mode?

Something like

while(condition) {
    new SomeCommand;

(assuming you are doing a command based robot, not sure how it works for others)

Careful with the while command. Better to use autonomusperodic

Could you explain a bit more? This is my first time doing programming.

There is a concept of a “heartbeat”. I believe it goes something like this: if your code does not return from periodic after a certain amount of time, the system presumes your code has crashed and disables all motors.

While loop can take too long to execute and trigger the fail safe.

Alright. Guess I’m researching AutonomousPeriodic then.

Autonomous periodic just runs periodically (something like every 20 ms?) throughout autonomous. In Java, if you check out the code they literally just loop through the code in autonomous periodic. Autonomous init is just the first iteration of that loop. I’m not entirely sure but I’m willing to wager that C++ works using the same logic.

We don’t use command based, but all while loops in any of our three main functions (Teleop, Autonomous, or Test) look like this:

while(IsOperatorControl() && IsEnabled()) {}
while(IsAutonomous() && IsEnabled()) {}

This prevents any loops going longer than they should, such as when the mode changes or the robot becoming disabled.

Hope that helps.