Autonomous starter

#1

Hi! I am from 1930 and I don’t really know how to code autonomous but would really like to know. All of the other articles are really confusing! could someone explain it to me? I already have most of my drive code done but still need to do autonomous

0 Likes

#2

You can look at our example code to get started:

0 Likes

#3

When creating a new program, simply press on open, then examples, and click on the competition template option. Put all of your autonomous code in the autonomous sections and your driver controls in the driver section. :ok_hand:t2:

1 Like

#4

how do I have it so two motors drive together

0 Likes

#5

It’s pretty simple if you have your competition template set up correctly (see this link for how to do that)

Create your autonomous task,

void autonomous(void){
}

then put your auton code in it. The code will look like

Motor.spin()
Motor.rotateFor()
Motor.startRotateFor()
Motor.rotateTo()
vex::task::sleep(%f)

Make sure that you call it in main.
You can put different values inside the () of the motor calls. These can be found in the VCS API.

0 Likes

#6

See the drive functions in the example I posted. One motor will be blocking so the drive function for that motor must complete before moving on to other commands.

We have improved the motion functions a lot in the past month, will be posting a new example template using quick and dirty gyro turns… (appropriate for novice middle school teams)

0 Likes

#7

Something my team did for testing autonomous routines this season was an if statement in driver control that would run autonomous if all of the buttons on the d-pad were pressed, something like:
if (controller.btnA && controller.btnB && controller.btnX && controller.btnY) {
autonomous();
}
Something like that; autonomous would only run if all of the letter buttons (ABXY) were pressed.

0 Likes

#8

You can start autonomous from the controller without a field switch.

1 Like

#9

Are you asking for the basics of writing an auton itself, or how to start it / create an auton selector?

if you are looking for the basics of writing an auton I would suggest a few things:

  1. create methods to do certain things to make your code more legible and allow you to write it faster.
  2. start with a time-based auton because it is a lot easier to implement than an encoder based auton.

an example would be the following:

//create a method to stop activity in the task for a inputted time in milliseconds
void Wait(int time){
    vex::thisthread::sleep_for(time);
}
//create a method to start the right side turning at the inputted power level
void RightDrive(int power){
    FrontRightMotor.spin(vex::directiontype::fwd, power, vex::percentunits::pct);
    BackRightMotor.spin(vex::directiontype::fwd, power, vex::percentunits::pct);
}
//create a method to stop the right side with the three basic stop types
void RightDriveStop(int stoptype){
    if(stoptype == 1){
         FrontRIghtMotor.stop(vex::braketype::brake);
         BackRIghtMotor.stop(vex::braketype::brake);
    }
    else if(stoptype == 2){
         FrontRIghtMotor.stop(vex::braketype::hold);
         BackRIghtMotor.stop(vex::braketype::hold);
    }
    else{
         FrontRIghtMotor.stop(vex::braketype::coast);
         BackRIghtMotor.stop(vex::braketype::coast);
    }
//create a method to power the right side for a given amount of time before stopping it
void RightDrive(int power, int time){
    RightDrive(power);//turn on the right drive at the power level
    Wait(time);//keep the motors running for the specified time by pausing the task
    RightDriveStop(1);//stop the drive with the brake type.
}
1 Like

#10

I think timed autonomous moves are a false start - use encoders. Our MS team got burnt when the Worlds field were sticky and every timed movement was off.

In the example project I have encoder based movements as examples with multiple motors.

1 Like

#11

I guess that is fair and makes a lot of sense. I was just going off of what I thought was the quickest to code for most matches in the season without anti-static sprayed fields.

0 Likes

#12

Right, and I have no context whether this is a team heading to Worlds - if they are, give them something they can adapt. Sounds like they have their driver under control…

My biggest advice, make sure you can turn off your autonomous - nothing worse than collisions of robots with non-complementary routines…

2 Likes

#13

I agree. My team actually uses a graphical user interface to select between 6 different autons and a no-auton and ever since we implemented that we have been placing much higher. I also spent time writing a recording function to record driver input and play it back for auton and since I implemented that we have been using no-auton less because we can quickly create a basic auton that does not conflict with our partner.

0 Likes

#14

Great - the feature selector I posted takes the approach of defining variables you need for autonomous - decision points… so you can have 256 different routines with 8 buttons.

0 Likes

#15

I think that is amazing. 256 different autons with 8 buttons allows a lot of customization. My goal when designing mine was to create something user friendly and intuitive and also to draw the field on the brain so that you can point to a model of the field when describing auton to your partner so there’s less confusion in naming ie flags vs front

0 Likes

#16

yes we had a field interface - but check list was easier:
Red/Blue
Near/Far
Park/NoPark
Shoot/No Shoot
16 configurations right there.
They then had added descore center/far

Definitely having user friendly is important.

They also added a controller update of the key state so the person setting on the field gets confirmation from other drive team members about the configuration.

Also looked at auto detecting the field tile color … but not robust enough…

9791-button-TPfield

Right side would be for debugging information.

0 Likes

#17

It looks nice, to be honest i had not thought of doing it like you did with toggles for parts of the code. It might be something for me to work on. Sometimes its hard because our school has 4 teams and 5 kids in robotics. We have only been around for 3 years so we are all trying to learn how to build the robots and spend so much time building that we get almost no time for driver practice or coding auton. It also isnt helped by the fact that i am the only programmer for all 4 teams and also build for quite a few. Because of this i had to design something simple and quick to modify so i can do all autons for a bot in a few hrs

2 Likes

#18

I feel the pain …

Hence why I post example code for others to learn. After Worlds I will do an update with the development process our middle school teams have been using. They seem comfortable with it.

1 Like

#19

Im trying to do the same, trying to help others learn. When one person benefits we all do. And i would be curious to learn other development processes

0 Likes

#20

If you use encoders, wherever possible, have a free spinning wheel with a shaft encoder mounted onto it. More advanced building techniques will use a suspension system but thats a bit over kill. These free spinning wheels don’t work on gear ratios or anything of that nature unlike the integrated motor encoders, they simply track the absolute position of the robot, thereby making it the most viable for autonomous.

2 Likes