Autonomous
Autonomous programming is a critical aspect of FRC robots, as it covers the first 15 seconds of the match where the robot operates without human intervention. During this period, the robot must perform a series of pre-programmed actions to score points, navigate the field, and interact with game pieces. Effective autonomous routines can provide a significant advantage in matches, as they allow the robot to maximize the points scored during this crucial phase where activity scores are higher.
Our autos are made of two things: paths, drawn in Choreo, and a behavior tree, built in Arbor, that says what the robot does and when. The tree asks the robot for the same states the driver's buttons do.
Presentation
Exercises
The exercises below are the Autonomous lesson in Scriptum. It starts from your finished Computer Vision robot and needs the Choreo and Arbor lessons done first. Open the lesson, start the simulated robot and follow its README. Each step is checked with the Verify button.
New Java in this lesson: a step state, picked by an if/else inside a switch case.
New tool: you build the routine in Arbor, which saves it as a file the robot reads at start, so a tree change needs no rebuild.
Draw the paths
- Set the Choreo project's Drive Type to Differential and enter the robot's numbers from the README
- Draw a path named
ToPickupfrom Start to Pickup, with a translation waypoint in between - Draw a path named
ToScorethat starts whereToPickupended and finishes on ScoreSpot- Optional: add a Max Velocity constraint of about 1.8 m/s
- Generate both paths
Build the tree
- Open the Arbor tab. The project is the robot's
deploy/autosfolder; the palette already knowsFollowPath,SetWantedStateandIsSystemState(with the robot's states),Timeout,RetryUntilSuccessfulandSleep - Open the tree
PickupAndScore. It is aSequencethat already drivesToPickup; add after it, in order:Sleepfor half a second, standing in for picking up a game pieceFollowPathwithtrajectory=ToScoreSetWantedStateAIM. Asking is instant, so the tree then waits for it:- A
Timeoutof 3 seconds aroundRetryUntilSuccessful(num_attempts-1) aroundIsSystemStateAIM, so the tree waits until the robot is inAIMand a bad aim cannot stall the auto SetWantedStateSHOOT, then aSleepof 2 seconds, thenSetWantedStateAUTO
- Save (Ctrl+S). Arbor writes
deploy/autos/trees/PickupAndScore.xml, the file the robot runs
Finish the aim step
- Run the tree first: it shoots without turning, because the robot reaches
AIMthe moment it is asked - In
RobotContainer.handleStateTransition, finish theAIMcase: the robot is in the step stateAIMINGwhile it turns, and inAIMonly once the drivetrainisAimed() - This is what makes the tree's wait mean "aimed":
IsSystemState AIMstays false while the robot is inAIMING. The left bumper asks for the sameAIM, so the sequence is written once
Run it
- Pick PickupAndScore in Elastic's Auto Chooser, then run Auto
- Watch the tree light up in Arbor's live view, and the true pose and your estimate on the AdvantageScope 2D field
- Optional: replay the run's
.btlog(inlogs/bt) in Arbor - Optional: declare a
pickup_wait_msectunable in the tree'sTreeNodesModeland change it from Elastic without a rebuild
Related Documentation
Software Tools
- Choreo: Tool for creating and testing autonomous trajectories.
- Arbor: The behavior-tree editor and live viewer.
- Elastic: Tool for logging and visualizing robot data.
Software
- Autonomous: How the competition robot's behavior-tree autos work.
- State Machines: The super state machine the tree asks for states.