Pre_auton method

I am scratching my head at the pre_auton method. As far as I can tell it is called once at the beginning of main(), and never again. Yet, it seems to be running in the background while usercontrol and autonomous are running. I can tell because graphics I use in the pre_auton stage are still being printed despite the fact they should be cleared from the screen. Help?

I am using Vexcode V5 C++, on the competition template

Code: GitHub - andrew-on-github/Robotics-Repo: 9635 vex robotics code, written in C++ with VEXCODE Pro editor

1 Like

I believe that it’s because the code for the pre-auton never technically stops. There might not be a bracket or a line that tells it to end, so the screen doesn’t get cleared even though the code is making the robot do a different action, since the screen isn’t directly told to clear. Maybe try to program a different graphic for the screen for the regular user control and autonomous.

1 Like

pre_auton() is just a standard function that main calls. If the function blocks (ie. has some sort of while(1) loop) then it will never exit, why would it ?

3 Likes

My autonomous selection contains a while(1) loop. I have tried to program it so that it exits when the competition switch is in user control or autonomous mode but I can’t seem to get that to work either.

My user control and autonomous both have a clear screen command in them

Send me the code and I will have a look

2 Likes

What program are you coding on? I know my team likes to use vex pro which separates the auton and the driver control

Put it on the main topic.

Vexcode text pro is what we’re using

Try adding this inside your pre_auton while loop:

if (Competition.isAutonomous() || Competition.isDriverControl()) break;

This code checks if the field control is currently in driver control or autonomous mode and breaks out of the loop if it is.

2 Likes

I did something similar by replacing my while(true) with the same condition, it didn’t seem to work either.

Unfortunately, the documentation for the API leaves one wanting…

I am curious if you need to be hooked up to a field switch to detect the status.

@jpearman is Competition utilized when a team uses the controller to simulate timers or does it need to be connected to a field control? Looking at the reference I would assume the latter.

Link to Competition reference

VCS Command Reference

Brain.Screen.clearLine();
// check what method of match control if any is being used
if (Competition.isCompetitionSwitch()) {
    // connected to a competition switch
    Brain.Screen.print("Connected to a competition switch");
} else if (Competition.isFieldControl()) {
    // connected to a field control system
    Brain.Screen.print("Connected to a field control system");
} else {
    // not connected to any control system
    Brain.Screen.print("not connected to a control system");
}

Brain.Screen.setCursor(2, 1);
3 Likes

It doesn’t seem to be working with a competition switch. Is that different than field control?

That would be the same.

You might want to try a separate program to test if the brain is reacting to the field switch.

void pre_auton(void) {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

    Brain.Screen.clearScreen();
    while(true){
        Brain.Screen.setCursor(1,1);
        Brain.Screen.print("FieldControl: %d  ", Competition.isFieldControl());

        Brain.Screen.setCursor(2,1);
        Brain.Screen.print("Auton: %d  ", Competition.isAutonomous());

        Brain.Screen.setCursor(3,1);
        Brain.Screen.print("Driver: %d  ", Competition.isDriverControl());

        wait(250,msec);
    }
}
3 Likes

I know for sure the brain is reacting to the competition switch, just not sure sure if those methods are working. I’ll give this a shot.

1 Like