How do you start coding auton?

Hey I am a beginner at coding for FRC and I have been stuck on where to start. If anyone has any tips, please let me know.

Your programming language will matter.

1 Like

Mark is right, language will absolutely matter, but I’ll try to answer generically.

Autonomous mode is mostly the same as for teleop mode, except that you don’t use joystick/controller input and use predefined values instead.

In general, there are a couple different approaches, dead-reckoning or closed-loop.

Dead-reckoning is the idea that the robot has no idea where it is, but will do exactly as told. You might tell it “drive forward for 3 seconds, then turn right for 2 seconds, then forward again for another 4 seconds, then shoot”.

Closed-loop control requires some feedback devices (encoders, rangefinders, etc). These devices allow the robot to track its position/orientation (known as “pose”) and how it changes over time (known as “odometry”). There are a few pages in the wpilib docs on how to implement this, though they’re generally more advanced topics.

3 Likes

It depends on how you are structuring your code. (I’m going to give info for Java/C++ because its the most popular and its what I know. I also recommend the Zero to autonomous series; it will outline some autonomous actions like the taxi.

Java/C++, timed robot

In the robot file, there is a method called autonomousperiodic. Fill this method with your autonomous routine. A one-ball + taxi auto will look like
if(Timer.getMatchTime()<5) { shooter.set(1); magazine.set(1); } else if(Timer.getMatchTime()<7) { drivetrain.arcadeDrive(-1,0); } else { drivetrain.arcadeDrive(0,0); shooter.set(0,0); }
This is time-based and a very basic auto.

Java/C++, command based

In the RobotContainer file, there is a method called getAutonomousCommand. Make sure this method returns the command object for your auto routine. Some teams write self-contained autos like the one for timed robot, but in a command file; others (mine included) use CommandGroups. This allows for extremely complicated autos, like my team’s 5-ball; however, simple 1 balls are also possible. We have an autochooser using the SmartDashboard sendableChooser object that allows us to select between all our different autos.

hey thanks for the response. The team is using Java to code the auton.

Hey thanks for the response. I am trying to achieve a closed-loop for the robot and we are using java to code it. Do you have any youtube tutorials you could recommend on the topic perhaps? Thanks for the information so far as well

When I approached making auto for our teams robot, I just made the standard teleop commands such as driving and shooting, and just made a version with a timer. This is my build. You can go to the commands and everything that says auto pretty much as a timer added to it so it stops. The twoballauto command is a command group that runs the commands in sequence. And then you go to RobotContainer and at the bottom you put your auto command in the getAutonomousCommand function at the bottom.

1 Like

What do you use to detect the balls?

For us at least we have the robot programmed to go to where the cargo is supposed to be placed on the field so we don’t need any cargo detection stuff and that’s what a majority of teams do. If you know where the cargo will be on the field and where your robot will start, you just need to know how long the robot needs to drive to get to the balls and how long/how much it needs to turn.

2 Likes

We strapped a Rev v3 Color Sensor in our indexer that feeds the balls into our shooter. When the sensor gets tripped, it will move to the next command in the sequential group. You can see how I set it up in the AutoIntake command. As for lining up, we kinda just have to guess since our limelight will target the upper hub and move around a bit. If we had more time I would have wanted a second limelight installed on the intake side so we can track cargo, but for now we just gotta manually line up before matches.

cargo detection is a hassle