How do you make a good auton?

Hi all, I am new to programming for robots and I would like to know some tips and tricks on how to write a good autonomous function.
We had our first competition of the year yesterday (December 7th) and the autonomous that I wrote was written that day since I started programming three days prior. Long story short I was too busy with college applications to do anything robotics and my team of three other people (two are freshmen) was working on building the robot.
The autonomous code that I wrote for skills did not work so we just pushed a cube backward to get 1 point. My original plan, though, involved a lot of guessing how far the robot would go after waiting a certain distance. I heard there is an extremely better way of doing this.
I originally wrote my code in VexCode V5, but I did not really like how the tutorials leaned toward pressing a button to automatically put in code for you with no explanation of what it actually put in. So I have migrated to using PROS.

VexCode is easier to start than PROS, unless you are an experienced C++ coder.
The best starting point is to learn about V5 motor API that has built-in PID loops. Take a look at rotateTo(), spinFor(), rotateFor() functions.

Then you can learn how to use V5 drivetrain classes: vexforum.com/t/vexcode-motor-groups-and-drivetrain-example/69161

Then you can take a look at examples of autonomous code that other people had posted, like this: Strange problem with autonomous

Then you can learn more hands on coding algorithms: vexforum.com/t/very-simple-very-accurate-chassis-control-code-release/60819

When you get comfortable with all above, then it may be useful to learn about PROS, okapilib and really advanced stuff like odometry: vexforum.com/t/7842f-2018-19-robot-showcase-flywheel-control-odometry-engineering-journals-more/65170

1 Like

Hi there!
Firstly, I agree with @weilin:

VexCode is easier to start than PROS, unless you are an experienced C++ coder.

when you have already built your main program (go forward, pick up cube, et cetera ad nauseam) I would recommend grouping your commands together, such as having your startRotateFor() commands for your base all in one function, so you can just call the function and it will tell the base to go forward, or turn.
Here’s an example for that:

    foldout();
    move(0.2, -80);
    vex::task::sleep(400);
    movePid(0.5, 120);

This will make your code WAY easier to write and debug, allowing you to code faster and more efficiently.
Also, I would recommend pausing between movements to make your autons more precise, and easier to estimate and fix.
Good luck with your coding! :smiley:

3 Likes

Thank you! I have some experience in coding. Our school has two teams and I noticed that the other team was just copy and pasting long strings of “motor1.spin(blah blah blah)” but I made some functions to allow for me to just do moveForward(); or stopAll(); to do what they imply.
This year is my last year to be able to do this before college, so I really want to learn how to do it well. I’ll try to use what was given to me by you. and @weilin

2 Likes