How to test the competition switch with V5? competition.isCompetitionSwitch

I would like to check to see if our V5 is working with our manually-operated competition switch, but I’m not even sure where the code should go. I think the proper command to use would be competition.isCompetitionSwitch, but I don’t know where it should be placed in the competition template, or even if the competition template is the right thing to use for this kind of test.

The command I’m talking about is listed on this API page along with the code snippet I hope to use:

Suggestions on what to do?

competition.isCompetitionSwitch will tell you if the competition switch is physically connected, that’s all. You can test the enabled and autonomous states using the “isEnabled()” and other methods. The competition template in VCS is using events to trigger the two competition phases, pretty much like ROBOTC did, I will post up some test code later for you, but I have to check it works on VCS 1.0 as sdk has changed slightly in that area since the V1.0 release. I would also suggest you wait to do these test until V1.0.1 is released and you have updated your V5 system, that will probably be later today.

Awesome! That is surely worth waiting for. Thanks!

Will the update list fixes and/updates?

I’m sure an update with details will be posted at some stage.

Here is a VCS test program for competition control, it’s very similar to the template in VCS.

I did not test with vexos 1.0.0, but it should be ok, all my test systems have been running new version all weekend as part of QC process. I will go through the code in the next post and explain some things.
comp_test.vex (7 KB)

int main() {        
    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.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" );          

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   " );

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.

The VCS competition control will only stop the two tasks designated by these lines of code when the robot is disabled or mode changes between autonomous and driver.

Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );

If you have started further tasks, they will not be stopped, that’s up to your code to determine what to do there.

What sort of changes will there be with v1.01 of VCS? Anything significant?

This is great! I’ll see if I can make this work. Thanks so much!

I tested it on one of our V5 systems (vexos 1.0.0) and it works perfectly. Thanks again!