How to interrupt/abort a program?

Some of my drivers forget to keep the bot stationary while the gyro is being calibrated, so we’re adding some startup code to read the current heading (a few times) to make sure it’s close to 0 or 360. If it’s not, we’d like to terminate the program and return to the “main” menu. How do we do that? We’re using Code Blocks. Thanks!

You can’t exit the program. You can just make it re calibrate.

image

myVariable is a dummy variable… I set it to 180 to start just so the loop executes at least once.

Then it calibrates for two seconds and waits for two seconds before it checks.

You could have it print to the brain the status of the loop, and adjust the values so it works like you want it to.

3 Likes

Our team uses a touch LED to indicate that the gyro has finished calibrating. So, you start the program in a while loop checking to see if the gyro is calibrated, and set the touch LED to colorGreen when it is and exit the loop.

During the course of the autonomous, we use the walls to recalibrate the gyro to eliminate any gyro drift that has accumulated.

2 Likes

you could try putting the rest of your code inside of an if statement that checks if a variable (set by the condition above) says that the calibration completed successfully

3 Likes

Yes, we ended up using LED’s to indicate success/failure. We don’t have a stand-alone gyro device, we have a drivetrain with a gyro. Can we still re-calibrate the gyro?

I’m not familiar with using the drivetrain option in VexCode IQ blocks, and if you can run the calibrate function. I know if you set up the gyro independently in VexCode IQ blocks there is a function to calibrate your gyro.

1 Like