Cookbook: "How do I...?"
Short answers to the questions students ask most, one page per topic. Each recipe has one question, a few lines of code to copy, one sentence on why, and links to the page that explains more.
To find your question: use the list below, or the site’s search with a word like lift,
double-tap or park.
The code works. Every code block in the cookbook is a copy of real Java files in
examples/.../cookbook. Each time
the library changes, we build those files and run them in the simulator. A check
(tools/check_docs.py) makes sure that the pages and the files say the same thing.
If you are new: do Pick your start and The five files first. They put the five files in your robot project, and these recipes go into those files. If you never coded before, read Words you will meet first.
The questions
Section titled “The questions”Start here
- Coming from Blocks: where did my blocks go? (if, loop, sleep, REVERSE, variables)
- Where does each line go? The files, whole
- Words you will meet
- Whole robots to start from: the templates (ten whole example robots) and the kit robots (goBILDA, REV, AndyMark, Studica starter bots)
Driving
- How do I set up a mecanum drive?
- How do I set up a tank (standard) drive?
- A wheel turns the wrong way. How do I fix it?
- How do I tell the robot how the Control Hub is mounted?
- How do I make the robot slower (or faster)?
- How do I let one driver do everything?
- How do I put slow mode on a trigger?
- Driving that is already built in (field-centric, pause, “forward”)
Buttons and gestures
- How do I make a button do something once?
- How do I run something only while a button is held?
- How do I switch something on and off with one button?
- How do I put a tap, a hold and a double-tap on one button?
- How do I make a button safe (“hold for 1 second”)?
- How do I use two buttons together (like a shift key)?
- How do I make the gamepad buzz?
- How do I control a part with a stick?
- How do I move a part’s button to another button?
- How do I put the launcher’s fire button on another button?
- How do I let the parts add their usual buttons by themselves?
- How do I move the library’s own buttons (slow, field-centric, pause)?
- How do I change the double-tap and hold times?
- How do I switch the alliance during TeleOp?
- Buttons that are already built in (button map, pause, switch alliance, set pose)
Mechanisms
- How do I add an intake on a motor?
- How do I add an intake on CR servos?
- How do I make the intake run from the start?
- How do I add a lift with set heights?
- My lift goes down when it should go up. How do I fix it?
- How do I run one lift on two motors?
- My motor isn’t in the catalog
- How do I add an arm that moves in degrees?
- How do I add a claw?
- How do I run a claw on two servos?
- How do I add a wrist?
- How do I add any servo with named positions (a gate, a fold-out)?
- How do I get my servo’s full range?
- How do I send a part to a position from a button?
- My robot doesn’t have this part yet. How do I keep its code?
- How do I add a launcher (flywheel and feeder)?
- How do I feed with two wheels, one on each side?
- How do I add a turret that follows the goal?
- How do I fire only when aimed, at the right speed?
Game pieces (what is in the robot, and what fires next)
- How do I know which piece is in the robot, and how many?
- How do I stop the intake when the robot is full?
- How do I tell pieces apart by size, or with a second camera?
- How do I use the count (buzz, LEDs, the shot table)?
- How do I let the next piece pick the shot table?
- How do I tune the piece sensors?
Aiming and shooting (the robot helps the drivers)
- How do I make the whole robot aim at the goal (no turret)?
- How do I make the gamepad buzz when the aim is on target?
- How do I keep aiming when the camera loses the goal?
- How do I aim with the odometry only (no camera)?
- How do I make the camera work in any venue’s light?
- How do I find game pieces with a HuskyLens?
- How do I shoot while the robot is driving?
- How do I use one shot table per game piece?
- Every shot is a bit short today. How do I trim the speed (a low battery)?
- How do I add a hood to my launcher?
Turrets and interlocks (any turret; parts that share space)
- How do I home my turret with a switch?
- How do I set up a turret on a servo?
- How do I set up a slip-ring turret (round and round)?
- How do I stop two parts from hitting each other?
- How do I pick up and score with a lift, a wrist and a claw?
Actions (several steps or parts together)
- How do I do several things one after the other?
- How do I repeat steps several times?
- How do I move two parts at the same time?
- How do I wait half a second (like sleep in Blocks)?
- How do I wait until something is true?
- How do I start an action from a button?
- How do I stop every running action?
- How do I run an action when the OpMode starts?
- How do I use the same action in an autonomous?
Autonomous
- How do I make my first autonomous (drive 2 feet)?
- How do I drive forward, sideways and turn?
- Does my autonomous need a RED version?
- How do I let the drivers choose before the match?
- How do I make sure there is time to park?
- How do I run a mechanism while the robot drives?
- How do I wait for my alliance partner?
- How do I write a step the list cannot say?
- How do I change a distance in an autonomous?
- How do I share the same first steps in several autos?
- How do I make the start delay shorter, or use a different number on RED?
Several autos and choosing one (more: Building autos 3: having multiple autos)
- How do I build several autos from the same pieces?
- How do I make two autos that differ by one piece?
- How do I let the drivers choose the start spot and the plan in INIT?
Odometry and driveTo (where is the robot on the field?)
- How do I add a goBILDA Pinpoint?
- How do I add a SparkFun OTOS?
- How do I add dead wheels?
- How do I tune the odometry?
- How do I drive to a point on the field?
- How do I get around field elements on the way to a spot?
- How do I show where the robot is?
- How do I use the robot’s position in an action?
- How do I set the pose when autonomous did not run?
Pedro paths (smooth curves, mecanum only)
- How do I add Pedro Pathing to Robot.java?
- How do I make a straight path and a curve?
- How do I follow a path in an autonomous?
- How do I drive two paths with no stop, slow down, or hold at the end?
- How do I keep facing the goal along a path?
- How do I drive first and turn at the end of a path (or turn first)?
- How do I start something partway along a path?
Telemetry (lines on the Driver Station)
- How do I show a value on the Driver Station screen?
- How do I round a number on the Driver Station?
- How do I show lines from my own autonomous step?
Lights (a color the drivers can see)
- How do I add a colored light for the drivers?
- How do I change a color on a REV Blinkin?
- How do I show a color when something is true?
- How do I show the alliance on the light before the match?
- How do I flash the light when something happens?
- How do I flash the light when an action is done?
- How do I blink the light in the last 20 seconds?
Tuning and finders (getting the numbers right)
- Where do the numbers go?
- How do I find a servo’s open and closed numbers?
- How do I find a lift’s limits and heights?
- How do I change a number while the robot runs?
- How do I tune the drive for autonomous?
- How do I set the flywheel numbers?
- How do I build a shot table (speed for each distance)?
- How do I find my hood’s stops and angles?
Simulator (try your code with no robot)
- How do I start the simulator?
- How do I see my own robot in the simulator?
- How do I make the simulator draw my part?
- How do I test my code with a script?
Not here?
Section titled “Not here?”- Every class and method: the reference and the module pages.
- Something goes wrong: Troubleshooting.
- Learn it step by step: The five files, then Add to your robot.
- A question the cookbook does not answer: tell us.
Something wrong on this page? Tell us with a short GitHub form.