HELP I don't know how to create auton for V5 vexcode

So our team just got V5 and we just finished building our robot, but the problem is we don’t know how to make the auton. We know how to make the robot move based on actions from the controller. Please any suggestions on how to make it move forward or turn.

Plus it would really help if I could get help on making functions.

I’ll quickly start you up with a n explanation of functions and how to use them to make your programming easier. I will use the drive as an example and you can use the example and apply it to make more functions.

Let’s say you have a 4 motor drive and you want to make your robot move forward. You could make your drive move forward 100 rotations by using the following code:

   void autonomous(){ 
    LBDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm,    false);
    LBDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm,    false);
    FBDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm,    false);
    LFDrive.rotateFor(100, rotationUnits::rev, 200, velocityUnits::rpm);
}

The first parameter is used to define the amount of rotations, the second parameter specifies the rotation units, the third parameter defines the velocity the motors, must move at, the fourth parameter defines the velocity units, and the final parameter defines whether the statement is a considered a blocking or non blocking statement.

Creating a function makes this task much easier.

void drive(Int rev, int spd){

        LBDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm,    false);
        LBDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm,    false);
        FBDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm,    false);
        LFDrive.rotateFor(rev, rotationUnits::rev, spd, velocityUnits::rpm);

}

void autonomous(){
drive(100,200);
}

In this instance, we defined a function called drive and included parameter for rotations and speed. In this sense, you can now callback the function using just those two parameters and you can easily make and autonomous. I will leave tuning and such to you. Think about how turning works and make sure you understand everything. If you have any questions please ask!

6 Likes

It looks like the first example tells the robot to move forward 100 rotations, not 10.

When you create the project, you need to check the competition template box. If you can’t do that now, here’s example code:

Your main method will look like this:

int main() {
  //Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  //Set up callbacks for autonomous and driver control periods.
  Competition.autonomous( autonomous );
  Competition.drivercontrol( usercontrol );
  //render();

  pre_auton();
  //Prevent main from exiting with an infinite loop.                        

  vex::task::sleep(10);//Sleep the task for a short amount of time to prevent wasted resources.
}

Then, you will need two functions for usercontrol and autonomous:

void autonomous( void ) {
  // Auton code goes here
}

void usercontrol( void ) {
  while (1) {
    // Driver control code goes here.
  }
}

You can also have code run while the competition switch is disabled in this method:

void pre_auton( void ) {
  while(!Competition.isEnabled()) {
    // Auton selectors can be put here
  }
}

The while(!Competition.isEnabled()) loop will be disabled while the competition is enabled, so you can feel free to delete this loop.

3 Likes

Thank you for the help

I love you. this is going to help alot