int main() {
pre_auton();
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );
The beginning of the main function.
I’m calling something called pre_auton, that’s just another function in my code and is really only there to mimic ROBOTC. You can run any code you like in main (or another task) before the competition or autonomous starts, the concept of “pre_auton” doesn’t mean that code has to be “before the autonomous” part of your program, it can be anything running at anytime. Obviously, you will have no motor control when the robot is disabled, but the touch screen will still be working and you will still be able to read status from sensors.
Competition.autonomous( autonomous ); tells VCS which function (which is really a new task/thread) to run during the autonomous phase of the match. Competition.drivercontrol( usercontrol ); does the same for the driver control period, you can only designate one function for each, if you needs further tasks then start them from once the initial function is called.
Brain.Screen.clearScreen();
Brain.Screen.printAt( 10, 40, "Competition control test");
int count = 0;
Brain.Screen.printAt( 270, 60, "Auton " );
Brain.Screen.printAt( 370, 60, "Driver " );
while(1) {
Brain.Screen.printAt( 10, 60, "loops %d", count++ );
Brain.Screen.printAt( 10, 80, "Enable/disable %d", Competition.isEnabled() );
Brain.Screen.printAt( 10, 100, "Driver/auton %d", Competition.isAutonomous() );
Brain.Screen.printAt( 10, 120, "Comp %d", Competition.isCompetitionSwitch() );
Brain.Screen.printAt( 10, 140, "Game %d", Competition.isFieldControl() );
// clear messages from auton and driver tasks
if( !Competition.isEnabled() ) {
Brain.Screen.printAt( 270, 100, "Disabled" );
Brain.Screen.printAt( 370, 100, "Disabled" );
}
task::sleep(10);
}
The remainder of the code in main is doing most of the display on the screen. The competition flags are displayed as well as the disabled status. None of this is needed for your competition code, it’s all there just to display interesting stuff.
void autonomous( void ) {
int count = 0;
while(true) {
Brain.Screen.printAt( 270, 80, "En %3d", count++ );
Brain.Screen.printAt( 270, 100, "Enabled " );
task::sleep(100);
}
}
In this demo the autonomous and driver control functions just display a counter to show they are running. They are both pretty much the same, you would insert your own code in a very similar way to we used to in ROBOTC.