User control and Autonomous

I’m sure there is already a topic for this somewhere, but I was not able to find it. How do I create the code for having autonomous and user control in the same program so that the competition switch works without having to touch the robot at all?

Use the competition template. Go to open then templates. Scroll down till you find it. Put your auton in the autonomous section and your driver control code in the usercontrol section.

7 Likes

hey do you have a sample code for x-drive

Use the search bar:

https://www.vexforum.com/search?expanded=true&q=how%20to%20code%20an%20x%20drive

1 Like

Yo since you haven’t marked a response as the solution ima throw my hat in the ring.

starting with the base code you need to do 5 small things to get code comp ready,

  1. Add the line “competition Competition;” at the start of the code or right after “using namespace vex;”
  2. in the “int main()” portion add the lines
    “Competition.drivercontrol(UserControl);”
    and
    “Competition.autonomous(Autonomous);”
  3. Create the user control and auton functions for each section of the code to be ran by adding
    void UserControl(){
    }
    and
    void Autonomous(){
    }
  4. Move the “int main” function to the bottom of the code (Won’t work without doing this)
  5. put driver and auton code into their respective functions

here is an example of how it should look

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\rylan                                            */
/*    Created:      Tue Oct 11 2022                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

competition Competition;

void UserControl(){
  //put driver code here
}

void Autonomous(){
  //put auton code here
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  Competition.drivercontrol(UserControl);
  Competition.autonomous(Autonomous);
}

2 Likes

vexcode literally does this all automatically for you.

1 Like

Not if you just click “new” from the file menu which is what a lot of people do

2 Likes

Yeah sorry Lmao. I don’t check on here that often so I didn’t mark it as solved.

1 Like