Coding Autonomous

I am new to coding this year (I am using VexCode v5 Text 1.0). Does anyone know where a good place to find examples of autonomous would be or references for it? Also what is supposed to go in the pre-autonomous code?

3 Likes

I think that vexcode has examples built in.

1 Like

Pre Autonomous is running right as you run the program. It is used for resetting values or setting values for different autonomous or as most teams do or plan to do. Currently my team has a graphics phase in the pre-auton to select which autonmous we want to run in the the autonomous phase.

1 Like

I used the sample competition program, and this is what my autonomous looks like.

#include “vex.h”

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/
/
/
You may want to perform some actions before the competition starts. /
/
Do them in the following function. You must return from this function /
/
or the autonomous and usercontrol tasks will not be started. This /
/
function is only called once after the V5 has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

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

// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}

/---------------------------------------------------------------------------/
/* /
/
Autonomous Task /
/
/
/
This task is used to control your robot during the autonomous phase of /
/
a VEX Competition. /
/
/
/
You must modify the code to add your own robot specific commands here. /
/
---------------------------------------------------------------------------*/

void autonomous(void) {
// …
// int main(void);

//Wait 2 seconds or 2000 milliseconds before starting the program.
vex::task::sleep(500);
//Print to the screen that the program has started.
Brain.Screen.print("Have a great match, Team CapTen.");
Brain.Screen.print("Autonomous will start soon.");

Brain.Screen.clearScreen(color::green);

FrontLeftDr.setVelocity(100, vex::velocityUnits::pct);
FrontRightDr.setVelocity(100, vex::velocityUnits::pct);
BackLeftDr.setVelocity(100, vex::velocityUnits::pct);
BackRightDr.setVelocity(100, vex::velocityUnits::pct);
LeftIntake.setVelocity(100, vex::velocityUnits::pct);
RightIntake.setVelocity(100, vex::velocityUnits::pct);
ChutePush.setVelocity(100, vex::velocityUnits::pct);

FrontLeftDr.spin(vex::directionType::fwd);
FrontRightDr.spin(vex::directionType::fwd);
BackLeftDr.spin(vex::directionType::fwd);
BackRightDr.spin(vex::directionType::fwd);
   vex::task::sleep(1000);
FrontLeftDr.spin(vex::directionType::rev);
FrontRightDr.spin(vex::directionType::rev);
BackLeftDr.spin(vex::directionType::rev);
BackRightDr.spin(vex::directionType::rev);
   vex::task::sleep(1000);
FrontLeftDr.stop();
FrontRightDr.stop();
BackLeftDr.stop();
BackRightDr.stop();
ChutePush.spin(vex::directionType::fwd);
LeftIntake.spin(vex::directionType::rev);
RightIntake.spin(vex::directionType::rev);
   vex::task::sleep(2300);
ChutePush.spin(vex::directionType::rev);
   vex::task::sleep(3000);
FrontLeftDr.stop();
FrontRightDr.stop();
BackLeftDr.stop();
BackRightDr.stop();
ChutePush.stop();
LeftIntake.stop();
RightIntake.stop();
Controller1.Screen.print("Autonomous has Ended.");
Controller1.rumble(".-.-");

// …
}

1 Like