# ftc-helper-lib docs: the main pages > ftc-helper-lib is a Java helper library for FIRST Tech Challenge (FTC) robots, for students with little or no Java. These are its docs for release v0.47.0 (docs updated 2026-11-21), from https://crossbotics.com/ftc-helper/docs/. Use only classes, methods and Tunables names that these docs show. A team's own library version can be older: it is in the project's ftc-helper-lib folder (git -C ftc-helper-lib describe --tags). --- # FTC-Helper-Lib docs URL: https://crossbotics.com/ftc-helper/docs/ Shortcuts for programming an FTC robot in Java. These pages match release **v0.47.0**. **New here?** [Set up](https://crossbotics.com/ftc-helper/docs/setup/), then [Pick your start](https://crossbotics.com/ftc-helper/docs/pick-your-start/). Then follow each page's **Next** link: it leads through every section below, in order. ## Start here - [Set up: the tools and the library](https://crossbotics.com/ftc-helper/docs/setup/) - [Pick your start](https://crossbotics.com/ftc-helper/docs/pick-your-start/) - [The five files: your robot's code](https://crossbotics.com/ftc-helper/docs/five-files/) - [Add to your robot](https://crossbotics.com/ftc-helper/docs/add-to-robot/) - [Controls](https://crossbotics.com/ftc-helper/docs/controls/) - [Building autos](https://crossbotics.com/ftc-helper/docs/building-autos/) - [Simulator](https://crossbotics.com/ftc-helper/docs/simulator/) - [Tuning](https://crossbotics.com/ftc-helper/docs/tuning/) - [Tests](https://crossbotics.com/ftc-helper/docs/tests/) - [Reference: search every class and method](https://crossbotics.com/ftc-helper/reference/) ## Go deeper: build it by hand Optional. The same things built by hand, with the library's building blocks, to see how they work inside. - [Tutorial 01: OpMode basics with the library](https://crossbotics.com/ftc-helper/docs/tutorials/01-opmode-basics/) - [Tutorial 02: Motors and servos](https://crossbotics.com/ftc-helper/docs/tutorials/02-motors-and-servos/) - [Tutorial 03: Buttons](https://crossbotics.com/ftc-helper/docs/tutorials/03-buttons/) - [Tutorial 04: Drive a mecanum robot](https://crossbotics.com/ftc-helper/docs/tutorials/04-drive-mecanum/) - [Tutorial 05: Drive a standard (tank) robot](https://crossbotics.com/ftc-helper/docs/tutorials/05-drive-tank/) - [Tutorial 06: A fast, clear loop](https://crossbotics.com/ftc-helper/docs/tutorials/06-fast-clear-loop/) - [Tutorial 07: PID: hold a lift at a height](https://crossbotics.com/ftc-helper/docs/tutorials/07-pid-lift/) - [Tutorial 08: A lift that cannot hurt itself](https://crossbotics.com/ftc-helper/docs/tutorials/08-safe-lift/) - [Tutorial 09: Autonomous by hand with AutoDrive](https://crossbotics.com/ftc-helper/docs/tutorials/09-first-auto/) - [Tutorial 10: Autonomous with mechanisms](https://crossbotics.com/ftc-helper/docs/tutorials/10-auto-with-mechanisms/) - [Tutorial 11: Driver assists](https://crossbotics.com/ftc-helper/docs/tutorials/11-driver-assists/) - [Tutorial 12: Organize a whole robot](https://crossbotics.com/ftc-helper/docs/tutorials/12-robot-structure/) - [Tutorial 13: Test your code without a robot](https://crossbotics.com/ftc-helper/docs/tutorials/13-testing/) - [Tutorial 14: Mechanism helpers](https://crossbotics.com/ftc-helper/docs/tutorials/14-mechanisms/) - [Tutorial 15: Telemetry, profiles and tuning](https://crossbotics.com/ftc-helper/docs/tutorials/15-telemetry-profiles-tuning/) - [Tutorial 16: Easy autonomous](https://crossbotics.com/ftc-helper/docs/tutorials/16-easy-autos/) - [Tutorial 17: Launcher](https://crossbotics.com/ftc-helper/docs/tutorials/17-launcher/) - [Tutorial 18: Vision aiming (webcam or Limelight 3A)](https://crossbotics.com/ftc-helper/docs/tutorials/18-vision-aim/) - [Check the hardware (tutorial 19)](https://crossbotics.com/ftc-helper/docs/tutorials/19-testing-procedures/) - [Tutorial 20: Easy TeleOp](https://crossbotics.com/ftc-helper/docs/tutorials/20-easy-teleop/) - [Tutorial 21: Find your numbers](https://crossbotics.com/ftc-helper/docs/tutorials/21-finders/) ## For teams - [Keep the library up to date](https://crossbotics.com/ftc-helper/docs/02-keep-up-to-date/) - [Starter kit: a whole robot program](https://crossbotics.com/ftc-helper/docs/starter-kit/) · the older six-file starter kit (EasyTeleOp, EasyAuto) - [Coming from last season's code](https://crossbotics.com/ftc-helper/docs/from-last-season/) - [Signs and units](https://crossbotics.com/ftc-helper/docs/conventions/) - [Troubleshooting](https://crossbotics.com/ftc-helper/docs/troubleshooting/) ## Guides - [How it all fits together](https://crossbotics.com/ftc-helper/docs/guides/architecture/) - [Ask an AI agent about the library](https://crossbotics.com/ftc-helper/docs/guides/ask-an-ai-agent/) - [Easy autonomous modes](https://crossbotics.com/ftc-helper/docs/guides/easy-autos/) · make autonomous modes the older way (EasyAuto) - [What runs every loop](https://crossbotics.com/ftc-helper/docs/guides/every-loop/) - [Example: drive, slow mode, and an intake that starts on](https://crossbotics.com/ftc-helper/docs/guides/example-drive-intake/) - [Extending the library](https://crossbotics.com/ftc-helper/docs/guides/extending/) - [Git and GitHub for FTC teams](https://crossbotics.com/ftc-helper/docs/guides/github/) - [How the simulator works](https://crossbotics.com/ftc-helper/docs/guides/how-the-simulator-works/) - [Two parts that must not collide (interlocks)](https://crossbotics.com/ftc-helper/docs/guides/interlocks/) - [Setting up Limelight lighting pipelines](https://crossbotics.com/ftc-helper/docs/guides/limelight-lighting/) - [A new season: what to do](https://crossbotics.com/ftc-helper/docs/guides/new-season/) - [Non-blocking code: keep the loop running](https://crossbotics.com/ftc-helper/docs/guides/non-blocking/) - [Parts catalog: motors, servos, wheels and rollers](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/) - [Profiles: practice vs competition](https://crossbotics.com/ftc-helper/docs/guides/profiles/) - [Your robot in the simulator: the robot-file skill](https://crossbotics.com/ftc-helper/docs/guides/robot-file-skill/) - [The BIOBUZZ starter bots: robot files and code](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/) - [Setting up a turret](https://crossbotics.com/ftc-helper/docs/guides/turret-setup/) - [Use only what you need](https://crossbotics.com/ftc-helper/docs/guides/use-only-what-you-need/) - [Your own code at INIT, ▶, every loop and STOP](https://crossbotics.com/ftc-helper/docs/guides/your-own-code/) ## Modules Every class and every function, one page per module. To look one thing up, [search the reference](https://crossbotics.com/ftc-helper/reference/). - [Auto module](https://crossbotics.com/ftc-helper/docs/modules/auto/) - [Control module](https://crossbotics.com/ftc-helper/docs/modules/control/) - [Core module](https://crossbotics.com/ftc-helper/docs/modules/core/) - [Drive module](https://crossbotics.com/ftc-helper/docs/modules/drive/) - [Finders module](https://crossbotics.com/ftc-helper/docs/modules/finders/) - [Gamepad module](https://crossbotics.com/ftc-helper/docs/modules/gamepad/) - [Hardware module](https://crossbotics.com/ftc-helper/docs/modules/hardware/) - [Launcher module](https://crossbotics.com/ftc-helper/docs/modules/launcher/) - [Match module](https://crossbotics.com/ftc-helper/docs/modules/match/) - [Mechanism module](https://crossbotics.com/ftc-helper/docs/modules/mechanism/) - [Odometry module](https://crossbotics.com/ftc-helper/docs/modules/odometry/) - [Pedro module (Pedro Pathing)](https://crossbotics.com/ftc-helper/docs/modules/pedro/) - [Robot module](https://crossbotics.com/ftc-helper/docs/modules/robot/) - [Safety module](https://crossbotics.com/ftc-helper/docs/modules/safety/) - [Telemetry module](https://crossbotics.com/ftc-helper/docs/modules/telemetry/) - [TeleOp module](https://crossbotics.com/ftc-helper/docs/modules/teleop/) - [Testing module](https://crossbotics.com/ftc-helper/docs/modules/testing/) - [Test kit module](https://crossbotics.com/ftc-helper/docs/modules/testkit/) - [Tuning module](https://crossbotics.com/ftc-helper/docs/modules/tuning/) - [Util module](https://crossbotics.com/ftc-helper/docs/modules/util/) - [Vision module](https://crossbotics.com/ftc-helper/docs/modules/vision/) ## Contributing to the library For people who change the library itself, not for robot code. - [Contributing: add or change something in the library](https://crossbotics.com/ftc-helper/docs/contributing/) - [Commenting style](https://crossbotics.com/ftc-helper/docs/commenting-style/) --- # Add to your robot URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/ **Why one at a time:** when only one part is new, a problem can only be in that part. Every page has the same steps: 1. **What it is:** what the part does, and what it needs on the robot. 2. **Add it to the five files:** the lines for `Robot.java`, `Tunables.java`, `Controls.java`, and `Actions.java` and the autos when you need them. 3. **Find its numbers:** the finder that measures them. 4. **Check it, then tune it:** a short test on the robot, then the numbers to tune. 5. **Look it up:** the reference page with every setting. | Part | Page | | --- | --- | | Lift: a slide that goes to named heights | [Add a lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/) | | Arm: a motor that turns to named angles | [Add an arm](https://crossbotics.com/ftc-helper/docs/add-to-robot/02-arm/) | | Claw, wrist and other servo parts | [Add a claw and other servo parts](https://crossbotics.com/ftc-helper/docs/add-to-robot/03-claw/) | | Intake: takes pieces in | [Add an intake](https://crossbotics.com/ftc-helper/docs/add-to-robot/04-intake/) | | Launcher: a flywheel that shoots pieces | [Add a launcher](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/) | | Turret: turns the launcher | [Add a turret](https://crossbotics.com/ftc-helper/docs/add-to-robot/06-turret/) | | Camera: sees the goal, to aim | [Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/) | | Lights: show the drivers what the robot does | [Add lights](https://crossbotics.com/ftc-helper/docs/add-to-robot/08-lights/) | | Odometry: knows where the robot is on the field | [Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/) | | Lift, arm and claw in one move, with a safety rule | [Make parts work together](https://crossbotics.com/ftc-helper/docs/add-to-robot/10-parts-together/) | | Pedro paths: drive smooth paths in autos (a Building autos page) | [Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/) | --- **Next:** [Add a lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/). --- # Signs and units URL: https://crossbotics.com/ftc-helper/docs/conventions/ ## Driving ![Robot seen from above: which way is positive](https://crossbotics.com/ftc-helper/docs/images/robot-signs.svg) | Value | Positive means | Where you see it | | --- | --- | --- | | `forward` | robot moves forward | `MecanumDrive.drive`, `TankDrive.arcade`, the mixers | | `strafeRight` | robot moves to its right (mecanum only) | `MecanumDrive.drive`, `MecanumMixer.mix` | | `turnClockwise` | robot turns right (clockwise, seen from above) | same | | IMU heading | robot turned **left** (counterclockwise) | `ImuSetup.headingDeg`, `AutoDrive.turn`, `AutoDrive.turnTo`, `FieldPose.headingDeg` | | `move(..., directionDeg, ...)` | counterclockwise from forward, like a heading: 0 forward, 90 **left**, 180 back, -90 **right** | `AutoDrive.move`, `Steps.move` | | `moveWithTurn(..., directionDeg, headingDeg, ...)` | both counterclockwise, from the start heading (the direction stays fixed on the field, because the robot turns on the way): 90 = left | `AutoDrive.moveWithTurn`, `Steps.moveWithTurn` | **In an autonomous, every angle counts the same way: counterclockwise, 90 = left.** This is true for a move's direction, a turn and a heading. In `Steps`, you can also use words with no angle at all: `forward`, `back`, `left`, `right`, `turnLeft`, `turnRight` ([the autos/ page](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#more-steps)). Before v0.40.0, a move's direction counted clockwise (90 = right). To update an old auto, read the CHANGELOG. **Why TeleOp's turn command is clockwise-positive, but every autonomous angle is counterclockwise-positive:** - The right stick's X is positive when you push it right. Pushing right should turn the robot right. So `drive(forward, strafe, gamepad1.right_stick_x)` works with no sign change. - The FTC SDK's IMU makes the heading grow when the robot turns left. That is the math rule (counterclockwise = positive), and we do not fight the SDK. The names tell you which one you have: `turnClockwise`, `headingCcwDeg` ("CCW" = counterclockwise). ## Gamepad sticks The SDK gives **negative** `left_stick_y` when you push the stick UP (away from you). So "forward" is `-gamepad1.left_stick_y`. Every example in these docs has the minus sign. ## Servos and motors: which way is "bigger"? There is **no standard** for this, so the library makes no promise about it: - A servo position from 0 to 1 is a pulse length: 0 is the short pulse, 1 the long one. Which way a bigger number turns the shaft (clockwise or counterclockwise) depends on the servo's brand and model. - Which way positive power turns a motor also depends on the motor and its gearbox. - `.reversed()` in Robot.java swaps the ends (servo: 0 and 1; motor: + and -). It changes the numbers, not the wiring. So **check each one by test**, never by its label. In the Servo Finder, press D-pad up (a bigger number) and watch which way the part moves. For a motor, use the Motor Finder or the Hardware Check. Then choose the numbers (or `.reversed()`) so they read the way you think about the part. Any order is fine for named positions: a claw's `open` can be higher or lower than `closed`. **Two servos that face each other** (one on each side of a claw, an arm or a pinch): the same number turns them opposite ways, as seen from outside. So such a part uses `alsoServoReversed` (the second servo mirrors the first). Two servos facing the same way use `alsoServo` ([two servos on one part](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/)). ## Units | Thing | Unit | | --- | --- | | Distances (drive) | inches | | Angles | degrees | | Motor power | -1 to 1 | | Servo position | 0 to 1 | | Mechanism positions (lifts, arms) | encoder ticks (counts) | | Time | seconds, unless the name ends in `Ms` (milliseconds) or `Nanos` | ## Wheel order Any array of four wheel values is in this order: `[front-left, front-right, back-left, back-right]` Standard (tank) drive left/right arrays are `[left, right]`. `MecanumMixer.FRONT_LEFT` (0), `FRONT_RIGHT` (1), `BACK_LEFT` (2), `BACK_RIGHT` (3) name the positions. ## Button names: START and ▶ - **▶** is the Driver Hub's start button: press it after INIT to start the OpMode. The screens never call it START. - **■** is the Driver Hub's stop button (STOP). - **START** is the small button on the gamepad (OPTIONS on a PS controller). - In the docs, the Driver Hub's start is always ▶: "press ▶ (start on the Driver Hub)" the first time on a page, then "▶" or "after ▶". The moment the OpMode starts is "at ▶" or "when the OpMode starts (▶)". The gamepad's button is "the gamepad's START button", or "START (OPTIONS on a PS controller)". Code names keep their words (`atStart`, `Btn.START`). - The docs use the Logitech names (A, B, X, Y, LB, RB, LT, RT, BACK, START, GUIDE). The library's screens show the names on YOUR controller: × ○ □ △, L1 R1 L2 R2, SHARE OPTIONS PS on a PlayStation one ([ButtonNames](https://crossbotics.com/ftc-helper/docs/modules/gamepad/#buttonnames)). --- # Cookbook: "How do I...?" URL: https://crossbotics.com/ftc-helper/docs/cookbook/ **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`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/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](https://crossbotics.com/ftc-helper/docs/pick-your-start/) and [The five files](https://crossbotics.com/ftc-helper/docs/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](https://crossbotics.com/ftc-helper/docs/cookbook/01-the-basics/#words-you-will-meet) first. ## The questions **Start here** - [Coming from Blocks: where did my blocks go?](https://crossbotics.com/ftc-helper/docs/cookbook/01-the-basics/#coming-from-blocks-where-did-my-blocks-go) (if, loop, sleep, REVERSE, variables) - [Where does each line go? The files, whole](https://crossbotics.com/ftc-helper/docs/cookbook/01-the-basics/#where-does-each-line-go-the-files-whole) - [Words you will meet](https://crossbotics.com/ftc-helper/docs/cookbook/01-the-basics/#words-you-will-meet) - Whole robots to start from: the [templates](https://crossbotics.com/ftc-helper/docs/templates/) (ten whole example robots) and the [kit robots](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/) (goBILDA, REV, AndyMark, Studica starter bots) **Driving** - [How do I set up a mecanum drive?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#how-do-i-set-up-a-mecanum-drive) - [How do I set up a tank (standard) drive?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#how-do-i-set-up-a-tank-standard-drive) - [A wheel turns the wrong way. How do I fix it?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#a-wheel-turns-the-wrong-way-how-do-i-fix-it) - [How do I tell the robot how the Control Hub is mounted?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#how-do-i-tell-the-robot-how-the-control-hub-is-mounted) - [How do I make the robot slower (or faster)?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#how-do-i-make-the-robot-slower-or-faster) - [How do I let one driver do everything?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#how-do-i-let-one-driver-do-everything) - [How do I put slow mode on a trigger?](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#how-do-i-put-slow-mode-on-a-trigger) - [Driving that is already built in](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#driving-that-is-already-built-in) (field-centric, pause, "forward") **Buttons and gestures** - [How do I make a button do something once?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-make-a-button-do-something-once) - [How do I run something only while a button is held?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-run-something-only-while-a-button-is-held) - [How do I switch something on and off with one button?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#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")?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-make-a-button-safe-hold-for-1-second) - [How do I use two buttons together (like a shift key)?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-use-two-buttons-together-like-a-shift-key) - [How do I make the gamepad buzz?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-make-the-gamepad-buzz) - [How do I control a part with a stick?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-control-a-part-with-a-stick) - [How do I move a part's button to another button?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-move-a-parts-button-to-another-button) - [How do I put the launcher's fire button on another button?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-put-the-launchers-fire-button-on-another-button) - [How do I let the parts add their usual buttons by themselves?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#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)?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-move-the-librarys-own-buttons-slow-field-centric-pause) - [How do I change the double-tap and hold times?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-change-the-double-tap-and-hold-times) - [How do I switch the alliance during TeleOp?](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-switch-the-alliance-during-teleop) - [Buttons that are already built in](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#buttons-that-are-already-built-in) (button map, pause, switch alliance, set pose) **Mechanisms** - [How do I add an intake on a motor?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-an-intake-on-a-motor) - [How do I add an intake on CR servos?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-an-intake-on-cr-servos) - [How do I make the intake run from the start?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-make-the-intake-run-from-the-start) - [How do I add a lift with set heights?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-lift-with-set-heights) - [My lift goes down when it should go up. How do I fix it?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#my-lift-goes-down-when-it-should-go-up-how-do-i-fix-it) - [How do I run one lift on two motors?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-run-one-lift-on-two-motors) - [My motor isn't in the catalog](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#my-motor-isnt-in-the-catalog) - [How do I add an arm that moves in degrees?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-an-arm-that-moves-in-degrees) - [How do I add a claw?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-claw) - [How do I run a claw on two servos?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-run-a-claw-on-two-servos) - [How do I add a wrist?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-wrist) - [How do I add any servo with named positions (a gate, a fold-out)?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-any-servo-with-named-positions-a-gate-a-fold-out) - [How do I get my servo's full range?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-get-my-servos-full-range) - [How do I send a part to a position from a button?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#my-robot-doesnt-have-this-part-yet-how-do-i-keep-its-code) - [How do I add a launcher (flywheel and feeder)?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-launcher-flywheel-and-feeder) - [How do I feed with two wheels, one on each side?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-feed-with-two-wheels-one-on-each-side) - [How do I add a turret that follows the goal?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-turret-that-follows-the-goal) - [How do I fire only when aimed, at the right speed?](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-know-which-piece-is-in-the-robot-and-how-many) - [How do I stop the intake when the robot is full?](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-stop-the-intake-when-the-robot-is-full) - [How do I tell pieces apart by size, or with a second camera?](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-tell-pieces-apart-by-size-or-with-a-second-camera) - [How do I use the count (buzz, LEDs, the shot table)?](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-use-the-count-buzz-leds-the-shot-table) - [How do I let the next piece pick the shot table?](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-let-the-next-piece-pick-the-shot-table) - [How do I tune the piece sensors?](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#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)?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-make-the-gamepad-buzz-when-the-aim-is-on-target) - [How do I keep aiming when the camera loses the goal?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-keep-aiming-when-the-camera-loses-the-goal) - [How do I aim with the odometry only (no camera)?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-aim-with-the-odometry-only-no-camera) - [How do I make the camera work in any venue's light?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-make-the-camera-work-in-any-venues-light) - [How do I find game pieces with a HuskyLens?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-find-game-pieces-with-a-huskylens) - [How do I shoot while the robot is driving?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-shoot-while-the-robot-is-driving) - [How do I use one shot table per game piece?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#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)?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/07-turrets-and-interlocks/#how-do-i-home-my-turret-with-a-switch) - [How do I set up a turret on a servo?](https://crossbotics.com/ftc-helper/docs/cookbook/07-turrets-and-interlocks/#how-do-i-set-up-a-turret-on-a-servo) - [How do I set up a slip-ring turret (round and round)?](https://crossbotics.com/ftc-helper/docs/cookbook/07-turrets-and-interlocks/#how-do-i-set-up-a-slip-ring-turret-round-and-round) - [How do I stop two parts from hitting each other?](https://crossbotics.com/ftc-helper/docs/cookbook/07-turrets-and-interlocks/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/07-turrets-and-interlocks/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-do-several-things-one-after-the-other) - [How do I repeat steps several times?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-repeat-steps-several-times) - [How do I move two parts at the same time?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-move-two-parts-at-the-same-time) - [How do I wait half a second (like sleep in Blocks)?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-wait-half-a-second-like-sleep-in-blocks) - [How do I wait until something is true?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-wait-until-something-is-true) - [How do I start an action from a button?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-start-an-action-from-a-button) - [How do I stop every running action?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-stop-every-running-action) - [How do I run an action when the OpMode starts?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-run-an-action-when-the-opmode-starts) - [How do I use the same action in an autonomous?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-use-the-same-action-in-an-autonomous) **Autonomous** - [How do I make my first autonomous (drive 2 feet)?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-make-my-first-autonomous-drive-2-feet) - [How do I drive forward, sideways and turn?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-drive-forward-sideways-and-turn) - [Does my autonomous need a RED version?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#does-my-autonomous-need-a-red-version) - [How do I let the drivers choose before the match?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-let-the-drivers-choose-before-the-match) - [How do I make sure there is time to park?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-make-sure-there-is-time-to-park) - [How do I run a mechanism while the robot drives?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-run-a-mechanism-while-the-robot-drives) - [How do I wait for my alliance partner?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-wait-for-my-alliance-partner) - [How do I write a step the list cannot say?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-write-a-step-the-list-cannot-say) - [How do I change a distance in an autonomous?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-change-a-distance-in-an-autonomous) - [How do I share the same first steps in several autos?](https://crossbotics.com/ftc-helper/docs/cookbook/09-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?](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#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](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/)) - [How do I build several autos from the same pieces?](https://crossbotics.com/ftc-helper/docs/cookbook/10-several-autos/#how-do-i-build-several-autos-from-the-same-pieces) - [How do I make two autos that differ by one piece?](https://crossbotics.com/ftc-helper/docs/cookbook/10-several-autos/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/10-several-autos/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-add-a-gobilda-pinpoint) - [How do I add a SparkFun OTOS?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-add-a-sparkfun-otos) - [How do I add dead wheels?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-add-dead-wheels) - [How do I tune the odometry?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-tune-the-odometry) - [How do I drive to a point on the field?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-drive-to-a-point-on-the-field) - [How do I get around field elements on the way to a spot?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-get-around-field-elements-on-the-way-to-a-spot) - [How do I show where the robot is?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-show-where-the-robot-is) - [How do I use the robot's position in an action?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-use-the-robots-position-in-an-action) - [How do I set the pose when autonomous did not run?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#how-do-i-add-pedro-pathing-to-robotjava) - [How do I make a straight path and a curve?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#how-do-i-make-a-straight-path-and-a-curve) - [How do I follow a path in an autonomous?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#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)?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/13-telemetry/#how-do-i-show-a-value-on-the-driver-station-screen) - [How do I round a number on the Driver Station?](https://crossbotics.com/ftc-helper/docs/cookbook/13-telemetry/#how-do-i-round-a-number-on-the-driver-station) - [How do I show lines from my own autonomous step?](https://crossbotics.com/ftc-helper/docs/cookbook/13-telemetry/#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?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-add-a-colored-light-for-the-drivers) - [How do I change a color on a REV Blinkin?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-change-a-color-on-a-rev-blinkin) - [How do I show a color when something is true?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-show-a-color-when-something-is-true) - [How do I show the alliance on the light before the match?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-show-the-alliance-on-the-light-before-the-match) - [How do I flash the light when something happens?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-flash-the-light-when-something-happens) - [How do I flash the light when an action is done?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-flash-the-light-when-an-action-is-done) - [How do I blink the light in the last 20 seconds?](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/#how-do-i-blink-the-light-in-the-last-20-seconds) **Tuning and finders** (getting the numbers right) - [Where do the numbers go?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#where-do-the-numbers-go) - [How do I find a servo's open and closed numbers?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-find-a-servos-open-and-closed-numbers) - [How do I find a lift's limits and heights?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-find-a-lifts-limits-and-heights) - [How do I change a number while the robot runs?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-change-a-number-while-the-robot-runs) - [How do I tune the drive for autonomous?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-tune-the-drive-for-autonomous) - [How do I set the flywheel numbers?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-set-the-flywheel-numbers) - [How do I build a shot table (speed for each distance)?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-build-a-shot-table-speed-for-each-distance) - [How do I find my hood's stops and angles?](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-find-my-hoods-stops-and-angles) **Simulator** (try your code with no robot) - [How do I start the simulator?](https://crossbotics.com/ftc-helper/docs/cookbook/16-simulator/#how-do-i-start-the-simulator) - [How do I see my own robot in the simulator?](https://crossbotics.com/ftc-helper/docs/cookbook/16-simulator/#how-do-i-see-my-own-robot-in-the-simulator) - [How do I make the simulator draw my part?](https://crossbotics.com/ftc-helper/docs/cookbook/16-simulator/#how-do-i-make-the-simulator-draw-my-part) - [How do I test my code with a script?](https://crossbotics.com/ftc-helper/docs/cookbook/16-simulator/#how-do-i-test-my-code-with-a-script) ## Not here? - Every class and method: the [reference](https://crossbotics.com/ftc-helper/docs/reference/) and the [module pages](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/README.md#what-is-inside). - Something goes wrong: [Troubleshooting](https://crossbotics.com/ftc-helper/docs/troubleshooting/). - Learn it step by step: [The five files](https://crossbotics.com/ftc-helper/docs/five-files/), then [Add to your robot](https://crossbotics.com/ftc-helper/docs/add-to-robot/). - A question the cookbook does not answer: [tell us](https://github.com/crossbotics/ftc-helper-lib/issues/new/choose). --- # Coming from last season's code URL: https://crossbotics.com/ftc-helper/docs/from-last-season/ Each reusable part of last season's code has a new name in the library, and some parts changed. Game-specific code (launcher, feed, intake, vision, routes) is NOT in the library. | Last season | Now | What changed | | --- | --- | --- | | `input/ControllerBindings` | `gamepad.ControllerBindings` | Same `bindPress`/`bindHold`/`bindToggle`/`bindTriggerPress`/`bindTriggerAxis`. New: `bindRelease`, `bindTriggerHold`, `setTriggerThreshold`, `ignoreHeldButtons` (replaces the per-button "seeded" press), `isDown`, `GUIDE` and `TOUCHPAD` buttons. Fixed: trigger presses no longer borrow the bumper's slot. `registerExtraButtonReader` is now `registerExtraButton`. | | `input/DriveInputScaling.slowScale` | `gamepad.StickShaping.slowScale(trigger, slowest)` | The slowest speed is a parameter instead of a static setting. New: `curve`, `shape`. | | `input/ReverseDriveControl` | `drive.ReverseDrive` | No longer binds a button itself; you bind it (see [drive.md](https://crossbotics.com/ftc-helper/docs/modules/drive/#reversedrive)). | | `utils/RumbleNotifier` | `gamepad.AimRumble` | Same feel and defaults. `setMinMax` is now `setFeel`; `setActive` is `setEnabled`. | | `utils/ToggleRumble` | `gamepad.ToggleRumble` | You set the pattern with `setPattern` instead of a static config class. `isConfirming` is now `isPlaying`. | | `drive/MecanumMixer` | `drive.MecanumMixer` | Same `mix`. `fieldVector` is now `fieldDirection`, and its first number counts counterclockwise (90 = left) since v0.40.0. New: `fieldToRobot` for field-centric TeleOp. | | `drive/MecanumDrive` | `drive.MecanumDrive` | Takes a `DriveConfig` object instead of the static `RobotConfig`. New: `driveFieldCentric`, `setPowers`, `setBrake`. | | `drive/Drivebase` (Auto helpers) | `drive.AutoDrive` | Settings come from `AutoDriveConfig` (same default numbers as `DriveTuning`). `moveWithTwist` is now `moveWithTurn`. New: `turnTo`, a `Result` for each move. Changes below. | | `config/DriveTuning` | `drive.AutoDriveConfig` | Fields renamed in plain words, for example `TURN_KP` is `turnKp`, `AUTO_MOVE_MIN_SPEED` is `moveMinPower`. | | `odometry/FieldPose`, `odometry/PoseStore` | `util.FieldPose`, `util.PoseStore` | `setLastKnownPose`/`consumeLastKnownPose` are now `save`/`consume`; `peek`, `has` and `clear` remain. | | `auto/BaseAuto` + `AutoSequence` | `auto.AutoRoutine`, `auto.EasyAuto` | Same idea (a chain of named steps, endgame/park reserve, remembered heading). Game steps (fire, intake rows) are gone: mechanisms give their own steps. The routine mirrors the steps for RED. | | `subsystems/Launcher`, `control/FiringController`, `config/AutoRpmConfig` | `launcher.Flywheel`, `launcher.Launcher`, `launcher.ShotTable` | General versions: RPM with settle time and shot detection; readiness gating with named checks and a give-up reason; distance table with hood angles. Last season's live speed scale is the speed trim (`robot.launcher.trimBy`, the D-pad), and the flywheel can make up for a low battery (`Flywheel.batteryCompensation`). Battery compensation is off by default. | | `subsystems/Feed` | `launcher.MotorFeeder`, `launcher.ServoFeeder` (`Feeder` interface) | One piece per call; the launcher decides when. | | `subsystems/Intake` jam logic | `mechanism.SpinMotor`, `safety.JamDetector` | General jam detection and back-out; the DECODE packing states are not included. | | `vision/*` | `vision.WebcamTags`, `vision.LimelightTags`, `vision.AimController` | Rewritten for SDK 12 (single tags and clusters). Bearing is + = left for both cameras. No field localization (BIOBUZZ tags move). | | `Alliance`, `TeleOp_Blue`/`TeleOp_Red` | `match.Alliance`, `match.MatchMemory` | One TeleOp for both alliances: it reads the alliance autonomous chose. | | TeleOp auto-stop timer | `match.MatchTimer` | Countdown with cues and gamepad buzzes. | | `config/*` tunables + FTC Dashboard | `tuning.Tunable`, `tuning.TuningMenu`, `core.Profile` | Tune from the gamepad, saved on the hub; Dashboard still optional. | | (new) | `drive.TankDrive` (standard drive), `safety.SafeMotor`, `control.PidController`, `control.SlewRateLimiter`, `telemetry.TelemetryHelper`, `hardware.*` | New helpers. | ## Behavior changes in AutoDrive (on purpose) - **Power limit:** `DriveConfig.powerLimit` now applies to every autonomous move and turn. - **Diagonal distance:** AutoDrive measures distance from the real forward and sideways travel. Before, a 45 degree move stopped short (about 17 of 24 inches), and the strafe correction had no effect on pure strafes. `strafeCorrection` also raises the sideways power, so diagonals keep their direction. **Re-tune `strafeCorrection`** with the steps in drive.md. - **moveWithTurn** finishes its turn only after a successful move, and inside the same time limit. Before, a stuck robot could start turning, and the time limit could nearly double. - **Negative distance** now drives the opposite way. Before, `move(-10, 0, ...)` drove FORWARD 10 inches. - **Stall check** looks at progress over a time window (0.25 in within 0.4 s by default). Before, it checked each loop, so a fast loop could wrongly decide a slow-moving robot was stuck. - `AUTO_STALL_VELOCITY_EPSILON` is gone; `stallProgressIn` and `stallTimeSec` do the whole job. - `turnMinPower` (new, default 0 = old behavior) can stop turns from stalling a little short. - Every move returns `DONE`, `STALLED`, `TIMED_OUT` or `STOPPED`. - We removed unused leftovers (`setRunToPosition`, `restoreBaseRunMode`, the TeleOp `drive()` inside Drivebase). For TeleOp, use `MecanumDrive`. --- # Simulator URL: https://crossbotics.com/ftc-helper/docs/simulator/ The simulator is a pretend Control Hub and Driver Hub. Your OpModes run as they are. The motors, servos, switches, turn sensor (IMU), cameras and the robot on the field are pretend, with simple physics. You drive the robot from a web page, with a gamepad, the keyboard or a phone. - **Good for:** checking buttons and screens, trying an autonomous, testing the finders and camera code, learning the controls, and finding crashes before a meeting. - **Not for:** exact speeds, real shots or real camera pictures. You still tune the real robot ([Tuning](https://crossbotics.com/ftc-helper/docs/tuning/)). ![The simulator page: the Driver Hub on the left, the field in 3D in the middle with the gamepads under it, and the Control Hub's panels on the right](https://crossbotics.com/ftc-helper/docs/images/simulator.png)
flowchart LR
    P["Browser page<br/>Driver Hub + gamepads + Control Hub"] <--> S["Simulator (Java on the laptop)<br/>your OpModes + pretend hardware + physics"]
    C["Real controller<br/>(USB or Bluetooth)"] --> P
    K["Keyboard"] --> P
    Ph["Phone on the same WiFi<br/>(touch gamepad)"] --> S
| # | Page | You learn | Use it | | --- | --- | --- | --- | | 1 | [Start it and drive](https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/) | Start the simulator, read the page, and drive with a gamepad, the keyboard or a phone. | when you have the library in your project | | 2 | [Your robot file](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/) | The text file that tells the simulator about your robot. The simulator makes it from `Robot.java`, and marks what it guessed. | when your robot has the five files | | 3 | [Make it match your robot](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/) | Size and wheels, then the parts and their shapes, where the pieces go in and out, and CAD (your robot's 3D design files). Worked examples for the common setups. | when you want the pretend robot to act like yours | | 4 | [Watch an autonomous](https://crossbotics.com/ftc-helper/docs/simulator/04-watch-an-autonomous/) | Run your autonomous, watch the score, and read the report. | after each change to an autonomous | **Tests:** the simulator can also check your code after every change. That is its own section: [Tests](https://crossbotics.com/ftc-helper/docs/tests/). --- **Next:** [Start it and drive](https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/). **Look it up:** [The robot file](https://crossbotics.com/ftc-helper/docs/reference/robot-file/): every line. [Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/): the test language. **Go deeper:** [How the simulator works](https://crossbotics.com/ftc-helper/docs/guides/how-the-simulator-works/): the physics, the game rules and the score, shots, cameras, and what it does not simulate. --- # Pick your template URL: https://crossbotics.com/ftc-helper/docs/templates/ **For:** a team that starts its robot code. **You need:** the library in your robot project ([Add the library](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/)). If you are new to the library, start at [Pick your start](https://crossbotics.com/ftc-helper/docs/pick-your-start/): short pages for the same choice, one per start. A **template** is robot code you copy and then change. Start from the one that looks most like your robot: you delete less and type less. Most of them (all but the last row) are a robot in five files: `Robot.java`, `Tunables.java`, `Controls.java`, `Actions.java` and an `autos` folder ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/) explains them). Some have extra files: a finder that knows the robot (`lessonbot/DriveTuner.java`, `odometrybot/OdometryTuner.java`, `turretbot/HoodFinder.java` and `ShotTuner.java`), or Pedro's numbers (`pedrobot/PedroConstants.java`). Copy them with the rest. ## Your robot looks like this: start from that | Your robot looks like... | Start from | What it has | | --- | --- | --- | | **anything, and its configuration is on the Driver Station** | `./gradlew :sim:newRobot` ([Blank slate, way A](https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/#way-a-from-your-configuration)) | five files made for you from your configuration, with each part's line and TODO marks, and every setting in `Tunables.java` as `DEFAULT` or `MEASURE` ([the two words](https://crossbotics.com/ftc-helper/docs/reference/tunables/#default-and-measure)) | | a mecanum drive and an intake, no configuration yet | [`quickstart`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/quickstart) ([Blank slate, way B](https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/#way-b-copy-the-smallest-files)) | the smallest robot, with STEP marks on every line to change | | a mecanum drive, an intake, a lift and a claw | [`lessonbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/lessonbot) | the example robot of The five files and Add to your robot, and its Drive Tuner | | **goBILDA's FTC StarterBot** (BIOBUZZ) | [`gobildabot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/gobildabot) | tank drive, intake with two corner wheels, flywheel and "windmill" feeder; goBILDA's own names | | **goBILDA's FTC StarterBot with Mecanum Wheels** (BIOBUZZ, Strafer chassis) | [`gobildastraferbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/gobildastraferbot) | mecanum drive, intake with two corner wheels, flywheel and "windmill" feeder; goBILDA's own names | | **REV's DUO FTC Starter Bot** (BIOBUZZ) | [`revbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/revbot) | tank drive, intake, flywheel and CR-servo feeder, the pollen pusher ("poker"); REV's own names | | **AndyMark's Robits BIOBUZZ StarterBot** | [`andymarkbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/andymarkbot) | tank drive, roller intake, the catapult (see the note below); AndyMark's own names | | **Studica's FTC Starter Bot** (BIOBUZZ) | [`studicabot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/studicabot) | tank drive, intake, flywheel and servo flap (see the note below); Studica's own names | | a tank drive and a flywheel shooter | [`flywheelbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/flywheelbot) | intake on from the start, a deploy servo, a flywheel the driver speeds up and down, a servo feeder, a webcam and whole-robot aim (no turret) | | a mecanum drive with a turret and a camera | [`turretbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/turretbot) | a Limelight that the turret follows, speed and hood angle from distance with a POLLEN and a NECTAR table (a hood servo, Hood Finder), a buzz when on target, a folding claw, a Shot Tuner ([Add a launcher](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/)) | | a turret shooter AND a lift with a wrist and a claw (two parts that share space) | [`v2bot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/v2bot) | team 8938's 2026-27 designs: a turret on a magnetic home switch (+/-190 degrees), a hood, odometry, a piece count, a Viper-Slide lift with a wrist and a claw, the lifter's steps as actions, and an [interlock rule](https://crossbotics.com/ftc-helper/docs/guides/interlocks/) that keeps the turret out of the back while the wrist holds the claw low behind the robot | | a mecanum drive with odometry (Pinpoint, OTOS or dead wheels) | [`odometrybot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/odometrybot) | `driveTo` field points, the Odometry Tuner ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/)) | | a mecanum drive with odometry and Pedro Pathing | [`pedrobot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/pedrobot) | `odometrybot` plus paths ([Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/)); add Pedro to the project first ([Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/#your-project-add-the-pedro-add-on-once)) | | you already use the older six-file starter kit | [`starter`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/starter) ([Starter kit](https://crossbotics.com/ftc-helper/docs/starter-kit/)) | `EasyTeleOp` and `EasyAuto`; kept for teams that use it. New teams: use a row above | **If you are not sure:** use `:sim:newRobot` if your configuration is ready, and `quickstart` if it is not. You can copy single lines from the other templates later (for example the launcher line from `flywheelbot`). **The kit bots** use the same configuration names as each seller's own code, so the files run on that kit as it is. Where each number comes from, and what each kit bot's code does differently (buttons, guessed numbers): [The BIOBUZZ starter bots](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/) ([REV](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#rev-bot-code), [goBILDA](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#gobilda-bot-code), [AndyMark](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#andymark-bot-code), [Studica](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#studica-bot-code)). Two kit mechanisms are not parts of the library, so their templates use the closest part and say so in `Robot.java`: - **AndyMark's catapult:** the library has no catapult. The template drives its motor as an `Indexer` that runs for a set time per press. Tune that time so one press is one throw. The library cannot tell when the catapult is wound, so it cannot wait for "ready" as a flywheel does. - **Studica's flywheel:** the launcher cannot take the 2:1 gear between the motor and the wheels. The flywheel speed in `Tunables.java` is the motor's (the wheels turn at half of it). Tune it by watching shots. The Maverick motors and the servo are not in the parts catalog: `Robot.java` describes them with Studica's numbers ([Parts not in the catalog](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-in-the-catalog)). ## Copy a template into TeamCode If you used `:sim:newRobot`, skip this part: it writes the files into TeamCode for you. For every other template, follow [Copy example files into TeamCode](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/): the `package` lines, the imports, the `@Disabled` lines and the OpMode names. Then build. Check the motor directions with the wheels off the ground ([Robot.java](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/)). Check every part with the Hardware Check: [Check the hardware](https://crossbotics.com/ftc-helper/docs/tutorials/19-testing-procedures/). **Numbers:** every number in `Tunables.java` is a starting value. Find the real ones with the [finders](https://crossbotics.com/ftc-helper/docs/tuning/). The hub saves a number you change live on the robot (in the tuning menu). It keeps using that saved value, even after you edit the number in `Tunables.java`, and another hub does not have it. So copy each new value back into `Tunables.java`. INIT lists the values that differ. **Try it first in the simulator.** The kit bots have robot files. Run one, then pick "REV Bot TeleOp" ([Simulator guide](https://crossbotics.com/ftc-helper/docs/simulator/)). `-PteamCode=none` runs the **library's** example, not your copy. **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ([Which folder](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#which-folder)) `./gradlew :sim:run -Probot=sim/robots/starter-bot-rev.properties -PteamCode=none` **Your copy in the simulator.** Run your TeamCode with the kit's measured robot file: **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ([Which folder](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#which-folder)) `./gradlew :sim:run -Probot=sim/robots/starter-bot-rev.properties -PteamCode=../TeamCode` You can also copy that file to `simulator/robot.properties` in your robot project. Then you do not need `-Probot`. Use the kit's file. A file from `:sim:fromRobot` guesses an 18 x 18 in robot. Then the REV, AndyMark and Studica bots start "overlapping the field wall" on BLUE. **What the simulator cannot show yet** (so you know the problem is not in your copy): - The REV, AndyMark and Studica bots do not shoot in the simulator: their robot files have no shot line. Their flywheels may also never say `READY`, because the example speeds are higher than the simulated motor reaches. Tune the speed on the real robot. - An autonomous whose `start(...)` gives no spot (only a note and a heading) starts where the last program left the robot. Press **Back to start** (Control Hub panel, Robot tab) before you run it. - Some INIT lines are normal in the simulator: `!! Drive not tuned: runs in the simulator only` (on the robot, the autonomous waits for the Drive Tuner), a turret's `Turret : no angle from a program before: ...` (turn it to its start angle on the robot), and a camera's `limelight lighting : trying ...` until it sees a tag. ## Next [The five files](https://crossbotics.com/ftc-helper/docs/five-files/): what each file is for. Then [Add to your robot](https://crossbotics.com/ftc-helper/docs/add-to-robot/): one page per part. --- # Tests URL: https://crossbotics.com/ftc-helper/docs/tests/ A test asks one of two questions: - **Is my robot code right?** A simulator test drives your robot on the laptop and checks the result. It finds a break you did not mean to make: a typo, a wrong button, a number in the wrong section. - **Is my robot right?** A check on the real robot finds a loose cable, a reversed motor, a flat battery or a wrong setting before a match. ![Two kinds of tests: simulator tests on the laptop check the robot code (pages 1 and 2); checks on the real robot check the robot (page 3)](https://crossbotics.com/ftc-helper/docs/images/tests-two-questions.svg) | # | Page | You learn | Use it | | --- | --- | --- | --- | | 1 | [Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/) | Record a test in the simulator, read it line by line, set how close is close enough, and update it after a planned change. | when your robot drives and has an autonomous | | 2 | [Run all your tests](https://crossbotics.com/ftc-helper/docs/tests/02-run-all-your-tests/) | Run every test with one button or one command. For programmers: laptop tests in Java. | after every code change, and before you commit | | 3 | [Checks before practice and matches](https://crossbotics.com/ftc-helper/docs/tests/03-checks-before-practice-and-matches/) | A fixed order of checks on the real robot, printable checklists, and what to do when something breaks. | after wiring, after a mechanism change, before practice, and before every match | **Why both:** a simulator test cannot find a loose cable, and a check on the robot cannot find a break in code that you did not run. Do both. --- **Next:** [Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/). --- # Troubleshooting URL: https://crossbotics.com/ftc-helper/docs/troubleshooting/ ## Build problems **Project directory '.../ftc-helper-lib/library' does not exist** The submodule folder is empty: someone cloned the project (copied it from GitHub) without the library in it. Run this command. **Where:** Android Studio's **Terminal** tab, in the **project folder** (a new Terminal tab starts there). ([Which folder](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#which-folder)) ```bash git submodule update --init ``` **Cannot resolve symbol 'crossbotics' / red imports** Gradle does not know about the library yet. Check steps 2 and 3 in [Add the library](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/), then **File > Sync Project with Gradle Files**. **Plugin [id: 'com.android.library'] was not found** Your project's top `build.gradle` (the one in the project folder, not in TeamCode) must list the Android library plugin. Every FtcRobotController project does (`id 'com.android.library' version '...' apply false`). If yours is very old, update the SDK. **Errors in the library after an FTC SDK update** See [A new FTC SDK version](https://crossbotics.com/ftc-helper/docs/02-keep-up-to-date/#a-new-ftc-sdk-version). ## Driver Station errors **INIT STOPPED: the robot did not start.** The library found a mistake at INIT. The line under it says what is wrong and how to fix it: find it below. Nothing moves. Press STOP, fix it, then press INIT again. (After ▶ on the Driver Hub, a mistake shows after every part has stopped. It shows as the FTC app's red line, User code threw an uncaught exception: .... The words after the dash are the same messages as below.) A mistake in your own code (not a library message) shows its kind and where it is. For example: NullPointerException in Robot.java line 42. Open that line. **No DcMotorEx named "..." in the active robot configuration** - or No Servo named "intake_deploy" ... The name in code and the name in the Driver Station configuration differ. The message lists the names that do exist. Fix the spelling, or pick the right configuration on the Driver Station. **When the part is not on the robot yet,** the message ends Not on the robot yet? Add .optional() ... Add `.optional()` to its line in Robot.java. Then INIT goes on and says the part is off. Its buttons and actions skip it until it is in the configuration ([parts not on the robot yet](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-on-the-robot-yet)). The [Hardware Check](https://crossbotics.com/ftc-helper/docs/modules/testing/#hardwarecheckopmode) with `robot()` lists every Robot.java device the configuration is missing. **libraryButtons: Two library features are on G1 BACK: "pause / go on" and "debug lines". A button can do only one. ...** - or Two hold-down library features are on ... - or G1 LT is the slow trigger, and also ... - or G1 A cannot open the tuning menu ... In `libraryButtons(...)` in Controls.java, you moved one of the library's features onto a button that already has one. The message ends with the line to change: move that feature to a free button (`lib.debug(g1.start, null)`), or turn it off with `null` (`lib.debug(null, null)`). [Moving the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/). **Tunables.Lift has no max: write max (the top of the safe range, in counts: Motor Finder, B). A safety limit never comes from a library default.** - or has no min - or Tunables.java has no Lift section - or the same for Arm, in deg INIT stops on purpose: a lift or arm must never use a library default for its safe range. Run the [Motor Finder](https://crossbotics.com/ftc-helper/docs/tuning/), then write `min` and `max` in that section of `Tunables.java`. **Tunables.Lift.max must be a public static number (like "public static double max = 1000;"): ...** The field is there but written another way: not `public`, or not a number (for example a `String`). Write it exactly like `public static double max = 2900;`. (Without `static`, it counts as missing: you get has no max instead.) **Tunables.Lift: max (...) must be more than min (...)** The two numbers are swapped or equal. `max` is the top of the safe range, `min` the bottom. **Tunables.Lift.Max looks like "max" (capitals and spelling count). Fix the name in Tunables.java; a position must not look like a setting.** A field name is a known setting with other capitals or an `_` (`Max`, `MAX`, `MIN`, `kp`, `KP`, `k_P`): INIT always stops on this. INIT also stops on a name up to two letters off a setting (`maxPowr`, `maxPwr` for `maxPower`) that the section does not write itself. (`slowZone2` next to a written `slowZone` is a position, not a typo.) Without this stop, the field would quietly become a named position, and the real setting would stay the library's default. Fix the spelling. If it is a position on purpose, give it a name that does not look like a setting. The known names: [Lift](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/). **Tunables.Intake.inPowr is not a setting of Intake (did you mean inPower?): the robot would quietly ignore it. ...** - or the same for any part: Tunables.Aim.goalx, Tunables.Launcher.nominalVolt, Tunables.TurretLift.turetFrom A field in that section is not a name the part reads: a typo, other capitals, or a leftover from an older robot. Before, the library quietly skipped the line, and the part used its default. Fix the name (the "did you mean" is the closest real one. Known: lists them all, and so does the [Tunables reference](https://crossbotics.com/ftc-helper/docs/reference/tunables/)), or delete the line. A number you keep for your own code goes in a section of your own (a name no part uses). An autonomous's distances go in its steps, not in `Tunables.java` ([why](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#the-numbers-are-in-the-step)). **!! Tunables.Launcher is not read by any part: your launcher's section is Tunables.Shooter (its device name "shooter" in CamelCase). Move the numbers there** A part reads the section named after its DEVICE (its configuration name in CamelCase), not after its kind: `Launcher.flywheel("shooter", ...)` reads `Tunables.Shooter`, `Indexer.servo("feeder")` reads `Tunables.Feeder`, `Lift.slide("lift_left")` reads `Tunables.LiftLeft`. Until you move the numbers, the part uses the library's defaults. (INIT also says did you mean Tunables.LiftLeft? for a section spelled almost like a part's.) An interlock rule's fields follow the same name: `liftLeftAbove`, not `liftAbove`. **The interlock line says ... held ...: Turret angle unknown (...)** The library does not know the other part's position yet (a turret looking for its home switch, a servo turret before ▶). So it counts that part as maybe in its zone, and this part waits. It goes on by itself when the angle is known. **AutoDriveConfig.calibrationConfirmed is false** - or AUTONOMOUS IS OFF: the drive is not tuned yet (EasyAuto, Auto) The autonomous stops on purpose: a robot with untuned numbers can drive much too far. Tune `AutoDrive`, then set it to `true`: [Tune AutoDrive](https://crossbotics.com/ftc-helper/docs/modules/drive/#tune-autodrive). With the robot in five files, run the Drive Tuner, then set `Tunables.Drive.calibrated = true`. ## Warnings on the Driver Station (!! ... at the top) | Warning | Meaning | | --- | --- | | lift: push it DOWN to the switch to home it | homing (finding where 0 is): drive it down to the switch once | | lift: no switch "lift_bottom" in the configuration | the switch name is wrong or missing: it runs without the switch | | claw: no position called "OPNE" | a typo in a position name: the library ignored the command | | homing failed: switch not found (turret) | the switch never closed: wire, magnet gap, or the wrong direction in `home(...)` | | follower encoder not reading: follower switched off (flywheel) | the second flywheel motor has no encoder cable: plug it in (or use one motor) | | Launcher gave up: flywheel (or hood, Turret...) | it was not ready in time: that part is the problem | | Launcher: defaults from the catalog (gobilda-5203-6000): kF 11.7, kP 1.17, ... | normal on a first run: with no gains written, it starts from the motor's catalog numbers. The wheel gets to speed, but slower after each shot than when tuned: run the [Flywheel Finder](https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/) and write its line ([First run](https://crossbotics.com/ftc-helper/docs/reference/tunables/#first-run-what-you-get-before-tuning)) | | Aim odometry: the pose was never set ... | TeleOp ran without autonomous, so the robot does not know where it is: aiming uses the camera only. Run autonomous first, or park on the reset spot and hold gamepad 1 START 1 s ("set pose here", `Tunables.Odometry.resetX, resetY, resetHeading`; [Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#teleop-starts-where-autonomous-ended)) | | No reset spot: add resetX, resetY, resetHeading to Tunables.Odometry | someone held gamepad 1 START 1 s ("set pose here"), but `Tunables.Odometry` has no spot: add the three numbers (inches and degrees from your wall, for BLUE) | | Alliance now RED (was BLUE) | the alliance switch is on (`lib.switchAlliance(...)`) and someone held gamepad 1 START, then BACK, 1.5 s: the alliance switched. Hold them again to switch back ([ControlMap](https://crossbotics.com/ftc-helper/docs/reference/controls/#controlmap)) | | Alliance now RED: odometry aim OFF until the pose is set (...) | someone switched the alliance on a turned field (`mirrorForRed = false`): the library cannot fix the pose from autonomous. Park on the reset spot and hold gamepad 1 START 1 s ([buttons guide](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/#switching-the-alliance-in-teleop)) | | Set pose here needs odometry: ... | someone held gamepad 1 START 1 s, but the robot has no `odometry(...)` line in Robot.java, so it cannot know where it is ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/)). Nothing changed | | Launcher : WAITING_READY left 1 waits for: turret aimed | the launcher holds the piece until that check is true (here: the turret on the goal). Launcher gave up: ... shows for 5 s when it waited too long | | Pose NOT set: stop first ... | someone held "set pose here" while the robot drove (a drive stick pushed) or whole-robot aim was on. Stop, then hold gamepad 1 START 1 s again | | No pause button (libraryButtons freed it): ... | `lib.pause(null)` in `libraryButtons`: nothing pauses the robot. Put it on a button: `lib.pause(g1.back)` | | No slow button (libraryButtons freed it): ... | `lib.slow(null)` with no `slow()` of your own: add one, for example `g1.rt.slow()` | | COMPETITION: "intake_deploy" not in the configuration: IntakeDeploy is OFF (optional part). On the robot? ... | the same as the note below, loud because the COMPETITION profile is on: at an event, a part that is off is most likely a misspelled or lost configuration name. Fix the name (or plug it in) and INIT again. If the part is not built yet, it is safe to play | | "intake_deploy" not in the configuration: IntakeDeploy is off (optional part) | a note, not a problem: the part is marked `optional()` and not on the robot yet. The library skips its commands, buttons (- off: ... not on the robot on the map) and action steps. When you plug it in, add it to the configuration and INIT again ([parts not on the robot yet](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-on-the-robot-yet)) | | Launcher: battery 11.2 V: low. The flywheel gets back to speed slower: charge or swap it | swap in a charged battery: the wheel gets back to speed slower, so shots wait longer | | Aim odometry: ... more than the field allows / Aim: camera says ... odometry ... | the pose is wrong or drifted, or `Tunables.Aim.goalX, goalY` are not where the camera measures to | | goal out of turret range (behind the robot: holding) | the goal is behind the robot: turn the robot toward it | | PRACTICE profile | set COMPETITION at events | | N tuned value(s) differ from the code | the hub uses saved tuning values: copy them into the code, then reset | | ... button job took N ms: the whole robot stopped that long. ... or a button job took N ms: ... | a button job waited: see "A job took N ms" under [Robot behavior](#robot-behavior) | | Lift update took N ms: update() must not wait or sleep | a part's `update()` took more than 25 ms: no wait or `sleep()` in `update()`. It goes away 5 s after the last slow update | | intake_color: not found: no color sensor called ... (or distance sensor) | a piece sensor's name is not in the robot configuration: it sees nothing, and Pieces counts nothing with it. Fix the name | | huskylens: not answering: check the cable... | the HuskyLens does not answer on I2C (with a loose cable or its Protocol Type on UART). Check the cable (its green wire goes to the hub's white wire on a home-made cable), and in its General Settings set Protocol Type to I2C or Auto Detect | | huskylens sees a tag but `target(34)` is null | it says only the number you taught it. Add `.tag(taughtNumber, 34)`, or teach that tag ([how](https://crossbotics.com/ftc-helper/docs/modules/vision/#huskylenscamera)) | | ready_color: no new reading for N s | a piece sensor (or its camera) stopped answering: a loose cable, or a camera that stopped streaming. It sees nothing until readings come back | | Intake: held back by stopsWhen for N s (the count says full) | the piece count says full. If it is not full, hold the in-button (RT) 1 s to pull in anyway, or hold G2's left stick button 1 s: count = 0 ([Pieces](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/)) | **EasyTeleOp needs your robot settings** - or EasyAuto needs your robot settings Add `robotConfig()` to the OpMode: `return new RobotSettings();` (starter kit) or `return RobotSettings.config();` (tutorials). See [RobotConfig](https://crossbotics.com/ftc-helper/docs/modules/core/#robotconfig). **Autonomous needs the IMU (turn sensor)** `RobotSettings.imu()` returned null. Return `ImuSetup.get(...)` there: every Control Hub has an IMU. ## Robot behavior **A lift or arm runs past its stop, never stops, or does not move; the flywheel never gets to speed; the robot drives the wrong distance** The encoder count is wrong: its cable is missing, in another motor's port, or counting backward. Run the [Encoder Check](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#encoder-check-each-encoder-cable-in-its-own-port) (Tune and check) with the robot on a block. It names the fault for each motor: | The Encoder Check says | Fix | | --- | --- | | NO COUNTS: encoder cable missing? | plug in the encoder cable, or replace it | | counts on "X" instead: encoder cables swapped? | put each encoder cable in its own motor's port | | counts on "lift_right" instead: plug the encoder cable into "lift_left"'s port | a two-motor lift: the library reads only the first motor's encoder. Move the cable | | counts BACKWARD | the motor's power wires are swapped (red and black), or an outside encoder is mounted the other way | **A route says Park: stopped: a drive stick moved, or it never seems to start** Any drive stick stops a TeleOp route at once. A route that a time starts waits 5 s for the driver to let go of the sticks, and the gamepad buzzes. If the Driver Station says Park: not started: ..., the words say why: [the table](https://crossbotics.com/ftc-helper/docs/modules/odometry/#keep-out-boxes-and-routes). **A route or `routeTo` says STALLED, or the robot touches a box on the way** The pose is wrong, the box is too small, or the margin is too small. Compare the `Pose` line with where the robot is on the field. Then measure the box again, or make the margin bigger ([what the margin is](https://crossbotics.com/ftc-helper/docs/modules/odometry/#keep-out-boxes-and-routes)). Another robot in the way also stops it: a route cannot see robots. A spot closer to a wall than half your robot also ends this way: the robot presses the wall. **INIT stops: ... is on "..." or ... a robot cannot drive in from outside** The spot you gave `routeTo` or `route` is on a box, or other boxes close every way to it. Move the spot. For the second one, a smaller margin in `fieldMap(...)` can also help. **A part does nothing on its buttons, and INIT says Intake: usual buttons not in Controls.java: ...** Since v0.39.0 a part has no buttons until `Controls.java` has its lines. Copy the part's lines from its "buttons to add" in the [reference](https://crossbotics.com/ftc-helper/docs/reference/robot-java/) (for example [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#buttons-to-add)) into `buttons(...)`. If a button that line wants is already in use, put the part's job on a free one (INIT lists them: G2 free: ...). **A servo turns less than its seller says (a goBILDA 2000 servo: about 270 degrees, not 300)** The hub sends 600 to 2400 microseconds for positions 0 to 1 (the FTC SDK's normal range). The servo's full turn needs 500 to 2500. Add `.fullRange()` to the part in Robot.java (`ServoSetup...fullRange()` or `PositionServo...fullRange()` without the five files). Then measure its positions again: they move when the range changes ([Full range](https://crossbotics.com/ftc-helper/docs/modules/hardware/#full-range)). INIT says cannot change its pulse range for a servo that is not on a REV hub. **My servo positions are off after adding (or removing) `.fullRange()`** You measure positions for one pulse range. Find them again with the Servo Finder (Y while choosing the servo = full range) or the Hood Finder, and copy the new numbers into `Tunables.java`. **Every shot is a little short (or long) today** The wheel is worn, the balls are softer, or the battery is lower than when you tuned. In the match: the operator's D-pad up/down trims every shot speed by 1% (Speed trim : +3% on the Driver Station). Held, it makes 4 steps a second. A double-tap on D-pad down sets it to 0. If it happens every match, the table is off. Multiply its speeds by the trim (or tune it again with the Shot Tuner), and copy the new line into `Tunables.java` ([Add a launcher](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#speed-trim-and-a-low-battery)). Battery compensation is off by default (nobody has proven it on a robot yet). To try it, read [Add a launcher: speed trim and a low battery](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#speed-trim-and-a-low-battery). **In an autonomous move the robot turns and stops short (in the simulator or on the field)** A corner touched a wall or a field part, and the robot pivoted on it. `move(...)` drives straight and does not turn by itself. Look at the start spot. On BIOBUZZ's field, a FLOWER stands against your wall about 20 to 27 in right of the center line. A spot at x 36 is only 0.3 in from it, so a move to the left drives into it. Start farther away (the example robots use x 44 to 48), or drive forward first. In the simulator, the robot box turns red on a bump, and a scenario can check `expect bumped none` ([having multiple autos](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/)). **The robot paused when I used the gamepad's START + BACK** (the debug lines, or the alliance switch) You pressed BACK first. BACK is the pause button, and it pauses the moment it goes down. Pressing START after it does not undo that, so you get a plain pause (and no debug lines or switch). Tap BACK to go on. Next time **hold START first, then press BACK** ([Move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/)). **Y does nothing (no field-centric) in an EasyTeleOp** Field-centric needs mecanum wheels and the IMU. A tank drivetrain, or `imu()` returning null, keeps it off on purpose. **Field-centric "forward" is wrong at the start of TeleOp** The robot did not start autonomous facing straight away from its driver. Set `startHeadingDeg()` in the autonomous (written for BLUE), or press BACK after turning the robot to face away from you. In a Controls.java TeleOp with field-centric on, hold BACK for 1 s: the press pauses the robot, and the hold also resets "forward". Tap BACK again to go on. **The robot drives diagonally, spins, or a wheel fights the others** A motor direction or a motor name is wrong. [Check motor directions](https://crossbotics.com/ftc-helper/docs/modules/drive/#check-motor-directions). **Pushing the stick up drives backward** You forgot the minus: forward is `-gamepad1.left_stick_y`. (The gamepad reports stick up as a negative number.) With the robot in five files, every direction is flipped: reverse the other side ([Wiring checks](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#motor-direction-check-each-wheel-rolls-forward)). **Field-centric goes the wrong way** 1. The IMU orientation (logo/USB) does not match the hub on the robot ([ImuSetup](https://crossbotics.com/ftc-helper/docs/modules/hardware/#imusetup)). 2. The heading was not 0 while facing away from the driver. Point the robot away and press your reset button. **A button action runs over and over** - In `Controls.java`: the job is a `hold(...)` (every loop while held) where you wanted `press(...)` (once per press). - Old style (`ControllerBindings`): `bindHold` where you wanted `bindPress`. **A button does nothing** - In `Controls.java`: check that it is on the right gamepad (`g1` = the driver, `g2` = the operator). - Check whether it is a hold where you pressed (or a press you hold). `heldFor(1.0, ...)` needs 1 s. A `tap` waits to know it is not a double-tap. - When you held it through ▶ (or while the tuning menu closed), let it go and press again. - When the robot is paused (PAUSED on the screen), tap BACK. - Old style (`ControllerBindings`): check that `controls.update(gamepad1, gamepad2)` is in the loop, and that it is the right pad (`Pad.G1` = gamepad1, `Pad.G2` = gamepad2). After `ignoreHeldButtons`, let it go and press again. **A job took N ms: the whole robot stopped that long** A button job has a `sleep()` or a `while` loop that waits (the library reports a job over 20 ms). The program does one thing at a time: while the job waits, nothing else runs, not even driving. Fix: make the steps an [Action](https://crossbotics.com/ftc-helper/docs/reference/steps/#action) and wait with `waitSeconds(...)` (the robot keeps running while it waits). Without the five files: set a target or a state and let the loop do the work ([Non-blocking code](https://crossbotics.com/ftc-helper/docs/guides/non-blocking/)). **The robot freezes when I press a button** An action has a `sleep()` or a waiting loop. Actions must be quick. **Why:** the program does one thing at a time, so while it waits, nothing else runs (not even driving). Set a target or a state variable instead and let the loop do the work ([Non-blocking code](https://crossbotics.com/ftc-helper/docs/guides/non-blocking/)). **A lift only goes down, and slowly, at the start** It is not homed yet (it has not found where 0 is). Push it down until the lower switch is pressed. Then it works normally. See [Homing](https://crossbotics.com/ftc-helper/docs/modules/safety/#homing-with-a-lower-switch). **A lift will not move** - `getAppliedPower()` is 0 while you push the stick: a limit stopped it. Check `getPosition()` and your limits. It may think it is at the bottom or top. - You turned the motor on with the lift half up, so 0 is in the wrong place. Lower it and restart, or use a lower limit switch for homing. - The motor direction is wrong (positive power must go up). Check with a low power. **The lift stops early or goes past the top** Re-measure the top position with `lift.getPosition()` on telemetry. A slipping belt or string changes the count: add a lower limit switch so it re-zeroes each time it reaches the bottom. **AutoDrive moves the wrong distance** Tune `wheelDiameterIn` and `strafeCorrection`: [Tune AutoDrive](https://crossbotics.com/ftc-helper/docs/modules/drive/#tune-autodrive). **An autonomous move stops past its end (short moves most, or fast ones)** A robot slides a little when it brakes, and a faster one slides further. There are two fixes. Run the [Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/) at the power your moves use (D-pad left/right on its test list). Also set `Tunables.Drive.slowDownIn = 6`, so every move slows down over its last 6 in ([tunables](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava)). Then a short move reaches the end as slowly as a long one. If it still goes past by the same amount every time, shorten that move by that amount. **AutoDrive turns overshoot or stop short** Overshoot: raise `turnKd` or lower `turnKp`. Stop short: raise `turnKp` a little or set `turnMinPower`. The [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/) measures the turns and finds these numbers for you. **AutoDrive stops early with "robot stuck"** It was blocked, or it moved too slowly. If it was not blocked, raise `moveMinPower` or `stallTimeSec`. **The loop is slow (telemetry shows under ~30 Hz, that is, under 30 loops per second)** Turn on [bulk reads](https://crossbotics.com/ftc-helper/docs/modules/hardware/#bulkreads), send fewer telemetry lines, and remove any `sleep()`. ### My JUnit tests time out or never fire, but only when run together A test used a pretend clock (`PretendClock.use()`) and did not give the real clock back. Time then stands still for every later test. Fix: put `PretendClock.stopUsing()` in that test class's `@After` method ([PretendClock](https://crossbotics.com/ftc-helper/docs/modules/testkit/#pretendclock)). ## Autonomous choice and git problems **The robot ran the wrong autonomous plan, or started in the wrong place** The first option of each INIT menu line runs when nobody changes it. The "Place robot" note says where the robot must stand. Read the menu and the note out loud before ▶: [match day checklist](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/). **An INIT menu option does nothing** The option is spelled differently in `menuChoice(...)` and in `onlyIf(...)` (capitals count). Test each option in the simulator: [Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/). **modified: ftc-helper-lib (new commits) in `git status`** Your library folder is at another version than the project expects. If you did not mean to update it, run `git submodule update` in the project folder. See [Keep it up to date](https://crossbotics.com/ftc-helper/docs/02-keep-up-to-date/#after-a-teammate-updates-it). **The build broke after a library update** Read the CHANGELOG's **Changed** list, or go back to the old version: [Go back to the old version](https://crossbotics.com/ftc-helper/docs/02-keep-up-to-date/#go-back-to-the-old-version). **'git' is not recognized (Windows)** - or git: command not found The Terminal cannot find git. GitHub Desktop does not fix this: it keeps its own git, and only GitHub Desktop can use that one. 1. Install Git for Windows from [git-scm.com/downloads/win](https://git-scm.com/downloads/win). On the page "Adjusting your PATH environment", keep **Git from the command line and also from 3rd-party software** (the recommended choice). The other choices are fine as they are. 2. Close Android Studio fully and open it again. A Terminal that was open before the install does not see git. 3. Type `git --version` in the Terminal. It prints git version 2... when it works. 4. If it is still not recognized, add git to the PATH (the list of folders Windows looks in for commands) by hand. You need no administrator for this. 1. Find the folder that has `git.exe` in it: `C:\Program Files\Git\cmd`, or `C:\Users\YOUR-NAME\AppData\Local\Programs\Git\cmd` when you installed Git for one user only. 2. Press the Windows key, type `environment`, and open **Edit environment variables for your account**. 3. Select **Path**, then **Edit**, then **New**. Paste the folder from step 1. Click **OK**, then **OK**. 4. Close Android Studio fully, open it again, and do step 3 again. **rejected, CONFLICT, divergent branches or another git message** See [Git and GitHub: problems](https://crossbotics.com/ftc-helper/docs/guides/github/#problems). ## Get more help Write down what you did, what you expected and what happened, and ask the programming lead. If it is a library bug, add a failing test for it: [Contributing](https://crossbotics.com/ftc-helper/docs/contributing/). --- # Pick your start URL: https://crossbotics.com/ftc-helper/docs/pick-your-start/ Your robot's code is five files in `TeamCode`: `Robot.java`, `Tunables.java`, `Controls.java`, `Actions.java` and an `autos` folder. You do not type them from nothing. You start from files that are already written, and then change them. **Why:** code that already builds and drives is a safe place to start. You change a few lines, not write a hundred. Pick **one** start: | Your robot | Your start | You get | | --- | --- | --- | | A **starter bot** from goBILDA (tank or Strafer), REV, AndyMark or Studica, built as the seller's guide says | [A starter bot](https://crossbotics.com/ftc-helper/docs/pick-your-start/01-starter-bot/) | The bot's whole code. Every part is in it, with the seller's names. | | A robot **like one of our example robots**: for example mecanum + intake, tank + flywheel, a turret, odometry | [A common setup](https://crossbotics.com/ftc-helper/docs/pick-your-start/02-common-setup/) | That example's code. You delete what your robot does not have. | | **Your own design** | [A blank slate](https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/) | The smallest code that drives. Then you add your parts one at a time. | **For a starter bot with your own changes** (a part added, taken off or moved): start from [a starter bot](https://crossbotics.com/ftc-helper/docs/pick-your-start/01-starter-bot/). Then make your changes one at a time: the page says how. **If you are not sure,** pick the start that is most like your robot. You delete less and type less. You can copy single lines from the other starts later. All three starts end in the same place: **the five files in `TeamCode`, and the project builds.** Then the [five files pages](https://crossbotics.com/ftc-helper/docs/five-files/) explain every line, and you make the robot drive. | # | Page | | --- | --- | | 1 | [A starter bot](https://crossbotics.com/ftc-helper/docs/pick-your-start/01-starter-bot/) | | 2 | [A common setup](https://crossbotics.com/ftc-helper/docs/pick-your-start/02-common-setup/) | | 3 | [A blank slate](https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/) | | 4 | [Copy example files into TeamCode](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/) (pages 1 to 3 send you here) | **Next:** pick one: [a starter bot](https://crossbotics.com/ftc-helper/docs/pick-your-start/01-starter-bot/), [a common setup](https://crossbotics.com/ftc-helper/docs/pick-your-start/02-common-setup/) or [a blank slate](https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/). --- # Start from a starter bot URL: https://crossbotics.com/ftc-helper/docs/pick-your-start/01-starter-bot/ The library has the whole code for each of these starter bots. It uses the same configuration names as the seller's own code, so it runs on the bot as it is. You copy it, change one line, and build. ## 1. Find your bot The folders are in the library, in `ftc-helper-lib/examples/src/main/java/com/crossbotics/ftchelper/examples/`. | Starter bot | Its folder | Its autonomous | | --- | --- | --- | | goBILDA FTC StarterBot (tank) | [`gobildabot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/gobildabot) | `autos/LaunchAndBackUp.java` | | goBILDA FTC StarterBot with Mecanum Wheels (Strafer) | [`gobildastraferbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/gobildastraferbot) | `autos/LaunchAndLeave.java` | | REV DUO FTC Starter Bot | [`revbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/revbot) | `autos/ShootAndLeave.java` | | AndyMark Robits BIOBUZZ StarterBot | [`andymarkbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/andymarkbot) | `autos/ThrowAndLeave.java` | | Studica FTC Starter Bot | [`studicabot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/studicabot) | `autos/ShootAndLeave.java` | goBILDA's folder also has `autos/AutoCookbook.java`: a menu of example steps. Copy it only if you want it. ## Try it first in the simulator You can drive the bot's code before you copy it. The simulator is a pretend robot on your laptop. It runs the library's copy of the code. **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ([Which folder](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#which-folder)) ```bash ./gradlew :sim:run -Probot=sim/robots/starter-bot-rev.properties -PteamCode=none ``` Open http://localhost:8780 and pick **REV Bot TeleOp**. `-PteamCode=none` runs the library's copy of the code, not yours. For another bot, change `rev` in the command: `gobilda`, `gobilda-strafer`, `andymark` or `studica`. The first time, do the [laptop setup](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#laptop-setup-for-gradlew-commands-once-per-laptop). ## 2. Check the configuration names The robot configuration must use the seller's names: [the names for each starter bot](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#the-configuration-names). You made the configuration in [Set up 7](https://crossbotics.com/ftc-helper/docs/setup/07-robot-configuration/). Check each name there. **Why:** the code finds each motor and servo by its name. One wrong letter, and INIT stops. ## 3. Copy the files Copy the bot's folder into `TeamCode`: [Copy example files into TeamCode](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/). Then come back here. ## 4. Check the IMU line Open `Robot.java`. Find the line with `.imu(`. It says where the Control Hub's **logo** faces, then where its **USB ports** face. Look at the hub on your robot. If your team mounted it another way, change the line ([How your Control Hub is mounted](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#how-your-control-hub-is-mounted)). **Why:** the IMU (the sensor in the hub that knows which way the robot faces) must know how the hub sits. Turns in autonomous use it. Change nothing else yet. ## 5. Read your bot's notes Some numbers in your bot's `Tunables.java` are guesses. Each bot's notes say which ones: [REV](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#rev-bot-code), [goBILDA](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#gobilda-bot-code), [goBILDA Strafer](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#gobilda-strafer-bot-code), [AndyMark](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#andymark-bot-code), [Studica](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#studica-bot-code). You measure them later, on the [Tunables.java page](https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/). Two kit mechanisms are not parts of the library. Their code uses the closest part and says so in `Robot.java`: - **AndyMark's catapult** runs as an `Indexer`: one press runs its motor for a set time. Tune that time so one press is one throw. - **Studica's flywheel** has a 2:1 gear. The speed in `Tunables.java` is the motor's speed. The wheels turn at half of it. Tune it by watching shots. ## 6. Build In Android Studio, click **Build > Make Project**. ## You changed your starter bot You may have added, taken off or moved a part, or used another motor or servo. Then do steps 1 to 6 first, with the seller's code as it is. Then make your changes **one at a time**: change, build, check. **Why:** when something breaks, you know which change did it. For each kind of change, [You changed your starter bot](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#you-changed-your-starter-bot) says what to change in each file. ## Done when - The bot's files are in `TeamCode`: `Robot.java`, `Tunables.java`, `Controls.java`, `Actions.java`, and the `autos` folder. - **Build > Make Project** ends with no red errors. ## Problems | Problem | Fix | | --- | --- | | A line is red: `cannot find symbol` | A `package` or `import` line still names the example folder. See [Copy example files, step 3](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/#3-change-the-imports). | | INIT stops: a name is not found | The configuration name is not the seller's name. INIT lists the real names. Fix the configuration ([Set up 7](https://crossbotics.com/ftc-helper/docs/setup/07-robot-configuration/)). | | The TeleOp is not on the Driver Station | The `@Disabled` line is still in `Controls.java`. See [Copy example files, step 4](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/#4-delete-the-disabled-lines). | --- **Next:** [The five files](https://crossbotics.com/ftc-helper/docs/five-files/). They explain every line you copied. **Look it up:** [the starter bots: names, numbers and notes](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/). --- # Start from a common setup URL: https://crossbotics.com/ftc-helper/docs/pick-your-start/02-common-setup/ Each example robot is a robot in five files that builds and drives. Pick the one most like your robot. You copy it, and then delete what your robot does not have. **Why:** deleting a line is easier than writing one, and the lines you keep already work together. ## 1. Pick the closest example The folders are in the library, in `ftc-helper-lib/examples/src/main/java/com/crossbotics/ftchelper/examples/`. | Your robot has | Start from | What is in it | | --- | --- | --- | | a mecanum drive and an intake | [`quickstart`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/quickstart) | the smallest robot with a part. A `// STEP` mark on each line to change | | a mecanum drive, an intake, a lift and a claw | [`lessonbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/lessonbot) | the example robot of The five files and Add to your robot, and its Drive Tuner | | a tank drive and a flywheel shooter | [`flywheelbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/flywheelbot) | an intake, a deploy servo, a flywheel, a servo feeder and a webcam that aims the whole robot | | a mecanum drive with a turret and a camera | [`turretbot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/turretbot) | a Limelight that the turret follows, a hood, a folding claw, and two finders | | a mecanum drive with odometry (Pinpoint, OTOS or dead wheels) | [`odometrybot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/odometrybot) | autos that drive to field points, and the Odometry Tuner | | odometry and Pedro Pathing | [`pedrobot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/pedrobot) | `odometrybot` plus curved paths | **Odometry** is a sensor set that tracks where the robot is on the field. **Pedro Pathing** is a separate library that drives curved paths. More detail on each one: [Pick your template](https://crossbotics.com/ftc-helper/docs/templates/#your-robot-looks-like-this-start-from-that). **`pedrobot`:** add Pedro to the project first ([Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/#your-project-add-the-pedro-add-on-once)). **Some have extra files.** Copy them with the rest: | Example | Extra files | What they are | | --- | --- | --- | | `lessonbot` | `DriveTuner.java` | a finder for the drive | | `turretbot` | `HoodFinder.java`, `ShotTuner.java` | finders for the hood and the shots | | `odometrybot` | `OdometryTuner.java` | a finder for the odometry | | `pedrobot` | `PedroConstants.java` | Pedro's numbers | `lessonbot` also has `OwnTeleOp.java`: the same TeleOp written as a plain FTC OpMode, to read. Do not copy it. A **finder** is a small program that measures a number on the real robot and shows the line to copy into your code. ## 2. Copy the files Copy the example's folder into `TeamCode`: [Copy example files into TeamCode](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/). Then come back here. ## 3. Make it match your robot Open `Robot.java`. Change only these, then build: 1. **The device names.** These are the names in quotes right after the part's kind, for example `"front_left"` in `Drive.mecanum("front_left", ...)` and `"claw"` in `Claw.servo("claw")`. Each one must be exactly the name in your robot configuration ([Set up 7](https://crossbotics.com/ftc-helper/docs/setup/07-robot-configuration/)). Capitals and `_` count. **Why:** the code finds each device by its name. Leave the other quoted words as they are. `.part("gobilda-2000-torque")` is a catalog id (which motor or servo it is), and words like `"high"` in `goTo("high")` are position names. 2. **The drive motor and wheels:** `.motor(...)` and `.wheel(...)` (or `.wheelMm(...)`) on the drive line ([the drive line](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#the-drive-attribute-by-attribute)). 3. **The IMU line** (`.imu(...)`): where the Control Hub's logo and USB ports face. Change it only if your team mounted the hub another way ([how](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#how-your-control-hub-is-mounted)). 4. **A part your robot does not have:** delete its line in `define()` and its field (`public Claw claw;`). Then build. Each red mark now shows a place that still uses the part. Fix each one, in any file: - A button line in `Controls.java`: delete the whole line, up to its `;`. - An action in `Actions.java` that uses the part: delete the whole action, from `/** ... */` and `public static Action` to its closing `}`. Then delete each line that used that action. - A step in an autonomous: delete the step. If it ends with `;`, put the `;` on the step before it. **Why:** the build finds every place that uses the part for you. Delete whole lines and whole actions: half a line does not build. For example, a robot with no claw, from `lessonbot`: - `Robot.java`: delete `public Claw claw;` and the `claw = add(...)` line. - `Controls.java`: delete the `g2.b.toggle(robot.claw)` line. - `Actions.java`: delete both actions. Each one uses the claw. - Build again. Now the lines that used those actions are red. In `Controls.java`, delete the `g2.rb.press(...)` line, and the `g2.lb.tap(...)` statement: two lines, up to the `;`. - `autos/ScoreAndPark.java`: delete the `.run("Hold the piece", ...)` and `.action(...)` steps. The part's section in `Tunables.java` (for example `public static class Claw`) can stay for now. It does no harm. Delete it when you tidy up. Keep the other numbers as they are for now. You measure them on the [Tunables.java page](https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/). When your robot has a part that the example does not have, add it later, one at a time, on the [Robot.java page](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#add-a-part). ## 4. Build In Android Studio, click **Build > Make Project**. ## Done when - The five files are in `TeamCode`: `Robot.java`, `Tunables.java`, `Controls.java`, `Actions.java`, and the `autos` folder. Your configuration names are in `Robot.java`. - **Build > Make Project** ends with no red errors. ## Problems | Problem | Fix | | --- | --- | | A line is red: `cannot find symbol` | A `package` or `import` line still names the example folder ([Copy example files, step 3](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/#3-change-the-imports)). Or the line uses a part you deleted: delete the line. | | INIT stops: a name is not found | A name in `Robot.java` is not the name in the configuration. INIT lists the real names. | | `pedrobot` does not build: `com.pedropathing` not found | Pedro is not in the project yet ([Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/#your-project-add-the-pedro-add-on-once)). | --- **Next:** [The five files](https://crossbotics.com/ftc-helper/docs/five-files/). They explain every line you copied. **Look it up:** [Pick your template](https://crossbotics.com/ftc-helper/docs/templates/): more about each example robot. --- # Start from a blank slate URL: https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/ You start with the **smallest robot that works: it drives.** Then you add your parts one at a time, on the five files pages. **Why:** when only one part is new, a problem can only be in that part. There are two ways to get the first files. Pick one: | Your robot | Use | | --- | --- | | It is wired, and its configuration is on the Driver Hub ([Set up 7](https://crossbotics.com/ftc-helper/docs/setup/07-robot-configuration/)) | [Way A: from your configuration](#way-a-from-your-configuration) (best) | | It is not wired yet, or you only use the simulator, or you want to type each part in yourself | [Way B: copy the smallest files](#way-b-copy-the-smallest-files) | ## Way A: from your configuration The library reads your configuration and writes the five files for you, with a line for each part. **Why:** it copies the names for you, so they cannot have typos. 1. **Copy the configuration file off the Control Hub.** It is `/sdcard/FIRST/.xml`, where `` is your configuration's name (for `MyRobot`, it is `MyRobot.xml`). Use Android Studio's **Device Explorer** (**View > Tool Windows > Device Explorer**) with the hub connected, or the REV Hardware Client. Save it in the project folder, next to `TeamCode`. 2. **Run the file maker.** The first time, do the [laptop setup](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#laptop-setup-for-gradlew-commands-once-per-laptop). **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ([Which folder](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#which-folder)) ```bash ./gradlew :sim:newRobot -Pconfig=../MyRobot.xml -PteamCode=../TeamCode ``` Change `MyRobot.xml` to your file's name. It writes `Robot.java`, `Tunables.java`, `Controls.java`, `Actions.java` and `autos/LeaveStart.java` into `TeamCode`. It never writes over your work: if one of the files is already there, it writes nothing and stops. 3. **Check each `TODO` line in `Robot.java`.** A `TODO` is a guess the file maker was not sure of, for example which part a motor drives. 4. **Build:** click **Build > Make Project**. In `Tunables.java`, each number is `DEFAULT` (the library's starting value) or `MEASURE` (a number only your robot can give). Leave them for now. The [Tunables.java page](https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/) says how to find each one. ## Way B: copy the smallest files The smallest files are in the library, in the [`firstrobot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/firstrobot) folder: `ftc-helper-lib/examples/src/main/java/com/crossbotics/ftchelper/examples/firstrobot/`. They are a mecanum drive and nothing else. They are the same files the five files pages show. 1. **Copy the folder** into `TeamCode`: [Copy example files into TeamCode](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/). Then come back here. 2. **Change the drive line** in `Robot.java`: your four motor names, your motor and wheels, and the IMU ([the drive line](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#the-drive-attribute-by-attribute), [how your Control Hub is mounted](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#how-your-control-hub-is-mounted)). For a tank drive, read [A tank drive instead](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#a-tank-drive-instead). 3. **Build:** click **Build > Make Project**. Your other parts come later, one at a time, on the [Robot.java page](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#add-a-part). ## Done when - The five files are in `TeamCode`: `Robot.java`, `Tunables.java`, `Controls.java`, `Actions.java`, and the `autos` folder. - **Build > Make Project** ends with no red errors. ## Problems | Problem | Fix | | --- | --- | | `... is already there: nothing written (move it away first)` | One of the five files is already in `TeamCode`. Move it to another folder, then run the command again. | | `./gradlew: No such file or directory` | You are not in the `ftc-helper-lib` folder. Type `cd ftc-helper-lib`. | | A line is red: `cannot find symbol` | A `package` or `import` line still names the example folder ([Copy example files, step 3](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/#3-change-the-imports)). | --- **Next:** [The five files](https://crossbotics.com/ftc-helper/docs/five-files/). They explain every line, and you make the robot drive. **Look it up:** [Robot.java](https://crossbotics.com/ftc-helper/docs/reference/robot-java/), [Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/tunables/) and [Drive](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/). --- # Copy example files into TeamCode URL: https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/ The example files are in the library. Your robot's code must be in `TeamCode`. You copy the files, then change a few lines so that they belong to `TeamCode`. On this page, `` is the name of the folder you copy, for example `gobildabot`. Put the real name there, without the `< >`. ## 1. Copy the files 1. In Android Studio's **Project** panel, pick **Project** in the menu at the top of the panel (not **Android**). **Why:** the **Android** view does not show the library's examples. 2. Open `ftc-helper-lib/examples/src/main/java/com/crossbotics/ftchelper/examples//`. 3. Select every `.java` file in it. Copy them (**Ctrl+C**, Mac: **Cmd+C**). 4. Open `TeamCode/src/main/java/org/firstinspires/ftc/teamcode/`. Right-click `teamcode` and pick **Paste**. Android Studio may show a **Copy** box: press **OK**. 5. Right-click `teamcode`, pick **New > Package**. Type `autos` after the `teamcode.` that is already there. 6. Copy every file from the example's `autos` folder into your new `autos` folder the same way. ## 2. Change the package lines The first line of each file is its `package` line. It must name the folder that the file is in now: | File | Its first line | | --- | --- | | next to `Robot.java` | `package org.firstinspires.ftc.teamcode;` | | in `autos` | `package org.firstinspires.ftc.teamcode.autos;` | Before: ```java package com.crossbotics.ftchelper.examples.gobildabot; ``` After: ```java package org.firstinspires.ftc.teamcode; ``` Android Studio may have changed some of them for you when you pasted. Check every file. **Why:** a file whose `package` line does not match its folder does not build. ## 3. Change the imports The files in `autos` import `Robot`, and some import `Actions`. Those imports still name the example folder. Change each one to `org.firstinspires.ftc.teamcode`. Before: ```java import com.crossbotics.ftchelper.examples.gobildabot.Robot; ``` After: ```java import org.firstinspires.ftc.teamcode.Robot; ``` Do the same in every file that has an `import com.crossbotics.ftchelper.examples` line. Android Studio marks each line it cannot find in red. ## 4. Delete the @Disabled lines Some example OpModes have this line above the class: ```java @Disabled ``` and this import: ```java import com.qualcomm.robotcore.eventloop.opmode.Disabled; ``` Delete both, in every file that has them: `Controls.java`, each autonomous, and each finder. **Why:** `@Disabled` hides an OpMode on the Driver Station. The examples use it, so they do not fill the list. Your copies must show. ## 5. Change the OpMode names In `Controls.java`, find `@TeleOp(name = "...")`. In each autonomous, find `@Autonomous(name = "...", preselectTeleOp = "...")`. Change the names to your own. `group = "Examples"`: change it to your own group, or delete it. Leave `group = "Finders"` on the finder files: the docs look for the finders in that group. **`preselectTeleOp`** must be the TeleOp's name, exactly. **Why:** after the autonomous, the Driver Station picks that TeleOp for you. ## Done when - No `package` or `import` line names `com.crossbotics.ftchelper.examples`. - No `@Disabled` line is left. - **Build > Make Project** ends with no red errors. **Next:** go back to your start page: [a starter bot](https://crossbotics.com/ftc-helper/docs/pick-your-start/01-starter-bot/#4-check-the-imu-line), [a common setup](https://crossbotics.com/ftc-helper/docs/pick-your-start/02-common-setup/#3-make-it-match-your-robot), or [a blank slate](https://crossbotics.com/ftc-helper/docs/pick-your-start/03-blank-slate/#way-b-copy-the-smallest-files). **Look it up:** [Search every class and method](https://crossbotics.com/ftc-helper/docs/reference/javadoc/) and [Troubleshooting: build problems](https://crossbotics.com/ftc-helper/docs/troubleshooting/#build-problems). --- # The five files: your robot's code URL: https://crossbotics.com/ftc-helper/docs/five-files/ Your robot's code is five files in the `teamcode` folder. Each file has one job: | File | What it holds | You change it when | | --- | --- | --- | | [`Robot.java`](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/) | What is on the robot: the drive and each part, with their names | you add, remove or change a part | | [`Tunables.java`](https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/) | The numbers: speeds, positions, powers | you measure or tune a number | | [`Controls.java`](https://crossbotics.com/ftc-helper/docs/five-files/03-controls-java/) | The buttons, and the TeleOp | you change what a button does | | [`Actions.java`](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/) | Steps that use several parts together, like "score" | you want one button or step to do several things | | [`autos/`](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/) | The autonomous programs, one file each | you write or change an autonomous | ## Five files? But two autos make more than five Yes. "Five files" counts the five jobs, not the exact number of files. The fifth one, `autos/`, is a folder. It has one file for each autonomous, so a robot with three autos has seven files. You can also see a few small files next to these. For example: a finder (a small program that measures one number for you), or `Routes.java` for routes that several autos share ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/)). They do not hold any of the robot's parts, numbers or buttons. Those always stay in the four files and the `autos/` folder. ## Start small, then add These pages build the **smallest robot that works first: it drives.** Then you add one part at a time, and test each one before the next. **Why:** when only one part is new, a problem can only be in that part. When five parts are new, the problem can be anywhere. ## Where your five files come from You do not type them from nothing. You copy them from [Pick your start](https://crossbotics.com/ftc-helper/docs/pick-your-start/) (a starter bot, a common setup, or a blank slate), then change them. When you start from a starter bot's or an example's files, these pages still explain every line you see. ## Java you will meet The five files use a few Java ideas again and again. Read the list once. Come back to it when you meet one. | You see | Its name | What it means | | --- | --- | --- | | `class Robot extends RobotDefinition` | **extends** | "built on": your class gets everything the library class does. You fill in the methods it leaves open (here `define()`), each marked `@Override`. | | `ControlMap`, `Auto` | **generics** | the name in angle brackets says which class the library class works with: your `Robot`. | | `Drive.tank(...).motor(...).wheelMm(96)` | **method chaining** | each method gives back the same thing, so the next one adds to it. Read it left to right as one sentence. | | `() -> r.launcher.fire(4)` | **lambda** | a small piece of code you give now, to run later (when a button is pressed, or an action gets to that step). `() ->` means "no inputs, run this". | | `r.intake::in` | **method reference** | the short way to write `() -> r.intake.in()`. | | `Runnable` | | Java's name for "code with no inputs that can run later". A lambda or a method reference is one. | **A name is red in Android Studio:** the file needs an `import` line. Click the name and press **Alt+Enter** (**Option+Enter** on a Mac). If it offers two, pick the one in `com.crossbotics.ftchelper.robot`. ## Done when At the end of the five files pages, the robot drives in TeleOp and runs a short autonomous. **Check yourself:** - Where do you change the launcher's speed? (`Tunables.java`, section `Launcher`.) - The operator wants the claw on X, not B. Which file? (`Controls.java`: `g2.x.toggle(robot.claw)`.) - An action lifts the lift, and the operator moves the lift stick. What happens? (The action stops: the driver always wins.) - Why does `define()` not move anything? (It runs in INIT, and the library moves nothing before ▶.) **Commit after each step that works,** so you can always go back ([Git and GitHub](https://crossbotics.com/ftc-helper/docs/guides/github/)). **Next:** [Robot.java](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/). --- # Robot.java: what is on the robot URL: https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/ `Robot.java` lists what is on your robot: the drive, and each part, with the names from the robot configuration. The buttons are in `Controls.java`, and the speeds are in `Tunables.java`. ## The smallest Robot.java This is a whole `Robot.java` for a robot that only drives. Click a **(+)** to read what a line does. ```java title="Robot.java" import com.crossbotics.ftchelper.robot.Drive; import com.crossbotics.ftchelper.robot.RobotDefinition; import com.qualcomm.hardware.rev.RevHubOrientationOnRobot.LogoFacingDirection; import com.qualcomm.hardware.rev.RevHubOrientationOnRobot.UsbFacingDirection; /** The five files, file 1 of 5: what is on the robot. The smallest robot that drives. */ public class Robot extends RobotDefinition { // (1)! @Override protected void define() { // (2)! drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") // (3)! .motor("gobilda-5203-312").wheel("gobilda-gripforce-mecanum-104") // (4)! .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); // (5)! } } ``` 1. `extends RobotDefinition`: your robot builds on the library's robot. The library's robot gives it the drive, the safety checks, the screen lines and the simulator. 2. `define()` runs once at INIT. Each line in it adds one thing to the robot. 3. The drive, and its four motor names **in this order**: front left, front right, back left, back right. Each name must be exactly the name in the robot configuration (capitals and `_` count). 4. Which motor drives the wheels, and which wheels: their ids in the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). The library reads the motor's speed and the wheel's size there, to work out speeds and distances. 5. The Control Hub's own IMU (the sensor that knows which way the robot faces), and which way the hub is mounted: where its **logo** faces, then where its **USB ports** face. **The first line of the file** (above the imports) must be: ```text package org.firstinspires.ftc.teamcode; ``` ## Make it your robot ### The drive, attribute by attribute You can put these attributes on the drive line. **Needed?** says which ones you must write. **yes** = the line does not work without it. recommended = it works without it, but less well. optional = only when your robot needs it. | Attribute | Needed? | What it sets | If you leave it out | | --- | --- | --- | --- | | `Drive.mecanum(fl, fr, bl, br)` | **yes**, one of the three | a mecanum drive (it can slide sideways) and its four motor names, in this order | - | | `Drive.tank(left, right)` | **yes**, one of the three | a tank drive, one motor per side | - | | `Drive.tank(fl, fr, bl, br)` | **yes**, one of the three | a tank drive, two motors per side | - | | `.motor(id)` | recommended | the drive motor, by its [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/#motors) id: speeds and distances come from it | Defaults to `gobilda-5203-312` | | `.wheel(id)` | recommended | the wheel, by its [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/#wheels-and-rollers) id: its size comes from the catalog | Defaults to a 96 mm wheel | | `.wheelMm(mm)` | optional | the wheel's diameter in mm, for a wheel that is not in the catalog, or the size the Drive Tuner measured (after `.wheel(...)`: the last one wins) | Defaults to 96 | | `.imu(name, logo, usb)` | recommended | the IMU's name, and where the hub's logo and USB ports face | Defaults to `"imu"`, `UP`, `FORWARD` | | `.reversed(names...)` | optional | exactly these motors run reversed: add it after the first drive test, if needed | Defaults to the left side reversed | | `.gearRatio(r)` | optional | motor turns per wheel turn, when gears, a belt or a chain sit between them | Defaults to 1 | | `.wheelsAtMm(track, base)` | optional | where the wheels sit, side to side and front to back, mm (the simulator only) | the simulator uses its robot file's numbers | | `.noImu()` | optional | no IMU: TeleOp drives robot-centric only, and autonomous will not start | Defaults to the hub's IMU | The drive's numbers (speeds, slow mode, auto turns) are in `Tunables.Drive`: [every drive number](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava). ### Your motor names Use the names from your robot configuration ([Set up 7](https://crossbotics.com/ftc-helper/docs/setup/07-robot-configuration/)). A starter bot's names are in [the table for your starter bot](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/#the-configuration-names). ### A tank drive instead A tank drive (one motor per side, or one name per side) uses `Drive.tank`: ```java title="Robot.java" drive(Drive.tank("left_drive", "right_drive") .motor("gobilda-5203-312").wheelMm(96) .reversed("right_drive") // only the motors that run backward .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); ``` ### Your motor and wheels Find your drive motor and your wheels in the parts catalog, and copy their ids: - [Motors](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/#motors), for example `gobilda-5203-312` for goBILDA's 312 RPM Yellow Jacket. - [Wheels and rollers](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/#wheels-and-rollers), for example `gobilda-gripforce-mecanum-104`, `gobilda-mecanum-96`, `rev-mecanum-75` or `gobilda-hogback-96`. When your wheel is not in the catalog, measure it across in millimeters. Then write `.wheelMm(mm)` in place of `.wheel(id)`. ### How your Control Hub is mounted Look at the hub on the robot. Write where its logo faces, then where its USB ports face: ```java title="Robot.java" drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") .motor("gobilda-5203-312").wheelMm(96) // Which way the hub's LOGO faces, then which way its USB PORTS face, on the robot. .imu("imu", LogoFacingDirection.LEFT, UsbFacingDirection.UP)); ``` **Why it matters:** the robot uses the IMU to know which way it faces. A wrong mounting makes turns and field-centric driving go the wrong way. **Check it** after the first drive test (it needs `Controls.java`): 1. Run your TeleOp. Hold gamepad 1's small **START** button, then press **BACK**. This shows the debug lines, with the `Heading`. It does not pause the robot. 2. Turn the robot LEFT by hand. The `Heading` must go UP. 3. If it goes down, or barely moves, the logo and USB directions are wrong. Look at the hub again. ### A wheel turns the wrong way Leave this until the first drive test. Without a `.reversed(...)` line, the library reverses the left side. When your robot is built the other way, list **every** reversed drive motor: ```java title="Robot.java" drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") .motor("gobilda-5203-312").wheelMm(96) // List EVERY reversed drive motor. Without this line the left side is reversed. .reversed("front_right", "back_right") .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); ``` The Motor Direction Check tells you which ones ([Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/)). ## Check it **Build:** in Android Studio, **Build > Make Project** ([the buttons](https://crossbotics.com/ftc-helper/docs/setup/06-build-and-install/#the-buttons)). **Done when:** the build finishes with no red errors. The robot cannot drive yet, because the buttons are in `Controls.java`, the next file. When the build shows red errors, read only the first one. It names the file, the line and the problem. ## Add a part When the robot drives, add your parts **one at a time**, and test each before the next. Each part is two lines in `Robot.java`: 1. At the top of the class: `public` + the kind of part + a name, for example `public Intake intake;`. 2. In `define()`: the line that makes it, with its name from the robot configuration. Every part has these attributes: | Attribute | Needed? | What it sets | If you leave it out | | --- | --- | --- | --- | | `.part(id)` | recommended | which motor or servo it is, by its [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/) id: the starting numbers and the simulator use its real speed and size | Defaults to general starting numbers | | `.optional()` | optional | the part may not be on the robot yet: INIT goes on without it | INIT stops if the part is missing | | `.looks(shapes...)` | optional | how it looks and where it sits, for the simulator | the simulator draws a guess | | `.tunables("Name")` | optional | read its numbers from another `Tunables.java` section | Defaults to the section named after the part | The two common parts come first, each with its usual line and its own attributes. The list at the end of the page has the other parts. ### Intake An intake is rollers or wheels that take pieces in. On one motor: ```java title="Robot.java" // At the top of the class: public Intake intake; Here in define(): // "intake" = the motor's name in the robot configuration. Its numbers: Tunables.Intake. // .part(...): which motor it is (optional, recommended). intake = add(Intake.motor("intake").part("gobilda-5203-1150")); ``` On continuous-rotation (CR) servos: ```java title="Robot.java" // Two continuous-rotation (CR) servos. The one that spins the wrong way is reversed. // "intake", "intake_right" = the servos' names in the robot configuration. Numbers: Tunables.Intake (the 1st name). // .part(...): which servo it is (optional, recommended). intake = add(Intake.crServos("intake", "intake_right").part("gobilda-2000-speed") .reversed("intake_right")); ``` | Attribute | Needed? | What it sets | If you leave it out | | --- | --- | --- | --- | | `Intake.motor(name)` | **yes**, one of the two | an intake on one motor | - | | `Intake.crServos(names...)` | **yes**, one of the two | an intake on CR servos that run together | - | | `.holds(n)` | recommended | how many pieces it carries: count them by hand | Defaults to 4 (the simulator's guess) | | `.withCrServos(names...)` | optional | CR servos that run with the motor, like side wheels next to a roller | - | | `.reversed(names...)` | optional | these devices run the other way, like the second of two facing servos | - | | `.holds(n, "KIND")` | optional | how many of one kind it carries. 0 = it cannot take that kind | every kind counts the same | | `.onAtStart()` | optional | runs in from ▶ until your code stops it | Defaults to off: a button starts it | | `.stopsWhen(test)` | optional | never runs in while the test is true, like "the robot is full" ([Pieces](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/)) | it runs whenever asked | Its numbers: `inPower`, `outPower` ([Tunables: Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#in-tunablesjava)). Every option and command: [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/). ### Launcher A launcher is a flywheel that shoots pieces, and the part that feeds it one piece at a time. ```java title="Robot.java" // A flywheel (in RPM) and the indexer that feeds it one piece at a time. // "launcher", "indexer" = names in the robot configuration. Numbers: Tunables.Launcher, .Indexer. // The motor's catalog id is in the brackets (needed). The indexer's .part(...) is optional, recommended. launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed"))); ``` | Attribute | Needed? | What it sets | If you leave it out | | --- | --- | --- | --- | | `Launcher.flywheel(motor, id)` | **yes** | a flywheel on this motor. The library needs the id for its speed in RPM | - | | `.feeder(Indexer.servo(name))` | recommended, one of the three | a servo arm pushes each piece in | nothing feeds the wheel | | `.feeder(Indexer.crServo(name))` | recommended, one of the three | a CR servo wheel feeds the pieces, like goBILDA's "windmill" | nothing feeds the wheel | | `.feeder(Indexer.motor(name))` | recommended, one of the three | a motor feeds the pieces | nothing feeds the wheel | | `.reversed()` | optional | the flywheel turns the other way | - | | `.spinAtStart()` | optional | spins up at ▶, so the first shot goes at once | Defaults to off: it spins up when asked | | `.hood(...)`, `.feedStop(...)`, `.feedWheel(...)` | optional | a hood, a feed stop, a feed wheel ([Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/)) | - | | `.speedFromDistance(camera)` | optional | the speed follows the camera's distance to the goal | Defaults to one speed, `speedRpm` | Its numbers: `speedRpm`, `readyBandRpm` and the speed control (`kP`, `kF`, ...) ([Tunables: Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava)). The feeder's numbers are in its own section ([Indexer](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-tunablesjava)). Every option and command: [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/). ### The other parts | Part | For | Look it up | | --- | --- | --- | | `Lift` | a slide that goes up and down | [Lift](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/) | | `Arm` | a part that swings on a hinge | [Arm](https://crossbotics.com/ftc-helper/docs/reference/parts/arm/) | | `Claw` | a servo that opens and closes | [Claw](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/) | | `Wrist` | a servo that tilts a claw | [Wrist](https://crossbotics.com/ftc-helper/docs/reference/parts/wrist/) | | `Positioner` | any servo or motor that goes to set positions, like a fold-out | [Positioner](https://crossbotics.com/ftc-helper/docs/reference/parts/positioner/) | | `Turret` | a part that turns to aim | [Turret](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/) | | `Camera` | a webcam or Limelight | [Camera](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/) | | `Lights` | a light strip or Blinkin | [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/) | Each part also gets its numbers in `Tunables.java` and its buttons in `Controls.java`. A part has no buttons until you write its lines there. The next pages show how. --- **Next:** [Tunables.java](https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/). **Look it up:** [RobotDefinition and every part](https://crossbotics.com/ftc-helper/docs/reference/robot-java/). **Go deeper:** [how the library fits together](https://crossbotics.com/ftc-helper/docs/guides/architecture/). --- # Tunables.java: the numbers URL: https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/ `Tunables.java` holds your robot's **numbers**: how fast it drives, how far the lift goes, how fast the launcher spins. `Robot.java` says which parts the robot has. `Tunables.java` says their numbers. **Why a separate file:** you change numbers all season. In their own file, you can change them without touching the code that works. ## The smallest Tunables.java This is a whole `Tunables.java` for the robot of the [Robot.java page](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/): only the drive. Click a **(+)** to read what a line does. ```java title="Tunables.java" import static com.crossbotics.ftchelper.robot.Starting.*; // DEFAULT and MEASURE (1)! /** The five files, file 2 of 5: the numbers. One section per part, one number per line. */ public class Tunables { public static class Drive { // (2)! public static double maxPower = 0.5; // top wheel power: slow for the first drives (1.0) (3)! public static double practiceMaxPower = DEFAULT; // top wheel power in PRACTICE (same as maxPower) (4)! public static double slowSpeed = DEFAULT; // top power with the slow trigger held (0.3) public static double strafeCorrection = DEFAULT; // sideways moves: the Drive Tuner finds it (1.15) public static double turnKp = DEFAULT; // auto turns: push per degree off (0.012) public static double turnKd = DEFAULT; // auto turns: brake near the end (0.003) public static double moveMinPower = DEFAULT; // auto: least power that moves it (0.30) public static boolean calibrated = false; // true after the Drive Tuner: auto runs then (5)! } } ``` 1. This line lets you write the words `DEFAULT` and `MEASURE` in place of a number. Without it, the build fails with `cannot find symbol`. 2. A **section**: the numbers of one part. The drive's section is always called `Drive`. 3. A number you chose: half power, so the first drives are slow and safe. The library's own value is in brackets at the end of the comment. 4. `DEFAULT`: use the library's starting value (the one in brackets). Leaving the line out does the same, but the line shows you every number you can change. 5. Autonomous drives the robot only when this is `true`. Set it after the Drive Tuner, when moves are the right length. **The first line of the file** (above the import) must be: ```text package org.firstinspires.ftc.teamcode; ``` ## How the file works **One section per part.** The section's name is the part's name in the robot configuration, in CamelCase: each word starts with a capital letter, with no `_` and no spaces. | The part in Robot.java | Its section | | --- | --- | | the drive | `Drive` (always) | | `Intake.motor("intake")` | `Intake` | | `Positioner.servo("intake_deploy")` | `IntakeDeploy` | | `Launcher.flywheel("shooter", ...)` | `Shooter` | **One number per line.** Write it as `public static double name = value;`, or `public static boolean name = true;` for an on/off setting. Always write `public static`, because the library cannot read a number without it. The name must match exactly, with its capitals: `maxPower` works, `MaxPower` does not. **What to write for each number:** | The number | Write | At INIT | | --- | --- | --- | | You know it | the number | the library uses it | | A tuning number you do not know yet (a speed, `kP`) | `DEFAULT` | the library uses its starting value | | A safety limit or a servo position only your robot can give (a lift's `min`, a claw's `open`) | `MEASURE` | the TeleOp and autos **stop** and name the tool that finds it | **Why `MEASURE` stops:** a guessed limit or servo position can drive a part into the frame and break it. A guessed tuning number only makes a part slow or soft. More: [DEFAULT and MEASURE](https://crossbotics.com/ftc-helper/docs/reference/tunables/#default-and-measure). **Your own numbers.** A section that no part reads is yours, for example `Score` for a wait in one of your actions. Your code reads it as `Tunables.Score.dropWaitSec`. An autonomous's distances stay in its own file ([why](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#the-numbers-are-in-the-step)). ## The drive's numbers | Number | Needed? | What it sets | If you leave it out | Found with | | --- | --- | --- | --- | --- | | `maxPower` | optional | the most power the wheels get | Defaults to 1.0 | test: lower it for new drivers | | `practiceMaxPower` | optional | the most power in the PRACTICE profile | Defaults to `maxPower` (practice at match speed) | test: lower only for a new driver's first day | | `slowSpeed` | optional | the most power while the slow trigger is pulled | Defaults to 0.3 | test | | `strafeCorrection` | recommended (mecanum) | makes autonomous sideways moves the right length | Defaults to 1.15 | the Drive Tuner | | `turnKp` | optional | how hard an autonomous turn pushes, per degree off | Defaults to 0.012 | test: turns stop short (more) or wobble (less) | | `turnKd` | optional | how much an autonomous turn brakes near the end | Defaults to 0.003 | test: turns overshoot (more) | | `moveMinPower` | optional | the least power that still moves the robot | Defaults to 0.30 | test: it stops a little short (more) | | `calibrated` | **yes**, for autonomous | autonomous drives only when it is `true` | Defaults to `false`: autonomous will not drive | the Drive Tuner, then set it | Every drive number, with its units: [Tunables: Drive](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava). ## Tune a number, then copy it back You find most numbers on the robot, with a finder or by testing. Two ways give you a number: - **A finder** (Tune and check, on the Driver Hub) measures it and shows the line to copy, for example `Tunables.Drive: strafeCorrection = 1.210`. The finders: [Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/). - **The tuning menu** changes a number while the robot runs. In the PRACTICE profile, after ▶, hold **GUIDE** for 1 second. Use the D-pad to choose and change a number, and press **A** to save ([tuning menu](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/)). **Copy every number back into `Tunables.java`, then build and install.** The next INIT lists the numbers saved on the hub under "Tuned on this robot (copy into Tunables.java)". **Why:** when you save a number only on the Control Hub, a new hub loses it, and the team's code does not have it. The file is the team's record. ## Check it **Build:** **Build > Make Project** ([the buttons](https://crossbotics.com/ftc-helper/docs/setup/06-build-and-install/#the-buttons)). **Done when:** the build has no red errors. At INIT, the Driver Hub shows one note per part with the numbers it used. A `MEASURE` stops INIT and names the tool that finds the number. ## A part's numbers When you add a part to `Robot.java`, add its section here. The sections below are for the two common parts. Each one shows the part's lines, so you can see what there is to change. Most lines hold `DEFAULT` or `MEASURE`, and a few have example numbers. ### Intake ```java title="Tunables.java" public static class Intake { // "intake" in the configuration public static double inPower = DEFAULT; // power taking pieces in, 0 to 1 (1.0) public static double outPower = DEFAULT; // power pushing pieces out (0.7) } ``` | Number | Needed? | What it sets | If you leave it out | Found with | | --- | --- | --- | --- | --- | | `inPower` | optional | power while it takes pieces in, 0 to 1 | Defaults to 1.0 | test: it throws pieces, or they jam (less) | | `outPower` | optional | power while it pushes pieces out, 0 to 1 | Defaults to 0.7 | test: pieces do not come out (more) | ### Launcher ```java title="Tunables.java" public static class Launcher { // "launcher" in the configuration public static double speedRpm = DEFAULT; // shot speed without the table (60% of top) public static double stepRpm = DEFAULT; // speed change per D-pad press (100) public static double readyBandRpm = DEFAULT; // "at speed" = this close to the target (60) public static double idleRpm = 1500; // spins between shots: quicker first shot (0) public static double shotIntervalSec = DEFAULT; // least time between two pieces (0.25) // The hub's speed control: the defaults for the motor until the Flywheel Finder (INIT shows them). // Then write the Finder's numbers in their place. public static double kP = DEFAULT; // push per speed error (kF / 10) public static double kI = DEFAULT; // fix a steady error (kP / 10) public static double kD = DEFAULT; // brake changes (0) public static double kF = DEFAULT; // steady power for a speed (from the motor) // {inches to the goal, RPM}, blended between rows. Example rows: write the Shot Tuner's instead. public static double[][] speedByDistance = {{24, 2200}, {48, 2550}, {72, 2900}, {96, 3250}}; } ``` | Number | Needed? | What it sets | If you leave it out | Found with | | --- | --- | --- | --- | --- | | `speedRpm` | recommended | the shot speed, in RPM | Defaults to 60% of the motor's top speed | the Shot Tuner, or test | | `kP`, `kI`, `kD`, `kF` | recommended | the hub's speed control | Defaults to numbers worked out from the motor | the Flywheel Finder | | `readyBandRpm` | optional | "at speed" means this close to the target | Defaults to 60 | test: it waits too long to fire (more) | | `idleRpm` | optional | the speed between shots. 0 = stop | Defaults to 0 | test: the first shot spins up too slowly | | `stepRpm` | optional | one D-pad press changes the speed by this | Defaults to 100 | the drivers' choice | | `shotIntervalSec` | optional | the least time between two shots | Defaults to 0.25 | the Flywheel Finder | | `speedByDistance` | optional | the shot table: `{inches, RPM}` rows, for a robot with a camera | Defaults to none: `speedRpm` always | the Shot Tuner | The part that feeds the launcher has its own section, named after its device. For a servo feeder: ```java title="Tunables.java" public static class Indexer { // "indexer" in the configuration public static double rest = MEASURE; // servo position, out of the way (Servo Finder) public static double push = MEASURE; // servo position, piece pushed (Servo Finder) public static double pushSec = DEFAULT; // time to push (0.25, or the servo's speed) public static double returnSec = DEFAULT; // time to come back (the same as pushSec) } ``` `rest` and `push` are **needed**: they are servo positions only your robot can give. The Servo Finder finds them. Every launcher and feeder number: [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava), [Indexer](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-tunablesjava). ### The other parts | Part | Its numbers | | --- | --- | | Lift, Arm | [Lift and Arm](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#in-tunablesjava): `min` and `max` are **needed** | | Claw, Wrist, Positioner | [Claw, Wrist and Positioner](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#in-tunablesjava): the positions are **needed** | | Turret | [Turret](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/#in-tunablesjava) | | Camera | [Camera](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#in-tunablesjava) | | Lights | [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/#in-tunablesjava) | --- **Next:** [Controls.java](https://crossbotics.com/ftc-helper/docs/five-files/03-controls-java/). **Look it up:** [every number of every part](https://crossbotics.com/ftc-helper/docs/reference/tunables/). **Go deeper:** [the finders](https://crossbotics.com/ftc-helper/docs/tuning/) and [the tuning menu](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/). --- # Controls.java: the buttons, and the TeleOp URL: https://crossbotics.com/ftc-helper/docs/five-files/03-controls-java/ `Controls.java` is your TeleOp: the program the drivers pick on the Driver Hub. It says what each button does. The library always sets up its own buttons (driving, pause, the button map). Each part's buttons are lines in this file, so you can read and change every one. ## The smallest Controls.java This is a whole `Controls.java`. The robot has no parts yet, so it has no buttons of its own. It drives on the library's buttons. The file writes them out so you can see each one, and it has a line for every free button. Click a **(+)** to read what a line does. ```java title="Controls.java" import com.crossbotics.ftchelper.robot.ControlMap; import com.crossbotics.ftchelper.robot.Pad; import com.crossbotics.ftchelper.teleop.LibraryButtons; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; /** The five files, file 3 of 5: the buttons, and the TeleOp. */ @TeleOp(name = "First Robot TeleOp") // (1)! public class Controls extends ControlMap { // (2)! public static boolean oneDriver = true; // (3)! // Always there: the library's buttons, on gamepad 1. These lines are the defaults (one driver): // without this method the buttons are the same. Change a line to move a button; null = no button. @Override protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2) { // (4)! lib.swapSticks(false); // left stick: drive and slide; right stick X: turn lib.slow(null); // slow while a trigger is pulled: none (the triggers are free) lib.slowToggle(g1.leftStickButton); // left stick click: slow on / off lib.fieldCentric(g1.rightStickButton); // right stick click, a double tap: field-centric on / off lib.pause(g1.back); // BACK: pause at the press; a tap goes on (5)! lib.resetForward(g1.back); // BACK held 1 s: "forward" is where the robot faces now lib.debug(g1.start, g1.back); // hold START, then press BACK: the debug lines lib.setPose(g1.start); // START held 1 s: set pose here (robots with odometry) lib.buttonMap(g1.guide); // GUIDE: the button map on the Driver Hub lib.tuningMenu(g1.guide); // GUIDE held 1 s: the tuning menu (PRACTICE profile) lib.allianceInInit(g1.x, g1.b); // in INIT: X = BLUE, B = RED } @Override protected void buttons(Robot robot, Pad g1, Pad g2) { // (6)! // Every other button is a line here: each part's buttons, then your own. This robot has no parts yet. // The free buttons: replace free() with a job, e.g. .press(...), .hold(...), .toggle(...), .tap(...). (7)! g1.a.free(); g1.b.free(); // B and X choose the alliance in INIT only: free in the match g1.x.free(); g1.y.free(); g1.lb.free(); g1.rb.free(); g1.lt.free(); // a trigger counts as pressed past half way g1.rt.free(); g1.dpadUp.free(); g1.dpadDown.free(); g1.dpadLeft.free(); g1.dpadRight.free(); g1.rightStickY.free(); // a stick: .use(...) gets its value every loop } } ``` 1. The TeleOp's name in the Driver Hub's list. Change it to your robot's name. 2. `ControlMap`: a TeleOp for the robot in your `Robot.java`. The library runs the loop, drives, and keeps every part updated. 3. `true`: one gamepad. The driver drives and runs the parts, and `g2` lines are on gamepad 1 too. Most teams start here. `false`: add gamepad 2 when you want to split the work, or for jobs that are hard to do while you drive (like arm control). Then the `g2` lines move to gamepad 2 ([One gamepad, and a second one](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#one-gamepad-and-a-second-one-when-you-want-it)). 4. **Always there:** the library's own buttons, one line each. These lines are the defaults, so without this method the buttons are the same. Change a line to move a button. `null` = no button. 5. BACK pauses the robot at once: every motor stops. Keep it on a button: it is the drivers' safety stop. 6. **Every other button is a line here.** A part has no buttons until you add its lines. The reference has each part's usual lines ([Intake: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#buttons-to-add), and the same for every part). 7. **Every free button has a line,** so you see what you can use. Replace `free()` with a job. When you add a part's lines, delete the `free()` lines of the buttons they use: one line per button. **The first line of the file** (above the imports) must be: ```text package org.firstinspires.ftc.teamcode; ``` ## Drive it With `Robot.java`, `Tunables.java` and this file, the robot drives. 1. **Build and install:** **Run** in Android Studio ([the buttons](https://crossbotics.com/ftc-helper/docs/setup/06-build-and-install/#the-buttons)). 2. Put the robot on a block, with its wheels off the floor. 3. On the Driver Hub, pick **First Robot TeleOp** and press **INIT**. The screen shows the button map. 4. Press **▶**. Push the left stick forward: all four wheels turn forward. 5. Take it off the block and drive. `Tunables.Drive.maxPower = 0.5` keeps it slow. 6. Check each one: - Stick up = forward, stick down = back, right stick right = turn clockwise. - Mecanum: left stick right = slide right, in a straight line. - Slow: pull LT (two gamepads; the further you pull, the slower), or click the left stick (one gamepad). - Mecanum: double-tap Y, or the right stick click with one gamepad (two buzzes: field-centric on). Turn the robot 90 degrees, and push the stick up. The robot still goes away from you. - Tap BACK: every part stops and the Driver Hub says PAUSED. Tap BACK again: it drives. **Robot-centric and field-centric.** Robot-centric (the start): stick up = the way the robot faces. Field-centric: stick up = away from the driver, whichever way the robot faces. "Away" is the way the robot faced at INIT, or what the autonomous left. When it is wrong: turn field-centric on, point the robot away from you, and hold BACK 1 s (one buzz). **In the simulator:** pick **Simulator** in the run list and click **Run**. Then pick the TeleOp on the simulator's Driver Hub. **Done when:** the robot drives forward, back, sideways (mecanum) and turns, the way the sticks say. When a wheel turns the wrong way, fix it in `Robot.java`: [a wheel turns the wrong way](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#a-wheel-turns-the-wrong-way). ## Two kinds of buttons **The library's own buttons are always there**, on gamepad 1. You write nothing for them, and every TeleOp has them. **Why:** BACK must always pause the robot, even in a file with a mistake. | Job | One gamepad (`oneDriver = true`) | Two gamepads | | --- | --- | --- | | Drive and slide | left stick | left stick | | Turn | right stick, left and right | right stick, left and right | | Slow | left stick click: slow on/off | LT (the further, the slower) | | Field-centric on/off (mecanum) | right stick click (a double tap) | Y (a double tap) | | Pause / go on | BACK (a tap) | BACK (a tap) | | Button map on the screen | GUIDE (a tap) | GUIDE (a tap) | | Tuning menu | GUIDE (held 1 s) | GUIDE (held 1 s) | | Choose the alliance (in INIT) | X = BLUE, B = RED | X = BLUE, B = RED | To move one: [Moving the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/). **Every other button is a line in `buttons(...)`.** A part has no buttons until you add its lines, so every button the robot has is a line you can read in this file. Each part's usual lines, ready to copy: | Part | Usual buttons | The lines | | --- | --- | --- | | Intake | RT: in (hold). LT: out (hold) | [Intake: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#buttons-to-add) | | Launcher | LB: spin up / down. RB: fire one (tap), keep firing (hold). D-pad up and down: speed | [Launcher: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#buttons-to-add) | | Lift | A, X, Y: heights. D-pad up and down: next height. Left stick: by hand | [Lift: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#buttons-to-add) | | Arm | right stick: by hand | [Arm: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/arm/#buttons-to-add) | | Claw | B: open / close | [Claw: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#buttons-to-add) | | Wrist | D-pad left and right: positions | [Wrist: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/wrist/#buttons-to-add) | | Turret | right stick, left and right: by hand. right stick click: follow the goal on / off | [Turret: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/#buttons-to-add) | **INIT tells you what is missing.** When a part's usual buttons are not in `Controls.java`, INIT shows a line for it, for example `Intake: usual buttons not in Controls.java: G2 RT (in (hold)), G2 LT (out (hold))`. INIT counts a button you used for something else as your choice. ## A whole robot's buttons The example [`allbuttons/Controls.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/allbuttons/Controls.java) is a robot with a mecanum drive, an intake, a launcher and two drivers. It has every library button in `libraryButtons(...)`, the intake's and the launcher's usual lines, and a `free()` line for every free button on both gamepads. A test checks that its lines are the parts' usual ones. ## Add your own button Each button line has up to four pieces: ```java // 1. which button 2. how it starts 3. what it does 4. what the drivers see g2.y .press( robot.claw::open) .says("open the claw"); ``` For example, two buttons for a claw and a lift: ```java title="Controls.java" // Once per press. "::" hands over the method; the button runs it later. g2.y.press(robot.claw::open).says("open the claw"); // Several commands: "() ->" starts a small piece of code (a lambda). g2.x.press(() -> robot.lift.goTo("low")).says("lift to low"); ``` **Always add `.says(...)`.** The words go on the button map, so the drivers know what the button does. ### 1. Which button | Buttons | Name in the code | | --- | --- | | Face buttons | `a`, `b`, `x`, `y` | | Bumpers | `lb`, `rb` | | Triggers (pressed past half way) | `lt`, `rt` | | D-pad | `dpadUp`, `dpadDown`, `dpadLeft`, `dpadRight` | | Stick clicks | `leftStickButton`, `rightStickButton` | | Small buttons | `back`, `start`, `guide` | | Sticks (a number from -1 to 1) | `leftStickX`, `leftStickY`, `rightStickX`, `rightStickY` | ### 2. How it starts: the press types | Press type | Write | The job runs | | --- | --- | --- | | Press | `.press(job)` | once, the moment the driver presses it | | Let go | `.release(job)` | once, the moment the driver lets it go | | Hold | `.hold(job)` | every loop while the driver holds it | | Hold, then stop | `.hold(job, stopJob)` | every loop while the driver holds it, then `stopJob` once when the driver lets go | | On / off | `.toggle(part)` | each press switches the part on or off | | On / off, two jobs | `.toggle(onJob, offJob)` | presses take turns | | Tap | `.tap(job)` | once per quick press | | Double tap | `.doubleTap(job)` | once, on the second quick tap | | Several taps | `.taps(3, job)` | once, on the last of 2 to 5 quick taps | | Tap, then hold | `.tapThenHold(job)` | a tap, then press again and hold: every loop while held | | Held for a time | `.heldFor(1.0, job)` | once, after the driver holds it 1 s: a safe "are you sure?" | | Two buttons | `g2.lb.with(g2.y, job)` | once, when the driver presses Y while holding LB | | A stick | `g2.leftStickY.use(robot.lift::manual)` | every loop, with the stick's value | **Gestures can share a button.** `tap`, `doubleTap`, `taps`, `tapThenHold`, `heldFor` and `hold` chain on one button, each with its own job: ```java g2.rb.tap(robot.launcher::fire).says("fire one") .hold(robot.launcher::fireWhileHeld, robot.launcher::ceaseFire).says("keep firing"); ``` `press`, `toggle` and `release` each need a button of their own. [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/) says when each gesture's job runs, and how to change the double-tap time and the hold time. ### 3. What it does | The job | Example | | --- | --- | | A part's command | `robot.claw::open` | | A few commands | `() -> { robot.claw.open(); robot.intake.stop(); }` | | An action: several steps, like "score" | `Actions.scoreHigh(robot)` (the next page: `Actions.java`) | | A part to switch on and off | `robot.intake` (with `.toggle(...)`) | **A job must never wait.** No `sleep(...)` and no `while` loop: it freezes the whole robot. To do steps one after another, use an action. ### 4. What the drivers see and feel | You want | Write | | --- | --- | | Words on the button map | `.says("open the claw")` | | A buzz when the job runs | `.rumble()`, or `.rumble(2)` for two buzzes | | A buzz when something becomes true | `g2.rumbleWhen(robot.launcher::isReady);` (a line of its own) | | A value on the Driver Hub | `show("Lift", robot.lift::position);` (a line of its own) | ## Change a part's button A part's buttons are your lines: change the button in its line. For example, the intake on the bumpers in place of the triggers: ```java title="Controls.java" // The intake's usual lines are on RT and LT: here the same jobs are on the bumpers. g2.lb.hold(robot.intake::holdIn, robot.intake::stop).says("intake in (hold)"); g2.rb.hold(robot.intake::out, robot.intake::stop).says("intake out (hold)"); ``` ## Check it **Build and install**, then INIT the TeleOp. **Done when:** INIT shows your button map with your words, and each button does its job. INIT stops with a message when a button has two jobs, or when your job is on one of the library's buttons. The message names the button. **If the drive goes wrong:** | Problem | Fix | | --- | --- | | INIT stops with a list of names | A motor name in `Robot.java` does not match the configuration (capitals too) | | It spins or drifts when it should go straight | A motor direction is wrong: [a wheel turns the wrong way](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#a-wheel-turns-the-wrong-way) | | Stick up drives backward | Every direction is flipped: reverse the other side | | It slides on a slant when it should slide sideways | Two motor names are on the wrong wheels (for example `front_left` and `back_left` swapped) | | Field-centric goes the wrong way or circles | The IMU's logo and USB directions ([check it](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#how-your-control-hub-is-mounted)), or "away" is wrong: hold BACK 1 s | | Everything stopped and does not move | It is paused: tap BACK | | Slow even without LT | `maxPower` is low, or `practiceMaxPower` is low in the PRACTICE profile | --- **Next:** [Actions.java](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/). **Look it up:** [every press type and option](https://crossbotics.com/ftc-helper/docs/controls/). **Go deeper:** [the cookbook's button recipes](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/). --- # Actions.java: several parts together URL: https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/ ## Do you need it yet? Maybe not. A job for one part is a button line in `Controls.java`, with no action. Some parts also come with **ready-made actions**, which need no line in `Actions.java`. | Ready-made action | What it does | Use it | | --- | --- | --- | | Fire 1, Fire 2 ... | fires that many pieces. It is done when the last one has left | `robot.launcher.fireAction(2)` | | Fire all | fires every piece the robot holds | `robot.launcher.fireAllAction()` | | Fire at a speed | the same, at this flywheel speed (RPM), then back to the usual speed | `robot.launcher.fireAction(2, 2250)` | | Ready to launch | spins up. It is done when the flywheel is at speed | `robot.launcher.readyAction(3)` (3 = at most 3 s) | | Eject | one piece out at a low speed, like a wrong-color piece | `robot.launcher.ejectAction()` | **You need `Actions.java`** when one button or one autonomous step must do several things in order, or must wait for one part before the next part moves. ## The smallest Actions.java This is a whole `Actions.java`. The robot has no parts yet, so it has no actions. Copy it now: the autonomous files on the next page use it. ```java title="Actions.java" import com.crossbotics.ftchelper.robot.Action; // (1)! /** The five files, file 4 of 5: steps that use several parts together. */ public class Actions { // One method per action: public static Action name(Robot r) { ... }. Use it in Controls.java and in autos. (2)! // This robot has no parts yet, so it has no actions. A part's ready-made actions need no line here. } ``` 1. Every action is an `Action`. This line lets the file use that name. 2. Each action is one method in this class. The next section shows one, line by line. **The first line of the file** (above the import) must be: ```text package org.firstinspires.ftc.teamcode; ``` ## Your first action This robot has the two common parts from the [Robot.java page](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#add-a-part): an intake and a launcher. Its action fires 3 pieces while the intake runs, to push each piece in. Click a **(+)** to read what a line does. ```java title="Actions.java" /** Fires 3 pieces with the intake running, to push each one in. Then the intake stops. */ public static Action fireWithIntake(Robot r) { // (1)! return Action.named("Fire with intake") // (2)! .then(r.intake::in, () -> r.launcher.fire(3)) // (3)! .waitUntil("the shots", () -> !r.launcher.isShooting(), 9.0) // (4)! .then(r.intake::stop); // (5)! } ``` 1. `public static Action`: a method that makes the action. `r` is your robot, so the steps can use `r.intake` and `r.launcher`. You start it with the class name: `Actions.fireWithIntake(robot)`. 2. `Action.named(...)` starts a new action. The Driver Hub shows the name while it runs. 3. `.then(...)` does these now, in the same loop, then goes to the next step. It has two commands, so the intake and the launcher start together. - `r.intake::in` is a **method reference**: "run `r.intake.in()` when the action gets here". - `() -> r.launcher.fire(3)` is a **lambda**: the same, for a command with inputs. 4. `.waitUntil(...)` waits until the test is true: the launcher is not shooting any more. - `"the shots"`: the words on the Driver Hub while it waits. - `9.0`: the **time limit**, in seconds. If the shots are not done in 9 s, the action stops and the Driver Hub says why. A wait never goes on forever. 5. The last step: the intake stops. Then the action is done. ## The steps Every action is built from four steps: | Step | What it does | Example | | --- | --- | --- | | `.then(command)` | does it now, then goes to the next step | `.then(r.claw::open)` | | `.then(command, command, ...)` | does them all now, in the same loop: the parts move together | `.then(r.intake::in, r.claw::close)` | | `.waitSeconds(s)` | waits this many seconds. The robot keeps running: this is `sleep`, done safely | `.waitSeconds(0.5)` | | `.waitUntil("words", test, s)` | waits until the test is true, at most `s` seconds. When it waits too long, the action stops | `.waitUntil("lift up", r.lift::isAtTarget, 2.0)` | **What you can wait for:** each part answers yes / no questions. | Part | Questions | | --- | --- | | Launcher | `isReady()` (at speed), `isShooting()`, `isSpinning()`, `isEjecting()` | | Intake | `isRunning()`, `isPushingOut()` | | Lift, Arm (a motor) | `isAtTarget()`, `isAt("high")` | | Claw, Wrist, Positioner (a servo) | `isDone()`, `isAt("open")`. A servo cannot say where it is: `isDone()` turns true after its travel time, `travelSec` ([Tunables](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#in-tunablesjava)) | | Turret | `isAimed()`, `isHomed()` | | Pieces | `isFull()`, `isEmpty()` | To wait for the opposite, put a `!` in front: `() -> !r.launcher.isShooting()` = "not shooting". ## Start it from a button Write the button's line in `Controls.java`, inside `buttons(...)`, in place of its `free()` line: ```java title="Controls.java" g2.y.press(Actions.fireWithIntake(robot)).says("fire 3 with the intake"); g2.x.press(robot.launcher.fireAllAction()).says("fire all"); // a ready-made action ``` - `press(action)` starts the action. **Press again while it runs, and it stops** (canceled, safely). - The other press types start an action too: `tap`, `doubleTap`, `heldFor`, `with` ([the press types](https://crossbotics.com/ftc-helper/docs/five-files/03-controls-java/#2-how-it-starts-the-press-types)). ## Use it in an autonomous In an autonomous, the same action is a step. The next page explains autonomous files. Below is only the action's line. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .alongside(robot.launcher.readyAction(3)) // spin up while it drives .forward("To the shooting spot", 24, 0.5) .action(Actions.fireWithIntake(robot), 9) // waits until it is done (at most 9 s) .right("Park", 12, 0.5); ``` | Step | What it does | | --- | --- | | `.action(action, s)` | starts the action and waits until it is done, at most `s` seconds (10 if you leave it out). When it takes too long, the autonomous cancels it, the report says so, and the autonomous goes on | | `.alongside(action)` | starts the action and goes on at once: it runs during the next steps | **Why write it once:** fix the action in `Actions.java`, and TeleOp and every autonomous get the fix. The simulator's **auto builder** lists your `Actions.java` actions too, next to the ready-made ones ([the auto builder](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/)). ## The rules every action follows - **It never makes the robot wait.** An action does a little every loop. The robot keeps driving and every other button works while it runs. **Why:** a `sleep()` or a `while` loop in a button job freezes the whole robot until it ends. Put the wait in an action: `.waitSeconds(...)`, `.waitUntil(...)`. - **The driver always wins.** When the driver moves a part the action uses, the action stops. - **One part, one action.** When a second action commands the same part, the first action stops. - **A wait that runs out of time stops the action.** The Driver Hub says why, for example `timed out waiting for the shots`. - **A stopped action leaves its parts safe.** An intake stops, a lift holds its height, and the launcher drops the shots still waiting. A finished action keeps its last commands. - **A part that is not on the robot yet** (`.optional()` in Robot.java): the action skips it and goes on with the other parts. ## An action when the OpMode starts An action can run once, right after ▶, in autonomous and in TeleOp. For example, it folds an intake down. **Where:** `Robot.java`, in `define()`. ```java title="Robot.java" // In Robot.java's define(): this action runs once, right after ▶ (autonomous and TeleOp). atStart(() -> Actions.deployIntake(this)); ``` It never runs in INIT. **Why:** people are still next to the robot in INIT, so the library moves nothing before ▶. This is the library's choice, not a game rule. ## Check it **In the simulator:** pick **Simulator** in the run list next to Android Studio's **Run** button, and click **Run**. Pick your TeleOp, INIT, ▶. Press the action's button. **On the robot:** 1. Put pieces in the robot. Stand clear of the launcher. Keep a hand near STOP. 2. INIT, ▶. Press the action's button. 3. Watch the Driver Hub: `Fire with intake: step 2 of 3 (the shots)`. After it ends: `done`. 4. Press the button, then press it again: the Driver Hub says `canceled`, and the intake stops. **Done when:** one button runs every step in order, and a second press stops it. ## If something goes wrong | Problem | Why, and the fix | | --- | --- | | `timed out waiting for ...` | The part needs more time than the limit, or it never got there. Tune the part, or give the wait more seconds. | | The action stops at once | Something else commands the same part: the driver's stick or button, or another action. | | Nothing happens on the button | Another line uses the same button (INIT stops and names it), or this press canceled the action. | | The robot freezes while a button job runs | The job has a `sleep()` or a `while` loop. Make it an action with `.waitSeconds(...)`. | | `cannot find symbol: Actions` | The file is not in the `teamcode` folder, or its first line is not `package org.firstinspires.ftc.teamcode;`. | --- **Next:** [autos/](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/). **Look it up:** [Action: every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#action). **Go deeper:** [Why commands never wait](https://crossbotics.com/ftc-helper/docs/guides/non-blocking/) and [the cookbook's action recipes](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/). --- # autos/: your autonomous programs URL: https://crossbotics.com/ftc-helper/docs/five-files/05-autos/ On this page you make the smallest auto: the robot drives out of its start spot. With it, your robot is the **smallest robot that works**. It drives in TeleOp, and it runs an autonomous. ## Make the folder **If you started from [Pick your start](https://crossbotics.com/ftc-helper/docs/pick-your-start/):** you already have the `autos` folder and an autonomous in it. Do not make them again. Read this page, and compare your file with the one below. In Android Studio's **Project** panel, right-click the `teamcode` folder, then **New > Package**. Type `autos` after the `teamcode.` that is already there. **Why "Package":** in Java, a folder of code is a package. More help: [make a new file or folder](https://crossbotics.com/ftc-helper/docs/start-from-zero/#make-a-new-file-or-folder). ## The smallest auto Make a new Java file `FirstAuto` in the `autos` folder (right-click `autos`, **New > Java Class**). Replace everything in it with this. Click a **(+)** to read what a line does. ```java title="autos/FirstAuto.java" import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; /** The five files, file 5 of 5: an autonomous. The smallest one: it drives out of the start spot. */ @Autonomous(name = "First Robot Auto", preselectTeleOp = "First Robot TeleOp") // (1)! public class FirstAuto extends Auto { // (2)! @Override protected void steps(Steps s, Robot robot) { // (3)! s.start("Against our wall, facing the field", 0) // (4)! .forward("Leave the start", 12, 0.4); // (5)! } } ``` 1. `name`: the auto's name on the Driver Station. `preselectTeleOp`: the name of your TeleOp, exactly as in `@TeleOp(name = ...)` in `Controls.java`. When the auto ends, the Driver Station has that TeleOp chosen and ready. 2. `extends Auto`: this file is an autonomous for your robot. `Auto` is the library's autonomous. `` is your `Robot.java`, so every part on the robot is in `robot`. 3. `steps(...)` is a **list of steps, read top to bottom**. Each step starts on a new line with a dot. The last step ends with `;`. 4. `start(...)`: where the drive team puts the robot. - The words show on the Driver Hub in INIT. Write them for a nervous driver. - `0` is the **heading**: the way the robot faces. 0 = straight away from your drivers. TeleOp's field-centric "forward" uses it too, so get it right. 5. `forward(...)`: drive forward. It waits until the move is done, then goes to the next step. - `"Leave the start"`: the step's name, in the report at the end. - `12`: how far, in inches. - `0.4`: the most power it may use (0 to 1). It slows down near the end, so it does not overshoot. **The first lines of the file** (above the imports) must be: ```text package org.firstinspires.ftc.teamcode.autos; import org.firstinspires.ftc.teamcode.Robot; ``` **Why the extra import:** `Robot.java` is in the folder above `autos`, called `teamcode`. This line tells Java where it is. `Controls.java` needs no such line, because it is in the same folder as `Robot.java`. ## The numbers are in the step Write each distance in the step: `12`, not a name from `Tunables.java`. **Why:** - Each auto has its own numbers. When you change one auto, the others do not change. - The [auto builder](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/) can read the auto, change a number, and give you the new file. `Tunables.java` keeps the **robot's** numbers: speeds, positions and gains. They are the same in every auto. ## Tune the drive first On a real robot, an auto **does not move** until you tell it that the drive is tuned. The Driver Hub says `AUTONOMOUS IS OFF: the drive is not tuned yet`. **Why:** the robot only knows how far its wheels turned. If the wheel size is a little wrong, every move is a little wrong. The library stops a robot that could drive much too far. 1. On the Driver Hub, pick **Tune and check** (TeleOp list, group "Finders"). You need no file for it. 2. Pick **Drive Tuner**, then run its **Drive** test, and its **Strafe** test for a mecanum robot. Each one drives 48 inches. Measure, and enter what you measured. 3. Copy the lines it shows into your files. The wheel size goes in `Robot.java`, and the strafe correction goes in `Tunables.java`. 4. In `Tunables.java`, set `calibrated = true` in the `Drive` section. Every step, and what each screen shows: [the Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/). **The simulator does not need this.** There, an auto runs before the Drive Tuner, with the warning `Drive not tuned: runs in the simulator only`. ## What you get with no extra code You wrote only the list of steps. Every auto also gets these: | You get | What it does | | --- | --- | | An INIT menu | **X** = blue alliance, **B** = red. A start delay (0 to 10 s), to keep out of a partner's way. The PRACTICE or COMPETITION profile. D-pad up/down picks a line, left/right changes it. | | The 30 s timer | The steps stop when autonomous ends. Everything stops, even after an error. | | The report | One line per step at the end, like `Leave the start: done`. It is in the robot log, and on TeleOp's INIT screen too. | | The change to TeleOp | The alliance and the robot's heading go to TeleOp, so field-centric stays right. | ### PRACTICE and COMPETITION A **profile** is a mode for the whole robot: autos and TeleOp. The Control Hub saves it, and it stays until someone changes it. | | PRACTICE | COMPETITION | | --- | --- | --- | | For | the shop, tests, first runs | matches | | Wheel power | the same: `maxPower` (unless you set `practiceMaxPower`) | `maxPower` | | Extra lines on the screen | yes | no | | The tuning menu | can open | stays closed | | INIT says | `!! PRACTICE profile` | nothing | **Change it** in any auto's INIT menu: the **Profile** line. COMPETITION is the default, so a new robot is safe at an event. **Before every match:** check that it says COMPETITION. More: [Profiles](https://crossbotics.com/ftc-helper/docs/guides/profiles/). **Red and blue:** a move straight forward or back is the same for both alliances. Moves to the side and turns can need a change for red: [red and blue](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue). ## More steps Start with these steps. Write each one on a new line, before the `;`: | Step | What it does | Example | | --- | --- | --- | | `.forward(name, inches, power)` | drives forward, then waits until it is there | `.forward("To the goal", 24, 0.5)` | | `.back(name, inches, power)` | drives backward | `.back("Off the wall", 6, 0.4)` | | `.left(name, inches, power)`, `.right(...)` | slides to the side, still facing the same way (mecanum only) | `.right("Park", 20, 0.7)` | | `.turnLeft(name, degrees, power)`, `.turnRight(...)` | turns in place | `.turnLeft("Face the goal", 45, 0.4)` | | `.waitSeconds(name, s)` | waits this many seconds | `.waitSeconds("Let it settle", 0.5)` | | `.action(action, s)` | runs an action from `Actions.java`, then waits until it is done (at most `s` seconds) | `.action(Actions.fireWithIntake(robot), 9)` | Write the numbers in these steps as plus numbers. The word says which way. (A minus number goes the other way: `back(..., -6, ...)` drives forward. Use the other word.) **At an angle.** `.move(name, inches, angle, power)` drives at any angle, and `.turn(name, degrees, power)` turns by any angle. Every angle in an autonomous counts the same way: **counterclockwise, 90 = left**, like the IMU (the hub's turn sensor). The same is true for the heading in `start(...)`. More, with a picture: [every angle counts counterclockwise](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#the-words-in-every-step). More: [signs and units](https://crossbotics.com/ftc-helper/docs/conventions/). An action in an auto: [Actions.java, use it in an autonomous](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#use-it-in-an-autonomous). ## Check it **In the simulator:** pick **Simulator** in the run list next to Android Studio's **Run** button, and click **Run**. Pick **First Robot Auto** (your auto's name), INIT, ▶. The robot drives forward 12 in. **To run it again,** press **Back to start** first (Control Hub panel, Robot tab). This auto gives no spot on the field, so the simulator leaves the robot where it stopped last time. **On the robot:** 1. Do [Tune the drive first](#tune-the-drive-first). 2. In INIT, pick the **PRACTICE** profile ([above](#practice-and-competition)). It shows the debug lines. For a slow first run, set `maxPower` low in `Tunables.Drive`. 3. Put the robot where the `start` words say. Keep a hand near STOP. 4. INIT, read the words, ▶. Read the report at the end. 5. Measure how far it went. Change the number in the step, build and install, and run it again. **Done when:** the robot drives out of its start spot, and the report says `Leave the start: done`. Your robot now drives in TeleOp and in autonomous. ## If something goes wrong | Problem | Why, and the fix | | --- | --- | | `AUTONOMOUS IS OFF: the drive is not tuned yet` | `calibrated` is `false`. Do [Tune the drive first](#tune-the-drive-first). | | The auto is not on the Driver Station | When it is in the TeleOp list, the file needs `@Autonomous`. When it is in no list, build and install again. | | `cannot find symbol: Robot` | The `import org.firstinspires.ftc.teamcode.Robot;` line is missing. | | It drives the wrong distance | The wheel size is wrong. Run the Drive Tuner's **Drive** test again. | | It drives the wrong way | The heading in `start(...)` is wrong, or the hub's direction in `imu(...)` in `Robot.java`. Check both. | | The TeleOp is not chosen after the auto | `preselectTeleOp` must be the TeleOp's name, exactly. | --- ## Next Your robot is the smallest robot that works. **Next:** [Add to your robot](https://crossbotics.com/ftc-helper/docs/add-to-robot/): add parts, one at a time. Then [Controls](https://crossbotics.com/ftc-helper/docs/controls/) and [Building autos](https://crossbotics.com/ftc-helper/docs/building-autos/): turns, actions, multiple autos, the auto builder, and choices in INIT. **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto). **Go deeper:** [the cookbook's autonomous recipes](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/). --- # Controls URL: https://crossbotics.com/ftc-helper/docs/controls/ | # | Page | You learn | | --- | --- | --- | | 1 | [How buttons work](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/) | One gamepad or two. The four pieces of a button line. What a job can be, and modes. What INIT checks. | | 2 | [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/) | Every way to press: tap, hold, double tap, toggle, two buttons together, and more. One line of code each. | | 3 | [What the drivers see and feel](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/) | Words on the button map, buzzes, lights, and values on the screen. | | 4 | [Move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/) | Driving, pause, field-centric, the menus: put them on other buttons, or free them. | **Start with page 1.** Each page has short examples. Copy the ones your robot needs. **Next:** [How buttons work](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/). --- # How buttons work URL: https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/ ## One gamepad, and a second one when you want it Most teams start with **one gamepad**. One driver drives and runs the parts. The second team member at the field helps: they watch the field, call out game pieces and time, and watch the robot's parts. **Gamepad 2 is optional.** Add it when your team wants to split the work, or for jobs that are hard to do while you drive, like arm control. Then the **driver** (gamepad 1) drives, and the **operator** (gamepad 2) runs the parts. | In the code | One gamepad (`oneDriver = true`) | Two gamepads (`oneDriver = false`) | | --- | --- | --- | | `g1` | gamepad 1, the driver | gamepad 1, the driver | | `g2` | **also gamepad 1** | gamepad 2, the operator | The switch is one line at the top of `Controls.java`. The starting files have `oneDriver = true`. **Where:** `Controls.java`, at the top of the class. ```java title="Controls.java" public static boolean oneDriver = true; // false: gamepad 2 runs the parts ``` **Write the parts' buttons on `g2` from the start.** With one gamepad, `g2` is gamepad 1, so they work now. When you add gamepad 2 later, change `oneDriver` to `false`, and those lines move to gamepad 2. You change no other line. With one gamepad, two lines on the same button stop INIT with a message. The library's own buttons also move a little with one gamepad: slow goes on the left stick click. So the triggers are free for your parts ([Every library button](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/#every-library-button)). ## The buttons The docs use the Logitech names (A, B, LB...). A PlayStation controller has the same buttons with other names. The code name is the same for both. The library's screens (the button map, the tuning menu) show the names on the controller that is plugged in. ![A gamepad with each button's code name, Logitech name and PlayStation name](https://crossbotics.com/ftc-helper/docs/images/gamepad-buttons.svg) | Buttons | Logitech | PlayStation | Name in the code | | --- | --- | --- | --- | | Face buttons | A, B, X, Y | × cross, ○ circle, □ square, △ triangle | `a`, `b`, `x`, `y` | | Bumpers | LB, RB | L1, R1 | `lb`, `rb` | | Triggers (they count as pressed past half way) | LT, RT | L2, R2 | `lt`, `rt` | | D-pad | D-pad | D-pad | `dpadUp`, `dpadDown`, `dpadLeft`, `dpadRight` | | Stick clicks (press the stick down) | left and right stick | L3, R3 | `leftStickButton`, `rightStickButton` | | Small buttons | BACK, START, GUIDE (the middle button) | SHARE, OPTIONS, PS | `back`, `start`, `guide` | | Sticks (a number from -1 to 1, up and right are +) | left and right stick | left and right stick | `leftStickX`, `leftStickY`, `rightStickX`, `rightStickY` | ## The four pieces of a button line Each button line has up to four pieces, like an order from a menu: ```java // 1. which button 2. how it starts 3. what it does 4. feedback g2.lb .tap( robot.launcher::fire) .says("fire one").rumble(); ``` 1. **Which button:** the gamepad, a dot, then the button: `g2.lb`. 2. **How it starts:** the press type, for example `.tap(...)` or `.hold(...)` ([Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/)). 3. **What it does:** the job (below). 4. **Feedback:** what the drivers see and feel. Optional, but always add `.says(...)`: the words go on the button map ([What the drivers see and feel](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/)). **Where:** `Controls.java`, inside `buttons(Robot robot, Pad g1, Pad g2) { ... }`. ```java title="Controls.java" g2.y.press(robot.claw::open).says("open the claw"); g2.x.press(() -> robot.lift.goTo("low")).says("lift to low"); ``` `buttons(...)` runs once, at INIT. It only connects the jobs to the buttons. The library's **loop** then runs many times a second: each time, it reads the gamepads, runs the jobs that are due, and updates every part. You never write the loop. ## What a job can be | Kind | Example | Notes | | --- | --- | --- | | A method of a part | `robot.claw::open` | `::` hands over the method, and the button runs it later | | A few commands | `() -> { robot.claw.open(); robot.intake.stop(); }` | `() ->` starts a small piece of code (a **lambda**) | | An action (several steps) | `Actions.scoreHigh(robot)` | for `press`, `tap`, `doubleTap`, `taps`, `heldFor`, `with`: the gesture starts it, and the same gesture again cancels it ([Actions.java](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/)) | | A part to switch | `robot.intake` | for `toggle(...)` only | | A mode to switch | `robot.turret.followMode()` | for `toggle(...)` only ([Modes](#modes), below) | **A job must never wait.** Put no `sleep(...)` and no `while` loop in a job. The code compiles, but it freezes the **whole robot** until the job ends: no driving, no other button, no part updates. The Driver Station then warns: `... took 512 ms: the whole robot stopped that long. No sleep() or while loop in a button job: use an Action with waitSeconds (docs: Actions.java)`. To wait between steps, make an action with `waitSeconds(...)` or `waitUntil(...)`, and put the action on the button ([Actions.java](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/)). ### Modes A **mode** is a rule a part follows every loop while the mode is on. For example, the turret follows the goal, or the robot turns to face the goal. A mode is for an "always" rule. An action is for steps that end. | Mode | What it does while it is on | | --- | --- | | `robot.turret.followMode()` | the turret turns to the goal ([Turret](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/)) | | `robot.aimMode()` | the whole robot turns to face the goal ([Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/)) | | `robot.launcher.speedMode()` | the launcher sets its speed from the distance to the goal ([Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/)) | | `robot.aim().movingShotMode()` | the aim corrects for the robot's motion, so it can shoot while it drives (needs odometry, [Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/)) | | `robot.reverseDriveMode()` | the back of the robot acts as the front: forward and slide flip, turning does not | A button switches a mode like a part. **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" g2.rightStickButton.toggle(robot.turret.followMode()).rumble().says("follow the goal on/off"); ``` With `.rumble()`, the drivers feel it: two buzzes = on, one buzz = off. Some modes turn on only when they can work: whole-robot aim needs a goal in view. A press that cannot turn it on gives one buzz (off). An action or an auto can switch a mode too: `robot.turret.followMode().on()` ([Modes in the reference](https://crossbotics.com/ftc-helper/docs/reference/steps/#modes)). ## The library's own buttons Some of gamepad 1's buttons have library jobs: driving, pause, the menus. You write nothing for them. **Why:** BACK must always pause the robot, even in a file with a mistake. | Job | One gamepad (`oneDriver = true`) | Two gamepads | | --- | --- | --- | | Drive and slide | left stick | left stick | | Turn | right stick, left and right | right stick, left and right | | Slow | left stick click: slow on/off | LT (the further, the slower) | | Field-centric on/off (mecanum with an IMU or odometry) | right stick click (a double tap) | Y (a double tap) | | Pause / go on | BACK (a tap) | BACK (a tap) | | Debug lines | START, then BACK | START, then BACK | | Set pose here (odometry) | START (held 1 s) | START (held 1 s) | | Button map on the screen | GUIDE (a tap) | GUIDE (a tap) | | Tuning menu | GUIDE (held 1 s) | GUIDE (held 1 s) | | Choose the alliance (in INIT) | X = BLUE, B = RED | X = BLUE, B = RED | Field-centric on/off needs a **double tap**: two presses within 0.35 s. **Why:** one tap by accident would turn the sticks around. You can move or free every one of these buttons: [Move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/). ## A part's buttons A part has no buttons until `Controls.java` has its lines. So every button the robot has is a line you can read in this file. Each part's page has its usual lines, ready to copy ("Buttons to add" in the [part pages](https://crossbotics.com/ftc-helper/docs/reference/)). INIT names each usual button of a part that is still free: `Intake: usual buttons not in Controls.java: G2 RT (in (hold)), ...`. ## The rules (INIT checks them) - **One job per button, or several gestures.** A button with `press(...)` and `tap(...)` stops INIT: `Controls.java: G2 B has two jobs`. The same gesture twice stops INIT too: `G2 A has two "tap" jobs`. - **A job of yours on a library button** stops INIT. The message names the button. Move the library's job first ([page 4](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/)). - **Two things on one button:** put both in one lambda: `g2.dpadLeft.press(() -> { robot.claw.open(); robot.intake.stop(); }).says("drop")`. - **`.free()` keeps a button empty**, for example `g2.rightStickX.free()`. INIT then does not name it as free. - **A button that is down as you press ▶** (start on the Driver Hub), or as the tuning menu closes, does nothing until you let it go. **Why:** a thumb that rests on a button must not start a job. ## Done when - Each button line in your `Controls.java` has a `.says(...)`. - INIT shows no stop message about buttons. - A tap of GUIDE shows the button map, and it lists every button you wrote. --- **Next:** [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/). **Look it up:** [Controls.java reference](https://crossbotics.com/ftc-helper/docs/reference/controls/). **Go deeper:** [the cookbook's button recipes](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/). --- # Press types URL: https://crossbotics.com/ftc-helper/docs/controls/02-press-types/ A **press type** says when the job runs: at the press, while the driver holds the button, on a double tap, and so on. Last season's fire button took about 40 lines of timers and "was it down last loop?" flags. Here it is one line per press type. "Every loop" below means each time round the library's loop, many times a second. ## Every press type **Where:** `Controls.java`, inside `buttons(...)`. | You want | Write | When the job runs | | --- | --- | --- | | Press once | `g2.y.press(robot.claw::open)` | once, the moment the driver presses it | | Let go | `g2.y.release(robot.claw::close)` | once, the moment the driver lets go | | Hold | `g1.a.hold(robot.intake::in)` | every loop while the driver holds it. The intake still runs after the release: add a stop job (next row) | | Hold, then stop | `g1.a.hold(robot.intake::in, robot.intake::stop)` | every loop while held, then the stop job once at the release | | On / off switch | `g1.x.toggle(robot.intake)` | each press switches the part (an intake, a launcher, a claw, a mode) | | On / off, two jobs | `g2.b.toggle(robot.claw::close, robot.claw::open)` | presses take turns: on, off, on... | | Tap (a quick press) | `g2.rb.tap(robot.launcher::fire)` | once per tap | | Double tap | `g2.rb.doubleTap(() -> robot.launcher.fire(3))` | once, on the second quick tap | | Several taps | `g2.x.taps(3, () -> robot.lift.goTo("high"))` (2 to 5) | once, on the last quick tap | | Tap, then hold | `g2.lb.tapThenHold(robot.intake::out, robot.intake::stop)` | a tap, then press again and hold: every loop while held | | Held for a time | `g2.dpadLeft.heldFor(1.0, robot.launcher::stop)` | once, after the driver holds it 1 s: a safe "are you sure?" | | Two buttons together | `g1.rb.with(g1.dpadUp, () -> robot.lift.goTo("high"))` | once, when the driver presses D-pad up while holding RB | | A stick | `g2.rightStickY.use(robot.lift::manual)` | every loop, with the stick's value (-1 to 1) | The method names (`open`, `in`, `fire`...) depend on the part. Each part's page lists its commands ([part pages](https://crossbotics.com/ftc-helper/docs/reference/)). ## Several press types on one button A **gesture** is a way of pressing: a tap, a hold, two taps. One button can have several gestures, chained with dots, each with its own job. `tap`, `doubleTap`, `taps`, `tapThenHold`, `heldFor` and `hold` can share a button. `press`, `release` and `toggle` each need a button of their own. ```java title="Controls.java" // Three gestures on one button: tap, hold, double-tap. g2.rb.tap(robot.launcher::fire).says("fire one") .hold(robot.launcher::fireWhileHeld, robot.launcher::ceaseFire).says("keep firing") .doubleTap(() -> robot.launcher.fire(3)).says("fire three"); ``` `.says(...)` and `.rumble()` belong to the gesture right before them. **One line puts the launcher's firing on a button.** `robot.launcher.fireOn(g2.y)` puts all of its firing (taps, hold, tap then hold) on Y. `spinOn(...)` puts its spin up / down on a button ([cookbook](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-put-the-launchers-fire-button-on-another-button)). ## When a gesture's job runs A job runs at once, unless the same button has a longer gesture that starts the same way. Then the library waits only until it knows which gesture it is: - **A button with a hold:** a tap runs when the driver lets go. A tap is a press that ends before the hold starts (`Tunables.Buttons.holdSec`, 0.3 s). With `heldFor` and no hold, any press that ends before the `heldFor` time is a tap. - **A button with a double tap** (or tap-then-hold, or taps): a tap waits 0.35 s for a second tap. **Why:** without the wait, every double tap would also run the tap job first. - **A button with no double tap:** two quick taps run the tap job twice. - **A button with a double tap (or taps):** a second press within 0.35 s counts as the second tap, not as a hold. To hold, wait a moment after the tap. Or use `tapThenHold` for "tap, then hold". - **`heldFor` and `hold` on one button:** both run. The hold starts at 0.3 s, and `heldFor` runs once at its time. ### Change the double-tap time and the hold time You can change two times: - **The double-tap time** (`tapGapSec`, 0.35 s): the most time between the two taps of a double tap. - **The hold time** (`holdSec`, 0.3 s): a press this long is a hold, not a tap. Without a `Buttons` section in `Tunables.java`, the library uses these defaults. Add the section only to change them. Then they are in the tuning menu too. When you tune a value there, copy it back into `Tunables.java`: the file is the record. **Where:** `Tunables.java`, inside `public class Tunables { ... }`. ```java title="Tunables.java" public static class Buttons { public static double tapGapSec = 0.35; // the most time between the taps of a double tap public static double holdSec = 0.3; // a press this long is a hold, not a tap } ``` The library's field-centric double tap always uses 0.35 s. `tapGapSec` does not change it. ## Tap and double tap: two ways | Write | A tap | A double tap | Use it when | | --- | --- | --- | --- | | `.tap(a).doubleTap(b)` | runs `a`, 0.35 s after the driver lets go (it waits to be sure no second tap comes) | runs only `b` | `a` must not run on a double tap | | `.tapOrDoubleTap(a, b)` (the older way) | runs `a` at once | runs `a` (first tap), then `b` (second tap) | both fit together, like intake on/off (tap), then push out (double tap) | `tapOrDoubleTap` always uses 0.35 s, not `Tunables.Buttons`. It is one job, so you cannot chain it with other gestures. ## Two buttons together `g1.rb.with(g1.dpadUp, job)` runs the job once, when the driver presses D-pad up while holding RB. **Why:** a pair is a safe place for big jobs that the drivers use only once in a while, like a climb. These jobs must not run by accident. - The first button (`rb` here) is the **shift key**. It gets no job of its own. - One shift key can start several pairs: `g1.rb.with(g1.dpadUp, ...)`, `g1.rb.with(g1.dpadDown, ...)`. - The second button keeps its own job when the driver presses it alone. While the shift key is down, the second button's own job does not run, and a hold that it started stops. - Neither button may be one of the library's buttons. Both must be on the same gamepad. - `.free()` on a shift key removes its pairs too. ## While the robot is paused A tap of gamepad 1 BACK pauses the robot. While it is paused, no button job runs, with one exception: a hold's stop job (the second job in `hold(job, stopJob)`) still runs at the release. It also runs when the pause starts in the middle of a hold. **Why:** a part that a hold started must stop, and it must stay stopped when the pause ends. Of the library's own buttons, field-centric on/off and slow on/off wait too. Pause, "forward", the menus, the debug lines, set pose and the alliance switch still work. ## Done when - Each button in your `Controls.java` uses the press type the drivers expect. - In the simulator or on the robot, each gesture runs its own job. A tap does not also run the double tap's job. --- **Next:** [What the drivers see and feel](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/). **Look it up:** [Reading a button line](https://crossbotics.com/ftc-helper/docs/reference/controls/#reading-a-button-line). **Go deeper:** [the cookbook's button recipes](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/). --- # What the drivers see and feel URL: https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/ The drivers watch the robot, not the Driver Hub. A buzz in their hands or a light on the robot tells them "done" or "ready", and they do not look away. The screen is for the pit and for practice. ## Feedback on a button **Where:** `Controls.java`, at the end of a button line. | You want | Write | What the drivers get | | --- | --- | --- | | Words on the button map | `.says("fire one")` | the line `G2 RB: fire one` at INIT and when the driver taps GUIDE | | A buzz when the job runs | `.rumble()` | one short buzz (a hold: when it starts) | | More buzzes | `.rumble(2)` (1 to 3) | that many short buzzes | | On / off you can feel | `.toggle(part).rumble()` | two buzzes = on, one buzz = off (a claw: two = closed). The same for a [mode](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#modes) | `.says(...)` and `.rumble()` belong to the gesture right before them. `g2.rb.tap(a).says("one").doubleTap(b).says("three").rumble()` buzzes on the double tap only. **Always add `.says(...)`.** The button map is the only list of every button that the drivers can see. ## Feedback from the robot These lines are not tied to a button. Each one is a line of its own inside `buttons(...)`, ends with `;`, and is not on the button map. **Where:** `Controls.java`, inside `buttons(...)`. | You want | Write | What the drivers get | | --- | --- | --- | | A buzz when something becomes true | `g2.rumbleWhen(robot.launcher::isReady);` | a buzz each time the test becomes true (`rumbleWhen(test, 2)`: two buzzes) | | A color on the robot | `robot.lights.show(LightColor.GREEN).when(robot.launcher::isReady);` | a light while the test is true ([Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/)) | | A value on the Driver Hub | `show("Lift ticks", robot.lift::position);` | the value, read again every loop | **`show(...)`:** you see what the robot "thinks" while you drive. The value must be fast to read: use a method reference or a small lambda. With the Quick start robot, try `show("Intake on", robot.intake::isRunning);`. **In the simulator,** a buzz shakes the gamepad picture. A real controller or a phone buzzes too. ## The button map and the TeleOp's INIT screen - **At INIT** the Driver Hub shows the whole button map, one line per button, with the part that gave it (`G2 A: down [Lift]`). Then it lists the free buttons (`G2 free: ...`). Read it before every match. - **In the match,** tap GUIDE to see the map again. The robot still drives. Tap GUIDE again to close it. - **The alliance:** in INIT, gamepad 1 X = BLUE, B = RED. After an autonomous, its alliance is already set. - **The INIT menu:** D-pad up/down picks **Alliance** or **Profile**, and left/right changes it. A practice that starts straight in TeleOp can switch to PRACTICE here. When your own INIT code uses gamepad 1's D-pad, turn the menu off in `Controls.java`: `@Override protected boolean initMenu() { return false; }`. ## Done when - Each button line has a `.says(...)`, and the button map shows every button. - The drivers feel a buzz for an on / off switch that matters in a match or is easy to miss, like a mode they cannot see. - A light or a buzz tells the drivers when the robot is ready to score. --- **Next:** [Move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/). **Look it up:** [Controls.java reference](https://crossbotics.com/ftc-helper/docs/reference/controls/). **Go deeper:** [the cookbook's button recipes](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/). --- # Move the library's buttons URL: https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/ **Why move one:** some drivers want slow on the right trigger, or a part needs Y. When you move the library's job, its button is free for your own line in `buttons(...)`. ## Move or free a button The library's own jobs (driving, pause, menus...) have default buttons. You can move every one to another button, or free it (`null`: no button). Do it in one method next to `buttons(...)`. **Where:** `Controls.java`, next to `buttons(...)`. ```java title="Controls.java" @Override protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2) { lib.fieldCentric(g1.a); // field-centric on/off: A instead of Y lib.slow(g1.rt); // slow on the right trigger: LT is free now lib.pause(g1.x); // pause on X (BACK still resets forward; lib.resetForward(null) frees it) lib.switchAlliance(g1.start, g1.back); // turn ON the alliance switch: hold START, then BACK, 1.5 s } ``` Add `import com.crossbotics.ftchelper.teleop.LibraryButtons;` at the top. In your own `EasyTeleOp`, write `libraryButtons(LibraryButtons lib)`, with `Key.g1(Btn.X)` instead of `g1.x`. ## Every library button | Job | One gamepad (the start) | Two gamepads | How it works | Move it with | | --- | --- | --- | --- | --- | | Drive / strafe, turn | left stick, right stick X | same | every loop | `lib.swapSticks(true)`: right stick drives, left stick X turns | | Slow | none | G1 LT | the further you pull it, the slower (a button: slow while you hold it) | `lib.slow(key)` | | Slow on/off | G1 left stick click | none | a press | `lib.slowToggle(key)` | | Field-centric on/off | G1 right stick click | G1 Y | a double tap (mecanum with an IMU or odometry) | `lib.fieldCentric(key)` | | Pause / go on | G1 BACK | same | pauses at the press, and a tap goes on | `lib.pause(key)` | | Reset "forward" | G1 BACK | same | held 1 s, field-centric only (a tap if its button has no other quick job) | `lib.resetForward(key)` | | Debug lines | G1 START + BACK | same | hold START, then press BACK. It runs when you let go | `lib.debug(key, with)` (`with` null: one button) | | Switch alliance | **off** | off | START, then BACK, both held 1.5 s, after you turn it on | `lib.switchAlliance(g1.start, g1.back)` turns it on | | Set pose here | G1 START | same | held 1 s with the drive sticks let go (robots with odometry). It also works in INIT | `lib.setPose(key)` | | Button map | G1 GUIDE | same | a tap | `lib.buttonMap(key)` | | Tuning menu | G1 GUIDE | same | held 1 s (a tap if its button has no other quick job) | `lib.tuningMenu(key)` | | Choose the alliance (INIT only) | G1 X = BLUE, G1 B = RED | same | a press, before ▶ (start on the Driver Hub) | `lib.allianceInInit(blue, red)` | **BACK, step by step.** A press of BACK pauses the robot **at once**: every motor stops on brake. So a driver who grabs BACK in a panic gets the stop. When you let go fast, the robot stays paused, and a second tap goes on. When you hold BACK 1 s, it also resets "forward" (only with field-centric on; robot-centric shows a note instead). The robot then stays paused until the next tap. Going on is always a tap, at the release, so holding BACK never starts the robot. **START + BACK: press START first.** Hold START, then press BACK: when you let go, you get the debug lines. Held 1.5 s, the pair switches the alliance, if the switch is on. The robot does not pause. **BACK first is always a plain pause.** BACK stops the robot the moment it goes down. When START joins a moment later, it does nothing, so the robot stays paused (a tap of BACK goes on). The reason: the pause has to act at the press. A pair that came later would have to un-pause the robot. Then the robot would stop for a moment and drive on, and that is a surprise. While the pair is down, START's "set pose" does nothing. When you press both in the same instant, it counts as START first. This applies only to pairs with the pause button in them. Any other pair works in either order. **START + A or START + B** pairs a gamepad on the Driver Station. The library cancels START's own job ("set pose here") for that press, so pairing a gamepad never moves the pose. **Set pose here** works only with the drive sticks let go and whole-robot aim off. Otherwise the note says "Pose NOT set: stop first". It also works in INIT: hold START 1 s before the match, so the pose is set before the buzzer. ## Switching the alliance in TeleOp The switch is off until you turn it on. Without it, you choose the alliance in INIT with X = BLUE, B = RED. Turn it on with one line in `libraryButtons(...)`: ```java lib.switchAlliance(g1.start, g1.back); // hold START, then BACK, 1.5 s: BLUE <-> RED ``` A fast press of both (START first) still gives the debug lines. Use the switch when autonomous ran as the wrong alliance. When the alliance switches, the goal flips, and so does the odometry's pose: - On a mirrored field (the reset spot's `mirrorForRed` true), the library mirrors the pose in place: x and the heading flip. - On a field turned half a turn (`mirrorForRed = false`, BIOBUZZ), the library cannot fix the pose. The odometry aim goes off ("Alliance now RED: odometry aim OFF until the pose is set"). It stays off until you park on the reset spot and hold START 1 s ("set pose here"). INIT's `Switch alliance` line says whether the switch is on. ## What INIT checks **INIT names the jobs you freed.** No pause button gives a warning: nothing on the gamepads pauses the robot. No slow at all gives a warning in `Controls.java`. No field-centric button gives a line: driving stays as it starts. With one gamepad, a library job that you put on `g2` goes on gamepad 1. **INIT checks these** (the message names the button): - two library jobs on one button. One quick job and one held job may share a button, like BACK's pause and reset. - the slow trigger with another job. - a pair on two gamepads. - the tuning menu on a button that the menu itself uses (D-pad, A, B, X, Y, LB, RB). - a job of yours on a library button. ## Done when - INIT shows no stop message about the library's buttons. - The button map (a tap of GUIDE) shows each library job on the button you chose. --- **Next:** [Building autos](https://crossbotics.com/ftc-helper/docs/building-autos/). **Look it up:** [Moving the library's buttons](https://crossbotics.com/ftc-helper/docs/reference/controls/#moving-the-librarys-buttons) (the reference). **Go deeper:** [the cookbook's button recipes](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/). --- # Building autos URL: https://crossbotics.com/ftc-helper/docs/building-autos/ | # | Page | You learn | | --- | --- | --- | | 1 | [What an auto can do](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/) | Every step, in groups: drive, turn, wait, parts, aim and shoot. Which steps wait, and which do not. | | 2 | [Put steps together](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/) | Start a part and drive at the same time. Keep time to park. The INIT menu. Red and blue. | | 3 | [Having multiple autos](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/) | One file per plan. Near and far starts. Good names. | | 4 | [Drive to points on the field](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/) | With odometry: `driveTo` a field point, and `routeTo` around field parts. | | 5 | [Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/) | Set up the Pedro add-on. Lines and curves, no stop between parts, face a point, start parts along a path. | | 6 | [The auto builder: steps](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/) | Build an auto on the field in the simulator, run it with your code, and copy the Java. | | 7 | [The auto builder: odometry and Pedro](https://crossbotics.com/ftc-helper/docs/building-autos/07-auto-builder-odometry-and-pedro/) | Build `driveTo` steps and Pedro paths on the field map. | | 8 | [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/) | Beyond the auto builder: choices in INIT, shared pieces of a route, a number for RED, waits for a part, your own step. | | 9 | [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/) | The setup card, the checks before each match, and the report after it. | **Where the numbers go.** Each auto keeps its own numbers in its steps: `.forward("To the goal", 24, 0.6)`. `Tunables.java` keeps the robot's numbers only (speeds, positions, gains). **Why:** a change to one auto never changes another, and the auto builder can read and change the numbers. More: [the numbers are in the step](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#the-numbers-are-in-the-step). **Start with page 1.** If you like to see the field before you read code, read pages 6 and 7 (the auto builder) first. **Next:** [What an auto can do](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/). --- # What an auto can do URL: https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/ An auto is a **list of steps, read top to bottom**. Each step is one line that starts with a dot. The last step ends with `;`. Pick the steps your robot needs from the groups below. ## Two kinds of steps - **A step that waits.** The list waits until the step is done. Then the next step starts. A drive waits until the robot is there. - **A step that does not wait.** It starts something, and the next step starts at once. The part keeps working during the next steps. A lift rises while the robot drives. The **Waits?** column in each table says which kind a step is. **Every part keeps working during every step.** A wait does not freeze the robot. A lift keeps its height, and a flywheel keeps its speed. ## The words in every step Most steps have the same parts, for example this step: ```java .forward("To the goal", 24, 0.5) ``` | Part | Here | What it is | | --- | --- | --- | | The step | `forward` | what the robot does | | The name | `"To the goal"` | the step's name in the report at the end. Write what the step is for. | | A number | `24` | how far, in inches. Angles are in degrees, times in seconds. | | The power | `0.5` | the most power the step may use, 0 to 1 | **About the power:** a drive slows down near its end, so it does not overshoot. A very small number still moves the robot: a drive always gets the least power that moves it (`moveMinPower` in `Tunables.Drive`). **Every angle counts counterclockwise:** 0 = forward, 90 = left, 180 = back, -90 = right. Drives, turns and headings all count this way. The words (`left`, `turnRight`) need no angle. ![Every angle counts counterclockwise: 0 forward, 90 left, 180 back, -90 right.](https://crossbotics.com/ftc-helper/docs/images/autonomous-angles.svg) **In each group below,** the code comes first. The comment at the end of a line names the numbers in order. Then a table says what each step does. **The auto builder** ([page 6](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/)) makes every step on this page, except the ones marked "not in the builder". ## Where the robot starts `start` is the first step. It tells the drive team where to put the robot. It does not move the robot. ```java s.start("Against our wall, facing the field", 0) // note, heading s.start("Our wall, left corner tile", -56, -61, 0) // note, x, y, heading ``` | Step | What it does | | --- | --- | | `start(note, heading)` | The note shows on the Driver Hub in INIT. The heading is the way the robot faces: 0 = away from your drivers. | | `start(note, x, y, heading)` | The same, plus the spot on the field in inches. The simulator puts the robot there. Odometry starts there. | ### Field numbers The spot is in **inches on the field**, seen from your drivers' wall, written for BLUE: - **x**: inches right of the field's center line (minus = left). - **y**: inches from the center toward the far wall (minus = your half). - **heading**: the way the robot faces. 0 = away from your wall. Counterclockwise: 90 = left. ![The field seen from your drivers' wall: (0, 0) in the center, x to the right, y toward the far wall, heading 0 away from your wall and 90 to the left. A start spot at (-56, -61) facing 0, and a driveTo point at (-30, -30) facing 45.](https://crossbotics.com/ftc-helper/docs/images/field-numbers.svg) `driveTo` and Pedro paths use the same numbers ([below](#drive-to-a-point-on-the-field)). **Find the numbers:** in the simulator, drag the robot on the field map before ▶. The numbers are under the map. Or let the auto builder write them ([page 6](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/#4-the-start-spot-and-the-note)). ## Drive ```java .forward("To the goal", 24, 0.5) // name, inches, power .back("Off the wall", 6, 0.4) // name, inches, power .left("Slide over", 12, 0.5) // name, inches, power .right("Park", 20, 0.7) // name, inches, power .move("Slide", 12, 45, 0.5) // name, inches, angle, power .moveWithTurn("Swing in", 24, 0, 90, 0.5) // name, inches, angle, heading, power ``` | Step | What it does | Waits? | | --- | --- | --- | | `forward`, `back` | Drives forward or backward. | yes | | `left`, `right` | Slides to the side, still facing the same way. **Mecanum only.** | yes | | `move` | Drives at an angle. 90 = left. A tank drive can only use 0 and 180. | yes | | `moveWithTurn` | Drives and turns at the same time. **Mecanum only.** Both angles count from the way the robot faced at the start. | yes | Write the inches as plus numbers. The word says which way. **A drive does not fix the heading on the way.** It counts wheel turns only. This is true with odometry too: only `driveTo` and `follow` use the odometry ([below](#drive-to-a-point-on-the-field)). After a bump or a long drive, add a `turnTo` to square up. A drive that cannot finish (stuck on a wall) ends by itself. The report then says `STALLED` or `TIMED_OUT`. ## Turn ```java .turnLeft("Face the goal", 45, 0.4) // name, degrees, power .turnRight("Face the wall", 90, 0.4) // name, degrees, power .turn("Face the goal", 45, 0.4) // name, degrees (90 = left), power .turnTo("Square up", 0, 0.4) // name, heading, power .rememberHeading("Before the shot") // name .turnBack("Back as before", 0.4) // name, power ``` | Step | What it does | Waits? | | --- | --- | --- | | `turnLeft`, `turnRight` | Turns in place, this many degrees. | yes | | `turn` | Turns by an angle. 90 = left, -90 = right. | yes | | `turnTo` | Turns to a heading. 0 = the way the robot faced at the start. | yes | | `rememberHeading` | Saves the heading now. | no | | `turnBack` | Turns back to the saved heading. | yes | ## Wait ```java .waitSeconds("Let it settle", 0.5) // name, seconds .waitUntil("Lift at the top", robot.lift::isAtTarget, 2) // name, check, seconds ``` | Step | What it does | Waits? | | --- | --- | --- | | `waitSeconds` | Waits this many seconds. | yes | | `waitUntil` | Waits until the check is true, at most this many seconds. **Not in the builder.** | yes | `robot.lift::isAtTarget` is a **method reference**: it names the method, and the step calls it later. The step calls it again and again until it gives true. If the time runs out, the report says `timed out`, and the list goes on. **Checks you can wait for.** Use the part's name from your `Robot.java` in place of `lift`, `launcher` and so on: | Check | True when | | --- | --- | | `robot.lift::isAtTarget` | a lift or an arm is at its position. Any part with positions has it. | | `robot.claw::isClosed` | the claw is closed | | `robot.launcher::isReady` | the flywheel is at speed, and every other launcher check passes | | `() -> !robot.launcher.isShooting()` | the launcher has fired everything (`!` = "not") | | `robot.pieces::isFull` | the robot holds as many pieces as it can | | `robot.pieces::isEmpty` | the robot holds no pieces | | `() -> robot.aim().isAimed()` | the robot or the turret is aimed at the goal | Write a check with a `!` or with `()` in it as a small piece of code (a **lambda**): `() -> ...`. ## Parts and actions ```java .run("Intake in", robot.intake::in) // name, command .action(Actions.scoreHigh(robot), 5) // action, seconds .alongside(Actions.fireAll(robot)) // action ``` | Step | What it does | Waits? | | --- | --- | --- | | `run` | Starts a part's command. | no | | `action` | Runs an action, and waits until it is done (at most this many seconds). | yes | | `alongside` | Starts an action. It runs during the next steps. | no | - **A command** is one thing a part does: `robot.intake::in`, `robot.claw::close`. A command that needs a word or a number is a lambda: `() -> robot.lift.goTo("high")`. - **An action** is several steps that use parts together. A TeleOp button runs the same action. - When an action runs out of time, it stops safely, and the report says why. **Actions you can use:** | Action | Where it comes from | What it does | | --- | --- | --- | | `robot.launcher.fireAllAction()` | the library | fires every piece the robot holds | | `robot.launcher.fireAction(2)` | the library | fires 2 pieces | | `robot.launcher.fireAllAction(2250)` | the library | fires every piece, at this flywheel speed (RPM) | | `robot.launcher.readyAction(3)` | the library | spins up, and is done at speed (at most 3 s) | | `robot.launcher.ejectAction()` | the library | shoots one piece out slowly, for example a piece of the wrong color | | `Actions.scoreHigh(robot)`, `Actions.grab(robot)`, ... | your `Actions.java` | what you wrote ([Actions.java](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/)) | You choose the names of the actions in your `Actions.java`. The example robots have `fireAll`, `scoreHigh`, `grab`, `grabAndLift`, `stow` and more. Copy one and change it. ## Aim and shoot For a robot with a launcher (a flywheel shooter) or a camera. ```java .readyToLaunch("Ready", 3) // name, seconds .action(robot.launcher.fireAllAction(), 8) // action, seconds .action(robot.launcher.fireAllAction(2250), 8) // action at 2250 RPM, seconds .aimAtGoal("Aim", 3) // name, seconds .aimAtGoal("Aim", 4, 45) // name, seconds, degrees to look each way .waitForGoal("See the goal", 5) // name, seconds ``` | Step | What it does | Waits? | | --- | --- | --- | | `readyToLaunch` | Spins the launcher up and waits until it is at speed. | yes | | `fireAllAction()` in an `action` | Fires every piece the robot holds. `fireAction(2)` fires 2. | yes | | `fireAllAction(rpm)` in an `action` | The same, at this flywheel speed. For a robot with no camera that shoots from more than one spot. | yes | | `aimAtGoal` | Turns the robot to the goal with the camera. With a turret that follows the goal, it waits until the turret is aimed. When no goal is in view, the robot does not turn, and the report says `not seen`. | yes | | `aimAtGoal` with degrees | The same. When the goal is not in view, it turns slowly up to this many degrees each way to find it. | yes | | `waitForGoal` | Waits until the camera sees the goal and the goal is still. It does not turn. After this many seconds, it goes on anyway. With no seconds, it waits until the park time. | yes | To spin up while the robot drives, start it and go on: `.run("Spin up", robot.launcher::spinUp)`. The auto builder lists the ones your robot can do under **What this robot can do** ([page 6](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/#1-robot-and-alliance)). ## Drive to a point on the field For a robot with **odometry** (sensors that track where the robot is on the field). Page 4 explains them: [Drive to points on the field](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/). The numbers are [field numbers](#field-numbers), like the start spot. ```java .driveTo("To the goal", -30, -30, 45, 0.6) // name, x, y, heading, power .routeTo("Park", -56, -36, 0, 0.8) // name, x, y, heading, power .follow("To the goal", TO_GOAL) // name, Pedro path ``` | Step | What it does | Waits? | | --- | --- | --- | | `driveTo` | Drives to a point on the field, and keeps correcting on the way. **Mecanum only.** | yes | | `routeTo` | The same, but around the field parts you list. **Not in the builder.** | yes | | `follow` | Follows a curved path with Pedro Pathing. **Mecanum only.** | yes | ## Your own step, and parking ```java .step("Clear the intake", ctx -> { ... }) // name, your code .parkWithSeconds(3) // seconds ``` | Step | What it does | Waits? | | --- | --- | --- | | `step` | Your own code, for what no other step can say. **Not in the builder.** | your code | | `parkWithSeconds` | Not a move. The steps after it always get the last seconds of the 30. | - | `step`: [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#write-your-own-step). `parkWithSeconds`: [page 2](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#keep-time-to-park). ## Try it Add a turn and a wait to your `FirstAuto.java`. Each new step goes before the `;`: ```java s.start("Against our wall, facing the field", 0) .forward("Leave the start", 12, 0.4) .turnLeft("Face the goal", 45, 0.4) .waitSeconds("Let it settle", 0.5) .turnTo("Square up", 0, 0.4); ``` Run it in the simulator: pick **Simulator** in the run list next to Android Studio's **Run** button, and click **Run**. Pick your auto, INIT, ▶. ## Done when The robot drives, turns left, waits, and turns back. The report at the end says `done` for every step. ## Problems | Problem | Why, and the fix | | --- | --- | | It turns the wrong way | Angles count counterclockwise: 90 = left. Or use the words `turnLeft` and `turnRight`. | | `Turn first, then move` | A tank drive cannot drive at an angle. Turn, then drive `forward`. | | `needs a mecanum drive` | `left`, `right`, `moveWithTurn` and `driveTo` slide sideways. A tank drive cannot. | | `';' expected` | A step line is missing its dot, or the `;` is not after the last step. | | A step says `timed out` | A wait or an action ran out of time. The list went on. Give it more seconds, or check the part. | **What each word in the report means** (`done`, `STALLED`, ...): [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#after-the-match-read-the-report). --- **Next:** [Put steps together](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/). **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto). **Go deeper:** [the cookbook's autonomous recipes](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/). --- # Put steps together URL: https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/ > **The auto builder writes everything on this page:** `run`, `action`, `alongside`, `parkWithSeconds` > and `mirrorForRed()`. [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/) covers what it cannot write (menus, your own > steps, ...). ## The example The example robot's (`lessonbot`) auto holds the piece, drives to the goal, scores, and parks. The library has it as a compiled file: [`lessonbot/autos/ScoreAndPark.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/lessonbot/autos/ScoreAndPark.java). ```java @Autonomous(name = "Lesson Bot Score and Park", group = "Examples", preselectTeleOp = "Lesson Bot TeleOp") public class ScoreAndPark extends Auto { @Override protected boolean mirrorForRed() { // (1)! return false; // BIOBUZZ's field is turned half a turn between the alliances } @Override protected void steps(Steps s, Robot robot) { s.start("Against our wall, facing the field", 0) .run("Hold the piece", robot.claw::close) // (2)! .forward("To the goal", 24, 0.6) .action(Actions.scoreHigh(robot), 5) // (3)! .parkWithSeconds(3) // (4)! .right("Park", 20, 0.7); } } ``` 1. `@Override` marks a method that replaces one `Auto` already has. Copy these lines as they are, and change only `false` or `true`: [red and blue, below](#red-and-blue). 2. `run` starts the claw and goes on at once. The claw closes while the robot already drives. 3. `action` runs the "score high" action from `Actions.java`, and waits until it is done (at most 5 s). 4. The steps after this line always get the last 3 seconds: [below](#keep-time-to-park). **The first lines of the file** (above `@Autonomous`), in your own copy: ```text package org.firstinspires.ftc.teamcode.autos; import org.firstinspires.ftc.teamcode.Actions; import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; ``` **Why the `Actions` line:** `Actions.java` is in the folder above `autos`, like `Robot.java`. ## Start something, or wait for it You can use a part in three ways. To pick one, decide whether **the next step must wait for it**. | You write | The next step starts | Use it when | | --- | --- | --- | | `.run("Intake in", robot.intake::in)` | at once | one command, and the robot can go on: an intake on, a claw closed, a flywheel spun up | | `.action(Actions.scoreHigh(robot), 5)` | when the action is done | the robot must not move until it is done: a score, a shot | | `.alongside(Actions.fireAll(robot))` | at once, and the action runs during the next steps | several steps that can happen while the robot drives | **Start early, wait late.** Start a slow part with `run` as early as you can. The robot then does two things at once. That saves time in a 30-second match. To wait for the part right before you need it, use `waitUntil` ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#wait-until-a-part-is-ready)). ## Keep time to park Parking points come at the very end of the 30 seconds. The park must never run out of time. `.parkWithSeconds(3)` splits the list in two: - **The steps before it** stop when only 3 s are left. The step that is running then stops at once, and the auto skips the rest. - **The steps after it** always run. The report says which steps were `cut short (time for park)` or `skipped (time for park)`. **To choose the seconds,** run the auto. Measure how long the park steps take, and add about 1 second. **Try it:** change `parkWithSeconds(3)` to `parkWithSeconds(28)`, and run the auto in the simulator. The auto cuts the score steps short, and the park still runs. Then change it back. ## The INIT menu Every auto already has an **INIT menu** on the Driver Hub. The drivers use gamepad 1: D-pad up/down picks a line, D-pad left/right changes it. | Line | What it is | | --- | --- | | Alliance | BLUE or RED. **X** = BLUE, **B** = RED. | | Start delay | 0 to 10 s. The auto waits this long before the first step. **Why:** to stay out of a partner's way. | | Profile | PRACTICE (for the shop: debug lines and the tuning menu) or COMPETITION (for matches): [what they change](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#practice-and-competition) | **The menu remembers:** Alliance starts at the last auto's alliance, and the hub saves the Profile. A longer start delay: [`maxStartDelaySec()`](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/). **Your own lines** (park or stay, near or far): [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#add-choices-to-the-init-menu). Or make one auto file per plan: [Having multiple autos](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/). ## Red and blue You write the auto **for BLUE**. The library changes it for RED. How it changes it depends on the season's field. > **This season, BIOBUZZ (2026-27): the field is ROTATED.** The red half is the blue half turned half a > turn. Write `return false;` in `mirrorForRed()`. RED then drives the same steps, seen from > the red wall. > > Last season, DECODE (2025-26), was **mirrored**. Old autos and old videos from DECODE use `true`. Do not > copy that. | The field | Write | RED then | | --- | --- | --- | | The red half is the blue half **turned half a turn** (BIOBUZZ) | `mirrorForRed()` returns `false` | drives the same steps, seen from the red wall | | The red half is the blue half **mirrored** left to right (DECODE) | `mirrorForRed()` returns `true` | drives the steps mirrored: left becomes right, and turns go the other way | **Write `mirrorForRed()` in every auto.** Without it, the auto uses the robot's setting: `mirrorForRed` in `Tunables.Aim`, else in `Tunables.Odometry`, else `true`. That setting is easy to miss. The auto builder writes `mirrorForRed()` for you (**Red's side** in [step 1](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/#1-robot-and-alliance)). **Where the drivers stand.** In BIOBUZZ and in DECODE, each alliance's drivers stand at their own wall. You need nothing more. A field where both alliances' drivers stand at one wall needs one more method: [`alliancesOnOneWall()`](https://crossbotics.com/ftc-helper/docs/modules/auto/). **One number different on RED** (a wait, a distance): `alliance().pick(blue, red)`, on [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#a-different-number-for-red). ## The first run on the robot 1. **On blocks,** wheels off the floor. Check that the wheels turn the right way and the parts move. 2. **On the field, in the PRACTICE profile** ([PRACTICE and COMPETITION](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#practice-and-competition)). For the very first runs, set `maxPower` in `Tunables.Drive` lower (0.4), and back to `DEFAULT` when it works. Keep a hand near STOP. 3. Read the report after every run. Measure where the robot ended, and fix the numbers in the steps. 4. When it works every time, run it in the **COMPETITION** profile. ## Done when - Your auto starts a part with `run`, and drives while the part works. - It has a `parkWithSeconds(...)` before its park steps. - It runs as BLUE and as RED in the simulator, and the robot goes the right way both times. ## Problems | Problem | Why, and the fix | | --- | --- | | `cannot find symbol: Actions` | Add `import org.firstinspires.ftc.teamcode.Actions;` at the top of the file. | | RED drives into a wall | `mirrorForRed()` is wrong for this field. Check the field drawing. | | The park did not run | It was before `parkWithSeconds(...)`. Put the park steps after it. | **What each word in the report means** (`done`, `STALLED`, ...): [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#after-the-match-read-the-report). --- **Next:** [Having multiple autos](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/). **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto), [keep time to park](https://crossbotics.com/ftc-helper/docs/reference/steps/#keep-time-to-park). **Go deeper:** [the cookbook's autonomous recipes](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/). --- # Having multiple autos URL: https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/ At an event you play with a new partner in every match. Sometimes you start near the goal, sometimes far. Sometimes your partner needs the space you usually drive through. So you need a few plans, with clear names, that the drive team can pick fast. ## One file per plan The simple way: **each plan is its own auto file.** Each file is one line in the Driver Hub's Autonomous list. The drivers pick the plan by its name. - **The auto builder works with it.** Build each plan in the builder ([page 6](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/)), and copy each one into its own file in `autos/`. Later, **Load** can read each file again. - **Start from a copy.** Copy a working auto file, give the class and the `@Autonomous` name a new name, and change the steps. - **Red and blue need no second file.** The Alliance line in the INIT menu does that ([red and blue](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue)). - **Waiting for a partner at the start needs no second file.** The Start delay line does that. **When it gets too big:** many files that share the same steps, or more plans than the drivers can pick from. Then put the shared steps in one place, or give the drivers a choice in INIT: [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#one-auto-with-choices-or-several-autos). ## Near and far starts A different start spot is the most common reason for a second plan. Two good ways: - **Two files**, `Near: Preload + Park` and `Far: Preload + Park`. Each has its own `start(...)`. The far one adds its first moves, then the same steps. Pick this when the far route is long and different. - **One file with a Start line** in the INIT menu ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#a-whole-example-one-auto-the-drivers-choose)). Pick this when the far route is "the near route, plus a few steps". The builder cannot write it. **Check the far route against the field.** On BIOBUZZ's field a FLOWER stands on your wall between the two start spots. A robot that slides along the wall from the far spot drives into it. So the far route drives off the wall first. Watch every new route in the simulator. ## Names on the Driver Station The drivers read the Autonomous list in a hurry, on a small screen. ```java @Autonomous(name = "Near: Preload + Park", group = "Autos", preselectTeleOp = "Main TeleOp") ``` - **Start the name with the start spot**, then the plan: `Near: Preload + Park`. The drivers look at where the robot is first. - **Say what it scores**, not how the code works. `Near: Preload + Cycle + Park`, not `AutoV3Fixed`. - **No alliance in the name.** One file works for both alliances. Two files `Red Near` and `Blue Near` are twice the work, and one day they do not match. - **`group`** lists autos together. `group = "Autos"` for match autos, `group = "Test"` for test routines. - **`preselectTeleOp`**: your TeleOp's exact name. After the auto, the Driver Station has it chosen. - **Hide old autos** with `@Disabled`, or delete them. A short list is a safe list. - **Start the note with the spot in CAPITALS**: `"NEAR: against our wall, ..."`. A second person checks the note against the robot. ## Done when - Each of your plans is one line on the Driver Hub list, with a clear name. - Each plan runs in the simulator, as BLUE and as RED. ## Problems | Problem | Why, and the fix | | --- | --- | | The drivers picked the wrong auto | The names look alike. Start each name with the start spot, and say what it scores. | | The drivers cannot find the auto | Too many on the list. Add `@Disabled` to the old ones, and use groups. | | A fix in one auto is missing in another | The two files share steps. Fix both, or put the shared steps in `Routes.java` ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes)). | | Two autos have the same name | Each `@Autonomous(name = ...)` must be different. The Driver Hub shows only one. | --- **Next:** [Drive to points on the field](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/): with odometry. No odometry yet? Go on to [the auto builder](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/). **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto). **Go deeper:** [cookbook: several autos and choosing one](https://crossbotics.com/ftc-helper/docs/cookbook/10-several-autos/). --- # Drive to points on the field URL: https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/ **You need:** odometry: the `odometry(...)` line in `Robot.java`, and the Odometry Tuner passed ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/)). **Odometry** is a sensor set (a Pinpoint, an OTOS, or dead wheels) that tracks where the robot is on the field, all the time. With it, a step can say **where to go** on the field, not only how far to drive. ## Drives and points: the difference | | `forward`, `turn`, ... (pages 1 to 3) | `driveTo` (this page) | | --- | --- | --- | | You say | "24 in forward from here" | "go to x -30, y -30, facing 45" | | On the way | it does not correct | it checks where the robot is, and corrects all the time | | After a bump or wheel slip | every later step is off | the robot still ends at the point | | You change one step | the steps after it move too | the other points stay where they are | | Needs | any drive | odometry, and a **mecanum** drive | ## Field numbers Every point uses the same **field numbers** as the start spot: x, y and heading, in inches and degrees, seen from your drivers' wall, written for BLUE. The picture and the words: [page 1, field numbers](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#field-numbers). **Give the spot** in every auto that uses `driveTo`: `start(note, x, y, heading)`. The odometry starts there. Without a spot, the odometry starts at (0, 0), and every point is wrong. **Find the numbers:** in the simulator, drag the robot on the field map before ▶. The numbers are under the map. Or use the auto builder ([page 7](https://crossbotics.com/ftc-helper/docs/building-autos/07-auto-builder-odometry-and-pedro/)): it writes them for you. ## Drive to a point: driveTo The odometry robot's auto, a compiled file in the library: [`odometrybot/autos/ToTheGoal.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/odometrybot/autos/ToTheGoal.java). ```java s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) .run("Intake on", robot.intake::in) .driveTo("To the goal", -30, -30, 45, 0.6) // x, y, heading, power .run("Intake off", robot.intake::stop) .parkWithSeconds(4) .driveTo("Park", -56, -36, 0, 0.7); ``` - `driveTo(name, x, y, heading, power)`: drives and turns at the same time, to the point and the heading. The step is done when the robot is within 1 inch and 2 degrees. - `driveTo(name, x, y, heading, power, inches)`: your own "close enough", in inches. Use a larger number for a point the robot only drives through. **Why `driveTo` and not a drive by distance:** 1. **It fixes bumps and slip.** After a bump, a `forward` still "finishes", in the wrong place. `driveTo` sees the real pose, so it drives back on course and ends at the point. 2. **It ends at a field place.** When you change one step, the next steps still go to the same places. 3. **It drives and turns at once,** straight at the point, even sideways. **In INIT**, the Driver Station shows `Odometry: Pinpoint ready`, or a warning with the reason, like `Odometry (Pinpoint): X pod not found: check its cable`. Look for it before ▶. **If a driveTo does not finish**, it stops, and the report shows a word: - `STALLED`: the robot is stuck. In the last 8 in, where it is slow on purpose, this means less than 0.1 in closer in 2 s. - `TIMED_OUT`: it took more than 10 s. - `NO_ODOMETRY`: the odometry stopped working (a pod or I2C cable) for more than 0.2 s. The next steps still run, from where the robot is. So put an action that needs the right place (score, drop) right after the `driveTo` that gets there. Read the report after each practice run. **Its heading is the field's.** `turnTo`'s 0 is the way the robot faced at the start. `driveTo`'s 0 is "away from your wall". They are the same only when the robot starts facing the field. With odometry, give headings in `driveTo`. **Red and blue** work like the start spot ([page 2](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue)): - `mirrorForRed()` true: RED flips x and the heading. `(-30, -30, 45)` becomes `(30, -30, -45)`. - `mirrorForRed()` false (BIOBUZZ): RED uses the same numbers, seen from the red wall. ## Go around field parts: routeTo A `driveTo` is one straight line. When the park time comes, the running step stops, wherever the robot is. A straight line home from there can go through a field part. So list the field parts in `Robot.java`, after the `odometry(...)` line: ```java fieldMap(FieldMap.margin(13) // needs: import com.crossbotics.ftchelper.drive.FieldMap; .keepOut("HIVE frame, near", -19.5, -24.8, 19.5, -15.4) .keepOut("HIVE frame, far", -19.5, 15.4, 19.5, 24.8)); ``` - `keepOut(name, x1, y1, x2, y2)`: a box, from two opposite corners, in field numbers. - `margin(13)`: the robot's center stays this far from every box, in inches. Then write `routeTo` where you wrote `driveTo`. It finds its way around the boxes when the step starts: ```java .parkWithSeconds(6) .routeTo("Park", -56, -36, 0, 0.8); ``` The whole file: [`odometrybot/autos/ParkAround.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/odometrybot/autos/ParkAround.java). The auto builder does not make `routeTo` steps yet: write them in the file. **TeleOp can do it too:** a button that drives to a spot, and stops when a driver pushes a stick ([Add odometry: a button that drives to a spot](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#a-button-that-drives-to-a-spot-in-teleop)). ## Done when - Your auto has a start spot (`start(note, x, y, heading)`). - It drives to a field point with `driveTo`, in the simulator, as BLUE and as RED. - The report says `done` for every point. ## Problems | Problem | Why, and the fix | | --- | --- | | `needs odometry: add an odometry(...) line` | `Robot.java` has no odometry line ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/)). | | The report says `skipped: Tunables.Odometry.checked is false` | On a real robot, `driveTo` waits for the Odometry Tuner. Run its loop test, then set `checked = true`. The simulator runs them anyway. | | `needs a mecanum drive` | `driveTo` slides sideways. On a tank drive, use `turnTo`, then `forward`. | | Every point is off by the same amount | The start spot in `start(...)` is not where the robot starts on the field, or it is missing. | | `NO_ODOMETRY` in the report | The odometry stopped answering on the way. Check its cable. | | `STALLED` near a field part | The straight line goes through it. Use `routeTo` with a `fieldMap`. | | RED goes to the wrong side | `mirrorForRed()` is wrong for this field. | | `STALLED` away from field parts | The robot was pushed against something, or the point is out of reach. The next steps still ran. | | `TIMED_OUT` | It did not arrive in 10 s: a point too far for one step, or the heading never settled. Run the [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/). | | `skipped` with `checked = true` | No time was left before the park time. | | It circles the point, or stops just short | Run the [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/). | **What each word in the report means** (`done`, `STALLED`, ...): [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#after-the-match-read-the-report). ## Try it in the simulator Run the odometry robot's example first. **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:fromRobot -PteamCode=none -ProbotClass=com.crossbotics.ftchelper.examples.odometrybot.Robot -Pout=build/odometrybot.properties ``` **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:run -PteamCode=none -Probot=build/odometrybot.properties ``` Open http://localhost:8780, choose **Odometry Bot To the Goal**, press INIT, choose **RED** in the INIT menu (gamepad 1 B), then ▶. The robot drives diagonally to the goal while it turns to 45 degrees, then parks. The simulator runs `driveTo` even with `checked = false`. On the robot, the steps wait for it. **Two places show where the robot is:** - The Driver Station's `Pose` line: where the odometry *thinks* the robot is, seen from your own wall. - The line under the simulator's field map (Control Hub panel, **Robot** tab): where the robot *really* is. The map is always seen from the **red** wall. On RED the two use the same numbers. On BLUE, x and y have the other sign, and the heading differs by 180. **See what bad tuning does:** add `odometry.scaleError = 0.05` (the pods measure 5% too far) at the end of `build/odometrybot.properties`, and run it again as RED. The `Pose` line says the robot is at the goal, but the real robot stops about 2 in short. The Odometry Tuner's Forward test finds this on the robot. Delete the line when you are done. More lines: [the odometry module's simulator lines](https://crossbotics.com/ftc-helper/docs/modules/odometry/#the-simulator). **Your own robot:** pick **Simulator** next to Android Studio's green Run button, and click Run. The simulator writes the odometry lines from your `Robot.java`. You can also run the Odometry Tuner there to learn its tests. Its Spin test always finds your own numbers back, so the real offsets must come from the real robot. --- **Next:** [Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/): curved paths, with no stop between parts. **Look it up:** [driveTo](https://crossbotics.com/ftc-helper/docs/modules/odometry/#driveto), [keep-out boxes and routes](https://crossbotics.com/ftc-helper/docs/modules/odometry/#keep-out-boxes-and-routes). **Go deeper:** [the odometry module](https://crossbotics.com/ftc-helper/docs/modules/odometry/). --- # Add Pedro paths URL: https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/ **You need:** - A robot with a **mecanum** drive and **checked odometry** ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/): `Tunables.Odometry.checked = true`). - A charged battery, clear floor, and a laptop that can join the robot's WiFi (for Pedro's tuner). ## 1. What it is A **path follower** drives the robot along a line or a curve, and corrects it all the way. **Pedro Pathing** is a separate library. The library's `pedro` add-on connects it to your robot. - **When you need it:** `driveTo` drives a straight line to a point and ends on it. That is enough for many autos. Pedro is for curves, for paths with no stop between parts, and for facing a point while the robot drives. - **Paths use the same field numbers as `driveTo`** ([Drive to points](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/#field-numbers)): inches, seen from your own drivers' wall. - **Pedro uses your `drive(...)` and `odometry(...)` lines.** You describe the robot only once. - **Pedro must measure your robot** with its own tuner: its top speed, how far it slides when it brakes, and how hard to correct (step 3). Until then, do not trust a path on the real robot. - Pedro paths run in **autonomous** steps. | | `driveTo` ([Drive to points](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/)) | Pedro (this page) | | --- | --- | --- | | How you say where | a point and a heading | a road: lines and curves | | Around a field part | a point in between (it stops there) | a curve (no stop) | | Speed | good | faster, with smooth braking | | Extra setup | none | an add-on, and Pedro's own tuning | **Our advice:** start with `driveTo`. Change to Pedro when you want curves, or when a stop at every point costs you time. One auto can use both. **Words you will meet:** | Word | What it means | | --- | --- | | **path** | the road the robot follows, from a start point to an end point | | **line** | a straight part between two points | | **curve** | a smooth bent part. Pedro uses **Bezier** curves (say "bez-ee-ay") | | **control point** | a point that **pulls** a curve toward it. The robot does **not** drive through it | | **part** | one line or curve. A path can have several parts, with no stop between them | | **follower** | the code that drives the robot along the path (Pedro's `Follower`) | | **Foresight** | Pedro's way of driving. It looks ahead to know when to brake | | **hold** | after the path, keep the robot on the end point, and push back when it is bumped | **How far a curve bends:** with one control point, the middle of the curve is halfway between the middle of the straight line (start to end) and the control point. ## 2. Add it to the five files ### Your project: add the Pedro add-on once **Where:** `settings.gradle`, in the project folder (not in TeamCode), under the two `ftc-helper-lib` lines. ```groovy include ':ftc-helper-lib-pedro' project(':ftc-helper-lib-pedro').projectDir = new File(rootDir, 'ftc-helper-lib/pedro') ``` **Where:** `TeamCode/build.gradle`, in `dependencies { ... }`, under the `ftc-helper-lib` line. ```groovy implementation project(':ftc-helper-lib-pedro') ``` Then click **Sync Now**. Wait until it ends with no red errors. Gradle downloads Pedro itself. ### Robot.java: one line, and Pedro's numbers file **Where:** `Robot.java`, in `define()`, **after** the `odometry(...)` line. ```java title="Robot.java" odometry(Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)); // Pedro needs odometry // Pedro drives the paths with the drive and odometry lines above. PedroConstants holds the // numbers from Pedro's Foresight tuner (docs/modules/pedro.md#tuning-pedro). follower(Pedro.follower(PedroConstants.foresight)); ``` - Only the `follower(...)` line is new. Keep your own `odometry(...)` line. - When `Pedro` is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. - Copy [`PedroConstants.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/pedrobot/PedroConstants.java) into TeamCode, next to `Robot.java`. Make its first line (`package ...`) the same as the first line of your `Robot.java`. Its numbers are from the simulated example robot. Pedro's tuner replaces them (step 3). ### Tunables.java: nothing new Pedro's numbers are in `PedroConstants.java`, not in `Tunables.java`. Paths use `Tunables.Drive.maxPower` and `Tunables.Odometry.checked`, which you already have. ### Controls.java: nothing new Paths run in autonomous. You need no button. ### Actions.java and autos: make paths, then follow them **Make each path once**, in your autonomous class, above `steps(...)`. **Where:** your autonomous class in `autos/`, above `steps(...)`. ```java title="autos/YourAuto.java" // Make each path once. A line: from (x1, y1) to (x2, y2). A curve: start, a control point // that pulls the curve toward it (the robot does not drive through it), end. static final PedroPath OUT = PedroPath.line(-56, -61, -56, -36).keepHeading(0); static final PedroPath TO_GOAL = PedroPath.curve(-56, -36, -44, -36, -30, -30).turnTo(0, 45); ``` - `keepHeading(0)`: the robot keeps facing 0 the whole way. - `turnTo(0, 45)`: it turns from 0 to 45 along the path. **Face one point the whole way**, for example the goal, so the camera or launcher stays on it: ```java title="autos/YourAuto.java" // Keep facing one field point the whole way (here x -60, y 60: put your goal's x and y). static final PedroPath WATCH_GOAL = PedroPath.line(-30, -30, -56, -36).facePoint(-60, 60); ``` **Follow the paths** in the steps. **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) .follow("Out", OUT) // brakes to a stop at its end .follow("To the goal", TO_GOAL) .run("Intake on", robot.intake::in) .follow("Back", WATCH_GOAL) .parkWithSeconds(4) .driveTo("Park", -56, -36, 0, 0.7); // driveTo works too (it ends any hold first) ``` Each `follow` brakes to a stop at its end. Start the next path where the last one ended. **Two parts with no stop, a slow part, and a hold at the end:** **Where:** your autonomous class, above `steps(...)`. ```java title="autos/YourAuto.java" // Two parts with NO stop between them (then), a slow part near the goal (maxSpeed), // and hold the end point while it scores (holdEnd: at most 5 s). static final PedroPath IN_ONE_GO = PedroPath.line(-56, -61, -48, -50).keepHeading(0) .then(PedroPath.curve(-48, -50, -44, -36, -30, -30)).turnTo(0, 45) .maxSpeed(0.6) .holdEnd(); ``` `holdEnd` pushes back when another robot bumps yours while it scores. **Rules for paths:** - **Start each part where the last one ended**, and each path where the robot is: the first at the start spot in `s.start(...)`. - **Headings must match at a join.** When part 1 ends facing 0, part 2 must start at 0 (`turnTo(0, 45)`). Else the robot turns fast at the join. - **A setting after a part is for that part.** `.turnTo(...)` after the curve sets the curve's heading. `.holdEnd()` is for the whole path. `.maxSpeed(...)` slows only its part, so make that part long enough. - **Do not drive straight back along the same line in one path.** In tests, Pedro took a shortcut onto the way back at once. Use two `follow` steps (out, then back), or a curve that turns around. - **Other ways to face:** `.facePath()` faces along the road (the default). `.facePathBackwards()` drives backwards along it. **Plan the path on the field map**, and check that no part goes through a field part. A curve bends toward its control point, so check the bend too. The example path, seen from the red wall: ![The example path: a line from the start to (-48, -50), a curve to the goal at (-30, -30), then a driveTo to park](https://crossbotics.com/ftc-helper/docs/images/biobuzz-pedro-path.svg) **Or draw it:** the [Pedro Path Builder](https://crossbotics.com/ftc-helper/path-builder/) is a web page, with no install. It draws the robot along the path, marks in red where it hits a field part or a wall, and writes the `PedroPath` code. The simulator's auto builder does the same, and runs the path ([page 7](https://crossbotics.com/ftc-helper/docs/building-autos/07-auto-builder-odometry-and-pedro/)). **Drive first, then turn** (or turn first): **Where:** your autonomous class, above `steps(...)`. ```java title="autos/YourAuto.java" // Turn from 0 to 90 only in the last 30% of the line (0.7 to 1): drive first, then turn. static final PedroPath DRIVE_THEN_TURN = PedroPath.line(-56, -61, -30, -30).turnTo(0, 90, 0.7, 1); ``` The two extra numbers say on which stretch it turns: 0 = the start of the part, 1 = its end. `0, 0.3` turns first, then drives. **Start a part along the path**, while the robot keeps driving: **Where:** a file in `autos/`, inside `steps(...)`. When `PathAt` is red, press Alt+Enter. ```java title="autos/YourAuto.java" s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) // PathAt: start things ALONG the path, once each, while the robot keeps driving. .follow("To the goal", Paths.IN_ONE_GO, PathAt.part(2, "Intake on", robot.intake::in), // where part 2 starts PathAt.inchesLeft(6, "Intake off", robot.intake::stop)) // 6 in before the end .waitSeconds("Score (the robot holds still)", 0.5); ``` Every way to start a part along the path: | `PathAt` | Starts it | | --- | --- | | `PathAt.fraction(0.5, name, command)` | halfway along the whole path | | `PathAt.inchesLeft(12, name, command)` | 12 in before the end | | `PathAt.inchesDone(12, name, command)` | 12 in after the start | | `PathAt.part(2, name, command)` | where part 2 starts | | `PathAt.near(x, y, inches, name, command)` | when the robot comes this close to a point | In place of a name and a command, `PathAt` can take an action from your `Actions.java`: `PathAt.inchesLeft(12, Actions.scoreHigh(robot))`. `driveTo` takes `PathAt` too. More: [PathAt](https://crossbotics.com/ftc-helper/docs/reference/parts/path-follower/#pathat). **Try every path in the simulator first.** It runs Pedro like the real robot. So it is the safe place to find a path that hits a wall. The field map draws the plan (orange, dashed) and where the robot went (green). Where the green line leaves the orange one, the robot hit something, or it went too fast to turn or brake. Then move a control point, or slow that part with `maxSpeed(0.5)`. Keep half the robot's width clear on each side of the line. The auto builder draws and runs paths too ([The auto builder: odometry and Pedro](https://crossbotics.com/ftc-helper/docs/building-autos/07-auto-builder-odometry-and-pedro/)). More: [the Pedro module's simulator part](https://crossbotics.com/ftc-helper/docs/modules/pedro/#the-simulator). Run the Pedro robot's example first. **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:fromRobot -PteamCode=none -ProbotClass=com.crossbotics.ftchelper.examples.pedrobot.Robot -Pout=build/pedrobot.properties ``` **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:run -PteamCode=none -Probot=build/pedrobot.properties ``` Open http://localhost:8780, choose **Pedro Bot Curve to the Goal**, press INIT, choose **RED** (gamepad 1 B), then ▶. The robot drives a short line, then curves to the goal with no stop, turning to 45. Halfway, the intake starts. In the simulator, `follow` runs even when `Tunables.Odometry.checked` is `false`. ## 3. Find its numbers Pedro's **Foresight tuner** measures your robot. It drives the robot by itself, **at full power**. The PRACTICE limit does not work here. Keep clear of the robot, and keep a hand on STOP. You need the odometry checked first, and a charged battery. 1. **Add Pedro's tuning library.** **Where:** `build.dependencies.gradle`, in the project folder, next to `settings.gradle`. Add one line to each block, and keep the lines that are there. ```groovy repositories { // ...the lines already here... maven { url 'https://repo.dairy.foundation/releases/' } } dependencies { // ...the lines already here... implementation 'com.pedropathing:tuning:1.0.1' } ``` A **repository** is a website that keeps Java libraries, so Gradle can download them. Pedro keeps its tuning library on its own site, so Gradle needs both lines. Click **Sync Now**. The simulator adds the tuning library to its own build too. 2. **Copy Pedro's tuner files.** From [Pedro's Quickstart](https://github.com/Pedro-Pathing/Quickstart), folder `TeamCode/src/main/java/org/firstinspires/ftc/teamcode/pedro`, copy the `procedures` folder and `Tuning.java` into a new `pedro` folder in your TeamCode. To make the folder, right-click the folder with `Robot.java`, choose **New > Package**, and type `pedro`. 3. **Point the tuner at your robot.** **Where:** `pedro/Tuning.java`. Make the whole file this. When your `Robot.java` is in another package, change the `Robot` import: its folder (from its first line) plus `.Robot`. ```java package org.firstinspires.ftc.teamcode.pedro; import com.crossbotics.ftchelper.pedro.PedroTuning; import com.pedropathing.tuning.autotune.Procedure; import com.pedropathing.tuning.autotune.Tuner; import org.firstinspires.ftc.teamcode.Robot; import org.firstinspires.ftc.teamcode.pedro.procedures.ForesightTuner; public class Tuning { @Tuner public static Procedure foresightTuner() { return new ForesightTuner(PedroTuning.localizer(Robot::new), PedroTuning.drivetrain(Robot::new)); } } ``` `Robot::new` means "make a new Robot": the tuner makes one when it starts. So it measures the robot with your own `drive(...)` and `odometry(...)` lines. `@Tuner` puts it on Pedro's web page. 4. Send the code to the robot. Connect the laptop to the robot's WiFi, and open `http://192.168.43.1:10158` in a browser. 5. Choose **Foresight Procedure** and follow the page. The robot drives forward, sideways, brakes and turns, many times. 6. At the end, open the **Java** tab. In `PedroConstants.java`, replace every `c.something.set(...);` line (between `c -> {` and `});`) with the lines from the Java tab. Keep the first and last lines of the file. The tuner does not change your code, so copy the lines in every time. 7. Send the code again. **Before an event, take the tuner out.** Its web page is not allowed at events (rule R704.D). Comment out the `tuning` line in `build.dependencies.gradle` (put `//` in front of it), and move `Tuning.java` and the `procedures` folder out of TeamCode. Build and install again. Your paths still work: they need only `PedroConstants.java`. Put the files back after the event to tune again. ## 4. Check it, then tune it **Check it:** 1. Optional, but useful: Pedro's own **Tests** procedure (its Line and Curve tests) checks the numbers first. Add it to `Tuning.java` the same way, from Pedro's [testing page](https://pedropathing.com/docs/pathing/tuning/test). 2. Make a short path: one straight `PedroPath.line(...)` of about 24 in, in open floor. 3. Set `Tunables.Drive.maxPower` low (0.6) for the first runs. 4. Put the robot on the start spot, facing the start heading. Press INIT, then ▶. Keep a hand on STOP. 5. The robot must drive the line and stop near the end. Pedro calls a path done within about 2.5 in and 11.25 degrees. 6. Then try your real path, still in PRACTICE. Then in COMPETITION. Set `maxPower` back to `DEFAULT`. **If it goes the wrong way, press STOP.** Then check the table below. **Tune it:** run Pedro's tuner again after a change to the robot's weight, wheels or motors. To make "done" tighter, see [When is a path done?](https://crossbotics.com/ftc-helper/docs/modules/pedro/#when-is-a-path-done). The `driveTo` steps in the same auto use the [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/) numbers. To try `maxPower` without a new build, use [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/). ## Fix a problem | Problem | Why, and the fix | | --- | --- | | `Pedro` or `PedroPath` is red in Android Studio | Add the Pedro add-on (step 2), then Sync | | INIT stops: `follower(...) needs an odometry(...) line too` | The `follower` line needs the `odometry` line above it | | INIT stops: `Pedro.follower needs a mecanum drive(...) line` | Pedro needs mecanum. A tank robot uses `turnTo` and `move` | | Every `follow` says `skipped` in the report | `Tunables.Odometry.checked` is `false`. Do [Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/), step 3 | | It overshoots and comes back, or shakes | `PedroConstants.java` still has another robot's numbers. Do step 3 | | It drives the wrong way at once | STOP. Run the Odometry Tuner again, and check the motor directions | | It stops a little short of the end | Normal: Pedro is done within 2.5 in | | The report says `STALLED` | The robot was stuck, against a wall or a robot. The next steps still run | | The report says `timed out` | The path took more than 10 s. Make it shorter, or give it more time: `.follow("To the goal", TO_GOAL, 15)` | | The tuner's page does not open | The laptop must be on the robot's WiFi. Check the address | | The tuner does not compile | Step 3, item 1: both lines, then Sync | | It is slow | `Tunables.Drive.maxPower` is low (or `practiceMaxPower`, in PRACTICE) | | The report says `STALLED, not fired: Spin up` | The path ended early, so that `PathAt` did not start | More: [the Pedro module, If something goes wrong](https://crossbotics.com/ftc-helper/docs/modules/pedro/#if-something-goes-wrong). ## Done when - `PedroConstants.java` has your robot's numbers from the Foresight tuner. - A 24 in line ends within about 2.5 in of its end point. - Your real path runs in COMPETITION, and the report shows no `skipped` or `STALLED`. --- **Next:** [The auto builder: steps](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/): build an auto on a picture of the field. **Look it up:** [PathFollower and PathAt](https://crossbotics.com/ftc-helper/docs/reference/parts/path-follower/): every command. [Pedro module](https://crossbotics.com/ftc-helper/docs/modules/pedro/): paths, holds and Pedro's numbers. --- # The auto builder: steps URL: https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/ You can come here first, if you like to see the field before you read code. Step 1 uses the red-and-blue table on [page 2](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue). The **auto builder** is part of the simulator. You tap the field to add drives, and pick the other steps from a list. **Run** drives the plan with **your real code**: your `Robot.java`, your parts and your `Actions.java`. Then you copy the Java. **Why use it:** you see the route on the field before the robot drives it. The builder checks it against the field walls, the field parts and the start rules. It also writes the start note for the drive team. **With no robot code yet:** the [web auto builder](https://crossbotics.com/ftc-helper/path-builder/) is the same builder in a web page, with no install. It writes the same Java. It cannot run your code. ## Open it Start the simulator with your own code. In Android Studio, pick **Simulator** in the run list next to the **Run** button, and click **Run**. Or: **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ([Which folder](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/#which-folder)) ```bash ./gradlew :sim:run ``` Open http://localhost:8780. Press **Auto builder** over the 3D view. It takes the Control Hub panel's place. Close it with the **x** to get the hub back. The top of the builder, with a plan on the map. A number on a dark badge is a place the robot drives to. A letter on an orange diamond is a step that does something: ![The auto builder panel: the robot (gobildastraferbot.Robot, a mecanum drive), Run as RED, Red's side "Rotated 180° (like BIOBUZZ)", the field map with a route from the left corner tile (steps 1 to 5, an "Intake on" and a "fireAll" marker), and under it the start spot, the note for the drive team, and the Print setup card and Auto sheet (PDF) buttons.](https://crossbotics.com/ftc-helper/docs/images/auto-builder-plan.png) ## 0. Start from an auto you have (optional) At the top, **Load an existing auto** lists your autos. Pick one and press **Load**. The builder reads its steps. - An older auto can name its numbers (`Tunables.Auto.parkInches`, or a name for a number at the top of the file). The builder works them out from your code, and lists what it could not read. - The builder does not change your file. You copy the Java back when you are done ([step 8](#8-copy-the-java)). ## 1. Robot and alliance - **The robot:** the builder finds your `Robot.java`. Its drive (tank or mecanum), size and parts come from your code. When you have more than one Robot class, pick yours in the list. - **What this robot can do:** a list of the library's ready-made steps for your parts. For example **Fire all** and **Ready to launch** with a launcher, **Aim at the goal** with a camera. Each one is ready, or says what to add. - **Run as:** RED or BLUE. - **Red's side:** **Rotated 180°** (BIOBUZZ) or **Mirrored**. The builder writes `mirrorForRed()` for you ([red and blue](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue)). ![The top of the auto builder, marked: the Robot list (your Robot class), Run as RED or BLUE, Red's side (mirrorForRed()), "What this robot can do" (ready-made steps for your parts), and "Tap adds" (what a tap on the map adds).](https://crossbotics.com/ftc-helper/docs/images/builder-robot-marked.png) ## 2. Add the steps Pick **Simple steps** (any drive). Then: | To add | Do this | | --- | --- | | A drive to a spot | Tap the field there. A spot ahead drives forward. A spot behind backs up. | | A turn to face a spot | Set **Tap adds** to **turn to face**, then tap the spot. | | Any other step | Press its button: drive, strafe (mecanum), turn, turn to, wait, start something, an action, aim at the goal, ready to launch, wait for the goal, park from here. | | A step between two | Point between the two steps in the list, and press the **+** there. Press **Done** when you are finished. | **Change a route on the map:** - **Drag a point** (the blue dot at the end of a drive). The drive and the turn before it change, and the other points stay where they were. - **Put a point between two:** move the pointer over a drive's line. Click the white dot with the plus to split the drive in two. - **Turn a turn:** drag the yellow knob in front of the robot. - **Right-click** a point, a line or the field (or press and hold on a touch screen) for a short menu. **On the map:** a number on a dark badge is a place the robot drives to. An orange diamond with a letter is a step that does something (an action, start something). The same letter is beside the step in the list. ![The map, close up and marked: the green start spot (drag it), the yellow knob in front of it (turn the start), a blue point at the end of a drive (drag it), the dark badge with the step number, the next point, and an orange diamond with the letter A (an action).](https://crossbotics.com/ftc-helper/docs/images/builder-map-marked.png) **A command or an action** opens a list of the ones your code has. Pick one, for example `Actions.scoreHigh(robot)`, or the library's `robot.launcher.fireAllAction()`. **A fire action** has a **flywheel** box. Leave it empty for the usual speed. Type a number (RPM) for this shot's own speed. **Why:** a robot with no camera can shoot from two spots at two speeds. **Mecanum: turn while driving.** Tick it on a drive to make one step that drives and turns at the same time (`moveWithTurn`). **A tank drive cannot slide sideways,** so the builder never makes a strafe for it. ## 3. Edit in 3D (optional) Tick **Edit in the 3D view**. The same points are balls in the 3D view: drag them, or tap the field to add a step. ## 4. The start spot and the note - **Pick a ready-made spot,** or drag the green dot. The robot must touch a field wall. With **Snap** ticked, it lines up with the tile seams, so the drive team can copy it by eye. - **Turn the start** with the yellow knob or the **Face** arrows. - **The numbers** under the map are [field numbers](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#field-numbers): x, y and heading. - **The note** is what the Driver Hub shows in INIT as `Place robot : ...`. **Write it for me** writes it from the spot, for example "Our wall, tile 3 from left, centered, facing field". About 50 characters fit one line. ![The Start spot part of the builder, with seven numbered marks.](https://crossbotics.com/ftc-helper/docs/images/builder-start-marked.png) 1. A ready-made spot. 2. The field numbers: x, y and heading. 3. Which way the robot faces at the start: the arrows, and 15° turns. 4. **Snap:** the robot lines up with the walls and the tile seams. 5. The note for the drive team. 6. **Write it for me:** writes the note from the spot. 7. The pages to print: the setup card and the auto sheet. The auto sheet (for your partner teams) and the setup card (for your drive team): [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#show-your-partners-what-your-robot-does). ## 5. Read the checks Before a run, the builder checks: - the field walls and field parts along the route, - the start rules (touching the wall, on your half, inside the 18 in box), - more than 30 seconds of steps, and the park time, - names left empty. The builder guesses the time from simple speed numbers. The run gives the real time. **A failed check is a warning.** **Run** still works, so you can watch what goes wrong. Fix each warning before you copy the Java. ## 6. Run it Press **Run**. The simulator puts the field's pieces back and puts the robot on the start spot. Then it runs the plan as a real auto: the INIT menu, the 30 s timer, the park time and the report. - A **purple robot** drives the plan. Your robot drives beside it. You see where they part. - The **green line** is the path your robot drove. To run it again, press **Run** again. ## 7. Read the result ![The simulator after a run: the Driver Hub shows "Autonomous finished" and each step done, the 3D view shows the robot after its route, and the builder shows the checks in green and a table: Intake on done, To the goal done 0.7 in off, Fire all done (4 fired), Park done 0.8 in off.](https://crossbotics.com/ftc-helper/docs/images/auto-builder-run.png) ![The checks and the result of a run, with six numbered marks.](https://crossbotics.com/ftc-helper/docs/images/builder-result-marked.png) 1. **The checks,** before the run. Green: fine. Yellow: advice. Red: a problem to fix. 2. **Run in the simulator.** 3. The run's time, of the 30 seconds. 4. **Report:** each step's word from the report. 5. **Off:** how far from the plan the step ended. 6. The result, and what to do next. A table shows each step's word from the report (`done`, `STALLED`, `timed out`, ...) and how far off the plan it ended. **A step can say `done` and still push a field part.** Watch the run. The saved scenario's `expect bumped none` line checks it ([step 8](#8-copy-the-java)). Under the table, **what to change** lists changes to try. Some changes have an **Apply** button, for example a short wait after a drive, so the robot stops rolling before it turns. Press **Run** again to check. ## 8. Copy the Java ![The Java and scenario part of the builder, with five numbered marks.](https://crossbotics.com/ftc-helper/docs/images/builder-java-marked.png) 1. **OpMode:** the auto's name on the Driver Hub. 2. **TeleOp next:** the TeleOp the Driver Hub picks after the auto. 3. **Copy the Java:** the whole file, or only the steps. 4. **Save the scenario:** a test file for this auto. 5. **With the end from the last run:** the test also checks where the robot ended. - **Copy the Java:** the whole file. Make a new file in your `autos` folder. Its name is the name after `public class` in the copied Java. Paste the Java in. - **After Load:** the copy is **only the steps**. Paste them over everything inside `steps(...)` in your file. Your file keeps its comments and its other methods. **First read the list of what Load did not carry over.** The copy leaves out menus (`menuChoice`, `onlyIf`), your own steps and `waitUntil`. When you paste over them, they are gone: a park that ran for one choice then runs every time. Put them back in your file by hand. - **Save the scenario:** a test file that checks the note, the start spot, that each step is `done`, and where the robot ends. Tick **with the end from the last run** to check the end your robot reached in the run. ([Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/).) Then stop the simulator (the red Stop button, or **Ctrl+C** in the Terminal) and start it again. Your new auto is in the Driver Hub list, like any auto. The builder keeps your plan in this browser. ## What it cannot do - Menus: `menuChoice`, `menuYesNo`, `onlyIf` ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#add-choices-to-the-init-menu)). - A number that differs for RED, `alliance().pick` ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#a-different-number-for-red)). - `waitUntil` and your own steps, `step(...)` ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#wait-until-a-part-is-ready)). - Pieces in `Routes.java` ([Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes)). **Load** cannot read an auto made from them. - `routeTo` ([page 4](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/#go-around-field-parts-routeto)). - A command that is not a part's method or an action, like two calls in one. Write it as a method in `Robot.java` or `Actions.java`, and pick that method. The builder reads only these shapes: `robot.part::method`, `robot::method`, `() -> robot.part.method(...)`, `() -> robot.method(...)`, `Actions.name(robot, ...)` and `robot.part.method(...)` that gives an Action, with plain values (text, numbers, true/false, `robot`). **Why:** the page can reach nothing else in your code or on the laptop, and nothing runs as a script. INIT checks every name before the first step, and names the parts there are when one is wrong. **Why learn the file too:** you change autos at events, often in a hurry, and the builder does not do everything. ## Done when - You built an auto in the builder, and **Run** shows `done` for every step. - You copied it into your `autos` folder, built the project, and it runs from the Driver Hub list in the simulator. ## Problems | Problem | Why, and the fix | | --- | --- | | It found the wrong Robot class | Pick yours in the robot list (step 1). | | **Run** is off | Your robot cannot do this mode (for example a Pedro path with no `follower(...)` line), or the Pedro path is empty. Read the message above **Run**. | | `Robot.java has no part called ...` | The command names a part your robot does not have. Pick one from the list. | | The real robot ends far from the plan | Tune the drive first ([Drive Tuner](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#tune-the-drive-first)). The builder's purple robot drives perfectly. Your robot does not. | | A new auto is not on the Driver Hub | The simulator reads your code when it starts. Stop it (the red Stop button, or **Ctrl+C** in the Terminal) and start it again. | --- **Next:** [The auto builder: odometry and Pedro](https://crossbotics.com/ftc-helper/docs/building-autos/07-auto-builder-odometry-and-pedro/). **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto). --- # The auto builder: odometry and Pedro URL: https://crossbotics.com/ftc-helper/docs/building-autos/07-auto-builder-odometry-and-pedro/ **You need:** - The auto builder: [The auto builder: steps](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/). - For `driveTo` steps: odometry ([Drive to points](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/)). - For a Pedro path: the Pedro add-on and the `follower(...)` line ([Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/)). What each path setting does is on that page. ## In the auto builder Open the auto builder ([page 6](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/#open-it)). Pick the mode: - **Simple steps:** the drives, turns and actions of page 6. - **Pedro path:** a mecanum robot with odometry. Tap to add lines or curves. Drag the ends and the curve points. Pick each part's heading and speed limit. Tick **Hold the end**. Add things to start along the path (`PathAt`). The Java has a `follow` with a `PedroPath`, or one `driveTo` per part. The builder says when your robot cannot do a mode, and **Run** stays off: - **follow** needs the `follower(...)` line in `Robot.java`. - **driveTo steps** need only odometry. The map in **Pedro path** mode, close up. The path has two parts: a straight line, then a curve: ![The Pedro path on the map, marked: the start, the end of part 1 (a straight line), the control point (a white dot with dashed lines to the curve), the end of part 2, the heading knob (the yellow dot that sets which way the robot faces at the end), and an orange diamond for a PathAt ("Intake on").](https://crossbotics.com/ftc-helper/docs/images/pedro-map-marked.png) - **Drag the ends** to move a part. **Drag the control point** to bend the curve. The robot does not drive through it: it pulls the curve toward it. - **Drag the heading knob** to change which way the robot faces. The settings for the path and each part: ![The Path settings, marked: follow (one Pedro path) or driveTo steps, the path name in the Java, Hold the end, and for a part: line or curve, which way it faces, when it turns, the speed limit, and "+ point" to add a control point.](https://crossbotics.com/ftc-helper/docs/images/pedro-parts-marked.png) **Actions along the path** are the `PathAt` lines: they start something while the robot drives. ![Actions along the path, marked: "+ Add one" (a PathAt), where it starts (here: a part of the path, 0 to 1), how far (0.5 = halfway), a command or an action, and what it starts (robot.intake::in).](https://crossbotics.com/ftc-helper/docs/images/pedro-pathat-marked.png) **A Pedro plan is one path.** Add the steps before and after it in your file. ## Done when - The builder runs your `driveTo` steps or your Pedro path in the simulator, as BLUE and as RED. - The report says `done` for every point or path. - The Java is in your auto file, with the steps before and after it. ## Problems | Problem | Why, and the fix | | --- | --- | | **Run** stays off in Pedro path mode | `Robot.java` has no `follower(...)` line ([Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/)) | | **Run** stays off for driveTo steps | `Robot.java` has no `odometry(...)` line ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/)) | | A step or path ends in the wrong place | See the problems on [Drive to points](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/#problems) and [Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/#fix-a-problem) | --- **Next:** [Advanced autos](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/): beyond the auto builder. **Look it up:** [the auto builder, every detail](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/). --- # Advanced autos URL: https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/ ## What this page is for Each part below adds one thing to an auto. Use only the parts you need. | Part | What it does for you | | --- | --- | | [Wait until a part is ready](#wait-until-a-part-is-ready) | The robot drives while a slow part moves. It waits for the part only when it must. | | [One auto with choices, or several autos?](#one-auto-with-choices-or-several-autos) | Pick how to offer plans: one file per plan, or one file with choices in INIT. | | [Add choices to the INIT menu](#add-choices-to-the-init-menu) | Your own lines in the INIT menu, like "Then: Park / Stay". Some steps run only for one choice. | | [Routes](#routes) | Steps that several autos share, written once in `Routes.java`. | | [A whole example](#a-whole-example-one-auto-the-drivers-choose) | One auto file: the drivers choose the start spot and the plan. | | [A different number for RED](#a-different-number-for-red) | One number (a wait, a distance) that is different on RED. | | [Keep code inside the steps](#keep-code-inside-the-steps) | Why a line between two steps runs in INIT, and the fix. | | [Write your own step](#write-your-own-step) | Your own Java code as one step, for what no other step can do. | > **The auto builder cannot write anything on this page.** Build the route in the builder first. Copy the > Java into your file, then add these by hand. **Note:** after you add them, the builder's **Load** may not > read the file again. Keep a copy of the plain plan, so you can change it in the builder later. ## Wait until a part is ready **What it does:** the robot does not stop for a slow part. It drives on, and waits only when it needs the part. **Start early, wait late.** Start a slow part with `run` as early as you can. Then wait for it with `waitUntil` right before you need it: ```java .run("Lift up", () -> robot.lift.goTo("high")) // starts the lift .forward("To the goal", 24, 0.6) // drives while the lift rises .waitUntil("Lift at the top", robot.lift::isAtTarget, 2) ``` **Why:** the robot does two things at once. That saves time in a 30-second match. The checks you can wait for: [page 1, wait](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#wait). ## One auto with choices, or several autos? **What it means:** you can give the drivers more than one plan in two ways. - **Several autos:** one file per plan ([page 3](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/)). Each plan is its own line in the Driver Hub's Autonomous list. The auto builder can make each one. - **One auto with choices:** one file with your own lines in the INIT menu. The drivers pick the auto, press INIT, then pick the plan with the D-pad. The steps for every choice are in the same file. One auto with choices can replace several autos that are almost the same. Pick by the difference between the plans: | The difference between the plans | Use | | --- | --- | | Red or blue | nothing: the Alliance line is in every menu | | Wait for a partner at the start | nothing: the Start delay line is in every menu | | Wait for a partner in the middle | `menuYesNo` + `onlyIf` | | Park near or far, leave or stay | `menuChoice` + `onlyIf` | | Score 1 piece or 2 | `menuChoice`, or two files | | Another start spot, the same idea | `menuChoice` for the start ([page 3](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/#near-and-far-starts)) | | A different route, nothing shared | a new file | | A test routine (drive a square) | a new file, in its own group, so nobody runs it in a match | **A rule of thumb:** use a menu line for what the drivers decide at the field. Use a new file for what the programmers decide in the pits. Keep the menu small. Two or three of your own lines are fine. Six lines make too many mixes to test. ## Add choices to the INIT menu **What it does:** adds your own lines to the INIT menu. Some steps then run only when the drivers pick one option. Every auto has an **INIT menu** with Alliance, Start delay and Profile ([page 2](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#the-init-menu)). You can add your own lines. **Add your own line,** then mark the steps that run only for one choice: ```java s.start("Against our wall, facing the field", 0) .menuChoice("Then", "Park", "Stay") // a line with two options .forward("To the goal", 24, 0.6) .action(Actions.scoreHigh(robot), 5) .onlyIf("Then", "Park") // only when "Park" is chosen .right("Park", 20, 0.7) .end(); // the end of the onlyIf ``` - `menuChoice(name, option, option, ...)`: a line with options. **INIT starts on the first option.** Make it your safest plan. - `menuYesNo(name, true)`: a YES/NO line. `true` = it starts at YES. Use it with `onlyIf(name)`. - `onlyIf(name, option)` ... `end()`: the steps in between run only for that choice. Every `onlyIf` needs its own `end()`. - Spell the options **exactly** the same in `menuChoice` and `onlyIf`, capitals too. A typo makes a branch that never runs. - **For an "else",** write a second `onlyIf` with the other option. An `onlyIf` can be inside another one: each `end()` closes the last one opened. - `choice(name)` and `isYes(name)` read a line in your own Java, with a plain `if` ([below](#a-whole-example-one-auto-the-drivers-choose)). - The menu cannot ask for a number. A number goes in the step. The indents inside `onlyIf` are only for people. Java does not read them. ## Routes **What it does:** puts the steps that several autos share in one file, `autos/Routes.java`. Each auto then uses them by name. **You do not need it.** One file per plan, each made in the auto builder, is fine ([page 3](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/#one-file-per-plan)). **Pick Routes when** many autos share the same steps, and you fix the same number in many files. | | Copies (one file per plan) | Routes | | --- | --- | --- | | The auto builder | works: **Load** reads each file | does not work: **Load** cannot read an auto made from Routes | | Fix a number | in every file that has the step | once | | Good for | a few plans, made in the builder | many plans that share steps | Each **piece** of a route is a **method** in `Routes.java` (a named group of lines that you run by its name). You build every auto from the pieces. When you fix a piece once, every auto that uses it gets the fix. The library has this example as a compiled file, for the cookbook's robot (a mecanum drive, a lift and a claw): ```java title="autos/Routes.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first two imports below to: import org.firstinspires.ftc.teamcode.Actions; // import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Actions; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Steps; /** The pieces every autonomous is made from. Write each piece once. No @Autonomous: not an OpMode. */ public class Routes { /** Score the piece the robot starts with: hold it, drive to the goal, score. */ public static Steps scorePreload(Steps s, Robot robot) { return s.run("Hold the preload", robot.claw::close) .forward("To the goal", 30, 0.6) .action(Actions.scoreHigh(robot), 5); } /** One more piece: back to the pieces, grab one, forward to the goal, score. */ public static Steps cycle(Steps s, Robot robot) { return s.back("To the pieces", 20, 0.6) .run("Grab", robot.claw::close) .waitSeconds("Let the claw close", 0.3) .forward("Back to the goal", 20, 0.6) .action(Actions.scoreHigh(robot), 5); } /** The park: back toward our wall. It keeps the last 3 seconds for itself, so it always runs. */ public static Steps park(Steps s) { return s.parkWithSeconds(3) .back("Park", 20, 0.7); } } ``` - `public static Steps scorePreload(Steps s, Robot robot)`: a method that adds its steps to the list `s`, and gives the list back. - `Routes.java` has no `@Autonomous` line. It only holds pieces, so it is not an auto. - The numbers are in the steps, like in any auto. You write the piece once, so you write each number once too. **An auto made from pieces** is only a few lines. Each line adds one piece to the same list: ```java title="autos/NearCycle.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first import below to: import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; /** Score the preload, one more piece, then park. Only the Routes.cycle line is new. */ @Autonomous(name = "Near: Preload + Cycle + Park", group = "Autos", preselectTeleOp = "Cookbook TeleOp") @Disabled // delete this line in your copy public class NearCycle extends Auto { @Override protected boolean mirrorForRed() { return false; } @Override protected void steps(Steps s, Robot robot) { s.start("NEAR: against our wall, 2nd tile left of center, facing the field", -36, -61, 0); Routes.scorePreload(s, robot); Routes.cycle(s, robot); Routes.park(s); } } ``` Here the lines do not chain the steps with dots. Each line calls a piece, and the piece adds its steps to the same list `s`. The result is the same list as one long chain. A second file, "Near: Preload + Park", is the same without the `Routes.cycle` line. The drivers pick it when the partner needs the pieces. **To copy these files,** change the `package` and `import` lines as the comments say, and delete `@Disabled` ([Copy example files into TeamCode](https://crossbotics.com/ftc-helper/docs/pick-your-start/04-copy-into-teamcode/)). In `preselectTeleOp`, write **your** TeleOp's name. ## A whole example: one auto, the drivers choose **What it does:** one auto file holds the plans from [Routes](#routes), a "Park only" plan, and two start spots. The drivers choose the start spot and the plan in INIT: ```java title="autos/ChooseInInit.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first import below to: import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; /** ONE autonomous: the drivers choose the start and the plan in INIT. */ @Autonomous(name = "Choose in INIT", group = "Autos", preselectTeleOp = "Cookbook TeleOp") @Disabled // delete this line in your copy public class ChooseInInit extends Auto { @Override protected boolean mirrorForRed() { return false; } @Override protected void steps(Steps s, Robot robot) { // Your menu lines (under the library's Alliance and Start delay lines). The FIRST option of // each is chosen at INIT: make it your safest plan. s.menuChoice("Start", "Near", "Far") .menuChoice("Plan", "Preload + Park", "Preload + Cycle + Park", "Park only"); // The start spot follows the "Start" line: the note and the simulator's robot change with it. s.onlyIf("Start", "Near") .start("NEAR: against our wall, 2nd tile left of center, facing the field", -36, -61, 0) .end() .onlyIf("Start", "Far") .start("FAR: against our wall, 2nd tile right of center, facing the field", 36, -61, 0) // Off the wall first: the FLOWER on our wall stands between the two start spots. .forward("Off the wall", 12, 0.5) .left("Across to the near side", 72, 0.7) .end(); // The plan: plain Java "if". choice(...) = the option chosen, as text. (1)! String plan = s.choice("Plan"); if (!plan.equals("Park only")) Routes.scorePreload(s, robot); if (plan.equals("Preload + Cycle + Park")) Routes.cycle(s, robot); Routes.park(s); } } ``` 1. `s.choice("Plan")` gives the option the drivers chose, as text. `plan.equals("Park only")` asks "is it the same text?". `!` means "not". So the first `if` reads: if the plan is not "Park only", score the preload. What the drivers see after INIT: ```text Place robot : NEAR: against our wall, 2nd tile left of center, facing the field --- Choose (D-pad), then ▶ --- > Alliance: BLUE Start delay: 0 s Start: Near Plan: Preload + Park Profile: COMPETITION X = BLUE B = RED ``` Change **Start** to Far, and the first line at once says `Place robot : FAR: ...`. **Why:** the library reads the steps again each time a menu line changes. So the note always matches the start the drivers chose. ## A different number for RED **What it does:** gives one number a different value on RED. Most autos need nothing more: the library turns or mirrors the steps ([page 2](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue)). Sometimes one thing is different on RED: a wait, a distance, an AprilTag number. `alliance().pick(blueValue, redValue)` gives the right one for the alliance the drivers chose: ```java @Override protected void steps(Steps s, Robot robot) { double parkInches = alliance().pick(20.0, 26.0); // BLUE 20 in, RED 26 in s.start("Against our wall, facing the field", 0) .forward("To the goal", 24, 0.6) .action(Actions.scoreHigh(robot), 5) .parkWithSeconds(3) .right("Park", parkInches, 0.7); } } ``` - `alliance()` is BLUE or RED, from the INIT menu. - `pick(20.0, 26.0)`: the first number for BLUE, the second for RED. Write both with a `.0`. - When the drivers change the Alliance line in INIT, the library reads the steps again. So the number always matches the alliance. **RED differs only** when the field is not the same for both alliances. Check the field drawing. Then run the auto as BLUE and as RED in the simulator. **The auto builder** shows both: **Run as** RED or BLUE. It cannot write `alliance().pick`. Add it in your file. ## Keep code inside the steps **What it means:** every line in `steps(...)` must be a step. A line between two steps runs at the wrong time. The library reads your list of steps **more than once**: 1. In INIT, to learn the menu, the start note and the park time. **No step runs then.** 2. In INIT again, each time the drivers change a menu line. 3. After ▶, to make the real list. Then it runs. So put only steps in `steps(...)`. A line like `robot.claw.close();` between two steps runs in INIT, several times. Put it in a step: `.run("Close the claw", robot.claw::close)`. ## Write your own step **What it does:** runs your own Java code as one step, for something no other step can do. The lines between `{` and `}` are your code: ```java .step("Clear the intake", ctx -> { robot.intake.out(); ctx.waitFor(0.3); // wait 0.3 s; every part keeps working robot.intake.stop(); }) ``` `ctx` is your step's helper (short for "context"). It gives you: | Inside your step | What it does | | --- | --- | | `ctx.waitFor(seconds)` | waits. Every part keeps working | | `ctx.waitUntil(check, seconds)` | waits until the check is true. It gives false if the time ran out | | `ctx.isActive()` | false when the auto is over or the park time came: stop then | | `ctx.secondsLeft()` | the seconds left in the auto | | `ctx.note(text)` | your words in the report, in place of `done` | | `ctx.loop()` | updates every part once: call it in your own loop | | `ctx.telemetry()` | add your own lines to the Driver Hub screen | **Never use `sleep()`.** It freezes every part, and the 30 s timer cannot stop the robot. Use `ctx.waitFor`. ([Why](https://crossbotics.com/ftc-helper/docs/guides/non-blocking/).) ## Done when - One auto file offers a choice in INIT, and each option runs in the simulator. - Each plan runs in the simulator, as BLUE and as RED. ## Problems | Problem | Why, and the fix | | --- | --- | | A menu choice does nothing | The option has a different spelling in `menuChoice` and in `onlyIf` or `equals`. | | The robot ran the wrong plan | Nobody changed the menu, so the first option ran. Read the menu out loud before ▶. | | Every step after an `onlyIf` runs only for one choice | The `end()` is missing. | | `end() without an onlyIf` | One `end()` too many. | | Something moves in INIT | Code is between the steps. Put it in a `run(...)` or a `step(...)`. | | One auto is fixed, another is not | Someone copied the steps. Fix each copy, or move the steps into `Routes.java`. | | `cannot find symbol: Routes` | `Routes.java` must be in the same `autos` folder, with the same `package` line. | | The builder's **Load** cannot read the file | It reads only plain steps. Load the plain copy, or change this file by hand. | **What each word in the report means** (`done`, `STALLED`, ...): [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#after-the-match-read-the-report). --- **Next:** [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/). **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto). **Go deeper:** [cookbook: several autos and choosing one](https://crossbotics.com/ftc-helper/docs/cookbook/10-several-autos/), [the cookbook's autonomous recipes](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/). --- # Match day URL: https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/ A good auto scores nothing when it starts in the wrong place, or runs the wrong plan. Most auto mistakes at an event are not code mistakes. These checks stop them. ## Before the event - **Pick the autos you bring.** Each partner is different, so you pick the auto in the talk before each match. Bring a few that start in different places or go for different pieces. Give each one good default menu settings, and write them on its setup card. - **Remove what you will not run.** Put `@Disabled` on old and untested autos, and put test routines in `group = "Test"`. - **The first runs of a new auto:** on blocks first, then in PRACTICE, then in COMPETITION ([the first run on the robot](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#the-first-run-on-the-robot)). - **Run every auto on the list** on a real field (or a practice field): as BLUE and as RED, with each menu option, in the COMPETITION profile. - **Save the code you will run:** commit and push it, and tag it ([Git and GitHub](https://crossbotics.com/ftc-helper/docs/guides/github/#before-an-event-backups-and-a-tag)). Then you can always get back to it. - **Print an auto sheet and a setup card** for each auto ([below](#show-your-partners-what-your-robot-does)). ## Show your partners what your robot does Before each match you plan the auto with your alliance partner. They need to know **exactly** what your robot does in auto: where it starts, where it drives, what it scores, and when. Then the two robots do not crash, and they do not go for the same pieces. The auto builder ([page 6](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/)) makes the pages for this. Print them before the event. - **Auto sheet (PDF): for your partner teams.** One page per auto: the start spot, the whole route on the field, and every step in plain words, with its time. Show it in the match talk. Bring one sheet for each auto you can run, so the partner can help pick the one that fits. - **Setup card: for your own drive team.** The start note in big letters, the field with the robot's start spot and heading, what RED does, the start delay, and three checks. The drive team uses it to put the robot down right. Keep one per auto in the drive team's box. To print: press **Auto sheet (PDF)** or **Print setup card**, then **Print or save as PDF**. Black and white is fine. An auto sheet, from the auto builder in the simulator: ![An auto sheet titled "Score and Park": the field map with the start box in the left corner tile, the route and the numbered step ends; beside it the start note, "Red and blue: the same route for both", and the planned time; under it the five steps with their times.](https://crossbotics.com/ftc-helper/docs/images/auto-sheet.png) A setup card, from the web auto builder: ![A setup card: the title "My Auto", the note "Left corner tile, right edge on seam, facing field" in big letters, the field with the robot in the left corner tile facing the field, and three checks for the drive team.](https://crossbotics.com/ftc-helper/docs/images/setup-card.png) ## Before each match A checklist for the drive team: 1. **Talk with the partner:** show your auto sheet. Agree who starts where, who goes where, and who needs a delay. 2. **Choose the auto** on the Driver Station. Read its name out loud. 3. Press **INIT**. **Read the menu out loud:** alliance, start delay, your lines. 4. Set the **Alliance**: **X** = BLUE, **B** = RED. 5. Check that **Profile** says **COMPETITION**. A `!! PRACTICE profile` warning at the top means it does not ([what changes](#practice-and-competition)). 6. **Place the robot** where the `Place robot` note says. A second person checks the note against the robot. 7. **Look for warnings** on the screen: a camera, the odometry, tuned values that differ from the code. 8. Hands off. Press ▶ when the match starts. ### Wrong alliance? | When you see it | What to do | | --- | --- | | In INIT, before ▶ | Press **X** for BLUE or **B** for RED. Read the menu out loud again. | | During auto | You cannot change it. Let the auto run. | | In TeleOp | Hold gamepad 1 **START**, then also hold **BACK**, for 1.5 s. The screen says `Alliance now RED (was BLUE)`. Hold them again to switch back. If you let go before 1.5 s, the alliance stays the same and the debug lines turn on or off. | **The TeleOp switch is off until you turn it on.** Add one line to `Controls.java`: `lib.switchAlliance(g1.start, g1.back);` ([switching the alliance in TeleOp](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/#switching-the-alliance-in-teleop)). With odometry on BIOBUZZ, a switch turns off aiming by odometry. The robot does not aim at a wrong spot: it does not aim by odometry at all. The screen says `odometry aim OFF until the pose is set`. To turn it on again, park on the reset spot and hold START 1 s. TeleOp keeps the alliance from the auto, so a wrong alliance in INIT is wrong in TeleOp too. Turn the switch on before the event, and write **START + BACK, 1.5 s** on the setup card. ### Practice and competition The **Profile** line in INIT has two settings. The Control Hub remembers it until someone changes it. | | PRACTICE (in the shop) | COMPETITION (at an event) | | --- | --- | --- | | Drive power | the same: `maxPower` (unless you set `practiceMaxPower`) | `maxPower` | | Debug lines on the screen | on | off | | Tuning menu (hold GUIDE) | opens | stays closed | | Camera live view | on | off (it costs speed) | | A part that is off | a quiet note | a loud `!!` warning | | The top of the INIT screen | `!! PRACTICE profile` | nothing | | Your own `Profile.pick(a, b)` | `a` | `b` | Safety (limits, time limits, jam checks) is the same in both. COMPETITION is the default. Back in the shop, set PRACTICE again. More: [Profiles](https://crossbotics.com/ftc-helper/docs/guides/profiles/). ## After the match: read the report When the auto ends, the Driver Station shows `Autonomous finished` and one line per step: ```text Start: done Hold the piece: done To the goal: done Score high: timed out Park: done ``` The robot log and TeleOp's INIT screen show the same report, so the drive team can read it while they set up for TeleOp. | The word | It means | | --- | --- | | `done` | The step finished. | | `timed out` | A wait or an action ran out of time. The list went on. | | `STALLED` | A drive could not finish: the robot was stuck. | | `TIMED_OUT` | A drive took too long. | | `STOPPED` | Something outside the drive stopped it: someone pressed STOP, or the 30 seconds ended. | | `NO_ODOMETRY` | A `driveTo` stopped: the odometry did not answer. | | `cut short (time for park)` | The auto stopped the step early, so the park steps had time. | | `skipped (time for park)` | The auto did not start the step: no time was left before parking. | | `skipped: Tunables.Odometry.checked is false` | A `driveTo` on a real robot before the Odometry Tuner. | | `not seen` | `aimAtGoal` did not see the goal, so the robot did not turn. | | `not seen in 5 s: went on` (your seconds) | `waitForGoal` did not see the goal in its time. | | your own words | From your own step, or an action's reason. | **Write down** every step that does not say `done`. Fix it in the pits: - `timed out` on an action: the part is slow, or its numbers are off. Check the part. - `STALLED`: the route hits something. Watch it in the simulator. Use `routeTo` near field parts. - `cut short` or `skipped (time for park)`: the auto is too long. Remove a step, or drive faster. Change the number in the step, test it, and commit. ## Common mistakes | What happens | Why, and the fix | | --- | --- | | The robot ran the wrong plan | Nobody changed the menu, so the first option ran. Read the menu out loud before ▶. | | The robot started in the wrong place | Nobody checked the note. Start the note with the spot in CAPITALS. A second person checks it. | | The robot drove at low power | `maxPower` in `Tunables.Drive` is still low from the first runs. Or someone set `practiceMaxPower`, and the profile was PRACTICE ([what changes](#practice-and-competition)). | | The robot went the wrong way in TeleOp | The alliance was wrong in INIT, and TeleOp kept it. [Wrong alliance?](#wrong-alliance) | | The robot went the wrong way for RED | The alliance was wrong, or `mirrorForRed()` is wrong for this field. | | The drivers could not find the auto | Too many on the list. Add `@Disabled` to the old ones. | | TeleOp was not chosen after the auto | `preselectTeleOp` must be the TeleOp's name, exactly. | | `AUTONOMOUS IS OFF` | `calibrated` is `false` in `Tunables.java` ([Tune the drive first](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#tune-the-drive-first)). | ## Done when - Each auto on the list has run on a field, as BLUE and as RED. - The drive team has a setup card for each auto, and the checklist. - After a match, the drive team reads the report and writes down each step that is not `done`. --- **Next:** [Simulator](https://crossbotics.com/ftc-helper/docs/simulator/): watch your autonomous and fix it on the laptop. **Look it up:** [every step](https://crossbotics.com/ftc-helper/docs/reference/steps/#auto). **Go deeper:** [test an auto with a scenario file](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/). --- # Tuning URL: https://crossbotics.com/ftc-helper/docs/tuning/ Every robot program is full of numbers: where a servo opens, how high a lift may go, how fast a flywheel spins, how big the wheels are. When you guess them, you waste practice time and break parts. The **finders** measure them for you and show the lines to copy into `Tunables.java` and `Robot.java`. ## The tuning order Go from top to bottom. Skip a tool for a part your robot does not have: the **Tune and check** menu leaves it out.
flowchart TB
    subgraph G1["Wiring"]
        H["Wiring checks<br/>devices, wheels, encoders"]
    end
    subgraph G2["Parts that move"]
        direction LR
        S["Servo Finder<br/>ends + positions"] --> HO["Hood Finder<br/>two stops"] --> M["Motor Finder<br/>limits + positions"]
    end
    subgraph G3["The launcher"]
        direction LR
        F["Flywheel Finder<br/>gains + recovery"] --> FS["Feed Stop Finder<br/>hold + release"]
        F --> FT["Feed Time Finder<br/>feedSec"]
    end
    subgraph G4["Driving"]
        direction LR
        D["Drive Tuner<br/>wheel size + strafe"] --> O["Odometry Tuner<br/>pods + offsets"] --> MV["Move Tuner<br/>stops + turns"]
    end
    subgraph G5["Scoring"]
        direction LR
        L["Camera lighting<br/>a setup, not a tool"] --> A["Aim Tuner<br/>camera offset"] --> T["Shot Tuner<br/>shot table"]
    end
    subgraph G6["Last"]
        direction LR
        P["Piece Tuner<br/>sensors"] --> C["Characterizer<br/>how it moves"]
    end
    G1 --> G2 --> G3 --> G4 --> G5 --> G6
| # | Page | It finds | Why it comes here | | --- | --- | --- | --- | | 1 | [Before you tune: the Tune and check OpMode](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/) | nothing: the menu, safety, help | read it once | | 2 | [Wiring checks](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/) | Hardware Check, Motor Direction, Encoder | every other number trusts the wiring, so it comes first | | 3 | [Servo Finder](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/) | ends and positions | a servo pushed past its end breaks, so find the ends before code moves it | | 4 | [Hood Finder](https://crossbotics.com/ftc-helper/docs/tuning/04-hood-finder/) | a hood's two stops | the Shot Tuner writes hood positions, so the hood needs its stops first | | 5 | [Motor Finder](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/) | limits and positions | a wrong limit breaks parts, so do it before you drive a mechanism with code | | 6 | [Flywheel Finder](https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/) | gains (the numbers that hold its speed) and recovery | the shot table is only true when the wheel holds its speed | | 7 | [Feed Stop Finder](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-stop-finder/), or [Feed Time Finder](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-time-finder/) for a CR servo or motor feeder with no feed stop, pushing parts or feed wheel (a robot gets one or the other) | hold and release; or `feedSec` (how long the feeder runs per shot) | the launcher must feed one piece at a time before you tune shots | | 8 | [Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/) | wheel size and strafe | autonomous moves need the right distances. Autonomous stays off until it passes | | 9 | [Odometry Tuner](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/) | pod directions and offsets (a pod is a small free wheel that measures how far the robot rolls) | `driveTo` and the shot distance need a true pose (where the robot is on the field, and which way it faces). Path steps stay off until it passes | | 10 | [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/) | where moves stop, how turns end | it needs the right distances (Drive Tuner) and, with odometry, a true pose to measure with | | 11 | [Camera lighting](https://crossbotics.com/ftc-helper/docs/tuning/11-camera-lighting/) (a setup, not a tool) | the camera setting for each kind of light | the camera must see the tags well before you aim or tune shots | | 12 | [Aim Tuner (own file)](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/) | camera offset | aim first, so you build the shot table with straight shots | | 13 | [Shot Tuner](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/) | the shot table | it needs a steady wheel, straight aim and a true distance: everything above | | 14 | [Piece Tuner](https://crossbotics.com/ftc-helper/docs/tuning/14-piece-tuner/) | what each sensor sees | nothing moves, so it can also come earlier | | 15 | [Characterizer (own file)](https://crossbotics.com/ftc-helper/docs/tuning/15-characterizer/) | how the motors move | it needs a robot that drives and lifts that work, so it comes last | **After the finders:** - [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/): change a number from the gamepad while your TeleOp runs (the tuning menu in TeleOp, not Tune and check). - [Fix it by what you see](https://crossbotics.com/ftc-helper/docs/tuning/17-fix-by-symptom/): "the lift sags" -> which number to change, and which way. --- **Next:** [Before you tune: the Tune and check OpMode](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/). --- # Before you tune: the Tune and check OpMode URL: https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/ **You need:** a robot with its configuration done, and a block to lift it. ## The Tune and check menu The library adds one OpMode by itself: **Tune and check** (TeleOp list, group "Finders"). You have no file to copy. It holds the Hardware Check and every finder that fits your Robot.java. 1. Pick **Tune and check** and press INIT. A menu shows. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. D-pad up/down picks a tool. **A** opens it, and you see its own INIT screen. Read its safety note. 3. Press **▶** (start) on the Driver Hub. The tool runs, the same as on its own. 4. For another tool, press STOP, then INIT. The menu starts on the last tool. In a tool's INIT, **BACK** goes back to the menu. The menu lists only the tools that fit your robot. It finds Robot.java by itself: any class in `org.firstinspires.ftc.teamcode` that extends `RobotDefinition`. With two robots, D-pad left/right picks one. | Tool | In the menu when | | --- | --- | | Hardware Check | always | | Motor Direction Check | there is a Robot.java | | Encoder Check | there is a Robot.java | | Servo Finder | the configuration has a servo | | Hood Finder | the robot has a hood | | Motor Finder | the robot has a lift or an arm (or there is no Robot.java) | | Flywheel Finder | the robot has a launcher (or there is no Robot.java) | | Feed Stop Finder | the launcher has a `.feedStop(...)` | | Feed Time Finder | the launcher's feeder is a CR servo or a motor, with no feed stop, pushing parts or feed wheel | | Drive Tuner | there is a Robot.java | | Odometry Tuner | Robot.java has an `odometry(...)` line | | Move Tuner | there is a Robot.java | | Shot Tuner | the robot has a launcher | | Piece Tuner | the robot has a piece sensor | Two tools are not in the menu: the **Aim Tuner** and the **Characterizer**. They need your camera or your lifts, so they keep their own file ([Aim Tuner](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/), [Characterizer](https://crossbotics.com/ftc-helper/docs/tuning/15-characterizer/)). Your own finder files still work: keep them or delete them. ## Before you start - Put the robot on a block for the Servo, Motor and Flywheel finders (wheels off the floor). - Wear eye protection for the Flywheel Finder, Shot Tuner and Aim Tuner. Keep everybody out of the line of fire. - Use a charged battery (12.5 V or more) for the Drive Tuner, the Move Tuner, the Characterizer, the Flywheel Finder and the Shot Tuner. Their numbers are powers and speeds, so they depend on the battery. Their screens show the battery and warn when it is low. Every finder writes the battery at the start (▶) in the results file (`== Drive Tuner, 2026-10-24 14:05, battery 12.8 V ==`). - The simplest way is **Tune and check** (above). It has every finder that fits your robot, with no file to copy. Or use one file per finder. The finders are in the starter kit (`ServoFinder`, `MotorFinder`, `FlywheelFinder`, `DriveTuner`, `Characterizer`) and in the examples (`ExampleShotTuner`, `ExampleAimTuner`: put your launcher and camera in them). Remove `@Disabled` and build. Then they are in the TeleOp list under "Finders". - The robot in five files: the Servo, Motor and Flywheel finders need no code. The Drive Tuner, the Odometry Tuner, the Move Tuner and the Shot Tuner need one line that names your robot. The line makes your `Robot`, so the tuner uses its parts. Examples: `lessonbot`'s [DriveTuner.java](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/lessonbot/DriveTuner.java), the turret robot's [ShotTuner.java](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/turretbot/ShotTuner.java): ```java @Override protected RobotDefinition robot() { return new Robot(); } ``` ## Help on the robot Press **GUIDE** (the center button) in any finder, in INIT or while it runs. A page shows every button and the steps. The Hardware Check has no help page. When your gamepad has no GUIDE button, or GUIDE does nothing, hold the gamepad's **START** for 1 second instead. While help is open, the finder's buttons pause and its motors stop. GUIDE again goes back. Then let go of every stick, trigger and button once: until then, the finder ignores them. Check once on your own Driver Hub and controllers that the help page fits and is easy to read. The screens show the button names on YOUR controller (× ○ □ △ on a PlayStation controller). These pages use the Logitech names ([every name](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#the-buttons)). **▶** on a screen is always the Driver Hub's start button, never a gamepad button. ## Put the lines into your code Every finder ends with lines for your code. The robot uses the files, not the finder's screen. You cannot copy and paste from the Driver Hub, so there are two ways: - **Type them.** First take a photo of the Driver Hub's screen with a phone. Then type each line from the photo into the file on the laptop. The photo keeps the numbers after you press STOP, and you can zoom in to read each digit. This is fine for a few numbers. Check each digit twice. - **Copy them from the results file.** When you press STOP, the finder saves its lines on the Control Hub. Get that file on the laptop, then copy and paste ([Get the results file on the laptop](#get-the-results-file-on-the-laptop)). This is best for long lines, like a shot table. Each finder shows two kinds of lines. Use the kind that fits your code: | Your code | Copy the lines that start with | Example | | --- | --- | --- | | the robot in five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)) | `Tunables.` or `Robot.java:` | `Tunables.Lift: min = 0, max = 2580, P1 = 1200` = in `Tunables.java`, section `Lift`, set those three numbers | | the older helpers | the rest (`PositionMotor.create(...)`, `c.wheelDiameterIn = ...`) | `PositionMotor.create(hardwareMap, "lift").limits(0, 2580)` | The section is the device's name in CamelCase (each word starts with a capital, with no spaces): `lift` -> `Lift`, `intake_deploy` -> `IntakeDeploy`. When you gave the part its own section with `.tunables("Name")` in Robot.java, copy the numbers into that section instead. The finders call positions P1, P2...: give them real names (`low`, `high`, `open`, `closed`). ### Get the results file on the laptop When you press STOP, every finder adds its lines to `/sdcard/FIRST/ftc-helper/finder-results.txt` on the Control Hub, with the date. The Driver Station says whether it worked. The newest results are at the end. 1. Connect the laptop to the Control Hub: a USB cable, or the robot's Wi-Fi. 2. Open the file with one of these: - the **REV Hardware Client**: its file manager, in the folder `FIRST/ftc-helper/` - **Android Studio**: **View > Tool Windows > Device Explorer**, then `sdcard/FIRST/ftc-helper/` 3. Copy the lines you need into `Tunables.java` or `Robot.java`. ## Done when - **Tune and check** is in the TeleOp list, and its menu shows the tools for your robot. - You know where the results file is. --- **Next:** [Wiring checks: motors and encoders](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/). **Look it up:** [finders module](https://crossbotics.com/ftc-helper/docs/modules/finders/), [How to read a finder's lines](https://crossbotics.com/ftc-helper/docs/reference/tunables/#how-to-read-a-finders-lines). --- # Wiring checks: motors and encoders URL: https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/ **In Tune and check:** always. **You need:** the robot on a block (the wheels spin), lifts and arms at their bottom stop, hands clear. Do these three checks first, on every new robot, and again after you change a motor or a cable. Every other number trusts the wiring. ## Get to the checks 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad up/down** until the arrow (`>`) is on the check you want: **Hardware Check**, **Motor Direction Check** or **Encoder Check**. Then press **A**. ![The Tune and check menu with the arrow on Hardware Check: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-wiring-checks-go-menu.svg) 3. The check's INIT screen shows. Nothing moves yet. Put the robot on a block, and press **▶** (start) on the Driver Hub. ![The Hardware Check's INIT screen: Found 12 devices. Robot on a block! Press start](https://crossbotics.com/ftc-helper/docs/images/hub-hardware-check-go-start.svg) For the next check, press STOP, then INIT again, and pick it in the menu. ## Hardware Check: every device answers The Hardware Check finds every device and moves each motor and servo. It spins a motor in its raw direction, so it does not check `reversed(...)`: the next check does. What to look for, device by device: [Hardware check](https://crossbotics.com/ftc-helper/docs/tests/03-checks-before-practice-and-matches/#3-hardware-check-after-a-wiring-or-configuration-change). ## Motor Direction Check: each wheel rolls forward The Hardware Check spins a motor in its raw direction. This check uses your directions, so it shows what the robot will do. It spins ONE drive motor at a time at 30%, set up exactly as Robot.java says: its direction comes from `reversed(...)` on the drive line. 1. Hold **X** (front-left), **Y** (front-right), **A** (back-left) or **B** (back-right). On a tank drive, X = left and Y = right. The screen shows the motor's name, and "(reversed)" when Robot.java reverses it. ![Hold X: the front-left wheel spins, and the Driver Hub shows X front-left : "front_left" RUNNING](https://crossbotics.com/ftc-helper/docs/images/hub-motor-direction-check-step-hold.svg) 2. Each wheel must roll the way that drives the robot FORWARD. For the robot in five files, the front is the end that Robot.java says. 3. When a wheel rolls backward, add its name to `reversed(...)` on the drive line in Robot.java (or take it out). Build and install the code, then check it again: press STOP, then INIT, open Motor Direction Check, and press ▶. ![Check it again, hold X: the Driver Hub shows X front-left : "front_left" (reversed) RUNNING](https://crossbotics.com/ftc-helper/docs/images/hub-motor-direction-check-step-fixed.svg) 4. When the wrong wheel turns, its name in the robot configuration is on the wrong port. Swap the names on the Driver Hub, not the wires. A wrong direction makes the robot drive in circles, strafe the wrong way, or fight itself. So run the check on every new robot, and again after you change any motor or wire. ## Encoder Check: each encoder cable in its own port A motor's encoder counts its turns. It has its own small cable, plugged into the hub next to the motor's power cable. A lift, an arm, a flywheel's speed and the drive's distances all trust that count. When the cable is in ANOTHER motor's port, the lift reads the wrong motor and never stops. When the cable is missing, the count stays at 0 and the lift pushes into its stop. The check pushes each motor in Robot.java a little (30% power for 0.3 s), one at a time. It reads EVERY motor port's count, and shows a result for each motor: | Result | What it means | Fix | | --- | --- | --- | | OK: counts up (or down) | its own port counted, the way the check pushed it | nothing | | NO COUNTS | no port counted | plug in the encoder cable, or replace it. Or the motor did not turn: check that you saw it move | | counts on "X" instead | another motor's port counted | the encoder cables are swapped: put each one in its own motor's port | | counts on "lift_right" instead: plug the encoder cable into "lift_left"'s port | a two-motor lift or arm: the library reads only the first motor's encoder | move the cable to the first motor's port | | counts BACKWARD | its port counted the other way from the push | the motor's power wires are swapped (red and black), or an outside encoder is mounted the other way | | no counts (fine: nothing reads this encoder) | an intake or feeder with no encoder cable | nothing | | could not read its encoder | the hub did not answer | press **Y** to check again. When the result stays, check the hub's cables | | NOT IN THE CONFIGURATION | Robot.java names a motor the configuration does not have | add it to the configuration, or mark the part `optional()` | 1. Put the robot on a block, with lifts and arms down. In **Tune and check**, open **Encoder Check**, then press **▶**. ![The Encoder Check's INIT screen: Then press start. Hold A: each motor gets a short push](https://crossbotics.com/ftc-helper/docs/images/hub-encoder-check-go-start.svg) 2. Hold **A**. Each motor gets its short push in turn. When you let go of **A**, everything stops at once. ![Hold A: the Driver Hub shows "back_left" (drive) : PUSHING, and OK for the motors before it](https://crossbotics.com/ftc-helper/docs/images/hub-encoder-check-step-hold.svg) 3. Read the results. Fix the cables. Press **Y** to check again. ![Fix the cables, then press Y: the Driver Hub shows "lift" (Lift) : NO COUNTS and 1 problem(s)](https://crossbotics.com/ftc-helper/docs/images/hub-encoder-check-step-again.svg) The check sets up each motor as Robot.java says (its direction). It pushes the motor toward the side where its part has room. It reads that side from your `Tunables.java`: a lift up from its bottom stop, a hood toward `posB`, a turret toward the end of its range that is farther from its start angle. Its count must move the same way. **Watch each part while the check pushes it.** The count turns with the direction setting, so the check cannot see a wrong `reversed()` in Robot.java. Only your eyes can. A lift or arm must move UP, away from its stop. When it moves down, fix `reversed()` on its line in Robot.java. For the drive, use the [Motor Direction Check](#motor-direction-check-each-wheel-rolls-forward). Before each push, the check waits until every port is still (for example, until a flywheel spins down). So it never mistakes one motor for another. When something keeps moving, the screen names it. The check does not check servos, CR servos, a CR servo turret, or a motor whose port reads something else. Those are an odometry pod (the [Odometry Tuner](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/) checks pods) and a CR servo turret's encoder. Run it on every new robot, and again after you change any motor or cable. ## Fix a mistake - **Hardware Check:** it only reads the devices. There is nothing to undo. - **Motor Direction Check:** a wheel runs only while you hold its button. Let go, and it stops. - **Encoder Check:** press **Y** to run the check again. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code These checks give no numbers to copy. You fix what they find in two places: | The check finds | Fix it in | | --- | --- | | a wheel rolls backward | `reversed(...)` on the drive line in `Robot.java` | | a lift or arm moves down when the check pushes it | `.reversed()` on its line in `Robot.java` | | the wrong wheel turns | the robot configuration on the Driver Hub (swap the names, not the wires) | | an encoder cable is missing, swapped or backward | the cables on the hub | ## Done when - The Hardware Check finds every device. - every drive wheel rolls the way that drives the robot forward. - every motor says OK (or "no counts (fine...)" for a motor whose encoder nothing reads). --- **Next:** [Servo Finder: ends and positions](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/). **Look it up:** [Hardware Check module](https://crossbotics.com/ftc-helper/docs/modules/testing/), [Troubleshooting: robot behavior](https://crossbotics.com/ftc-helper/docs/troubleshooting/#robot-behavior). --- # Servo Finder: ends and positions URL: https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/ **In Tune and check:** yes, when the configuration has a servo. **You need:** the robot on a block. ## Get to the Servo Finder 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Servo Finder**, then press **A**. ![The Tune and check menu with the arrow on Servo Finder: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-go-menu.svg) 3. The Servo Finder's INIT screen shows. Nothing moves yet. Press **▶** (start) on the Driver Hub. ![The Servo Finder's INIT screen: Nothing moves until you nudge it. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-go-start.svg) 4. Press **D-pad up/down** until the arrow is on your servo's name, then press **A**. The names come from the robot configuration. ![Choose a servo: the arrow on claw, then press A](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-go-choose.svg) The screen now shows `Start point : 0.500`. Nothing has moved yet. Go on with the steps below. ## A new servo part, step by step With a new servo, the hard part is that you do not know which way it turns, or where its ends are. Go in this order, slowly. Use **Tune and check > Servo Finder**: it knows Robot.java (`reversed()`, a second servo, the servo's catalog part). 1. **Arm off.** Put the servo in, but leave its arm (the horn) off, or its screw loose. Then nothing can hit the frame while you start. 2. **Go to the middle.** Leave the start point at 0.500 and press **A**. The servo goes to the middle of its turn and holds there. ![Press A: the servo arm points straight up, the middle, and the Driver Hub shows Position : 0.500](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-step-middle.svg) 3. **Put the arm on in the middle of the part's swing**, so the part can move both ways from here. Tighten the screw. Mark the horn and the shaft with a paint pen, so a new horn later goes on the same tooth ([Put an arm back on](#put-an-arm-back-on)). 4. **Find the direction.** Press **D-pad left** once (a 0.01 step), then press **D-pad up** (bigger) a few times and watch the part. Write it down: "bigger = open", "bigger = up". No standard says which way a servo turns ([why](https://crossbotics.com/ftc-helper/docs/conventions/#servos-and-motors-which-way-is-bigger)). For a catalog servo, the screen shows a **Hint** (goBILDA: "bigger = clockwise (seller)"). But only your test counts, because the part's way depends on how you mount the servo. ![Press D-pad up: the arm turns clockwise, and the Driver Hub shows Position : 0.600 and the Hint line](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-step-direction.svg) 5. **Find the first end, slowly.** Move toward one end in small steps (D-pad up/down) until the part BARELY touches the frame. D-pad left makes the step smaller, down to 0.001. **A servo that hums is pushing on something: back off at once.** It gets hot and can strip its gears. Back off 0.01 more and press **X**. ![At one end, press X: the arm is just before the frame, and the Driver Hub shows End X : 0.120](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-step-end-x.svg) 6. **Find the other end.** Move the part all the way back with the D-pad, past the middle, to the other end. Use a big step first, then small steps near the frame. Stop just before the frame in the same way, and press **B**. ![At the other end, press B: the arm moved across to just before the other frame, and the Driver Hub shows End B : 0.880](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-step-end-b.svg) 7. **Save each position you need** (open, closed, rest, push...): move there and press **A**. Then copy the lines into `Tunables.java` ([Put the numbers in your code](#put-the-numbers-in-your-code)). ![Press A at each position: the Driver Hub shows Tunables.Claw: P1 = 0.210, P2 = 0.770 under Copy into your code](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-step-positions.svg) 8. **To make "bigger" go the other way** (for example, bigger = up), add `.reversed()` to the part in Robot.java. Then find the positions again: each old number becomes 1 minus it. **Two servos on one part:** do step 1 for BOTH arms. Choose the FIRST servo: the second moves with it, mirrored. Then put both arms on at the middle (step 3), so they match, and go on from step 4. If they do not quite meet, set `alsoTrim` afterward, in TeleOp. **At ▶**, the part goes straight to its first position from wherever it is, because a servo always knows its own angle. Keep hands clear. ## The finder's buttons ![Servo Finder: X and B mark the two ends, right before the frame; A saves each position between them](https://crossbotics.com/ftc-helper/docs/images/finder-servo.svg) 0. **Full range:** when the part has `.fullRange()` in Robot.java, press **Y** while you choose the servo, so the finder uses the same range. Full range is the servo's whole turn: for a goBILDA 2000 servo, 300 degrees instead of 270 ([why](https://crossbotics.com/ftc-helper/docs/modules/hardware/#full-range)). Positions that you find with one range are wrong with the other. 1. Choose the servo (D-pad, A). A servo cannot tell the program where it is. So first choose a START POINT near where it sits now (D-pad up/down; nothing moves), then press A, and it moves there. Then nudge it with the D-pad. Up/down moves it by the step. Left/right makes the step smaller/bigger (0.1, 0.05, 0.01, 0.005, 0.001). The step starts at 0.05, and the screen shows it. Use a big step to get close, then a small one for the exact spot. 2. Move it toward one end until it BARELY stops pushing on the frame. Listen: a straining servo hums. Back off a little (0.01), and press **X**. Do the same at the other end, and press **B**. From then on, the finder keeps the servo between them. To go past an end, for example to mark it again, hold **LB** while you nudge. The ends are for you: keep every position you save between them. In five files, there are no end lines to copy. The older helpers get the ends as the servo's limits. 3. Move to each position you need (open, closed...) and press **A**. Rename P1, P2 in your code. Five files: the line `Tunables.Claw: P1 = 0.210, P2 = 0.770` becomes `public static double open = 0.210, closed = 0.770;` in `Tunables.Claw`. Keep every position between the ends that the finder shows. **Y** undoes the last saved position. **BACK** chooses another servo, and the lines found so far stay on the screen. **`reversed()` in Robot.java:** in **Tune and check**, the finder turns the servo the same way. The screen says `Direction: reversed, as in Robot.java`, so its numbers go straight into Tunables.java. Either order is fine: `rest` may be higher or lower than `push`, and `open` higher or lower than `closed`. Which way a bigger number turns depends on the servo, because there is no standard. D-pad up shows you ([Signs and units](https://crossbotics.com/ftc-helper/docs/conventions/#servos-and-motors-which-way-is-bigger)). **A part on two servos** (`alsoServoReversed(...)` or `alsoServo(...)` in Robot.java): for example, a claw with a servo for each finger, or two feed arms. Choose the FIRST servo. In **Tune and check**, the second servo moves with it (mirrored or the same way, as Robot.java says), so the two never fight. The screen shows `Moves with it: claw_right (mirrored)`. You cannot choose the second servo alone. The finder does not use `alsoTrim`: check it afterward, in TeleOp. A Servo Finder of your own (not from Tune and check) does not know Robot.java and moves only one servo. It would drag the other, unpowered servo through its gears. So take the other side's arm off first, or unplug the second servo's wire. ## Fix a mistake - **Saved a wrong position (A):** press **Y**. It undoes the last saved position. Press it again for the one before. - **Marked the wrong end (X or B):** move to the right place and press the same button again. The new end replaces the old one. To move past the old end, hold **LB** while you press the D-pad. - **Chose the wrong servo:** press **BACK** and choose again. When you choose a servo again, its ends and positions start over. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code When you have saved both ends and your positions, the screen looks like this. The marked lines are the ones for the robot in five files. The `PositionServo.create(...)` lines above them are for the older helpers. ![The Driver Hub with both ends marked (0.120 and 0.880), two saved positions, and the lines to copy: Tunables.Claw: P1 = 0.210, P2 = 0.770](https://crossbotics.com/ftc-helper/docs/images/hub-servo-finder-done.svg) The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Claw: P1 = 0.210, P2 = 0.770` | the part's section in `Tunables.java`. Rename them: `public static double open = 0.210, closed = 0.770;` | ## Put an arm back on Do this after a new horn, a broken arm, or a repair. Then your numbers in `Tunables.java` stay right. **Keep the servo on while you put the arm on.** A servo with no power turns freely. When you push the horn onto the shaft, the shaft can turn, and the arm goes on one tooth off. A servo with power holds its shaft still. 1. **Look for the paint pen marks** on the horn and the shaft. No marks? Make them before you take the old arm off. 2. **Hold the servo at a known number.** In **Tune and check > Servo Finder**, choose the servo. Set the start point to a number from `Tunables.java`, for example your `rest` (D-pad up/down), and press **A**. The servo goes there and holds. It holds only while the finder runs: do not press STOP yet. 3. **Put the part where that number puts it**, for example against its rest stop. A block or a jig helps you find the same spot each time. 4. **Push the horn on**, with the paint marks lined up. When the teeth do not let the part sit exactly there, use the closest tooth. Do not turn the servo by hand: it is holding. 5. **Tighten the screw** while the servo still holds. Mark the horn and the shaft again. 6. **Check each position.** Press STOP, run your TeleOp, and move the part to each position. A little off (less than one tooth)? Find that position again with the finder and change its number in `Tunables.java`. One spline tooth on a goBILDA servo is about 0.05 in position. **Two servos on one part:** loosen or take off BOTH arms first. Choose the first servo in step 2: both servos go to the number and hold. Put both arms on, then check that they meet. ## Done when every position you use is in `Tunables.java`, between the two ends. --- **Next:** [Hood Finder](https://crossbotics.com/ftc-helper/docs/tuning/04-hood-finder/). **Look it up:** [Claw, Wrist and Positioner: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#in-tunablesjava), [ServoFinderOpMode](https://crossbotics.com/ftc-helper/docs/modules/finders/). --- # Hood Finder URL: https://crossbotics.com/ftc-helper/docs/tuning/04-hood-finder/ **In Tune and check:** yes, when the robot has a hood. **You need:** the hood mounted, the flywheel off. ## Get to the Hood Finder 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Hood Finder**, then press **A**. ![The Tune and check menu with the arrow on Hood Finder: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-hood-finder-go-menu.svg) 3. The Hood Finder's INIT screen shows. Nothing moves yet. Press **▶** (start) on the Driver Hub. A motor hood's screen says `Motor hood: nothing is powered` instead. ![The Hood Finder's INIT screen: Servo hood: nothing moves until you choose a start point and press A. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-hood-finder-go-start.svg) ## Steps The Hood Finder is for a launcher's [hood](https://crossbotics.com/ftc-helper/docs/reference/parts/hood/) (`Tunables.Hood`). It reads the hood from Robot.java, so it works before Tunables.Hood has numbers. A hood with `.fullRange()` gets the same full range here. 1. **A servo hood:** choose a START POINT near where the hood sits (D-pad up/down; nothing moves), and press **A**. Then nudge it with the D-pad. Up/down moves it by the step. Left/right makes the step smaller/bigger (0.1, 0.05, 0.01, 0.005, 0.001). The step starts at 0.05, and the screen shows it. **A motor hood:** nothing is powered. Start the OpMode with the hood on the stop that you want as 0 ticks (the same as before a match). Then move the hood by hand and watch the encoder. ![Press A: the hood's servo goes to the start point, and the Driver Hub shows Position : 0.500](https://crossbotics.com/ftc-helper/docs/images/hub-hood-finder-step-start.svg) 2. Go to one stop until the hood BARELY touches it (a servo hums when it strains). Back off a little, and press **X** (stop A). ![At one stop, press X: the Driver Hub shows Stop A : 0.205](https://crossbotics.com/ftc-helper/docs/images/hub-hood-finder-step-stop-a.svg) 3. Move the hood to the other stop in the same way, and press **B** (stop B). The screen shows `Tunables.Hood: posA = 0.205, posB = 0.648`. That is all you need: the hood then works in servo positions, and the Shot Tuner writes positions into the table. ![At the other stop, press B: the Driver Hub shows Stop B : 0.648 and Tunables.Hood: posA = 0.205, posB = 0.648](https://crossbotics.com/ftc-helper/docs/images/hub-hood-finder-step-stop-b.svg) 4. **Angles (optional).** Measure the hood's angle at each stop, with an angle app on a phone laid on the hood. **Hold LB + D-pad** to type it in BEFORE you press X / B. Then you get `angleA = 0, angleB = 25` too. The finder uses each angle you type for ONE place (a stop or a point), so measure again at the next place. When only one stop has an angle, the finder writes no angles, and the screen says which stop still needs its angle. An angle of 0 counts only when you type it: hold LB and press D-pad up, then D-pad down, so the screen shows `Angle here : 0.0`. ![Hold LB and press the D-pad: the Driver Hub shows Angle here : 25.0](https://crossbotics.com/ftc-helper/docs/images/hub-hood-finder-step-angle.svg) 5. **A linkage** (the angle is not a straight line of the servo position): add points in between. Move there, type in the angle (LB + D-pad), and press **A**. With points and the angles at both stops, you get a `calibration` line INSTEAD of the posA / posB line. The hood reads one or the other, and both together stop INIT. The table's first and last rows are the stops. INIT checks that the angles keep going one way along the hood. The finder shows a point that breaks this as a warning, and writes no table. **Y** undoes the last point. 6. Copy the lines into `Tunables.java`: the robot uses the file, not this screen. Then, for a servo hood, time a stop-to-stop move for `travelSec`. The launcher waits that long before firing (a share of it for a shorter move). ## Fix a mistake - **Saved a wrong point (X, B or A):** press **Y**. It undoes the last point. - **Marked the wrong stop:** move to the right place and press the same button (X or B) again. The new stop replaces the old one. - **Typed a wrong angle:** hold LB and press the D-pad again, before you press X, B or A. After you press, the finder uses the angle: press **Y**, then type the angle and mark the place again. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Hood: posA = 0.205, posB = 0.648` | `Tunables.Hood` | | `angleA = 0, angleB = 25` (optional) | `Tunables.Hood` | | a `calibration` line (a linkage) | `Tunables.Hood`, in place of `posA` / `posB` | | `travelSec` (you time it) | `Tunables.Hood` | ## Done when `posA`, `posB` (or a `calibration` table) and `travelSec` are in `Tunables.Hood`. --- **Next:** [Motor Finder: limits, positions, top speed](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/). **Look it up:** [Hood](https://crossbotics.com/ftc-helper/docs/reference/parts/hood/). --- # Motor Finder: limits, positions, top speed URL: https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/ **In Tune and check:** yes, when the robot has a lift or an arm (or there is no Robot.java). **You need:** the robot on a block, the mechanism at its bottom. ## Get to the Motor Finder 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Motor Finder**, then press **A**. ![The Tune and check menu with the arrow on Motor Finder: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-go-menu.svg) 3. The Motor Finder's INIT screen shows. Nothing moves yet. Put the mechanism at its bottom, then press **▶** (start) on the Driver Hub. ![The Motor Finder's INIT screen: Put the mechanism at its BOTTOM before you choose it. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-go-start.svg) 4. Press **D-pad up/down** until the arrow is on your motor's name, then press **A**. The names come from the robot configuration. ![Choose a motor: the arrow on lift, then press A](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-go-choose.svg) ## Steps 1. **Put the mechanism at its bottom**, then choose the motor (D-pad, A). Its count starts at 0 there. 2. Move it slowly with the right stick (max power starts at 0.3). Stop a little before the bottom, and press **X**. ![Near the bottom, press X: the Driver Hub shows LOW end (X) : 0](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-step-low.svg) 3. Move it up to the top. Stop a little before the top, and press **B**. From now on, the power goes off at those marks. The mechanism coasts a little past them (more at a higher max power), so mark them with some room. ![Near the top, press B: the Driver Hub shows HIGH end (B) : 2580](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-step-high.svg) 4. Press **A** at each height you need. A height outside the two marks gets a warning, because the robot stops at min and max and could never get there. **Y** undoes it. ![At each height, press A: the Driver Hub shows Tunables.Lift: min = 0, max = 2580, P1 = 1200](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-step-position.svg) 5. Hold **RT** for a speed test: full power up, stopping before the top. The top speed helps you choose a max power and PID gains. ![Hold RT: the Driver Hub shows Top speed : 2310 counts/s](https://crossbotics.com/ftc-helper/docs/images/hub-motor-finder-step-speed.svg) 6. Five files: the line `Tunables.Lift: min = 0, max = 2580, P1 = 1200` becomes `min = 0, max = 2580` and `low = 1200` (your name) in `Tunables.Lift`. When it also says `Robot.java: add .reversed()`, add `.reversed()` to that part in `Robot.java`. An `Arm` reads degrees, not counts: see the [reference](https://crossbotics.com/ftc-helper/docs/modules/finders/#motorfinderopmode). Watch the current (amps). A high number while the part does not move means it is pushing on something. Stop. ## Fix a mistake - **Saved a wrong position (A):** press **Y**. It undoes the last saved position. - **Marked the wrong end (X or B):** move to the right place and press the same button again. The new end replaces the old one. - **Chose the wrong motor:** press **BACK** and choose again. **Put the mechanism at its bottom first**: choosing a motor sets its encoder to 0 where it is now. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Lift: min = 0, max = 2580, P1 = 1200` | `Tunables.Lift`. Rename `P1` to a real name: `low = 1200` | | `Robot.java: add .reversed()` | the part's line in `Robot.java` | ## Done when `min`, `max` and every named height are in `Tunables.java`. --- **Next:** [Flywheel Finder: gains and recovery](https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/). **Look it up:** [Lift and Arm: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#in-tunablesjava), [MotorFinderOpMode](https://crossbotics.com/ftc-helper/docs/modules/finders/#motorfinderopmode). --- # Flywheel Finder: gains and recovery URL: https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/ **In Tune and check:** yes, when the robot has a launcher (or there is no Robot.java). **You need:** safety glasses, nobody in the line of fire, a charged battery. ## Get to the Flywheel Finder 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Flywheel Finder**, then press **A**. ![The Tune and check menu with the arrow on Flywheel Finder: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-flywheel-finder-go-menu.svg) 3. The Flywheel Finder's INIT screen shows. Nothing moves yet. Put your safety glasses on, then press **▶** (start) on the Driver Hub. ![The Flywheel Finder's INIT screen: Hands away from the wheel. Eye protection on. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-flywheel-finder-go-start.svg) 4. The arrow starts on the flywheel motor: the launcher's motor in Robot.java (from Tune and check), else a name with "fly", "launch" or "shoot" in it. Check the name, then press **A**. Another motor: press **D-pad up/down** first. The names come from the robot configuration. ![Choose the flywheel motor: the arrow on launcher, then press A](https://crossbotics.com/ftc-helper/docs/images/hub-flywheel-finder-go-choose.svg) ## Already have gains in Tunables.java? From Tune and check, when your launcher's part of `Tunables.java` has `kP`, `kI` and `kF`, the finder holds the wheel with **those** gains (and their battery compensation). The `Gains` line shows them: `Gains : Tunables.java (kP 10.00, kI 0.000, kF 14.68, for 13.0 V)`. - Step 1 is not needed: press **B** at once (step 2), set your shot speed, and fine-tune F with **RB** / **LB**. - The `Tunables.Launcher` line keeps your kP, kI and kD, with the new kF. Copy only that line. - After step 1, **Y** switches to the finder's own gains (from the top speed) and back. The F you fine-tuned on each stays. **Why:** F does most of the work, and it fits only the kP and kI it was tuned with. With the finder's own kI, a small F error is hidden while the wheel is held, then shows up in a match with your kI. Tuned with your own gains, F is right for the robot as it is. ## Steps 1. After you choose the motor, let go of A, then hold **A** again: the wheel runs at full power until the speed stops rising. The finder works out the gains from the top speed. From Tune and check, the motor starts in the direction Robot.java gives it: with `.reversed()` on the launcher, the screen shows `Direction : reversed, as in Robot.java`. When the wheel spins the wrong way, let go, press **X** (reverse), and try again. Then the results tell you to add or remove `.reversed()` in Robot.java. **Why the direction matters:** a wheel that spins backward pushes the piece back. The piece jams on the wheel, and the wheel stops when the piece touches it. **`Still speeding up at 5 s`:** full power stops after 5 s, for safety. A heavy wheel (a wheel with added weight) can still speed up then, so its real top speed is higher than the one shown. Extra weight does not lower the top speed much, but it makes the wheel take longer to get there. Because the finder works out F from the top speed, F is then a little high. Check that the wheel turns freely by hand, with no rubbing. Then fine-tune F in step 2 (step 3 below): the error must stay near 0 at your shot speed. ![Let go of A, then hold A: the Driver Hub shows Top speed : 5600 RPM](https://crossbotics.com/ftc-helper/docs/images/hub-flywheel-finder-step-top-speed.svg) 2. Press **B**: the finder holds a speed (60% of the top, or 3000 RPM before step 1). Change it with the D-pad to the speed you shoot at. ![Press B: the Driver Hub shows Target : 3350 RPM and Error : 40 RPM](https://crossbotics.com/ftc-helper/docs/images/hub-flywheel-finder-step-hold.svg) 3. When the measured speed stays below the target at every speed, press **RB** (more F). When it stays above, press **LB**. ![When it stays too slow, press RB: the Driver Hub shows F gain : 12.79 and Error : 5 RPM](https://crossbotics.com/ftc-helper/docs/images/hub-flywheel-finder-step-more-f.svg) 4. Feed one piece with the robot's own feeder, or push it in with a stick. **Never use your fingers**: they would be next to a wheel at full speed. Put safety glasses on. The screen shows the recovery time (on the robot only, because the simulator has no piece to feed). Use it for the launcher's `shotInterval(...)`: make that a little longer than the recovery time. 5. Check that the robot sees each shot (for `stopOnShot`). Set the target to your shot speed with the D-pad. Feed 10 pieces, one at a time. Wait for "Ready: YES" before each. Read two lines: - "Shots seen": the drops of more than 150 RPM (the default `shotDropRpm`). - "Shot drop": every drop, also the ones under 150. It shows the last drop, the smallest drop and how many drops it saw. "Shots seen" shows 10: the default is good. It shows fewer: set `shotDropRpm` in `Tunables.Launcher` to about half the smallest shot drop. Keep it more than `readyBandRpm`. Then fire with no piece in TeleOp: the feed must run its full `feedSec`. The finder always counts with 150, not with your `shotDropRpm`. 6. Five files: copy the `Tunables.Launcher: kP = ..., kI = ..., kD = 0, kF = ..., nominalVolts = ...` line into `Tunables.Launcher` (the section is the motor's name). A slow recovery adds `shotIntervalSec`. `nominalVolts` is the battery voltage at which the finder found the gains. The launcher's battery compensation uses it, so a low battery spins the wheel back up as fast. The compensation is off unless you write `batteryCompensation = true`. The RB/LB F changes are only on the screen: copy the line (with the F you ended on) into `Tunables.java`. ## Fix a mistake - The finder saves no positions, so there is nothing to undo. Each button changes one setting, and you can change it back. **X** again turns the reverse off, **B** again stops the held speed, and **LB** lowers F again after an **RB**. - **Chose the wrong motor, or a bad top-speed test:** press **BACK** and choose the motor again. It starts over, with a new top-speed test. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Launcher: kP = ..., kI = ..., kD = 0, kF = ..., nominalVolts = ...` | `Tunables.Launcher` (the section is the motor's name) | | the recovery time | `shotIntervalSec` in `Tunables.Launcher`: a little longer than the recovery time | | "Shots seen" fewer than the pieces | `shotDropRpm` in `Tunables.Launcher`: about half the smallest "Shot drop" (from the screen) | ## Done when you copied the `Tunables.Launcher` gains line, and the speed holds the target. --- **Next:** [Feed Stop Finder](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-stop-finder/) (a launcher with a feed stop), or [Feed Time Finder](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-time-finder/) (a CR servo or motor feeder with no feed stop, pushing parts or feed wheel). **Look it up:** [Launcher: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava). --- # Feed Stop Finder URL: https://crossbotics.com/ftc-helper/docs/tuning/07-feed-stop-finder/ **In Tune and check:** yes, when the launcher has a `.feedStop(...)`. **You need:** the launcher's Robot.java line with `.feedStop(...)`, 5 pieces, and eye protection for the test shots. ## Get to the Feed Stop Finder 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Feed Stop Finder**, then press **A**. ![The Tune and check menu with the arrow on Feed Stop Finder: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-go-menu.svg) 3. The Feed Stop Finder's INIT screen shows. Nothing moves yet. Press **▶** (start) on the Driver Hub. ![The Feed Stop Finder's INIT screen: Nothing moves until you press A. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-go-start.svg) ## Steps A feed stop holds the pieces back, and lets one through at a time. This finder finds both positions, for a launcher with `.feedStop("feed_stop")` in Robot.java. For such a robot, it is in [Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#the-tune-and-check-menu). 1. Put a piece behind the feed stop. The wheel stays off. 2. A servo's position is a number from 0 to 1. With the D-pad, pick a start number near where the feed stop sits now (nothing moves yet). **A** moves the servo there. ![Press A: the feed stop goes to the start point, and the Driver Hub shows Position : 0.500](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-step-start.svg) 3. D-pad up/down moves it by the step. Left/right makes the step smaller/bigger (0.1, 0.05, 0.01, 0.005, 0.001). The step starts at 0.05, and the screen shows it. 4. Where the stop holds the piece firmly, without straining on the frame, press **X** to save the hold position. ![Where it holds the piece, press X: the Driver Hub shows Hold (X) : 0.150](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-step-hold.svg) 5. Move the feed stop with the D-pad until the piece rolls through freely. Press **B** to save the release position. **A** then goes between the two, so you can try them. ![Where the piece rolls through, press B: the Driver Hub shows Release (B) : 0.550 and the line to copy](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-step-release.svg) 6. Copy the line it shows, for example `Tunables.Launcher: feedStopHold = 0.150, feedStopRelease = 0.550`. The section is your launcher's: a launcher on `shooter` says `Tunables.Shooter`. ## Find the firing times Two times are in your launcher's section of `Tunables.java`. With both positions saved, the finder finds them too: | Time | What it does | Start value | The finder finds it | | --- | --- | --- | --- | | `feedStopMoveSec` | how long the stop takes to open. The indexer and the pushing parts wait this long before they push | 0.1 s | from the servo's speed in the parts catalog | | `feedStopOpenSec` | the backup time. When the wheel sees no shot, the stop closes after this time | 0.5 s | with test shots | The stop does not stay open for the whole `feedStopOpenSec`. It closes as soon as the wheel sees the shot (the wheel's speed drops). `feedStopOpenSec` is a backup, for a piece that does not reach the wheel. ### The open time The finder works out the open time from the angle between hold and release and the servo's speed from the seller. It adds 25%, because the seller's speed is with no load. For this, Robot.java must name the servo's part. **Where:** `Robot.java`, the launcher's line. ```java title="Robot.java" .feedStop("feed_stop", "gobilda-2000-speed") // the servo's catalog id ``` The screen then shows, for example, `Opens in : about 0.25 s (gobilda-2000-speed, +25%)`. **Why it matters:** a goBILDA torque servo that turns from 0.150 to 0.550 needs about 0.6 s. That is much more than the 0.1 s start value. With 0.1 s, the indexer pushes the piece against a stop that is still half closed. A servo that is not in the catalog: measure the open time with a video (below). ### The backup time: test shots 1. Wear eye protection, and keep everybody out of the line of fire. Put a piece behind the stop, where it sits in a match. 2. Press **LB**. The wheel spins up to your `speedRpm`. While the wheel is on, the D-pad, A, X and B do nothing, so the positions you saved stay. ![Press LB: the wheel spins up, and the Driver Hub shows Wheel (LB = off) : 2990 / 3000 RPM, ready: RB = test shot](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-step-wheel.svg) 3. When the screen says `ready`, press **RB**. The stop opens, and the indexer and the pushing parts run as in a match. The finder measures the time until the wheel sees the shot. 4. Put the next piece behind the stop. Do 5 test shots in all. The screen shows each time. ![After 5 test shots with RB: the Driver Hub shows Test shots : 0.31, 0.28, 0.35, 0.30, 0.29 s and the times line to copy](https://crossbotics.com/ftc-helper/docs/images/hub-feed-stop-finder-step-test.svg) 5. Copy the times line, for example `Tunables.Launcher: feedStopMoveSec = 0.25, feedStopOpenSec = 0.55`. The backup time is the longest test shot plus 0.2 s, because a low battery or a worn piece is slower. 6. Press **LB** to stop the wheel. When you change hold or release after the test shots, the finder clears the old times: do the test shots again. ### When the finder warns - **`No shot seen in 3 s`:** the piece did not reach the wheel. Check the release position (the piece must roll through freely). With `.pushedBy(...)`, try a larger `assistSec`. A heavy wheel that slows by less than 150 RPM gives this warning too, even when the piece fired. In that case, measure the time with a video (below). - **`2 pieces in one opening`:** the next piece got past before the stop closed. Check that the hold position catches the next piece. Pieces that sit tight against each other can slip through together: a gap between them, or a faster servo, helps. ### Check the times in TeleOp To check the times as the robot fires in a match, use the PRACTICE profile ([profiles](https://crossbotics.com/ftc-helper/docs/guides/profiles/)): the debug lines show only there. Fire 5 to 10 pieces, and read: ``` Last feed ended : shot seen ``` `shot seen` for every piece is right. `backup time` means that the stop closed before the wheel saw a shot: do the test shots again, or measure with a video. ### Measure the times with a slow-motion video Use a video only when the finder cannot find a time. This happens with a servo that is not in the catalog, or with a heavy wheel that the finder cannot see slow down. A phone's slow-motion video shows what happens too fast for your eyes. 1. Film the feed stop and the wheel from the side, in slow motion. Use 240 frames a second, if the phone can. 2. Fire one piece. 3. Go through the video one frame at a time, and count the frames: - **The open time:** from the frame where the stop starts to move to the frame where it is fully open. - **The piece time:** from the frame where the stop starts to move to the frame where the piece touches the wheel. 4. Change frames to seconds: time = frames ÷ frames a second. For example, 60 frames at 240 frames a second is 0.25 s. 5. Do it 3 times, and use the longest of each time. 6. Set `feedStopMoveSec` to the open time, rounded up to the next 0.05 s. Set `feedStopOpenSec` to the piece time plus 0.2 s. **Why extra time:** a low battery makes the parts slower, and a worn piece can roll slower. ## Fix a mistake - **Saved the wrong hold or release:** move to the right place and press the same button (X or B) again. The new position replaces the old one. While the wheel is on, press **LB** first to stop it. - **A bad test shot** (no piece, or a piece that was not loaded right): stop the wheel with **LB**, then press **X**. It saves the same hold again and clears all the test shots. Then do the 5 test shots again. - A test shot that saw no shot does not count. Its time is not used. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Launcher: feedStopHold = 0.150, feedStopRelease = 0.550` | your launcher's section (a launcher on `shooter`: `Tunables.Shooter`) | | `Tunables.Launcher: feedStopMoveSec = 0.25, feedStopOpenSec = 0.55` | the same section | ## Done when - `feedStopHold`, `feedStopRelease`, `feedStopMoveSec` and `feedStopOpenSec` are in `Tunables.java`. - In 5 test shots, the wheel saw every shot, and no shot let 2 pieces through. --- **Next:** [Drive Tuner: wheel size and strafe correction](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/). **Look it up:** [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/). --- # Feed Time Finder URL: https://crossbotics.com/ftc-helper/docs/tuning/07-feed-time-finder/ **In Tune and check:** yes, when the launcher's feeder is a CR servo or a motor, with no feed stop, no pushing parts (`.pushedBy(...)`) and no feed wheel. **You need:** the launcher and its feeder in Robot.java, 5 pieces or more, and eye protection for the test shots. A robot with a feed stop uses the [Feed Stop Finder](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-stop-finder/) instead. Its test shots time the same thing, for `feedStopOpenSec`. A robot with pushing parts or a feed wheel gets neither finder for `feedSec`: tune it by hand ([fix it by what you see](https://crossbotics.com/ftc-helper/docs/tuning/17-fix-by-symptom/)). ## Why test shots A CR servo or motor feeder runs for `feedSec` per piece, then stops. The time a piece needs changes with where it sits. A piece near the wheel gets there fast. A piece far back takes longer. `feedSec` must be long enough for the piece that starts farthest back. One test shot does not tell you that. Fire several, from every place a piece can sit in a match. The finder keeps each time and gives `feedSec` from the longest. ## Get to the Feed Time Finder 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Feed Time Finder**, then press **A**. 3. The Feed Time Finder's INIT screen shows. Nothing moves yet. Press **▶** (start) on the Driver Hub. ## Steps 1. Wear eye protection, and keep everybody out of the line of fire. 2. Press **LB**. The wheel spins up to your `speedRpm`. 3. Load one piece where a piece sits in a match. 4. When the screen says `ready`, press **RB**. The feeder runs at its `power`. The finder times the piece from the start of the feed to the shot (the wheel's speed drops). The feeder stops at the shot. 5. Do it 5 times or more. Load each piece in a different place, and the farthest back place more than once. The screen shows the times: ``` Test shots : 0.31, 0.42, 0.28, 0.45, 0.33 s (5) Shortest / average / longest : 0.28 / 0.36 / 0.45 s feedSec : 0.55 s (the longest + 0.1); now 0.40 ``` 6. Copy the line it shows, for example `Tunables.Feeder: feedSec = 0.55`. The section is your feeder's. 7. Press **LB** to stop the wheel. **Why the extra 0.1 s:** a low battery and a worn wheel make the feed slower. ## When the finder warns - **`No shot seen in 3 s`:** the piece did not reach the wheel. Check that a piece was loaded, and that the feeder turns the right way (its `power` sign, or `.reversed()` in Robot.java). This test shot does not count. A heavy wheel that slows by less than `shotDropRpm` (150 by default) gives this warning too, even when the piece fired: make `shotDropRpm` smaller. - **`The times differ by ... s`:** a `feedSec` long enough for the slowest piece can push the next piece in too, when it sits close. Set `stopOnShot = true` in the feeder's section. Each feed then stops at the shot, and `feedSec` is only the time limit ([stop on the shot](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-robotjava)). With `stopOnShot = true`, this warning does not show. - **`Test shot stopped part way`:** the wheel went off (LB, help, or STOP) before the shot. That test shot does not count. - **`A piece took almost 3 s`:** `feedSec` cannot be more than 3 s. Check the feeder's `power`, and what slows the piece. ## Fix a mistake - **A bad test shot** (no piece, or two pieces loaded): press **X**. It clears all the times. Then do the test shots again. - A test shot that saw no shot does not count. Its time is not used. **Start over:** press STOP, then INIT, and open the tool again. It starts empty. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java`, not the finder's screen. Take a photo of the screen, and type the line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Feeder: feedSec = 0.55` | your feeder's section (the name in its `.tunables("...")`, or the feeder's own name) | ## Done when - `feedSec` is in `Tunables.java`. - In TeleOp, each press of fire sends one piece, from every place a piece can sit. --- **Next:** [Drive Tuner: wheel size and strafe correction](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/). **Look it up:** [Indexer](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/), [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/). --- # Drive Tuner: wheel size and strafe correction URL: https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/ **In Tune and check:** yes, when there is a Robot.java. **You need:** a charged battery, tape, 5 ft of clear floor. ## Get to the Drive Tuner 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Drive Tuner**, then press **A**. ![The Tune and check menu with the arrow on Drive Tuner: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-go-menu.svg) 3. The Drive Tuner's INIT screen shows. Nothing moves yet. Press **▶** (start) on the Driver Hub. ![The Drive Tuner's INIT screen: Tape 48 in long on the floor. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-go-start.svg) The screen now shows the test list, with the arrow on `Push (by hand)`. Go on with the steps below. ## Steps ![The Drive Tuner floor from above: a tape line marked 0 and 48 in along the robot's left wheels, the push and drive arrow along it, the strafe arrow to the right, and 5 ft of clear floor ahead and to the right (to the left too for the optional Strafe left test)](https://crossbotics.com/ftc-helper/docs/images/finder-drive-tuner.svg) **Set up the floor:** a straight line of tape, marked **0** and **48 in**. Clear 5 ft of floor ahead of the robot and to its right (and to its left, for the optional Strafe left test). **Start each test** with the robot's **left wheels touching the tape** (their outside edge) and the front left wheel's front edge on **0**. **Why the left wheels:** when you push by hand, a wheel edge against a line is easy to keep straight. It is also easy to measure from: forward from 0 to that wheel's front edge, and sideways from the tape to the left wheels. 1. **Start the push test:** with the arrow on `Push (by hand)`, press A. The wheels are now free to roll. ![Press A with the arrow on Push (by hand)](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-step-push-start.svg) 2. **Push and stop:** roll the robot by hand, its left wheels along the tape, until the front left wheel's front edge is on 48 in. Then press B. This gives the wheel size from the encoder counts alone. Every wheel must count up by about the same amount. When one does not, fix its direction or encoder cable first. ![At 48 in, press B: the Driver Hub shows Wheel counts : 2134, 2129, 2140, 2131, about the same for each wheel](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-step-push-end.svg) 3. **The power:** on the test list, D-pad left/right sets the power for the Drive and Strafe tests (`Power : 0.5`; 0.3 to 1.0). Set the power that your autonomous moves use (`.move("...", 24, 0, 0.6)`: 0.6). **Why:** a faster robot slides farther when it stops, so the numbers fit the power you measured them at. When you change the power, the tests must measure right again. For moves of very different lengths, see `Tunables.Drive.slowDownIn` ([tunables](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava)). 4. **Start the drive test:** put the arrow on `Drive forward` and press A. The robot drives 48 in. While it drives, the screen keeps showing the heading and the wheel counts. ![Press A with the arrow on Drive forward, and the Driver Hub shows Power : 0.6](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-step-drive-start.svg) 5. **Measure the drive:** when the robot stops, measure how far it went. Set the real distance with the D-pad, and press A. The tuner uses the new wheel size at once. Run the test again until it measures 48. Wheels slip a little on tiles, so this test has the final word. The tuner does not measure a move that got stuck. ![When it stops, set the distance with the D-pad, then press A: the Driver Hub shows Measured : 47.50 in](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-step-drive-measure.svg) 6. **Strafe test** (mecanum): put the robot back at the start, and press A. It strafes right, away from the tape. Measure from the tape to the left wheels, straight across. The steps are the same as in the Drive test, for `c.strafeCorrection`. There is no push test sideways. When you push a mecanum robot sideways by hand, its wheels' rollers spin, and its encoders count almost nothing. The strafe correction is about the slip of a **powered** strafe, so only the robot strafing by itself can measure it. **Strafe left:** use it only when moves to the left come up short or long while moves to the right are right. Start with the robot's **right** wheels on the tape, and it strafes left. Measure from the tape to the right wheels. The steps are the same, for `Tunables.Drive: strafeCorrectionLeft`. When you do not write it, the left uses `strafeCorrection` too. ![When the Strafe test measures 48 in, press A: the Driver Hub shows Strafe measures 48 in: right, and Tunables.Drive: calibrated = true under Copy into your code](https://crossbotics.com/ftc-helper/docs/images/hub-drive-tuner-step-calibrated.svg) 7. **Turn 90 left** (a check, with nothing to copy): the robot turns 90 degrees left. Put a square against the robot to see it. The screen shows the IMU's heading, and it should say 90. 8. Copy the lines, then switch autonomous on: - five files: `Robot.java: .wheelMm(96.8)` goes in the drive line, after `.wheel(...)` if you used a catalog wheel (the last one wins). `Tunables.Drive: strafeCorrection = 1.180` goes in `Tunables.Drive`. Once the Drive test (and on a mecanum the Strafe test) measures 48 within 0.5 in, the tuner also shows `Tunables.Drive: calibrated = true`: copy that too. - older helpers: the `c.` lines go in `RobotSettings.auto()`, then `c.calibrationConfirmed = true`. ## Fix a mistake - **Typed a wrong distance:** run the same test again. Each run corrects the number in use now, so the next good run fixes a bad one. - **Stop a test that drives:** press **GUIDE** (or hold **START**). The robot stops, and that run is not used. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Robot.java: .wheelMm(96.8)` | the drive line in `Robot.java`, after `.wheel(...)` (the last one wins) | | `Tunables.Drive: strafeCorrection = 1.180` | `Tunables.Drive` (and `strafeCorrectionLeft`, if you ran Strafe left) | | `Tunables.Drive: calibrated = true` | `Tunables.Drive`. Autonomous moves run only with it | ## Done when the Drive test (and on a mecanum the Strafe test) measures 48 within 0.5 in, and you copied `calibrated = true`. --- **Next:** [Odometry Tuner: directions, offsets and a loop check](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/). **Look it up:** [Drive: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava). --- # Odometry Tuner: directions, offsets and a loop check URL: https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/ **In Tune and check:** yes, when Robot.java has an `odometry(...)` line. **You need:** a 48 in tape strip with a start mark, room to spin. ## Get to the Odometry Tuner 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Odometry Tuner**, then press **A**. ![The Tune and check menu with the arrow on Odometry Tuner: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-go-menu.svg) 3. The Odometry Tuner's INIT screen shows. Press **▶** (start) on the Driver Hub. ![The Odometry Tuner's INIT screen: press start on the Driver Hub](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-go-start.svg) 4. The test list shows. For each test below, press **D-pad up/down** until the arrow is on the test, then press **A** to start it. ![The test list with the arrow on 1 Forward 48 in: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-go-choose.svg) ## Steps ![A Pinpoint seen from above: the X pod 84 mm right of the center and the Y pod 168 mm behind it give offsetsMm(-84, -168); the five tests in order](https://crossbotics.com/ftc-helper/docs/images/finder-odometry.svg) The Odometry Tuner is for a robot in five files with an `odometry(...)` line ([odometry](https://crossbotics.com/ftc-helper/docs/modules/odometry/)). It needs your robot, in a small file next to `Robot.java` (the odometry robot's [OdometryTuner.java](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/odometrybot/OdometryTuner.java); the whole file to type: [the odometry module](https://crossbotics.com/ftc-helper/docs/modules/odometry/#the-odometry-tuner)). Put a 48 in strip of tape on the floor, with a mark at its start. In every test, the sticks drive slowly (30%). You can also push the robot by hand. The D-pad chooses, **A** starts, and **B** ends the test. 1. **Forward 48 in:** drive or push the robot 48 in straight forward along the tape, and press B. The screen says "Forward OK" (and how many % off), or "counted BACKWARD". For BACKWARD, add `"x"` to `.reversed(...)` (dead wheels: that pod's port name). The simulator's Pinpoint works the same way. `odometry.reversed = x` in the robot file is a pod wired backward. The code's `.reversed(...)` (and `.offsetsMm(...)`) is what the library tells the Pinpoint. So a robot file that differs from Robot.java shows the same mistakes as a real robot. An OTOS gets `Tunables.Odometry: linearScalar = ...` to copy (multiply it with the one in use). More than 2% off: check the pod type (Pinpoint) or `ticksPerMm(...)` (dead wheels), and the tape. More than 10% off: the screen asks "was it really 48 in?". It is a mistake in the test: measure and run it again. ![At 48 in, press B: the Driver Hub shows Forward OK: 47.6 in for 48 (-0.8% off)](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-step-forward.svg) 2. **Left 24 in:** drive or push the robot 24 in to its LEFT, and press B. The screen says "Left OK", or "counted RIGHT". For RIGHT, add `"y"` to `.reversed(...)` (dead wheels: the sideways pod's name). Push a tank robot by hand. ![At 24 in to the left, press B: the Driver Hub shows Left OK: 23.8 in for 24](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-step-left.svg) 3. **Spin 3+ turns:** turn the robot in place at least 3 times with the right stick, and press B. With fewer turns, the screen says how many and asks for more. The tuner measures the turn from the Pinpoint's own heading. For dead wheels and the OTOS, it uses the Control Hub's IMU, so they need `.imu(...)` in `drive(...)`. Without it, the tuner stops at INIT and says so. The tuner shows the offsets as the numbers to change: `Robot.java: in the odometry(...) line, .offsetsMm(-84.2, -167.5)` (three wheels: `.trackWidthIn(..).perpForwardIn(..)`; two: `.parallelLeftIn(..).perpForwardIn(..)`). Change only those numbers: `.reversed(...)` and the pod type stay as you wrote them. With `.podsFromEdgesMm(...)` in the line, write the measured `.offsetsMm(...)` in its place. The tuner cannot measure where an OTOS sits. Measure it from the robot's edges with a tape (`.robotSizeMm(...).mountFromEdgesMm(...)`), and its turn scale [by hand](https://crossbotics.com/ftc-helper/docs/modules/odometry/#otos-turn-scale-by-hand). ![After 3 turns, press B: the Driver Hub shows the line to copy, .offsetsMm(-84.2, -167.5)](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-step-spin.svg) 4. Copy the numbers into your odometry line, and rebuild. 5. **Loop and back:** start on the mark and drive anywhere, at least 24 in away. A robot that never left the mark proves nothing, and the tuner says so. Come back onto the mark, facing the same way, and press B. Within 1 in and 2 degrees, the screen shows `Tunables.Odometry: checked = true`: set it in `Tunables.java`. Until then, the robot skips autonomous `driveTo` steps. ![Back on the mark, press B: the Driver Hub shows Tunables.Odometry: checked = true](https://crossbotics.com/ftc-helper/docs/images/hub-odometry-tuner-step-loop.svg) ## Fix a mistake - **A bad test** (the robot slipped, or you pressed B at the wrong place): choose the same test and run it again (**A**, then **B**). The new result replaces the old one. - The Forward test does not use a result that is more than 10% off. The screen says so: run it again. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Robot.java: in the odometry(...) line, .offsetsMm(-84.2, -167.5)` | the odometry line in `Robot.java`. Change only those numbers | | `Tunables.Odometry: linearScalar = ...` (OTOS) | `Tunables.Odometry` (multiply it with the one in use) | | `Tunables.Odometry: checked = true` | `Tunables.Odometry`. Autonomous `driveTo` steps run only with it | ## Done when the Loop test shows `checked = true` and it is in `Tunables.java`. --- **Next:** [Move Tuner: how exactly moves stop and turns end](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/). **Look it up:** [Odometry: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/odometry/#in-tunablesjava), [Odometry module](https://crossbotics.com/ftc-helper/docs/modules/odometry/). --- # Move Tuner: how exactly moves stop and turns end URL: https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/ **In Tune and check:** yes, when there is a Robot.java. **You need:** a charged battery, the Drive Tuner done (`calibrated = true`), clear floor (about 6 ft by 6 ft of tiles; on a game field, see [On a game field](#on-a-game-field)), a tape measure. The Drive Tuner makes a move the right length. The Move Tuner makes it **stop** in the right place. A fast robot slides past the end of a move, and a turn can swing past its heading or stop short of it. Each test drives real autonomous moves, measures them, and changes one number. The tuner uses the new number at once, so you run the test again until it says OK. Every test ends about where it began. ## Get to the Move Tuner 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Move Tuner**, then press **A**. ![The Tune and check menu with the arrow on Move Tuner: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-go-menu.svg) 3. The Move Tuner's INIT screen shows. Nothing moves yet. Press **▶** (start) on the Driver Hub. When the screen says `Run the Drive Tuner first`, do that first ([Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/)). ![The Move Tuner's INIT screen: Clear floor: 5 ft around the robot. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-go-start.svg) 4. The test list shows. For each test below, press **D-pad up/down** until the arrow is on the test, then press **A** to start it. **D-pad left/right** sets the power of the moves and turns (`Power : 0.5`; 0.3 to 1.0). Set the power that your autonomous moves use (`.move("...", 24, 0, 0.6)`: 0.6). **Why:** a faster robot slides farther, so the numbers fit the power you measured them at. ![The test list with the arrow on 1 Creep and Power : 0.5: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-go-choose.svg) ## On a game field Spare tiles off the field are best: the same floor, with nothing in the way. On a game field, the tests fit between the field's parts, because each test ends where it began. Each test needs room on some sides only, and you can put the robot in a new spot before each test: | Test | Clear floor it needs | | --- | --- | | 1 Creep | a few inches ahead, and (mecanum) to the right | | 2 Stops | 24 in ahead of the robot's front edge | | 3 Turns | a circle as wide as the robot's diagonal (an 18 in robot: about 26 in), with the robot in its middle | | 4 Drift | 48 in ahead of the front edge. Mecanum: also 48 in to the right of the right edge | | 5 Move and turn | 24 in to the left of the left edge and 24 in to the right of the right edge, and room to turn | **BIOBUZZ:** only the HIVE frame's two feet are on the floor in the middle of the field. The HIVE is higher than 29 in, so the robot drives under it. Between the frame's feet and each side wall there is a clear strip, about 50 in wide and as long as the field. In that strip: - **Creep, Stops, Turns and Drift:** the robot's front points along the strip (along the side wall). On a mecanum, Drift's 48 in move to the right does not fit. Drift only gives a report, so do it on spare tiles, or skip it. - **Move and turn:** the robot's front points at the side wall, in the middle of the strip. Then its moves to the left and right go along the strip. Keep the robot away from the FLOWERs on the walls, and from the frame's feet. ## Steps Run the tests in this order. Each one uses the numbers that the tests before it found. ![The five tests from above, in order: 1 Creep rolls a few inches forward, then right, and finds moveMinPower. 2 Stops drives 6, 12 and 24 in out and back, and finds slowDownIn. 3 Turns turns left and back, and finds the turn numbers. 4 Drift drives 48 in forward and back, a report only. 5 Move and turn slides 24 in sideways while it turns 90 degrees left, and finds moveTurnScale and moveMaxTurnPower](https://crossbotics.com/ftc-helper/docs/images/move-tuner-tests.svg) 1. **1 Creep** (finds `moveMinPower`): the robot creeps forward, then (mecanum) to the right, with a little more power each step. It stops when the robot rolls. The tuner sets `moveMinPower` to that power x 1.3, for a lower battery. **Why:** each move ends at `moveMinPower`. With too much, the robot arrives fast and slides. With too little, it stalls before the end. ![Press A with the arrow on 1 Creep: the Driver Hub shows moveMinPower now 0.10 and the line to copy](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-step-creep.svg) 2. **2 Stops** (finds `slowDownIn`): the robot drives 6, 12 and 24 in, each out and back. Then it tries again with a bigger `slowDownIn` (0, 3, 6, 9, 12) until every move slides 0.5 in or less past its end. The screen shows a line for each try: the worst slide, and how long the 24 in move took. A bigger `slowDownIn` stops better, but every move takes longer, so the tuner keeps the smallest one that is good. ![A 24 in move's power: full power, then down to moveMinPower at the end. With slowDownIn 0 it slows down over the last 2.4 in only, arrives fast and slides past the end. With slowDownIn 6 it slows down over the last 6 in and stops on the end](https://crossbotics.com/ftc-helper/docs/images/move-tuner-slowdown.svg) - `STUCK`: a move stalled before its end. Run Creep first, or clear the path. - `slowDownIn does not help`: every move already ends at `moveMinPower`. Run Creep, then Stops again. ![Press A with the arrow on 2 Stops: the Driver Hub shows a line per slowDownIn tried and OK: slowDownIn 3](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-step-stops.svg) 3. **3 Turns** (finds the turn numbers): the robot turns 90, 135 and 45 degrees left, and back each time. The screen shows a line per turn: how far it went past its target, how far off it stopped, and how long it took. Then the tuner changes **one** number: | What the turns do | The tuner changes | | --- | --- | | stop off target (short of it, or past it) and stay there | `turnMinPower` up (0.05, then 0.08, then 0.11), then `turnKp` up | | rock in and out, just outside the tolerance | `turnToleranceDeg` + 0.5 (up to 3) | | swing past the target, or back and forth | `turnKd` up (more brake), or `turnKp` down (less push) | | end on target, but a 90-degree turn takes more than 2 s | `turnKp` up | ![Four turn shapes, heading over time, with the target band: 1 stops off target and stays, turnMinPower up then turnKp up. 2 rocks in and out at the band's edge, turnToleranceDeg up. 3 swings past and back and forth, turnKd up or turnKp down. 4 ends on target but slowly, turnKp up](https://crossbotics.com/ftc-helper/docs/images/move-tuner-turns.svg) **Why `turnMinPower` first:** near the target, the push (`turnKp` x the degrees left) is too weak to move the robot at all. More `turnKp` would also make the turn come in faster and swing more. Run Turns again until it says `OK`. ![Press A with the arrow on 3 Turns: the Driver Hub shows a line per turn and turnMinPower now 0.05](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-step-turns.svg) 4. **4 Drift** (a report, nothing to copy): the robot drives 48 in forward and back (on a mecanum, also right and left). The screen shows how much the heading changed on each move. A plain move does not correct its heading. More than 2 degrees: check the weight and the wheels, and use `moveWithTurn` on long moves (it holds the heading). ![Press A with the arrow on 4 Drift: the Driver Hub shows the heading change of each 48 in move](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-step-drift.svg) 5. **5 Move and turn** (mecanum; finds `moveTurnScale` and `moveMaxTurnPower`): the robot drives 24 in sideways while it turns 90 degrees (`moveWithTurn`), four times. The screen shows how far the heading was still off when the move ended. When the turn lags, the tuner raises `moveTurnScale` (up to 1), then `moveMaxTurnPower`. When the heading swings past its target, it lowers `moveTurnScale`. Run it again until it says `OK`. ![Press A with the arrow on 5 Move and turn: the Driver Hub shows the heading at the end of each move and moveTurnScale now 0.94](https://crossbotics.com/ftc-helper/docs/images/hub-move-tuner-step-move-turn.svg) 6. **Check with a tape:** without odometry, the tuner measures with the wheel counts. A robot can slide with its wheels locked, and the wheel counts do not see that. So check one move with a tape. Use the Drive Tuner's tape line ([Set up the floor](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/#steps)): the front left wheel's front edge on **0**. Run a 24 in forward move in an autonomous, at your autonomous's power. Read where that wheel edge stops. Within 0.5 in of 24: done. Else, find what you see in the table: | The tape shows | Why | Do this | | --- | --- | --- | | short or long by the same share on every move (run a 48 in move too: 1 in short on 24 and 2 in short on 48) | the wheel size number is wrong | run the [Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/) again, then the Move Tuner again | | past the end, by more than the tuner's screen said | the wheels skid when the move stops, and the wheel counts miss it | in `Tunables.Drive`, make `slowDownIn` 3 bigger. Install, then run the move again | | still past the end with `slowDownIn = 12` | the robot is too fast for this floor | use a lower power for the move (0.6 to 0.5), and run the Move Tuner at that power. Clean the tiles and check the wheels | **Why `slowDownIn`, and not the tuner:** the tuner cannot see the skid, so it thinks the stops are good. A bigger `slowDownIn` makes the robot slower at the end, so it skids less. With an `odometry(...)` line, the tuner measures with the odometry, which sees a skid (`Measures with : the odometry`). Then the tuner finds this number by itself. ## Fix a mistake - **A test went wrong** (something was in the way, the robot hit a wall): run the same test again. Each run starts from the numbers in use now. - **Stop a test that drives:** press **GUIDE** (or hold **START**). The robot stops, and that run is not used. A Stops test that you stop goes back to the `slowDownIn` it had before. - **A number got worse:** the screen's `Now using` and `Turns` lines show the numbers in use. Start over to go back to the numbers in `Tunables.java`. **Start over:** press STOP, then INIT, and open the tool again. It starts from the numbers in `Tunables.java`: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java`, not the finder's screen. Take a photo of the screen, and type each line that starts with `Tunables.Drive:` into `Tunables.Drive`. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | What it does | | --- | --- | | `Tunables.Drive: moveMinPower = 0.10` | the slowest power at the end of a move | | `Tunables.Drive: slowDownIn = 3` | every move slows down over at least its last 3 in | | `Tunables.Drive: turnMinPower = 0.05` | the least turn power while the heading is still off | | `Tunables.Drive: turnKp = ...`, `turnKd = ...` | how hard a turn pushes, and how hard it brakes near the end | | `Tunables.Drive: turnToleranceDeg = 1.5` | a turn is done this close to its heading | | `Tunables.Drive: moveTurnScale = ...`, `moveMaxTurnPower = ...` | how hard `moveWithTurn` turns while it moves | Older helpers: the `c.` lines go in `RobotSettings.auto()`. ## Done when Stops, Turns and (on a mecanum) Move and turn say `OK`, the lines are in `Tunables.Drive`, and one 24 in move ends within 0.5 in on the tape. --- **Next:** [Camera lighting](https://crossbotics.com/ftc-helper/docs/tuning/11-camera-lighting/). **Look it up:** [Drive: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava), [Move Tuner in the finders reference](https://crossbotics.com/ftc-helper/docs/modules/finders/#movetuneropmode). --- # Camera lighting URL: https://crossbotics.com/ftc-helper/docs/tuning/11-camera-lighting/ **In Tune and check:** no. The camera tests the light by itself, at each INIT. This page sets it up. **You need:** a camera in Robot.java, AprilTags on the field (or printed ones), and for a Limelight, a laptop and the Limelight's USB-C cable. ## Why the light matters Each place has different light: a bright gym, a dim classroom, spotlights at an event. A camera setting that finds the tags at school can miss them at an event. Then the robot cannot aim, and the Shot Tuner gets no distance. So the camera tests a few settings at INIT, and keeps the one that sees the most tags. Do this setup before the Aim Tuner and the Shot Tuner: both need a camera that sees the tags well. | Camera | What it tests | Turn it on in Robot.java | | --- | --- | --- | | Limelight | its **pipelines**: sets of camera settings that you save on the Limelight by number | `.autoPipelines(0, 1, 2)` | | Webcam | exposures: how long each picture collects light | `.autoExposure()` (auto, 3, 6 and 12 ms) | | HuskyLens | nothing: it has no lighting test | - | ## Set it up ### A Limelight 1. Save 3 pipelines on the Limelight: one for your usual light, one for bright light, and one for dim light. The [Limelight lighting guide](https://crossbotics.com/ftc-helper/docs/guides/limelight-lighting/) has the steps, on a laptop. 2. Add `.autoPipelines(0, 1, 2)` to the camera's line. **Where:** `Robot.java`, inside `define()`, the camera's line. ```java title="Robot.java" camera = add(Camera.limelight("limelight").autoPipelines(0, 1, 2).goal("BLUE SCORING", "RED SCORING")); ``` ### A webcam Add `.autoExposure()` to the camera's line. **Where:** `Robot.java`, inside `define()`, the camera's line. ```java title="Robot.java" camera = add(Camera.webcam("Webcam 1").autoExposure()); // or your own list: autoExposure(6, 3, 12) ``` ## Check it 1. Turn the robot so that the camera sees a tag. Press INIT. 2. Read the lighting line on the Driver Station, for example `limelight lighting : pipeline 2 (9 of 10 pictures saw tags)`. When the camera sees no tag, this line is a warning. 3. Look at the camera's picture: [See what the camera sees](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/#see-what-the-camera-sees). ## At an event 1. In the queue, press INIT with the robot facing a tag. The test stops at ▶ and keeps the best setting so far, so a tag must be in view. 2. The Driver Station shows the result, and two lines for `Tunables.java`. Copy them into the camera's section (`Tunables.Limelight`). Then every match at this venue uses that setting, with no test. **Where:** `Tunables.java`, inside the camera's section. ```java title="Tunables.java" public static double pipeline = 2; public static boolean autoLighting = false; ``` A webcam shows `public static double exposureMs = 6;` in place of `pipeline`. 3. Back home, set `autoLighting = true` again. ## Fix a mistake - **The robot started with no tag in view:** the test kept the setting it had. Turn to a tag and INIT again. In a match, a button can run the test again: `relight()` ([Buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#buttons-to-add)). - **Back home, the camera misses tags:** check that `autoLighting` is `true` again (step 3 above). ## Done when - At INIT, facing a tag, the lighting line shows a setting and no warning. - A Limelight has its 3 pipelines saved. --- **Next:** [Aim Tuner: camera offset](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/). **Look it up:** [Camera: Venue lighting](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#venue-lighting), [how the test works](https://crossbotics.com/ftc-helper/docs/modules/vision/#venue-lighting). --- # Aim Tuner: camera offset URL: https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/ **In Tune and check:** no. It has its own file: it needs your camera. **You need:** its own file, safety glasses, pieces, the target 4-6 ft away, and the [camera lighting](https://crossbotics.com/ftc-helper/docs/tuning/11-camera-lighting/) set up. ## Get to the Aim Tuner 1. On the Driver Hub, open the TeleOp list and pick your Aim Tuner file (group "Finders"). Its name is the one in its `@TeleOp(name = ...)` line, like **Aim Tuner**. Press **INIT**. ![The Driver Hub's TeleOp list with Aim Tuner under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-aim-tuner-opmode.svg) 2. The Aim Tuner's INIT screen shows, with the camera's status. Press **▶** (start) on the Driver Hub. ![The Aim Tuner's INIT screen: Camera : STREAMING 30 fps. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-aim-tuner-go-start.svg) ## What the offset is The camera finds the goal, and the turret or the robot turns until the goal is in the camera's center. But the camera is not on the launcher. So when the goal is in the camera's center, the launcher points a little to the side. The **offset** is the angle that fixes this: the robot aims until the goal sits that far from the camera's center. ![Top view: the camera sits left of the launcher, so the goal looks a little right of the camera's center when the launcher points at it. The angle is bigger for a near goal than for a far one. Shots land left: press D-pad right](https://crossbotics.com/ftc-helper/docs/images/aim-camera-offset.svg) The sign of the offset depends on where the camera sits: ![Three top views: a camera left of the launcher gives a negative offset, a camera right of it gives a positive offset, and a camera on the launcher's line gives 0](https://crossbotics.com/ftc-helper/docs/images/aim-offset-examples.svg) The Aim Tuner finds this angle by test shots. It does not change how fast or how smoothly the robot turns. For the whole robot, `turnKp` and `turnKd` in `Tunables.Aim` set that ([Fix it by what you see](https://crossbotics.com/ftc-helper/docs/tuning/17-fix-by-symptom/)). ## See what the camera sees Before you tune, check the camera's picture. The goal's tag must be in the picture, sharp, and not too dark or too bright. - **A webcam:** the Driver Hub can show its picture. 1. Use the PRACTICE profile ([profiles](https://crossbotics.com/ftc-helper/docs/guides/profiles/)). In COMPETITION the live view is off, because it slows the robot. 2. Press INIT. Do not press ▶ yet. 3. On the Driver Hub, open the menu (the three dots, top right) and choose **Camera Stream**. Tap the picture to get a new one. 4. Close it, then press ▶. A webcam in Robot.java does this by itself. In an Aim Tuner file of your own with the older helpers, add `.liveView(true)` to the webcam. - **A Limelight:** it sends no picture to the Driver Hub. Leave it where it is on the robot, and plug its USB-C cable into a laptop instead of the Control Hub. Open http://limelight.local:5801: the page shows the live picture, with the tags it finds marked. Plug it back into the Control Hub after. ([Limelight lighting](https://crossbotics.com/ftc-helper/docs/guides/limelight-lighting/) has more.) - **No picture? Use the numbers.** While the tuner runs, the screen shows `Bearing : ... deg (left = +)` when the camera sees the goal, and `No target in view.` when it does not. Turn the robot a little to the left: the bearing must go down. ## Steps **Before you start:** the Aim Tuner uses the older helpers' pieces, not `robot()`. It needs your `createCamera()`, and `createTurret()` or `robotConfig()` (to aim by turning the robot), and `createLauncher()` for test shots ([reference](https://crossbotics.com/ftc-helper/docs/modules/finders/#aimtuneropmode)). For a robot in five files, `robotConfig()` is `return new Robot().robotConfig();`. The Characterizer is the same: it needs `robotConfig()`. 1. Park the robot 4-6 ft from the target, facing it. For a turret with a home switch, press **X** first. 2. Hold **A**, and the robot aims. ![Hold A: the Driver Hub shows Still to turn : 0.1 deg](https://crossbotics.com/ftc-helper/docs/images/hub-aim-tuner-step-aim.svg) 3. Still holding **A**, shoot (**RB**). LB stops the flywheel. ![Still holding A, press RB when the Driver Hub shows Launcher : ready](https://crossbotics.com/ftc-helper/docs/images/hub-aim-tuner-step-shoot.svg) 4. When shots go LEFT of the middle, press D-pad RIGHT (aim more to the right). When shots go right, press LEFT. ![Shots go right, so press D-pad left: the Driver Hub shows Offset : -1.5 deg and Tunables.Aim: cameraOffset = -1.5](https://crossbotics.com/ftc-helper/docs/images/hub-aim-tuner-step-offset.svg) 5. Repeat until shots go in the middle, at two or three distances. Copy the offset line (five files, with a turret: `Tunables.Turret: cameraOffset = -1.5`; aiming by turning the whole robot: `Tunables.Aim: cameraOffset = -1.5`). When the offset that works changes with distance, the camera is off to the side of the launcher. Move the camera onto the launcher's line (or as close as you can), or tune at the distance you shoot from most. ## Fix a mistake - **Pressed the D-pad the wrong way:** press it the other way. Each press changes the offset by 0.5 degrees (left and right) or 2 degrees (up and down), so the opposite press undoes it. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.Turret: cameraOffset = -1.5` (a turret) | `Tunables.Turret` | | `Tunables.Aim: cameraOffset = -1.5` (the whole robot aims) | `Tunables.Aim` | ## Done when shots go in the middle at two or three distances, and you copied the `cameraOffset` line. --- **Next:** [Shot Tuner: the shot table](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/). **Look it up:** [Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/), [AimTunerOpMode](https://crossbotics.com/ftc-helper/docs/modules/finders/#aimtuneropmode). --- # Shot Tuner: the shot table URL: https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/ **In Tune and check:** yes, when the robot has a launcher. **You need:** a charged battery, safety glasses, pieces, the aim tuned. ## Get to the Shot Tuner 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Shot Tuner**, then press **A**. ![The Tune and check menu with the arrow on Shot Tuner: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-go-menu.svg) 3. The Shot Tuner's INIT screen shows. The flywheel stays off. Choose your alliance: **X** = BLUE, **B** = RED (the `Alliance` line). Only that alliance's goal counts. Point the camera at a tag: the camera's lighting test runs now, as in a match. Wait until its line says it is done, then press **▶** (start) on the Driver Hub. ![The Shot Tuner's INIT screen: The flywheel stays off until you press LB. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-go-start.svg) ## One table or two A **shot table** is a list of rows: at this distance, this flywheel speed. A bigger or heavier piece needs a different speed. In BIOBUZZ, POLLEN (2.8 in, 25 g) and NECTAR (3.6 in, 41 g) fly differently. So a robot that shoots both needs a table for each. | Your robot shoots | The tables in `Tunables.Launcher` | In a match, the table comes from | | --- | --- | --- | | one kind only (only POLLEN, or only NECTAR) | one: `speedByDistance` | nothing to choose | | both kinds | two: `speedByDistancePollen` and `speedByDistanceNectar` | a piece sensor, or a driver's button (below) | ### One kind only Use the plain `speedByDistance` table. When Robot.java takes the speed from the distance (`.speedFromDistance(...)`), INIT stops without a table, so write one guess row first: **Where:** `Tunables.java`, inside `Tunables.Launcher`. ```java title="Tunables.java" public static double[][] speedByDistance = {{36, 3000}}; // a guess: the Shot Tuner replaces it ``` Load only that kind of piece, and tune. The screen shows no `Table` line. ### Both kinds 1. **Before you tune, write both tables, with one row each.** The tuner shows only the tables that have a row. A guess is fine: the tuner replaces the rows. **Where:** `Tunables.java`, inside `Tunables.Launcher`. ```java title="Tunables.java" public static double[][] speedByDistancePollen = {{36, 3000}}; // a guess: the Shot Tuner replaces it public static double[][] speedByDistanceNectar = {{36, 3200}}; // a guess: the Shot Tuner replaces it ``` 2. **Tune one table at a time, with only that piece loaded.** Pick POLLEN (step 1 below), load only POLLEN, and do every spot. Then pick NECTAR, load only NECTAR, and do every spot again. A NECTAR shot marked in the POLLEN table makes both tables wrong. 3. **Check the `Table` line before you press X.** X saves the point in the table that the screen shows. `Points: POLLEN 4, NECTAR 0` says how many points each table has. 4. **Copy one line for each table** (step 7 below). 5. **Tell the launcher which piece it holds, in a match.** In `Robot.java`, on the launcher's line: - **A piece sensor (best):** `.tableFrom(pieces.nextKind())` picks the table for the next piece, by itself. Both NECTAR colors use one table: add `.tableFor("nectar", "RED_NECTAR", "BLUE_NECTAR")` ([Pieces](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/); find the sensor's colors with the [Piece Tuner](https://crossbotics.com/ftc-helper/docs/tuning/14-piece-tuner/)). A robot that holds both kinds at once needs this. - **No sensor:** a driver's button picks the next table: `robot.launcher.tableOn(g2.dpadRight);` in `Controls.java`. The Driver Station shows `Shot table: POLLEN, 48 in (camera)`, so the driver sees which one is in use. - At the start, the launcher uses `.startTable("pollen")`, or NECTAR when you write none. ## It aims and sees like a match A table made from shots that were not aimed, or with another camera setting, does not fit the match. So with your robot in five files and a camera with `goal(...)` in Robot.java, the Shot Tuner uses the robot's own camera and aim, the same code as TeleOp and the autos: - **The camera:** the same camera and settings, and its lighting test in INIT. **Hold Y 0.5 s** to run the test again (aim the camera at a tag first). A short **Y** press still changes what the D-pad changes. - **The goal:** only the goal of the alliance you chose in INIT, read right side up, from fresh pictures. Its distance is the tags' distance, as the launcher reads it in a match. - **The aim:** **RB** turns the whole robot to the goal with TeleOp's aim (`Tunables.Aim`: `toleranceDeg`, the saved `cameraOffset`, the angle aim when `angleAim` is on), then shoots when it is aimed and `Ready`. The `Aim` line shows how far off it is. The robot keeps facing the goal after the shot. Your turn stick still wins. - **No shot** when the camera does not see the goal (an odometry guess does not count here), the robot is not aimed for 2 s, or the flywheel is not `Ready` in 4 s. The screen says why. So the table holds only aimed shots. After each shot the aim lets go: the robot does not turn by itself while you move it to the next spot. A robot whose turret follows the goal: the turret aims in a match, so the tuner shoots where the robot points (point it with the sticks), and the distance is to the first target the camera sees, as before. Its lighting test and alliance choice still run. A camera with no `goal(...)`: the first target with a distance, as before. ## Where the distance comes from The table holds a speed for each **distance** to the goal. The tuner gets the distance in one of three ways. The screen says which one, after the distance: `Distance : 36.2 in (camera, 12 readings)`. | Way | When | You can tune from | | --- | --- | --- | | **camera** | the camera sees the goal | spots where the camera sees the goal | | **odometry** | the camera does not see the goal, and the robot has odometry and a goal point | **any spot on the field**, even with no camera | | **by hand** | neither | spots you measure with a tape | When the camera sees the goal, it wins. The tuner uses the average of the last half second of readings, so one bad picture does not go into the table. ### Tune from any spot with odometry With odometry, the robot knows where it is on the field. It also knows where the goal is, from `Tunables.Aim`. So it can work out the distance from any spot: in front of the goal, from the side, or from far away. Tune from the spots where your drivers shoot in a match. **BIOBUZZ:** the goal is your HIVE's up CELL, near the middle of the field. Straight back from it, you reach the wall after about 4 ft, and the HIVE frame is in the way on one side. So do not test in one line: go out toward your corner. The farthest spot is about 66 in from the goal. ![The BIOBUZZ field from your drivers' wall: the two HIVEs in the middle, the goal on your HIVE, spots 1 to 4 going toward your corner at 30, 42, 54 and 66 in, two side-check spots at 42 in, and the odometry start in the middle](https://crossbotics.com/ftc-helper/docs/images/shot-tuner-test-spots.svg) **Before you start:** 1. **The odometry works.** Robot.java has an `odometry(...)` line, and the [Odometry Tuner](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/) is done (`Tunables.Odometry: checked = true`). 2. **The goal point is in `Tunables.Aim`:** `goalX` and `goalY`, in inches, for the BLUE goal, seen from your drivers' wall. x counts to the right from the center line, and y counts from the center toward the far wall. Take them from the season's field map ([Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/)). The tuner mirrors the goal for RED when the last OpMode you ran chose RED. **Each time you start the tuner:** 1. Put the robot in the **middle of the field**, facing away from your drivers' wall. This is where the odometry starts counting. (In a Shot Tuner file of your own, `startSpotIn()` can give another start spot.) 2. INIT, then **▶**. 3. Check that the screen says `(odometry, ...)` after the distance. Drive straight away from the goal by one field tile (24 in): the distance must grow by about 24 in. 4. Drive with the sticks to your first spot, and tune there (the steps below). Then drive to the next spot. The distance follows the robot. The screen also shows a `bearing`: how far the goal is to the side. Turn the robot with the sticks until the bearing is near 0, so that the robot points at the goal before you shoot. **When the camera also sees the goal,** the screen shows both: `Distance` (from the camera) and `Odometry says` (from the odometry). They should be within a few inches. When they are far apart, the goal point in `Tunables.Aim` is wrong. Or the robot did not start in the middle of the field facing away from you. Fix it before you tune: one table must fit both. **Odometry drifts a little over time,** most after bumps. When the distance looks wrong, press STOP: it saves the points so far in the results file (step 7). Put the robot back in the middle of the field, and INIT again. The new run starts with no points, and its table line has only the new ones. So put the lines of both runs together by hand in `Tunables.java`: one `{distance, speed}` pair per point, nearest first. ## Steps ![Shot Tuner: the robot at the nearest spot, then 1-2 ft further back each time; at each spot shoot 3-5, mark HIT or MISS, and X saves the best speed](https://crossbotics.com/ftc-helper/docs/images/finder-shot-tuner.svg) The Shot Tuner works the way experienced teams tune. At each distance, shoot 3-5 pieces at a speed, and mark each one **HIT** or **MISS**. Try the next speed. Keep the speed with the best **hit ratio** (hits out of shots: 3 in out of 4 beats 2 out of 3). Every button is on **gamepad 1**. 1. **Pick the table** (only with two tables: [One table or two](#one-table-or-two)). Press **Y** until `> Table`. Then **D-pad left / right** picks the table. Load only that kind of piece. ![Press Y, then D-pad: the Driver Hub shows > Table : POLLEN](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-step-table.svg) 2. Park at the nearest distance you will shoot from. The screen shows the distance and where it came from ([Where the distance comes from](#where-the-distance-comes-from)). Press **LB** to start the flywheel (it is off at the start). ![At the nearest spot, press LB: the Driver Hub shows Speed : 2600 RPM, measured 2594, the distance, and Ready : YES](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-step-spin.svg) 3. The speed starts at what your table already gives at this distance (or `Tunables.Launcher.speedRpm`), so you only fine-tune. Shoot 3-5 (**RB** one at a time, or hold **RT**). A robot that aims turns to the goal first ([It aims and sees like a match](#it-aims-and-sees-like-a-match)). ![Press RB: the Driver Hub shows Shots fired : 1, 1 to mark](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-step-shoot.svg) 4. After each shot, press **A** = HIT or **B** = MISS. The marks go to the shots in the order you fired them. Each shot keeps the speed, hood angle and distance it was **fired** with. So when you change the speed or the hood before you mark, the mark does not move. The screen shows `Hits at 2600: 3/4` and every speed tried here (`Tried here: 2500: 1/3, 2600: 3/4 (best)`). Change the speed with the D-pad, and shoot 3-5 again. A short **Y** press steps through what the D-pad changes: SPEED, HOOD with a hood, TABLE with two tables, and DISTANCE. DISTANCE is a distance you type in when neither the camera nor the odometry gives one. 2-3 speeds are usually enough. - **When you pressed the wrong one,** a **left stick click** takes back the last HIT / MISS. That shot waits to be marked again. - **A "shot" with no piece:** the wheel slowed down by itself, so `Shots fired` went up. A **right stick click** drops the last shot that is not marked yet. ![After each shot, press A = HIT or B = MISS: the Driver Hub shows Hits at 2600 : 3/4 and Tried here : 2500: 1/3, 2600: 3/4 (best)](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-step-mark.svg) 5. Press **X** to save. The tuner keeps the speed with the **best hit ratio** at this distance. In a tie, it keeps the one with more shots. You must mark all shots before you save. With no shots marked at all, X only warns. X again within 3 s saves the speed now anyway: a guess, not a tested speed. With a hood, it also saves the hood angle that you fired those shots with. Each point also keeps the flywheel speed **measured** as the pieces were fed. When the flywheel was well under the speed asked for, it **sagged**. The last shot or a low battery slowed it, and it was not back yet. Then the screen warns. Wait for `Ready: YES` between shots and charge the battery, or the table will not match a match. To delete a wrong point, stand there and **hold BACK 1 s**. It is a hold, so that nobody presses it by mistake. ![Press X: the Driver Hub shows Saved 24.2 in -> 2600 RPM (3/4 in) POLLEN](https://crossbotics.com/ftc-helper/docs/images/hub-shot-tuner-step-save.svg) 6. Move 1-2 ft further from the goal (drive with the sticks) and do it again. The spots do not need to be in a line. When the wall or a field part is in the way, go out at another angle ([BIOBUZZ](#tune-from-any-spot-with-odometry)). When the distance moves more than 4 in, the hit counts start again by themselves. The tuner also drops the unmarked shots fired at the old spot. `Points: POLLEN 3, NECTAR 0 (4-6 per table)` says how far you are: 4-6 points per table cover the field. Then go to the next table (step 1). 7. **Copy the tables into `Tunables.java`**: the robot uses the file, not the tuner's screen. There is one line per table, like `public static double[][] speedByDistancePollen = {{24, 2600}, {48, 3100}}; // in Tunables.Launcher` (with a hood: `{{24, 2600, 4}, {48, 3100, 12.5}}`, where the third number is the hood). It replaces the line with the same name in `Tunables.Launcher`. When you press STOP, the tuner also saves the lines on the Control Hub (`/sdcard/FIRST/ftc-helper/finder-results.txt`). Older helpers: the `new ShotTable()` lines go into your Robot class (each with a comment like `// 4/5 in, measured 2531 RPM`). Between the points, the launcher **blends** the speed: halfway between two points, it uses the speed halfway between theirs. Outside them, it uses the nearest point. With `robot()`, the Shot Tuner uses your robot's launcher, camera and drive. A robot with whole-robot aim turns to the goal before each shot. A turret stays still, and its "fire only when aimed" checks are off: point the robot at the goal with the sticks. **With a hood** (`.hood(...)` in Robot.java, or the older helpers' `.hood(servo)`), **Y** also chooses HOOD. The D-pad then steps the hood by a fifth / a fiftieth of its range: 5 / 0.5 deg for a 0-25 deg hood. The hood starts at the table's hood for this distance, like the speed. Each speed and hood angle is its own try in the hit counts (`Tried here: 2550 @ hood 10: 3/4 (best), 2550 @ hood 12.5: 1/3`). X saves the hood angle that you fired the winning shots with. A weak battery changes how far the shots go, so charge the battery before you tune speeds. The screen shows the battery and warns below 12.5 V. The tuner does not use the launcher's speed trim (the D-pad in a match), so the table holds the real speeds. ## Fix a mistake - **Marked HIT when it was a MISS (or the other way):** click the **left stick**. It undoes the last mark, and that shot waits to be marked again. - **A shot counted that did not happen:** click the **right stick**. It drops the newest shot that is not marked yet. - **Saved a wrong speed at this spot (X):** find the right speed, and press **X** again at the same spot. The new point replaces the old one. - **Delete the point at this spot:** hold **BACK** for 1 second. - **Saved a point in the wrong table:** pick that table (**Y**, then the D-pad), stand at the same spot, and hold **BACK** for 1 second. Then pick the right table and tune the spot again. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `public static double[][] speedByDistance = {{30, 2600}, {42, 2850}, ...};` | one kind only: `Tunables.Launcher`, in place of the line with the same name | | `public static double[][] speedByDistancePollen = {{30, 2600}, {42, 2850}, ...};` and the same for `Nectar` | both kinds: `Tunables.Launcher`, in place of the lines with the same names. One line per table | ## Done when - each table has 4-6 points, copied into `Tunables.Launcher`. - with both kinds: the launcher picks the right table in a match (a piece sensor, or a driver's button). --- **Next:** [Piece Tuner: what each sensor sees](https://crossbotics.com/ftc-helper/docs/tuning/14-piece-tuner/). **Look it up:** [Launcher: In Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava). --- # Piece Tuner: what each sensor sees URL: https://crossbotics.com/ftc-helper/docs/tuning/14-piece-tuner/ **In Tune and check:** yes, when the robot has a piece sensor. **You need:** one piece of each kind. ## Get to the Piece Tuner 1. On the Driver Hub, open the TeleOp list and pick **Tune and check** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Tune and check under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-tune-and-check-opmode.svg) 2. The menu shows. Press **D-pad down** until the arrow (`>`) is on **Piece Tuner**, then press **A**. ![The Tune and check menu with the arrow on Piece Tuner: press D-pad, then A](https://crossbotics.com/ftc-helper/docs/images/hub-piece-tuner-go-menu.svg) 3. The Piece Tuner's INIT screen shows. Nothing moves. Press **▶** (start) on the Driver Hub. ![The Piece Tuner's INIT screen: 2 sensor(s). Nothing moves. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-piece-tuner-go-start.svg) ## Steps The Piece Tuner is for a robot with a [`Pieces` or `PieceSensor`](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/) line. Its file names your robot, like the Odometry Tuner (the cookbook's [piece-tuner recipe](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-tune-the-piece-sensors)). Nothing moves, so you need no block. 1. Mount the sensor where it will stay. Put a piece at the spot where it sits or passes on the robot. At the intake, that is the spot where the sensor sees it go by. 2. D-pad up/down chooses the sensor. D-pad left/right chooses which kind is in front of it. ![Press D-pad: the Driver Hub shows Sensor 1/2: intake_color and In front of it: < POLLEN >](https://crossbotics.com/ftc-helper/docs/images/hub-piece-tuner-step-choose.svg) 3. Hold that kind of piece in its spot. **A** measures (20 readings, about half a second: hold still). ![Hold the piece still and press A: the Driver Hub shows Measured POLLEN and Tunables.IntakeColor: POLLEN = 74](https://crossbotics.com/ftc-helper/docs/images/hub-piece-tuner-step-measure.svg) 4. Do every kind, then EMPTY (nothing there). ![With nothing there and EMPTY chosen, press A: the Driver Hub shows Measured EMPTY and Tunables.IntakeColor: nearMm = 51](https://crossbotics.com/ftc-helper/docs/images/hub-piece-tuner-step-empty.svg) 5. Copy the lines into `Tunables.java` (for example `Tunables.IntakeColor: POLLEN = 74`), rebuild, and run it again. "It sees" should name each piece you hold up, and NONE with nothing there. The tuner warns about two problems. One: two kinds that read nearly the same (a color sensor too far away, a distance sensor that does not look straight across). Two: EMPTY that looks like a piece. For that, aim the sensor at a far wall or a gray or black background. ## Fix a mistake - **Measured the wrong piece:** put the right piece in front of the sensor, choose its kind, and press **A** again. The new measurement replaces the old one. - **Start this sensor over:** press **B**. It forgets every measurement for this sensor. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | `Tunables.IntakeColor: POLLEN = 74` | the sensor's section in `Tunables.java` | ## Done when "It sees" names each piece you hold up, and NONE with nothing there. --- **Next:** [Characterizer: how the robot really moves](https://crossbotics.com/ftc-helper/docs/tuning/15-characterizer/). **Look it up:** [Pieces and PieceSensor](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/). --- # Characterizer: how the robot really moves URL: https://crossbotics.com/ftc-helper/docs/tuning/15-characterizer/ **In Tune and check:** no. It has its own file: it needs your lifts. **You need:** its own file, a charged battery, 5 ft of clear floor. ## Get to the Characterizer 1. On the Driver Hub, open the TeleOp list and pick **Characterizer** (group "Finders"). Press **INIT**. ![The Driver Hub's TeleOp list with Characterizer under Finders, then press INIT](https://crossbotics.com/ftc-helper/docs/images/hub-characterizer-go-opmode.svg) 2. The Characterizer's INIT screen shows. Nothing moves yet. Clear the floor, then press **▶** (start) on the Driver Hub. ![The Characterizer's INIT screen: Drive test: about 5 ft clear in front and behind. Press start](https://crossbotics.com/ftc-helper/docs/images/hub-characterizer-go-start.svg) ## Steps Run the **Characterizer** last, when the robot drives and its lifts work. It measures how each motor behaves: the power to start moving, the power per speed, how fast it speeds up, and for a lift the power that holds it against gravity. You use these numbers in two places: for feedforward in your code (see [Feedforward](https://crossbotics.com/ftc-helper/docs/modules/control/#feedforward)), and as real numbers for the [simulator](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/#6-real-speeds-optional). 1. In `Characterizer.java`, list your lifts/arms with soft limits a little inside the hard stops (counts from the bottom), and your flywheels. 2. Drive test: about 5 ft clear in front and behind, on tiles. Turn test: room to turn. 3. Lifts start at the BOTTOM. An arm's high limit stays below straight up. 4. The D-pad chooses a test, and **A** runs it. ![Press D-pad, then A: the arrow on Drive (forward and back)](https://crossbotics.com/ftc-helper/docs/images/hub-characterizer-step-choose.svg) 5. **B** stops the test now. The tool stops by itself when something turns the wrong way, goes past a limit, or pushes without moving. ![While a test runs, the screen shows Drive (forward and back): ramp + (B = stop). To stop it now, press B](https://crossbotics.com/ftc-helper/docs/images/hub-characterizer-step-stop.svg) 6. Run each test 2-3 times on a charged battery. ![Press A to run it again: the Driver Hub shows Drive (forward and back): done. Fit r2 0.981 (good)](https://crossbotics.com/ftc-helper/docs/images/hub-characterizer-step-again.svg) Details: [finders module](https://crossbotics.com/ftc-helper/docs/modules/finders/#characterizeropmode). ## Fix a mistake - **Stop a test:** press **B** (or **GUIDE**). The robot stops, and that test gives no numbers. - **A bad test** (the robot hit something, or the lift was not at the bottom): run the same test again with **A**. Its new lines replace the old ones. **Start over:** press STOP, then INIT, and open the tool again. It starts empty: nothing carries over. The lines saved at STOP stay in the results file, the newest at the end. ## Put the numbers in your code The robot uses `Tunables.java` and `Robot.java`, not the finder's screen. Take a photo of the screen, and type each line into the file. Or copy it from the [results file](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/#get-the-results-file-on-the-laptop): | The finder shows | Put it in | | --- | --- | | the feedforward numbers | your code ([Feedforward](https://crossbotics.com/ftc-helper/docs/modules/control/#feedforward)) | | the motor numbers | the simulator's robot file ([real numbers](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/#6-real-speeds-optional)) | ## Done when each test ran 2-3 times and the numbers agree. --- **Next:** [Live tuning: change numbers while the robot runs](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/). **Look it up:** [CharacterizerOpMode](https://crossbotics.com/ftc-helper/docs/modules/finders/#characterizeropmode). --- # Live tuning: change numbers while the robot runs URL: https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/ **You need:** a robot whose parts work, and the PRACTICE [profile](https://crossbotics.com/ftc-helper/docs/guides/profiles/) (the menu stays closed in COMPETITION). The finders FIND a number the first time. This menu adjusts numbers you already have: a PID gain, a position, a speed. Building and installing again for each small change is slow. The menu changes the number at once.
flowchart LR
    B["PRACTICE profile<br/>run the TeleOp"] --> C["Open the menu<br/>(hold GUIDE 1 s)"]
    C --> D["change, watch, repeat"]
    D --> E["A = save on the hub"]
    E --> F["COPY the numbers<br/>into Tunables.java"]
## What is in the menu With the robot in five files, you set up nothing. Every part's numbers are in the menu already, and so is every number in your own sections of `Tunables.java` (a section no part reads). Limits (`min`, `max`) are never in the menu, so tuning can never drive a part past a hard stop. Each part's reference page says, for each number, whether the menu has it ([the "In tuning menu" column](https://crossbotics.com/ftc-helper/docs/reference/tunables/#the-in-tuning-menu-column)). ## Open it and change a number **Where:** the Driver Hub, in your TeleOp, after ▶ (start on the Driver Hub). Hold **GUIDE** for 1 s. (A tap of GUIDE shows the button map.) While the menu is open, gamepad 1's buttons and sticks do not drive the robot. Gamepad 2 keeps working. | Button | Does | | --- | --- | | GUIDE, held 1 s | open / close. A tap shows the button map | | D-pad up / down | choose | | D-pad right / left | +/- one step (hold a bumper: x10) | | A | save all on the hub | | X | the chosen one back to the code value | | Y | ALL back to the code values, and deletes the saved values | | B | the changed values as lines to copy into `Tunables.java` (also in the robot log, tag `ftc-helper`). B again: the list | Changed values show the code value next to them: `Lift/kP = 0.0050 (code 0.004)`. ## Copy the numbers back **The code is the record.** A value saved only on the hub is lost with a new Control Hub. Teammates cannot see it, and you can forget it at an event. 1. Press **B** in the menu. It shows the changed values as lines to copy, for example `Lift: kP = 0.0050`. The lines are in the robot log too (tag `ftc-helper`). 2. Put each value in its section in `Tunables.java`. 3. Press **Y** to put every value back to the code values and delete the saved values. The next INIT lists every value you did not copy yet, under "Tuned on this robot (copy into Tunables.java)". A save cannot leave a half-written file: after a power cut, the hub has either the old values or the new ones. ## The battery Numbers that set a power (a hold power, a drive gain) are right only for about the battery you tuned them on. Tuned on a low battery, they are too strong on a charged one. So the menu shows the battery's voltage, and warns below 12.5 V. Each change notes the battery: the copy lines say `Lift: kF = 0.06 // tuned at 12.7 V`. Copy that note into `Tunables.java` too. Tune on a charged battery (12.5 V or more). ## Older programs: add the menu yourself A TeleOp in five files has the menu already. Your own TeleOp (`LinearOpMode`, `EasyTeleOp`) needs two things. **Make numbers tunable.** On mechanisms, add `.tunable(...)`: ```java PositionMotor lift = PositionMotor.create(hardwareMap, "lift") .pid(0.004, 0, 0.0002, 0.05) .position("DOWN", 0).position("HIGH", 2400) .tunable("Lift"); // "Lift/kP".."Lift/kF", "Lift/DOWN", "Lift/HIGH" PositionServo claw = PositionServo.create(hardwareMap, "claw") .position("OPEN", 0.2).position("CLOSED", 0.75) .tunable("Claw"); // "Claw/OPEN", "Claw/CLOSED" ``` For any other number, make a `Tunable`. `static final` makes one `Tunable` for the whole program, made once. The menu still changes its value: ```java // (menu name, value in the code, change per D-pad press), kept between 0.1 and 1.0 static final Tunable SLOW_SPEED = Tunable.number("Drive/slow", 0.35, 0.05).range(0.1, 1.0); ... double speed = slowMode ? SLOW_SPEED.get() : 1.0; // read it EVERY loop ``` For a PID controller you made yourself, call `PidTunables.of("Arm", kP, kI, kD, kF).applyTo(pid)` every loop. **Add the menu to the TeleOp.** The menu uses gamepad 1's D-pad, A, X, Y and bumpers. Without a pause, pressing Y in the menu ("reset all") would ALSO do whatever Y does for the driver. So give the menu key its own small button list. Pause the driver's gamepad-1 buttons (and sticks) while the menu is open: ```java TuningMenu tuning = new TuningMenu(gamepad1); ControllerBindings menuKey = new ControllerBindings().bindPress(Pad.G1, Btn.GUIDE, tuning::toggle); // tuning::toggle = run toggle() on press ControllerBindings driver = new ControllerBindings()...; // gamepad 1 buttons ControllerBindings operator = new ControllerBindings()...; // gamepad 2 buttons (keep working) boolean menuWasOpen = false; // was the menu open last loop? // loop: menuKey.update(gamepad1, gamepad2); operator.update(gamepad1, gamepad2); tuning.update(); // the menu reads gamepad 1 (only while open) if (tuning.isOpen()) { menuWasOpen = true; tuning.addTelemetry(t); // and ignore gamepad 1's sticks } else { if (menuWasOpen) driver.ignoreHeldButtons(gamepad1, gamepad2); // a button held from the menu does not fire menuWasOpen = false; driver.update(gamepad1, gamepad2); } ``` The starter kit's `MainTeleOp` already has this code. ## FTC Dashboard (practice only) > **Not at events (2026-27 rule R704.D):** the game manual bans "additional logging/streaming > services, such as those hosted by third party plugins and tools such as FTC Dashboard, FTControl > Panels, and others". Only the Driver Station app may stream telemetry. Use these tools at home and > in practice only. **Take them out of the robot project before an event**: remove or comment out > their Gradle lines, then build and install again. The library's own tuning menu works through the > Driver Station, so the rule allows it. [FTC Dashboard](https://acmerobotics.github.io/ftc-dashboard/) shows graphs. It also lets you change `public static` fields (settings that belong to the class, not to one object) from a laptop browser. Teams used it in the 2025-26 season. You add it in the robot project, not in this library. Add its Maven repository and dependency (where to download it, and its name and version) to `build.dependencies.gradle`. Then put `@Config` on a class with `public static` fields. It works alongside the tuning menu. Use the one that fits the job: Dashboard for graphs, and the menu at the field without a laptop. ## Done when - The menu opens in PRACTICE, and a change shows on the robot. - Every value you keep is in `Tunables.java`, and INIT lists no "Tuned on this robot" lines. --- **Next:** [Fix it by what you see](https://crossbotics.com/ftc-helper/docs/tuning/17-fix-by-symptom/). **Look it up:** [Tunable](https://crossbotics.com/ftc-helper/docs/modules/tuning/), [Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/tunables/). --- # Fix it by what you see URL: https://crossbotics.com/ftc-helper/docs/tuning/17-fix-by-symptom/ **You need:** the finders done for the part ([the tuning order](https://crossbotics.com/ftc-helper/docs/tuning/)). Find what you see in the first column. Change the setting in the middle column, in the direction it says. Change one number at a time, and test after each change. The [tuning menu](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/) changes most of them while the robot runs. Then copy the good value back into `Tunables.java`. When the last column names a finder, run that finder again: a guess is worse than a measurement. | What you see or want | Setting | Which way | | --- | --- | --- | | **Driving** | - | - | | The robot is too fast for the drivers | [`Drive.maxPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | less | | A brand-new driver needs a slower robot for a day | [`Drive.practiceMaxPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | less, then back to `DEFAULT` | | Fine moves with the slow trigger are too slow or too jumpy | [`Drive.slowSpeed`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | more / less | | Double taps are missed, or single taps wait too long | [`Buttons.tapGapSec`](https://crossbotics.com/ftc-helper/docs/reference/controls/#buttons-in-tunablesjava) | more / less | | **Autonomous moves** | - | - | | Autonomous does not run ("AUTONOMOUS IS OFF") | [`Drive.calibrated`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | `true`, after the Drive Tuner | | Sideways moves are short or long (mecanum) | [`Drive.strafeCorrection`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Drive Tuner | | Turns stop a few degrees off target | [`Drive.turnMinPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava), then [`Drive.turnKp`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Move Tuner (Turns), or more | | Turns wobble or overshoot | [`Drive.turnKp`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) / [`Drive.turnKd`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Move Tuner (Turns), or less / more | | Turns rock near the end and take long to finish | [`Drive.turnToleranceDeg`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Move Tuner (Turns), or more | | The robot stops just before the end of a move | [`Drive.moveMinPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Move Tuner (Creep), or more | | Moves slide past the end | [`Drive.slowDownIn`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Move Tuner (Stops), or more (try 6) | | `moveWithTurn` ends its move before the turn is done | [`Drive.moveTurnScale`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava), then [`Drive.moveMaxTurnPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/#in-tunablesjava) | Move Tuner (Move and turn), or more | | Path steps do not run on the real robot | [`Odometry.checked`](https://crossbotics.com/ftc-helper/docs/reference/parts/odometry/#in-tunablesjava) | `true`, after the Odometry Tuner | | The odometry's distances are off (OTOS) | [`Odometry.linearScalar`](https://crossbotics.com/ftc-helper/docs/reference/parts/odometry/#in-tunablesjava) | Odometry Tuner | | **Intake** | - | - | | Pieces are thrown or jam on the way in | [`Intake.inPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#in-tunablesjava) | less | | Pieces do not come out | [`Intake.outPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#in-tunablesjava) | more | | **Lift, arm, servos** | - | - | | A lift or arm is slow to arrive, or shakes | [`kP`](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#in-tunablesjava) | more / less | | A lift sags | [`kF`](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#in-tunablesjava) | more | | A lift or arm slams into its ends | [`slowZone`](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#in-tunablesjava) | more | | A claw does not open or close far enough | [positions](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#in-tunablesjava) | Servo Finder | | Actions go on before a servo arrives | [`travelSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#in-tunablesjava) | more | | **Launcher** | - | - | | Shots land short or long | [`speedRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) (or the shot table) | Shot Tuner, or more / less | | The flywheel is slow to reach speed, or its speed swings | [`kP`, `kF`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | Flywheel Finder | | The flywheel suddenly speeds up now and then | [`kD`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | 0 (the Flywheel Finder's line has `kD = 0`: copy each number to its own name) | | In the Flywheel Finder, the wheel stops when a piece touches it | the direction | `Direction` must say "as in Robot.java"; else press X ([why](https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/#steps)) | | It waits too long before it fires | [`readyBandRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | more | | With the speed from the camera, it waits to fire and the `Shot distance` line wobbles | [`distanceSmoothSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | more (and check the shot table for a steep part) | | Shots land at different distances | [`readyBandRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | less | | The second of two quick shots lands short | [`shotIntervalSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | more | | The first shot takes too long to spin up | [`idleRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | more (uses more battery) | | One D-pad press changes the speed too much or too little | [`stepRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | less / more | | **Feeding** | - | - | | It feeds two pieces at once | [`feedSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-tunablesjava) | less | | It feeds two at once, but less `feedSec` feeds none from farther back | [`stopOnShot`](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-tunablesjava) | true | | It feeds no piece | [`feedSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-tunablesjava) | more | | It feeds the near pieces but not the ones far back | [`feedSec`](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-time-finder/) | the Feed Time Finder's number | | The Flywheel Finder's "Shots seen" is less than the pieces fed | [`shotDropRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | less | | With `stopOnShot`, the wheels still run the full `feedSec` after a shot | [`shotDropRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | less | | An eject pushes out two pieces | [`ejectFeedSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | set it, then less | | With the speed from the camera, a shot waits while its speed keeps changing | [`lockSpeedWhileFiring`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | true | | With `stopOnShot`, the wheels stop before the piece gets to the flywheel | [`shotDropRpm`](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava) | more | | A pusher comes back before the piece is gone | [`pushSec`](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/#in-tunablesjava) | more | | **Aiming** | - | - | | Aim is slow, or swings past the goal | [`Aim.turnKp`](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#in-tunablesjava) | more / less | | Shots miss although it says "AIMED" | [`Aim.toleranceDeg`](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#in-tunablesjava) | less | | The robot or turret aims a little to one side | [`cameraOffset`](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#in-tunablesjava) | Aim Tuner | | A turret swings too hard | [`Turret.maxPower`](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/#in-tunablesjava) | less | | The wires allow a turret to turn more or less | [`Turret.min`, `max`](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/#in-tunablesjava) | Motor Finder | | **Camera and sensors** | - | - | | The camera pictures are too dark or noisy | [`Camera.gain`](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#in-tunablesjava) | more / less | | A HuskyLens's turn angles are too big or too small | [`Camera.hfovDeg`](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#in-tunablesjava) | measure it | | A color sensor sees pieces that are not there | [`nearMm`](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/#in-tunablesjava) | less | | A color sensor mixes up kinds of piece | [`hueTolerance`](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/#in-tunablesjava) | less | When nothing here fits, read [Troubleshooting](https://crossbotics.com/ftc-helper/docs/troubleshooting/): it covers error messages, and problems with wiring and code. ## Done when - The robot does what you want, and each changed number is in `Tunables.java`. --- **Next:** [Tests](https://crossbotics.com/ftc-helper/docs/tests/): check your code and your robot after every change. **Look it up:** [Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/tunables/), [Troubleshooting](https://crossbotics.com/ftc-helper/docs/troubleshooting/). --- # Add a lift URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: a lift motor with an encoder, and hard stops at the top and the bottom. We recommend a touch switch at the bottom. In the robot configuration, call them `lift` and `lift_bottom`. ## 1. What it is A **lift** holds named heights. You send it to a height by its name, and it goes there and holds still. - **Heights are encoder counts.** An encoder is a sensor on the motor that counts how far the shaft has turned. 0 is the bottom, and bigger numbers are higher. - **It never goes past its safe range** (`min` to `max`). The library slows it down near both ends. - **It needs a known 0** (homing). An encoder counts only changes, so it does not know where the bottom is. - **With a switch at the bottom:** a press of the switch sets 0. Until the first press, the lift goes only down, at most 0.3 power, and the screen says `Lift: push it DOWN to the switch to home it`. Each later press fixes drift from a slipped belt or a skipped tooth. - **Without a switch:** 0 is where the lift is at INIT. Press INIT with the lift all the way down, every time, also in TeleOp after an autonomous that left it up ([Where 0 is](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#where-0-is)). **Hard stops and software limits:** `min` and `max` are software limits. The program stops the motor there. Software can be wrong (a bad number, a slipped encoder). So the lift also needs physical blocks at both ends. Set `min` and `max` just inside them. The rules also require this: the robot must stay inside its size limits without software (rule R105). ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field goes at the top of the class. The line goes in `define()`, after the drive. ```java title="Robot.java" // At the top of the class: public Lift lift; Here in define(): // "lift", "lift_bottom" = the motor's and the bottom switch's names in the robot configuration. // .part(...): which motor it is (optional, recommended). lift = add(Lift.slide("lift").part("gobilda-5203-435").bottomSwitch("lift_bottom")); ``` - `.part(...)` names the motor from the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). The number is on its label. **Why:** the library then starts the lift's numbers from that motor, and the simulator moves it like the real one. - `.bottomSwitch(...)` is the switch at the bottom. Until the lift has pressed it once, the lift goes only down, slowly. Leave it out when your lift has no switch. - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. ### Tunables.java: its numbers **Where:** `Tunables.java`, a new section. The section's name is the device's name in CamelCase: `"lift"` reads `Tunables.Lift`. ```java title="Tunables.java" public static class Lift { // "lift" in the configuration public static double min = MEASURE; // lowest safe point, counts (Motor Finder) public static double max = MEASURE; // highest safe point, counts (Motor Finder) public static double kP = DEFAULT; // push toward the target (from the motor) public static double kI = DEFAULT; // fix a small steady miss (0) public static double kD = DEFAULT; // brake near the target (from the motor) public static double kF = DEFAULT; // hold up against gravity (0.05) public static double down = MEASURE; // a named height, counts: any name you like public static double low = MEASURE; // a named height (Motor Finder) public static double high = MEASURE; // a named height (Motor Finder) } ``` - `MEASURE` means "find this on the robot". INIT stops until you write a number. **Why:** a guessed `max` can pull the lift off its rails. - `DEFAULT` means "use the library's starting value". The PID numbers (`kP` to `kF`) start from the motor in `.part(...)`. You tune them later (step 4). - `down`, `low` and `high` are **named heights**. Use any names you like. Every number in the section that is not a setting is a height. ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. A part has no buttons until you add them. ```java title="Controls.java" g2.a.press(() -> robot.lift.goTo("down")).says("down"); g2.x.press(() -> robot.lift.goTo("low")).says("low"); g2.y.press(() -> robot.lift.goTo("high")).says("high"); g2.dpadUp.press(robot.lift::stepUp).says("next height up"); g2.dpadDown.press(robot.lift::stepDown).says("next height down"); g2.leftStickY.use(robot.lift::manual).says("by hand"); ``` With one gamepad (`oneDriver = true`), these `g2` lines work on gamepad 1 ([One gamepad, and a second one when you want it](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#one-gamepad-and-a-second-one-when-you-want-it)). The left stick moves the lift by hand. When you let go, it holds there. ### Actions.java and autos: use it in steps You need no line here for the lift alone. When the lift works with another part, an action puts them in order. For example, with a claw ([Claw](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/)): **Where:** `Actions.java`, one method per action. ```java title="Actions.java" /** Lift up, open the claw, lift down: one step after the other. */ public static Action scoreHigh(Robot r) { return Action.named("Score high") .then(() -> r.lift.goTo("high")) .waitUntil("lift at the top", r.lift::isAtTarget, 2.0) // at most 2 s .then(r.claw::open) .waitSeconds(0.3) // let the piece drop .then(() -> r.lift.goTo("down")); } ``` An autonomous uses the same action as one step ([Actions.java](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/)). ## 3. Find its numbers INIT stops on `MEASURE`. The finders still run, because they do not read `Tunables.java`. 1. **Motor Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/)): put the lift at the bottom. Press **X** just above the bottom block (`min`) and **B** just below the top block (`max`). Press **A** at each height you want. 2. Put the numbers in `Tunables.Lift`. Give each P a real name (`P1` -> `low`, `P2` -> `high`). 3. When the Motor Finder says `Robot.java: add .reversed() to the "lift" part`, do that. It means the motor counts down as the lift goes up. ## 4. Check it, then tune it **Check it:** 1. Lift the wheels off the floor, and keep a hand near STOP. Put the lift at the bottom, on its switch. 2. Press INIT. Check that no warning names the lift. Press ▶. 3. Push gamepad 2's left stick up a little. The lift must go **up**. If it goes down, add `.reversed()`. 4. Press X, then Y, then A. The lift must reach and hold each height. **Tune it** with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/), while the robot runs. Change one number, then send the lift between its heights: 1. **kP:** raise it until the lift moves fast to each height. If it shakes, go back a step. 2. **kD:** if it goes past the height and comes back, raise it a little at a time. 3. **kF:** if it stops a little low and sags, raise it until it holds still. 4. **kI:** only if a small error stays, a very small number. Then put the tuned numbers in `Tunables.Lift`, in place of `DEFAULT`. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: `Tunables.Lift.max = MEASURE` | Not measured yet. Do step 3 | | The lift goes only down, slowly | Not homed yet. Push it down to the switch once | | Every height is too high (no switch) | It was not at the bottom at INIT. Lower it, and INIT again | | The lift goes down when it should go up | Add `.reversed()` to the lift in `Robot.java` | | It sags below a height | `kF` is too small | | It shakes at a height | `kP` or `kD` is too big | **Two motors on one lift:** name the second motor on the same line, `.alsoMotorReversed("lift_right")` ([Two motors](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#two-motors-on-one-lift-or-arm)). ## Done when - INIT shows no warning for the lift. - Each button sends the lift to its height, and it holds still there. - `min`, `max` and every height in `Tunables.Lift` are numbers, not `MEASURE`. --- **Next:** [Add an arm](https://crossbotics.com/ftc-helper/docs/add-to-robot/02-arm/), or the part you need next ([Add to your robot](https://crossbotics.com/ftc-helper/docs/add-to-robot/)). **Look it up:** [Lift](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/): every setting, number and command. --- # Add an arm URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/02-arm/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: an arm motor with an encoder, and hard stops at both ends of the swing. In the robot configuration, call the motor `arm`. ## 1. What it is An **arm** works like a [lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/), but in **degrees**, not encoder counts. You send it to an angle by its name, and it goes there and holds still. - **0 degrees is where the arm is at INIT.** So put the arm on its bottom stop before you press INIT. Then 0 is the same place each time ([Where 0 is](https://crossbotics.com/ftc-helper/docs/reference/parts/arm/#in-robotjava)). - **It never goes past its safe range** (`min` to `max`). Set them just inside the hard stops. The hard stops are still necessary: software can be wrong, and the robot must stay inside its size limits without software (rule R105). - **It needs its gear ratio.** The library changes motor turns to arm degrees with the motor from the catalog and `gearRatio`. **A servo at the end of the arm** that tilts a claw is a **wrist**. Add it after the arm: [Add a claw and other servo parts](https://crossbotics.com/ftc-helper/docs/add-to-robot/03-claw/). ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field (`public Arm arm;`) goes at the top of the class. The line goes in `define()`, after the drive. ```java title="Robot.java" // "arm" = the motor's name in the robot configuration. Its numbers: Tunables.Arm. // "gobilda-5203-117" = the motor's catalog id (needed: it works in degrees). // gearRatio: motor turns per arm turn. 0 degrees = where it is at INIT. arm = add(Arm.motor("arm", "gobilda-5203-117").gearRatio(2)); ``` - `"gobilda-5203-117"` names the motor from the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). The number is on its label. **Why:** the library needs the motor's counts per turn to work in degrees. - `.gearRatio(2)` means the motor turns 2 times for 1 turn of the arm. Count the teeth: the gear on the arm divided by the gear on the motor. With no gears between them, leave it out (1). - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. ### Tunables.java: its numbers **Where:** `Tunables.java`, a new section. The device `"arm"` reads `Tunables.Arm`. ```java title="Tunables.java" public static class Arm { // "arm" in the configuration public static double min = MEASURE; // lowest safe angle, degrees, 0 = at INIT public static double max = MEASURE; // highest safe angle, degrees (Motor Finder) public static double kP = DEFAULT; // push toward the target (0.02) public static double kI = DEFAULT; // fix a small steady miss (0) public static double kD = DEFAULT; // brake near the target (0.001) public static double kF = 0.1; // hold up against gravity (0) public static double stowed = MEASURE; // a named angle, degrees: any name you like public static double pickup = MEASURE; // a named angle (Motor Finder) public static double score = MEASURE; // a named angle (Motor Finder) } ``` - `MEASURE` means "find this on the robot". INIT stops until you write a number. - `DEFAULT` means "use the library's starting value" (the number in brackets). - `kF = 0.1` starts the arm with some push against gravity. An arm sags more than a lift. - `stowed`, `pickup` and `score` are **named angles**. Use any names you like. ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. A part has no buttons until you add them. ```java title="Controls.java" g2.rightStickY.use(robot.arm::manual).says("by hand"); ``` The operator's right stick moves the arm by hand. When you let go, it holds there. For each named angle, add a line on a free button, like the lift's: `g2.y.press(() -> robot.arm.goTo("score")).says("score");`. ### Actions.java and autos: use it in steps You need no line here for the arm alone. When the arm works with another part, an action puts them in order. It is the same as the lift's action: `goTo(...)`, then `waitUntil(..., r.arm::isAtTarget, ...)` ([the lift's example](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#actionsjava-and-autos-use-it-in-steps)). ## 3. Find its numbers INIT stops on `MEASURE`. The finders still run, because they do not read `Tunables.java`. 1. **Motor Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/)): put the arm on its bottom stop, then choose `arm`. Press **X** just above the bottom stop (`min`) and **B** just before the top stop (`max`). Press **A** at each angle you want. 2. **Change counts to degrees.** The Motor Finder shows encoder counts. `Tunables.Arm` takes degrees. Divide each count by the counts per degree: - counts per degree = the motor's counts per turn x `gearRatio` / 360. The counts per turn are in the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). - Example: `gobilda-5203-117` (1425.1 counts per turn) with `gearRatio(2)`: 1425.1 x 2 / 360 = 7.92. So 712 counts is 712 / 7.92 = 90 degrees. 3. Put the degrees in `Tunables.Arm`. Give each P a real name (`P1` -> `pickup`, `P2` -> `score`). 4. When the Motor Finder says to add `.reversed()` to the part, add it to the arm's line in `Robot.java`. It means the motor counts down as the arm goes up. ## 4. Check it, then tune it **Check it:** 1. Keep hands away from the arm's swing, and keep a hand near STOP. Put the arm on its bottom stop. 2. Press INIT. Check that no warning names the arm. Press ▶. 3. Push gamepad 2's right stick up a little. The arm must go **up**. If it goes down, add `.reversed()`. 4. Press each button for a named angle. The arm must reach and hold each angle. **Tune it** with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/), while the robot runs. Change one number, then send the arm between its angles: 1. **kF:** raise it until the arm holds still at a level angle, with no sag. Do this first: gravity pulls an arm hardest when it is level. 2. **kP:** raise it until the arm moves fast to each angle. If it shakes, go back a step. 3. **kD:** if it goes past the angle and comes back, raise it a little at a time. 4. **kI:** only if a small error stays, a very small number. Then put the tuned numbers in `Tunables.Arm`, in place of `DEFAULT`. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: `Tunables.Arm.max = MEASURE` | Not measured yet. Do step 3 | | Every angle is wrong by the same amount | The arm was not on its bottom stop at INIT. Put it there, and INIT again | | Every angle is too big or too small | A count was not changed to degrees, or `gearRatio` is wrong. Do step 3 again | | The arm goes down when it should go up | Add `.reversed()` to the arm in `Robot.java` | | It sags below an angle | `kF` is too small | | It shakes at an angle | `kP` or `kD` is too big | **Two motors on one arm:** name the second motor on the same line, `.alsoMotorReversed("arm_right")` ([Two motors](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#two-motors-on-one-lift-or-arm)). ## Done when - INIT shows no warning for the arm. - Each button sends the arm to its angle, and it holds still there. - `min`, `max` and every angle in `Tunables.Arm` are numbers in degrees, not `MEASURE`. --- **Next:** [Add a claw and other servo parts](https://crossbotics.com/ftc-helper/docs/add-to-robot/03-claw/). **Look it up:** [Arm](https://crossbotics.com/ftc-helper/docs/reference/parts/arm/): every setting, number and command. --- # Add a claw and other servo parts URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/03-claw/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: the servo, plugged into a servo port. In the robot configuration, call it `claw` (or `wrist`). ## 1. What it is A servo part holds **named positions**. A position is a number from 0 to 1. You send the servo to a position by its name. | Part | What it does | Its positions | | --- | --- | --- | | **Claw** | opens and closes | `open` and `closed` (both needed) | | **Wrist** | tilts a claw, for example at the end of an [arm](https://crossbotics.com/ftc-helper/docs/add-to-robot/02-arm/) | any names, for example `down`, `level`, `up` | | **Positioner** | any other servo with named positions: a gate, a kicker, a fold-out intake | any names, for example `stowed`, `deployed` ([a fold-out intake](https://crossbotics.com/ftc-helper/docs/add-to-robot/04-intake/#a-fold-out-intake)) | - **A servo cannot say where it is.** The library guesses when it has arrived, from `travelSec` (the time for a full move). - **A servo does not move until the first command after ▶.** - **Never let a servo push on something.** At a hard stop it gets hot and can strip its gears. The finder helps you find the positions just before the stops. ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field goes at the top of the class. The line goes in `define()`, after the drive. ```java title="Robot.java" // At the top of the class: public Claw claw; Here in define(): // "claw" = the servo's name in the robot configuration. Its numbers: Tunables.Claw. // .part(...): which servo it is (optional, recommended). claw = add(Claw.servo("claw").part("gobilda-2000-torque")); ``` - `.part(...)` names the servo from the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). **Why:** the library then takes `travelSec` from the servo's speed. - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. **A wrist** is the same line with `Wrist`: ```java title="Robot.java" // At the top of the class: public Wrist wrist; Here in define(): // "wrist" = the servo's name in the robot configuration. Its numbers: Tunables.Wrist. // .part(...): which servo it is (optional, recommended). wrist = add(Wrist.servo("wrist").part("gobilda-2000-speed")); ``` **A claw on two servos**, one for each finger: name the second servo on the same line. ```java title="Robot.java" // "claw_left", "claw_right" = the servos' names in the robot configuration. Numbers: Tunables.ClawLeft. // Find open and closed in Tune and check > Servo Finder on the FIRST servo: the second moves with it. // The servos face each other, so the second turns the other way: alsoServoReversed. claw = add(Claw.servo("claw_left").part("gobilda-2000-torque").alsoServoReversed("claw_right")); ``` Two servos that turn the same way use `.alsoServo(...)` ([Two servos on one part](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#two-servos-on-one-part)). **The servo's whole turn:** a servo turns a little less than its seller says, on the FTC normal range. `.fullRange()` gives it its whole turn. Add it **before** you find the positions: the same number points somewhere else after the range changes. ```java title="Robot.java" // fullRange(): positions 0 to 1 = the servo's whole turn (300 degrees on a goBILDA 2000). // Turn it on FIRST, then find the positions (Servo Finder: press Y while choosing the servo). wrist = add(Wrist.servo("wrist").part("gobilda-2000-speed").fullRange()); ``` ### Tunables.java: its numbers **Where:** `Tunables.java`, a new section. The section's name is the device's name in CamelCase: `"claw"` reads `Tunables.Claw`. ```java title="Tunables.java" public static class Claw { // "claw" in the configuration // The Servo Finder shows "Tunables.Claw: P1 = 0.210, P2 = 0.770": write P1 as open, P2 as closed. public static double open = MEASURE; // servo position, open (Servo Finder) public static double closed = MEASURE; // servo position, closed (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) } ``` The wrist's section has its own names. Every number except `travelSec` is a position: ```java title="Tunables.java" public static class Wrist { // "wrist" in the configuration public static double down = MEASURE; // servo position: any name you like public static double level = MEASURE; // servo position (Servo Finder) public static double up = MEASURE; // servo position (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) } ``` A claw on two servos takes the **first** servo's name, and has one more number, `alsoTrim`: ```java title="Tunables.java" // A claw on two servos, Claw.servo("claw_left").alsoServoReversed("claw_right"): its section is the // FIRST servo's name in CamelCase. public static class ClawLeft { // "claw_left" in the configuration public static double open = MEASURE; // servo position, open (Servo Finder on claw_left) public static double closed = MEASURE; // servo position, closed (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) public static double alsoTrim = DEFAULT; // the second servo: raw position added so the two meet (0; used at the next move) } ``` - `MEASURE` means "find this on the robot". INIT stops until you write a number. - `DEFAULT` means "use the library's starting value" (the number in brackets). ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. A part has no buttons until you add them. ```java title="Controls.java" g2.b.toggle(robot.claw).says("open / close"); ``` ```java title="Controls.java" g2.dpadLeft.press(robot.wrist::previous).says("previous position"); g2.dpadRight.press(robot.wrist::next).says("next position"); ``` - The operator's B opens and closes the claw. - D-pad left and right move the wrist to the next position, in order of value. To send it to one position, use `goTo`: `g2.x.press(() -> robot.wrist.goTo("level")).says("level");`. With one gamepad (`oneDriver = true`), these `g2` lines work on gamepad 1 ([One gamepad, and a second one when you want it](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#one-gamepad-and-a-second-one-when-you-want-it)). ### Actions.java and autos: use it in steps You need no line here for the claw alone. When the claw works with another part, an action puts them in order. For example, lift up, open the claw, lift down ([the lift's example](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#actionsjava-and-autos-use-it-in-steps)). A servo cannot say when it has arrived. So wait for it with `.waitUntil("claw done", r.claw::isDone, 1.0)`, or a short `.waitSeconds(...)`. ## 3. Find its numbers INIT stops on `MEASURE`. The finders still run, because they do not read `Tunables.java`. 1. **Servo Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/)): choose the servo. Find the two ends: press **X** just before one hard stop, and **B** just before the other. 2. Move to each position you need (open, closed) and press **A**. 3. Put the numbers in the servo's section. Give each P a real name: `P1` -> `open`, `P2` -> `closed`. **Two servos:** choose the **first** servo. The second moves with it. When the two sides do not meet, change `alsoTrim` in TeleOp, a little at a time. ## 4. Check it, then tune it **Check it:** 1. Keep fingers out of the claw. Press INIT. Check that no warning names the part. Press ▶. 2. Press B. The claw must open. Press B again. It must close. 3. Listen at each position. **A servo that hums or gets hot is pushing on something.** Move that position 0.01 away from the stop. 4. For a wrist: press D-pad right and left. It must go to each position in turn. **Tune it** with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/), while the robot runs. The positions change at once: 1. **`closed`:** close the claw on a game piece. It must hold the piece without humming. 2. **`open`:** wide enough to let the piece go, and no wider. A smaller move is a faster move. 3. **`travelSec`:** when an action goes on before the servo arrives, make it longer ([Timing travelSec](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#timing-travelsec)). Then put the tuned numbers in the servo's section, in place of the old ones. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: `Tunables.Claw.open = MEASURE` | Not measured yet. Do step 3 | | The servo does not move at all | No command after ▶ yet. Press its button. Still nothing? Check the port and the name in the robot configuration | | The servo hums or gets hot at a position | It pushes on a stop. Move that position 0.01 away | | The two fingers do not meet | Change `alsoTrim` in Live tuning | | The second servo fights the first | Change `.alsoServoReversed(...)` to `.alsoServo(...)`, or the other way | | Every position is a little off after a repair | The arm on the servo went on one tooth off ([Put an arm back on](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/#put-an-arm-back-on)) | | Every position is off after you added `.fullRange()` | The range changed. Find the positions again | | An action goes on before the claw has closed | `travelSec` is too short | ## Done when - INIT shows no warning for the part. - Each button sends the servo to its position. No servo hums at a position. - Every position in its section is a number, not `MEASURE`. --- **Next:** [Add an intake](https://crossbotics.com/ftc-helper/docs/add-to-robot/04-intake/). **Look it up:** [Claw](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/) (every setting, number and command for all servo parts), [Wrist](https://crossbotics.com/ftc-helper/docs/reference/parts/wrist/), [Positioner](https://crossbotics.com/ftc-helper/docs/reference/parts/positioner/). --- # Add an intake URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/04-intake/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: the intake motor (call it `intake` in the robot configuration), or two continuous-rotation servos (call them `left_intake` and `right_intake`). An intake needs no encoder. ## 1. What it is An **intake** has two jobs: **in** (take pieces) and **out** (push them back out). - **It runs on power, not to a position.** So it has no limits and no positions to measure. - **A continuous-rotation (CR) servo** spins all the way round, like a small motor. Set the servo to CR mode before you put it on (for a goBILDA servo, with its programmer). - **It can stop by itself when the robot is full.** That needs a count of the pieces ([Stop when full](#stop-when-the-robot-is-full)). ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field goes at the top of the class. The line goes in `define()`, after the drive. **On a motor:** ```java title="Robot.java" // At the top of the class: public Intake intake; Here in define(): // "intake" = the motor's name in the robot configuration. Its numbers: Tunables.Intake. // .part(...): which motor it is (optional, recommended). intake = add(Intake.motor("intake").part("gobilda-5203-1150")); ``` **Or on CR servos (one, two or more):** ```java title="Robot.java" // Two continuous-rotation (CR) servos. The one that spins the wrong way is reversed. // "intake", "intake_right" = the servos' names in the robot configuration. Numbers: Tunables.Intake (the 1st name). // .part(...): which servo it is (optional, recommended). intake = add(Intake.crServos("intake", "intake_right").part("gobilda-2000-speed") .reversed("intake_right")); ``` - `.part(...)` names the motor or servo from the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). **Why:** the simulator then spins it like the real one. - **One CR servo:** `intake = add(Intake.crServos("intake").part("gobilda-2000-speed"));`. Leave out `.reversed(...)`, or reverse that one servo when it spins out. - `.reversed("intake_right")`: two servos that face each other must spin opposite ways. Reverse the one that spins the wrong way. - **Add `.holds(n)`**, the number of pieces it carries: `.holds(3)`. Count them by hand: load pieces until no more fit. The simulator and the piece count use it. INIT warns when it is above the game's limit. - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. **Run from ▶:** some teams keep the intake on all match. Add `.onAtStart()`: ```java title="Robot.java" // Runs in from ▶ until stopped. Its button (operator RT) then switches it on/off. // .part(...): which motor it is (optional, recommended). add(Intake.motor("intake").part("gobilda-5203-1150").onAtStart()); ``` ### Tunables.java: its numbers **Where:** `Tunables.java`, a new section. The device `"intake"` reads `Tunables.Intake`. With CR servos, the section comes from the **first** name: `crServos("intake", "intake_right")` reads `Tunables.Intake`. ```java title="Tunables.java" public static class Intake { // "intake" in the configuration public static double inPower = DEFAULT; // power taking pieces in, 0 to 1 (1.0) public static double outPower = DEFAULT; // power pushing pieces out (0.7) } ``` Both numbers start at `DEFAULT`, so the intake works at once. Change them only when a test shows a problem (step 4). ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. A part has no buttons until you add them. ```java title="Controls.java" robot.intake.inOn(g2.rt); robot.intake.outOn(g2.lt); ``` `inOn` and `outOn` put "in" and "out" on a button the right way for your intake: | Your Robot.java | `inOn(g2.rt)` does | `outOn(g2.lt)` does | | --- | --- | --- | | plain | in while held | out while held | | `.onAtStart()` | a press switches it on and off | out while held | | `.stopsWhen(...)` | in while held; held 1 s = in anyway | out while held | With one gamepad (`oneDriver = true`), these `g2` lines work on gamepad 1 ([One gamepad, and a second one when you want it](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#one-gamepad-and-a-second-one-when-you-want-it)). ### Actions.java and autos: use it in steps You need no line in `Actions.java` for the intake alone. In an auto, a step turns it on or off: `.run("Intake in", robot.intake::in)`, and later `.run("Intake off", robot.intake::stop)` ([what an auto can do](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/)). ### A fold-out intake Some intakes fold out after ▶, on a servo. That servo is a **Positioner**, a servo with named positions ([servo parts](https://crossbotics.com/ftc-helper/docs/add-to-robot/03-claw/)). **Where:** `Robot.java`. The field (`public Positioner intakeDeploy;`) goes at the top of the class. The lines go in `define()`, after the intake line. ```java title="Robot.java" // Any servo with named positions: a gate, a kicker, a fold-out intake. // "intake_deploy" = the servo's name in the robot configuration. Numbers: Tunables.IntakeDeploy. // .part(...): which servo it is (optional, recommended). intakeDeploy = add(Positioner.servo("intake_deploy").part("gobilda-2000-torque")); // Right after ▶ (autonomous and TeleOp): fold the intake out. atStart(() -> Action.named("Deploy").then(() -> intakeDeploy.goTo("deployed"))); ``` **Where:** `Tunables.java`, a new section. Find both positions with the [Servo Finder](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/). ```java title="Tunables.java" public static class IntakeDeploy { // "intake_deploy" in the configuration public static double stowed = MEASURE; // servo position, folded (Servo Finder) public static double deployed = MEASURE; // servo position, folded out (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) } ``` The robot must fit its size limit at the start. So the fold-out waits for ▶. ### Stop when the robot is full The game limits how many pieces a robot holds (BIOBUZZ: 4, rule G407). The intake can stop by itself at that count. It needs `Pieces`, which counts the pieces with color sensors ([Pieces](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/)). Then add `.stopsWhen(...)` to your intake line: ```java title="Robot.java" // ADD .stopsWhen(...) to your intake line (no second intake line); the Pieces line goes above it. // .part(...): which motor it is (optional, recommended). intake = add(Intake.motor("intake").part("gobilda-5203-1150").stopsWhen(() -> pieces.isFull())); ``` - Pushing out still works when it is full. - When the count is wrong, the operator holds the in button for 1 s. Then it runs in anyway. - The Driver Station warns when `stopsWhen` has kept the intake from running in for more than 2 s. ## 3. Find its numbers An intake has no finder. Its two powers start at good values. Only `.holds(n)` needs a count: load pieces by hand until no more fit. ## 4. Check it, then tune it **Check it:** 1. Keep hands away from the rollers. Press INIT. Check that no warning names the intake. Press ▶. 2. Hold gamepad 2's RT. The rollers must pull a piece **in**. If they push it out, add `.reversed()` to the intake line in `Robot.java`. 3. Hold LT. The rollers must push the piece **out**. 4. Two CR servos: both must spin toward the inside. If one fights the other, reverse that one with `.reversed("its name")`. **Tune it** with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/), while the robot runs. Feed it pieces, and change one number at a time: 1. **`inPower`:** lower it when pieces jam or bounce out. Keep it as high as you can for fast pickup. 2. **`outPower`:** raise it when pieces do not come out. Then put the tuned numbers in `Tunables.Intake`, in place of `DEFAULT`. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | It pushes out when it should take in | Add `.reversed()` to the intake in `Robot.java` | | One CR servo fights the other | Reverse that servo: `.reversed("intake_right")` | | A CR servo goes to one place and stops | It is not in CR mode. Set it with the servo's programmer | | Pieces jam or bounce out | `inPower` is too big | | Pieces do not come out | `outPower` is too small | | It does not run in, and the screen says it is full | `stopsWhen` says full. Hold the in button 1 s to run in anyway. Then check the piece count | | INIT warns about `holds` | `.holds(n)` is above the game's limit | ## Done when - INIT shows no warning for the intake. - RT takes a piece in, and LT pushes it out. - `.holds(n)` is on the intake line, with the number you counted. --- **Next:** [Add a launcher](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/). **Look it up:** [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/): every setting, number and command. --- # Add a launcher URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: a flywheel motor with an encoder, and a feeder (a servo arm, a CR servo wheel or a motor). In the robot configuration, call them `launcher` and `indexer`. - Safety glasses, and nobody in front of the launcher when the wheel spins. ## 1. What it is A **launcher** spins a wheel to a speed, and feeds a piece only when the wheel is at that speed. - **The speed is in RPM** (turns a minute). The library needs the motor's catalog id to know its top speed. - **The feeder pushes one piece at a time** into the wheel. The launcher tells it when. - **It never feeds into a slow wheel.** It waits until the speed is within `readyBandRpm`. When the wheel is not ready within 3 s, it gives up the shot and says why: `Launcher gave up: flywheel`. - **It spins up at ▶** when it has a feeder of its own, so the first shot does not wait. ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field goes at the top of the class (`public Launcher launcher;`). The line goes in `define()`, after the drive. ```java title="Robot.java" // A flywheel (in RPM) and the indexer that feeds it one piece at a time. // "launcher", "indexer" = names in the robot configuration. Numbers: Tunables.Launcher, .Indexer. // The motor's catalog id is in the brackets (needed). The indexer's .part(...) is optional, recommended. launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed"))); ``` - The motor's catalog id (`"gobilda-5203-6000"`) is needed. The number is on the motor's label ([parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/)). - `.feeder(...)` is the part that pushes the pieces in. `Indexer.servo` is a servo arm. Use `Indexer.crServo(name)` for a CR servo wheel, or `Indexer.motor(name)` for a motor ([Indexer](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/)). - **Two arms** that pinch the piece from both sides: `Indexer.servo("feeder_left").alsoServoReversed("feeder_right")`. Both arms use the same `rest` and `push`. - **Two wheels** that squeeze the piece from both sides: `Indexer.crServo("feeder_left").alsoServoReversed("feeder_right")`. Both CR servos get the same `power`, and the second spins the other way. Add `.feedWheelOutWith(intake)` to run them backward while the intake pushes out. - **A wheel and an arm:** a CR servo wheel brings each piece up, and the arm pushes it in. Write the arm as the feeder, and add `.feedWheel(Indexer.crServo("feeder_wheel"))` ([Feed wheel](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#feed-wheel)). - **A motor that is not in the catalog:** write `Motors.custom("my-motor", 28, 5800)` in place of the id (counts per turn, then top RPM). - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. **A feed stop, and an intake that pushes the pieces in.** Add these only when your robot has them: **Where:** `Robot.java`, in `define()`. The intake line goes **before** the launcher line ([Add an intake](https://crossbotics.com/ftc-helper/docs/add-to-robot/04-intake/)). ```java title="Robot.java" intake = add(Intake.motor("intake")); // first: the launcher's pushedBy(...) needs it launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feedStop("feed_stop", "gobilda-2000-speed") // a servo that holds the pieces back .pushedBy(intake)); // the intake pushes each piece into the wheel ``` - `.feedStop(servo, part)`: a servo that holds the pieces back until a shot is allowed. The servo's catalog id is optional. With it, the Feed Stop Finder works out how long the stop takes to open. - `.pushedBy(intake)`: for each piece, the intake runs in for a short time (`assistSec`, 0.25 s), even when the driver has it off. - **A hood** changes the shot angle. Add `.hood(Hood.servo("hood"))` to the launcher line ([Hood](https://crossbotics.com/ftc-helper/docs/reference/parts/hood/)). ### Tunables.java: its numbers **Where:** `Tunables.java`, two new sections. A section's name is the device's name in CamelCase: `"launcher"` reads `Tunables.Launcher`, and `"indexer"` reads `Tunables.Indexer`. ```java title="Tunables.java" public static class Launcher { // "launcher" in the configuration public static double speedRpm = DEFAULT; // shot speed without the table (60% of top) public static double stepRpm = DEFAULT; // speed change per D-pad press (100) public static double readyBandRpm = DEFAULT; // "at speed" = this close to the target (60) public static double idleRpm = 1500; // spins between shots: quicker first shot (0) public static double shotIntervalSec = DEFAULT; // least time between two pieces (0.25) // The hub's speed control: the defaults for the motor until the Flywheel Finder (INIT shows them). // Then write the Finder's numbers in their place. public static double kP = DEFAULT; // push per speed error (kF / 10) public static double kI = DEFAULT; // fix a steady error (kP / 10) public static double kD = DEFAULT; // brake changes (0) public static double kF = DEFAULT; // steady power for a speed (from the motor) // {inches to the goal, RPM}, blended between rows. Example rows: write the Shot Tuner's instead. public static double[][] speedByDistance = {{24, 2200}, {48, 2550}, {72, 2900}, {96, 3250}}; } ``` ```java title="Tunables.java" public static class Indexer { // "indexer" in the configuration public static double rest = MEASURE; // servo position, out of the way (Servo Finder) public static double push = MEASURE; // servo position, piece pushed (Servo Finder) public static double pushSec = DEFAULT; // time to push (0.25, or the servo's speed) public static double returnSec = DEFAULT; // time to come back (the same as pushSec) } ``` - `DEFAULT` means "use the library's starting value". The speed gains (`kP` to `kF`) start from the motor in `Launcher.flywheel(...)`. INIT says `Starting gains (worked out, not tuned)` until you write your own. - `speedRpm` is the shot speed. Its starting value is 60% of the motor's top speed. - `speedByDistance` is the **shot table**: a speed for each distance to the goal. The launcher uses it only with a camera or odometry (`.speedFromDistance(camera)`, [Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/)). Until then, it uses `speedRpm`. - `rest` and `push` are `MEASURE`: INIT stops until you write them (step 3). - **With a feed stop:** add `feedStopHold`, `feedStopRelease`, `feedStopMoveSec` and `feedStopOpenSec` to `Tunables.Launcher`. The Feed Stop Finder gives all four. ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. A part has no buttons until you add them. ```java title="Controls.java" robot.launcher.spinOn(g2.lb); robot.launcher.fireOn(g2.rb); robot.launcher.speedOn(g2.dpadUp, g2.dpadDown); robot.launcher.tableOn(g2.dpadRight); ``` | Button | What it does | | --- | --- | | LB | spins up, or spins down | | RB | a tap fires one piece. More taps fire more pieces. Held, it keeps firing | | D-pad up / down | the speed + / - `stepRpm`. With a shot table, the speed trim + / - 1% | | D-pad right | the next shot table (only with two tables or more) | With one gamepad (`oneDriver = true`), these `g2` lines work on gamepad 1 ([One gamepad, and a second one when you want it](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#one-gamepad-and-a-second-one-when-you-want-it)). **How it fires:** - **A tap of RB is CAREFUL:** each piece waits until the wheel is at speed, and `shotIntervalSec` after the last piece. - **RB held is QUICK:** the first piece waits the same way. The next ones go a little sooner. Let go, and no more pieces go. - **Many quick taps** line up shots, at most `maxFiringQueue` (4). More taps do nothing. A nervous driver who taps 10 times does not get 10 shots. - **SPRAY** does not wait for the speed. It is off until you set `sprayEnabled = true`. Then tap RB, press it again and hold it: the launcher empties the robot fast. In the last seconds of a period, the launcher picks SPRAY by itself. - **It spins up at ▶** when it has a feeder or a feed stop. A launcher that only the intake feeds (`pushedBy` only) waits for LB. Change it with `spinAtStart = true` or `false` in `Tunables.Launcher`. - **Other buttons:** `robot.launcher.fireOn(g2.y);` puts the fire job on Y. Do not give the fire button a double tap or a long press of your own. With one, a quick press waits to see the gesture, and does not fire at once. Every setting: [Firing: shot modes](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#firing-shot-modes-feed-stop-piece-path). ### Actions.java and autos: use it in steps When the intake must run while the launcher fires, an action puts them together. **Where:** `Actions.java`, one method per action. ```java title="Actions.java" /** Fires 3 pieces with the intake running, to push each one in. Then the intake stops. */ public static Action fireWithIntake(Robot r) { return Action.named("Fire with intake") .then(r.intake::in, () -> r.launcher.fire(3)) .waitUntil("the shots", () -> !r.launcher.isShooting(), 9.0) .then(r.intake::stop); } ``` **Where:** `Controls.java`, inside `buttons(...)`. A button runs the action. The second line is a ready-made action: it needs nothing in `Actions.java`. ```java title="Controls.java" g2.y.press(Actions.fireWithIntake(robot)).says("fire 3 with the intake"); g2.x.press(robot.launcher.fireAllAction()).says("fire all"); // a ready-made action ``` **Where:** an autonomous in `autos/`. The wheel spins up while the robot drives to the shooting spot. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .alongside(robot.launcher.readyAction(3)) // spin up while it drives .forward("To the shooting spot", 24, 0.5) .action(Actions.fireWithIntake(robot), 9) // waits until it is done (at most 9 s) .right("Park", 12, 0.5); ``` **With no camera:** the launcher has no distance, and shoots at `speedRpm`. An auto that shoots from two spots gives each spot its own speed: `.action(robot.launcher.fireAllAction(2250))` fires every piece at 2250 RPM, then goes back to `speedRpm`. ## 3. Find its numbers INIT stops on `MEASURE`. The finders still run, because they do not read `Tunables.java`. 1. **Servo Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/)): find the indexer's two positions. `rest` is out of the way. `push` has pushed a piece into the wheel. Put them in `Tunables.Indexer`. 2. **Flywheel Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/)): it finds the speed gains and the recovery time after a shot. Until then, the wheel runs on starting gains from the motor, and INIT says so: `Launcher: defaults from the catalog (gobilda-5203-6000): kF 11.7, ...`. Put the gains line in `Tunables.Launcher`. Make `shotIntervalSec` a little longer than the recovery time. Feed 10 pieces and read "Shots seen": it must show 10. Fewer: see `shotDropRpm` in [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#in-tunablesjava). 3. **Feed Stop Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-stop-finder/)), only with a feed stop: the hold and release positions, and the firing times. With a CR servo or motor feeder and no feed stop, pushing parts or feed wheel: the **Feed Time Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/07-feed-time-finder/)) instead. Its test shots give `feedSec`. 4. **Hood Finder** ([how](https://crossbotics.com/ftc-helper/docs/tuning/04-hood-finder/)), only with a hood: the hood's two stops. 5. **Shot Tuner** ([how](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/)), after the camera or the odometry: the shot table. ## 4. Check it, then tune it **Check it:** 1. Put on safety glasses. Keep everybody out of the front of the launcher. 2. Press INIT. Check that no warning names the launcher or the indexer. Press ▶. 3. Press LB to spin up. Read the speed on the Driver Station. It must reach the speed and stay there. 4. Press LB to stop the wheel. Load the pieces by hand. Keep your hands away from the wheel once it spins. 5. Spin up, then tap RB. The feeder must push **one** piece for each tap. **Tune it** with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/), while the robot runs: 1. **speedRpm:** change it until the shots land where you want, from your usual shooting spot. 2. **The feeder:** when it pushes two pieces at once, make `pushSec` shorter. When the piece does not reach the wheel, move `push` further. Then put the tuned numbers in `Tunables.java`, in place of `DEFAULT`. ## More for your launcher Add these when your robot needs them. ### Two kinds of pieces: two shot tables Two pieces that fly differently need two speeds for the same distance. BIOBUZZ has POLLEN (a 2.8 in ball) and NECTAR (a 3.6 in ball). Each `speedByDistance...` line in `Tunables.Launcher` is a table, and the part after `speedByDistance` is its name: **Where:** `Tunables.java`, in `Tunables.Launcher`, in place of the `speedByDistance` line. ```java title="Tunables.java" public static double[][] speedByDistancePollen = {{36, 1970}, {48, 2250}, {60, 2520}, {72, 2790}}; public static double[][] speedByDistanceNectar = {{24, 2400}, {48, 2800}, {72, 3200}, {96, 3600}}; ``` - `.startTable("pollen")` on the launcher's line in `Robot.java` picks the table at ▶. - **Change the table:** D-pad right picks the next table (`tableOn`, above). Or one button for each piece: `g2.x.press(() -> robot.launcher.useTable("pollen"));`. In an action: `.then(() -> r.launcher.useTable("nectar"))`. - The Driver Station shows the table: `Shot table : POLLEN, 48 in (camera)`. - The [Shot Tuner](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/) fills each table: press Y until `> Table`, and pick it with the D-pad. ### Speed trim and a low battery In some matches every shot lands a little short or long (a worn wheel, soft balls). With a shot table, D-pad up and down make every shot 1% faster or slower. Hold it for more. Double-tap D-pad down to go back to 0. The Driver Station shows `Speed trim : +3% READY`. - The trim starts at 0 at every INIT. At INIT, the Driver Station offers the last trim: double-tap D-pad up after ▶ to use it. - **The same trim match after match:** the table is off. Multiply each speed in the table by the trim (+3%: x 1.03), put the new line in `Tunables.java`, and go back to no trim. - **A low battery** makes the wheel slow to get back to speed after a shot. Under 11.5 V the Driver Station warns. Swap the battery. Battery compensation is off, and not yet tested on a robot ([Speed trim and battery compensation](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#speed-trim-and-battery-compensation)). ### A hood: the shot angle A **hood** is the curved plate over the flywheel. It sets how steep the piece leaves. Near the goal, a steep shot drops in. Far away, a flatter shot goes further. With a hood, each row of a shot table has a third number: `{48, 2550, 11}` (inches, RPM, hood angle). **Where:** `Robot.java`, the launcher's line. The `.hood(...)` line is new. Add `import com.crossbotics.ftchelper.robot.Hood;`. ```java title="Robot.java" // The hood goes on the launcher; its numbers are in Tunables.Hood. // .part(...): which servos they are (optional, recommended). launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .hood(Hood.servo("hood").part("gobilda-2000-torque")) .speedFromDistance(camera)); ``` **Where:** `Tunables.java`, a new section, `Tunables.Hood`. ```java title="Tunables.java" public static class Hood { // "hood" in the configuration // posA and posB: the servo positions a hair off the hood's two hard stops. Never past them. public static double posA = MEASURE; // servo position at stop A (Hood Finder) public static double posB = MEASURE; // servo position at stop B (Hood Finder) // Optional: the hood's angle at each stop (any scale, e.g. 0 = steep end, 30 = flat end). public static double angleA = MEASURE; // the angle at stop A (an angle app) public static double angleB = MEASURE; // the angle at stop B (an angle app) public static double travelSec = DEFAULT; // stop to stop, seconds (0.5, or the servo's) public static double startAngle = DEFAULT; // where it goes at ▶ (angle A) } ``` - **`posA` and `posB` are the hood's two hard stops.** The hood never goes past them, because a servo that pushes on a stop gets hot and breaks. The [Hood Finder](https://crossbotics.com/ftc-helper/docs/tuning/04-hood-finder/) finds them. - **The launcher waits for the hood.** A servo cannot say where it is, so the launcher waits `travelSec` for a stop-to-stop move (`Launcher waits for: hood`). A piece fired while the hood moves flies wrong. - **By hand:** gamepad 2's left stick moves the hood. With a shot table, it trims the hood angle. Use the speed trim for shots that are short or long. Use the hood trim for shots that arrive at the wrong slope. - The [Shot Tuner](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/) finds the speed and the hood angle together: press Y until `> Hood`. Every setting, a linkage and a motor hood: [Hood](https://crossbotics.com/ftc-helper/docs/reference/parts/hood/). ### Know which piece fires next Two color sensors let the robot count what it holds and know the next piece: one where the pieces come in, and one at the "ready to fire" place. Then the next piece picks the shot table, and the drivers do not switch tables by hand. **Where:** `Robot.java`, in `define()`, **before** the launcher line (the launcher uses `pieces`). The field goes at the top of the class (`public Pieces pieces;`). ```java title="Robot.java" pieces = add(Pieces.kinds("POLLEN", "RED_NECTAR", "BLUE_NECTAR") .comingIn(PieceSensor.color("intake_color")) .readyToFire(PieceSensor.color("ready_color")) .max(4)); ``` Then add these two lines to the launcher's line: ```java title="Robot.java" .tableFrom(pieces.nextKind()) // the next piece picks the table .tableFor("nectar", "RED_NECTAR", "BLUE_NECTAR") // both NECTAR colors use "nectar" ``` - The [Piece Tuner](https://crossbotics.com/ftc-helper/docs/tuning/14-piece-tuner/) measures each kind's color. Until then, a piece reads `UNKNOWN`, and an `UNKNOWN` piece keeps the table in use. - The count can be wrong (two pieces that touch, a piece that bounces out). The drivers, not the count, keep the robot to its piece limit. Every sensor and command: [Pieces](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/). ### Try it in the simulator The goBILDA starter bot has a measured simulator robot. **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:run -PteamCode=none -Probot=sim/robots/starter-bot-gobilda.properties ``` Open http://localhost:8780, choose "goBILDA Bot TeleOp", press INIT, then ▶. Tap LB and watch the speed go up, then tap RB. Tap RB before the wheel is at speed, and the piece waits. The turret and camera robots: [Add a camera: Try it in the simulator](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/#try-it-in-the-simulator). ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: `Tunables.Indexer.rest = MEASURE` | Not measured yet. Do step 3 | | INIT stops: `speedRpm` is above the motor's top speed | The number is too high for that motor, or the catalog id is wrong | | `Launcher gave up: flywheel` | The wheel never got to its speed. Check the encoder cable, run the Flywheel Finder, or lower `speedRpm` | | INIT: `Launcher fire one; hold: keep firing: no button (G2 RB is your "..." in Controls.java)` | One of your own jobs is on the launcher's button. Move your job to a free button | | Two pieces go in at once | The feeder runs too long. Lower `pushSec` | | The wheel spins the wrong way | Add `.reversed()` to the launcher in `Robot.java` | | `Launcher gave up: turret aimed` | The goal is not in view, or out of the turret's range, or `tolerance` is too small | | `Launcher: no shot table "nectr"` | No `speedByDistance...` line has that name. The warning lists the names there | | Shots short (or long) in every match | Trim with the D-pad. If you need the same trim again and again, tune the table again | | INIT stops: `Tunables.Hood has no posA` | Run the Hood Finder, and put its line in `Tunables.Hood` | | `Launcher waits for: hood`, and it never fires | `travelSec` is very long, or a motor hood cannot reach the angle | | INIT stops: `the row at 48 in has hood 30, outside the hood's range` | A table row asks past a stop. Fix the row, or the stops | | `battery 11.2 V: low` | Swap the battery. A low battery makes the wheel slow to get back to speed | ## Done when - INIT shows no warning for the launcher or the indexer. - LB spins the wheel up, and the speed holds. - Each tap of RB fires one piece. - The gains line from the Flywheel Finder is in `Tunables.Launcher`. --- **Next:** [Add a turret](https://crossbotics.com/ftc-helper/docs/add-to-robot/06-turret/), or [Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/) when your robot has no turret. **Look it up:** [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/): every setting, number and command. --- # Add a turret URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/06-turret/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: a turret turned by a motor with an encoder, and hard stops at both ends. In the robot configuration, call the motor `turret`. - To follow the goal: a camera ([Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/)). ## 1. What it is A **turret** turns to an angle and holds it. With a camera, it follows the goal by itself. - **Angles are in degrees.** 0 is straight forward. Counterclockwise (to the left, seen from above) is +. - **It never turns past its range** (`min` to `max`). When the goal is outside, it waits at the limit, and the Driver Station says `goal out of turret range`. - **It needs a known 0.** Without a switch, 0 is where the turret points at INIT. Put it straight forward by hand before every INIT. A home switch finds 0 by itself at ▶. **Hard stops and software limits:** `min` and `max` are software limits. They are your wires' limits too. Software can be wrong, so the turret also needs physical blocks at both ends. Teams build turrets in many ways. This page adds a motor turret. For a servo, a CR servo, a slip ring or a home switch, see [Your turret is different](#your-turret-is-different) below. ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field goes at the top of the class (`public Turret turret;`). The line goes in `define()`, after the camera line. ```java title="Robot.java" // The camera knows the goal of each alliance (BLUE first, then RED). camera = add(Camera.limelight("limelight").goal("BLUE SCORING", "RED SCORING")); // "turret" = the motor's name in the robot configuration. 5 motor turns per turret turn. // follows(camera): it follows the goal from ▶, but never past Tunables.Turret min and max. turret = add(Turret.motor("turret", "gobilda-5203-117").gearRatio(5).follows(camera)); ``` - `.gearRatio(5)`: how many turns the motor makes for one turn of the turret. Count the teeth: turret gear / motor gear. A 20-tooth gear on a 100-tooth ring is 5. - `.follows(camera)`: the turret follows the goal from ▶. **With no camera yet:** leave out the camera line and `.follows(camera)`. Add them on [Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/). - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. ### Tunables.java: its numbers **Where:** `Tunables.java`, a new section. The section's name is the device's name in CamelCase: `"turret"` reads `Tunables.Turret`. ```java title="Tunables.java" public static class Turret { // "turret" in the configuration public static double min = MEASURE; // furthest right, degrees (Motor Finder) public static double max = MEASURE; // furthest left, degrees: 0 = forward, + = left public static double startAngle = DEFAULT; // where you set it by hand before INIT (0) public static double kP = DEFAULT; // push per degree off (0.02) public static double kD = DEFAULT; // brake near the target (0.001) public static double maxPower = DEFAULT; // the most power (0.8) public static double tolerance = DEFAULT; // "aimed" within this, degrees (1.0) public static double cameraOffset = DEFAULT; // aims a little to one side: Aim Tuner (0) } ``` - `MEASURE` means "find this on the robot". INIT stops until you write a number. **Why:** a guessed range can pull the wires off. - `DEFAULT` means "use the library's starting value". You tune `kP` and `kD` later (step 4). - `cameraOffset` comes from the Aim Tuner, after the camera. ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. A part has no buttons until you add them. ```java title="Controls.java" g2.rightStickX.use(v -> robot.turret.manual(-v)).says("by hand (right = clockwise)"); g2.rightStickButton.toggle(robot.turret.followMode()).rumble().says("follow the goal on/off"); // only with follows(...) ``` The operator's right stick turns the turret by hand. A click of the same stick switches following on and off: 2 buzzes = on, 1 buzz = off. **With one gamepad** (`oneDriver = true`): the stick click is also the library's field-centric button. Move field-centric first ([Turret: Buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/#buttons-to-add)). ### Actions.java and autos: use it in steps You need no line here for a turret that follows the goal. The launcher can wait until the turret is aimed. Add this to the launcher's line in `Robot.java`: **Where:** `Robot.java`, at the end of the launcher's line, before the `);`. ```java title="Robot.java" .requireReady("turret aimed", () -> turret.isAimed()) ``` For a turret that follows the goal, "aimed" means **at the goal now**. The robot sees the goal (camera or odometry), and the turret is in range and on it. When the robot loses the goal, the turret is not aimed. So the launcher never fires blind. To point it at an angle in an action, use `r.turret.aimAt(45)`. It stops following. ### Your turret is different **A home switch** (a touch sensor or a magnetic switch). At ▶ the turret turns slowly until it finds the switch. Then its angle is right, even when someone turned it by hand. ```java title="Robot.java" // "turret", "turret_home" = the motor's and the home switch's names in the robot configuration. // At ▶ the turret turns slowly until it finds the switch. turret = add(Turret.motor("turret", "gobilda-5203-312").gearRatio(2.75) .homeSwitch("turret_home") .follows(camera)); ``` ```java title="Tunables.java" public static class Turret { // "turret" in the configuration public static double min = MEASURE; // furthest right, degrees (Motor Finder) public static double max = MEASURE; // furthest left, degrees: 0 = forward, + = left public static double homeAngle = MEASURE; // where the switch closes (turret-setup.md) public static double homingPower = DEFAULT; // how slowly it looks for the switch (0.2) public static double homingTimeout = DEFAULT; // the most seconds it looks (5) } ``` **A servo turret.** A servo goes to a position by itself. It uses two servo positions and the turret's angle at each. It has no PID numbers and no homing. ```java title="Robot.java" // "turret" = the servo's name in the robot configuration. Numbers: Tunables.Turret. // fullRange(): the servo's whole turn. Turn it on BEFORE you measure posA and posB. turret = add(Turret.servo("turret").part("gobilda-2000-speed").fullRange().follows(camera)); ``` ```java title="Tunables.java" public static class Turret { // "turret" in the configuration // Two servo positions and the turret's angle at each: 0 = straight forward, counterclockwise // (left) +. Its range is between the two angles. public static double posA = MEASURE; // servo position at one end (Servo Finder) public static double angleA = MEASURE; // the turret's angle there (an angle app) public static double posB = MEASURE; // servo position, other end (Servo Finder) public static double angleB = MEASURE; // the turret's angle there (an angle app) public static double travelSec = DEFAULT; // posA to posB, seconds (0.6, or the servo's) public static double startAngle = DEFAULT; // sent here at ▶ (0) } ``` **A slip ring** (the turret turns round and round). A CR servo turns it, and an absolute encoder says where it points. ```java title="Robot.java" // A CR servo turns it, an absolute encoder says where it points, continuous(): no limits. // "turret", "turret_pos" = the servo's and the encoder's names in the robot configuration. // .part(...): which servo it is (optional, recommended). turret = add(Turret.crServo("turret").part("axon-max-mk2").analogEncoder("turret_pos").continuous() .follows(camera)); ``` ```java title="Tunables.java" public static class Turret { // "turret" in the configuration // No min and max: it turns round and round. public static double kP = 0.015; // push per degree off, CR servo (0.02) public static double kD = DEFAULT; // brake near the target (0.001) public static double maxPower = 1.0; // a CR servo's full speed (0.8) public static double tolerance = DEFAULT; // "aimed" within this, degrees (1.0) public static double encoderOffset = MEASURE; // encoder reading, pointing forward } ``` [Setting up a turret](https://crossbotics.com/ftc-helper/docs/guides/turret-setup/) has every way to build a turret, with the lines for each. **It can hit another part** (a lift, an arm): write an interlock rule. While the lift is up, the turret stays out of its way ([Interlock](https://crossbotics.com/ftc-helper/docs/reference/parts/interlock/)). ## 3. Find its numbers INIT stops on `MEASURE`. 1. **`min` and `max`:** turn the turret by hand to where the wires are tight, both ways. Take a few degrees less. Measure the angle from straight forward with a phone angle app. 2. **`homeAngle`** (a home switch): remove the `.homeSwitch(...)` line. Put the turret straight forward, press INIT, then ▶. Turn it with the stick until the switch clicks. Read the angle on the Driver Station (`Turret : 43 deg`). That is `homeAngle`. Then add the line again. 3. **`posA`, `posB`, `angleA`, `angleB`** (a servo turret): the [Servo Finder](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/) gives the two positions. Measure the turret's angle at each with a phone angle app. 4. **`encoderOffset`** (an absolute encoder): put the turret straight forward, press INIT, and read the encoder's degrees. 5. **`cameraOffset`:** the [Aim Tuner](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/), after the camera. ## 4. Check it, then tune it **Check it:** 1. Put the turret straight forward by hand. Press INIT. Check that no warning names the turret. Press ▶. 2. Push gamepad 2's right stick to the right. The turret must turn **clockwise**. If it turns the other way, add `.reversed()`. 3. Turn it to each end with the stick. It must stop before the hard stops. 4. With a camera: click the right stick to turn following on. Point the robot at the goal. The Driver Station must say `following: camera`, then `AIMED`. **Tune it** with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/), while the robot runs. Change one number, then let the turret follow the goal: 1. **kP:** raise it until the turret aims fast. If it shakes, go back a step. 2. **kD:** if it goes past the goal and comes back, raise it a little at a time. 3. **kI:** only if it stops a degree short, a very small number. Then put the tuned numbers in `Tunables.Turret`, in place of `DEFAULT`. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: `Tunables.Turret.min = MEASURE` | Not measured yet. Do step 3 | | The turret turns away from the goal | Add `.reversed()` to the turret in `Robot.java` | | Every angle is off by the same amount | It did not point at `startAngle` at INIT. Use a mark, or add a home switch | | The angles are wrong | `.gearRatio(...)` is wrong (count the teeth again), or it did not point forward at INIT | | `goal out of turret range` | The goal is past `min` or `max`. Turn the robot | | `goal out of turret range (behind the robot: holding)` | The odometry says the goal is far behind. The turret holds where it points. Turn the robot toward the goal | | `homing failed: switch not found` | Homing turns the wrong way: set `homeDirection` (+1 or -1) | | INIT: `Turret : no angle from a program before: ...` | Turn it to `startAngle` by hand, then INIT again | | It is aimed, but the shots go wide by the same angle | The camera is beside the launcher. Run the Aim Tuner (`cameraOffset`) | ## Done when - INIT shows no warning for the turret. - The stick turns the turret, and it stops before both hard stops. - `min`, `max` and every other `MEASURE` in `Tunables.Turret` are numbers. - With a camera: the turret follows the goal and shows `AIMED`. --- **Next:** [Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/). **Look it up:** [Turret](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/): every setting, number and command. --- # Add a camera URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot: a Limelight 3A or a webcam. In the robot configuration, call it `limelight` (or `Webcam 1` for a webcam). - AprilTags to look at: the field's goal, or printed tags. - For a Limelight: a laptop and the Limelight's USB-C cable. ## 1. What it is A **camera** finds the goal and says how far away it is and in which direction. AprilTags are the square black-and-white codes on the field. - **It knows each alliance's goal.** `.goal("BLUE SCORING", "RED SCORING")` names each alliance's HIVE. The camera gives this match's goal only, never the other alliance's. - **It aims only at the up CELL.** In BIOBUZZ, teams can score only in the CELL whose tags read right side up. The camera never aims at a down CELL. - **Everything that aims uses it:** a turret that follows the goal, the launcher's speed from the distance, whole-robot aim and the aim buzz. - **It tests the light at INIT.** Each place has different light. The camera tries a few settings and keeps the one that sees the most tags. ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field goes at the top of the class (`public Camera camera;`). The line goes in `define()`, after the drive and **before** the parts that use it (a turret, a launcher). ```java title="Robot.java" // In INIT the Limelight tries these pipelines (your usual one FIRST) and keeps the best one. camera = add(Camera.limelight("limelight").autoPipelines(0, 1, 2).goal("BLUE SCORING", "RED SCORING")); // A webcam: Camera.webcam("Webcam 1").autoExposure().goal(...) tries the camera's own // exposure, then 3, 6 and 12 ms. ``` - `.autoPipelines(0, 1, 2)`: the lighting test at INIT. A **pipeline** is a set of camera settings that you save on the Limelight by number. Put your usual one first, because it wins a tie. - A webcam: `Camera.webcam("Webcam 1").autoExposure()`. It tries exposures in place of pipelines. - A webcam mounted upside down: add `.upsideDown()`, like `Camera.webcam("Webcam 1").upsideDown().autoExposure()`. Without it, the robot aims the wrong way ([A webcam upside down](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#a-webcam-upside-down)). - A HuskyLens works too, with fewer features: no lighting test, and a rough distance ([Camera: A HuskyLens](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#a-huskylens)). - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. **Use it in the other parts.** Add `.follows(camera)` to the turret ([Add a turret](https://crossbotics.com/ftc-helper/docs/add-to-robot/06-turret/)). Add `.speedFromDistance(camera)` to the launcher, so its speed comes from the shot table: **Where:** `Robot.java`, at the end of the launcher's line, before the `);`. ```java title="Robot.java" .speedFromDistance(camera) ``` **Fire only when aimed** (no turret): add this check to the launcher's line too. It feeds a piece only when the camera sees the goal now and the robot points at it. So the robot never fires blind. It needs `import com.crossbotics.ftchelper.robot.Aim;`. ```java title="Robot.java" .requireReady("aimed", () -> aim().stage() == Aim.Stage.LOCKED) ``` With a turret, use the turret's check in place of this one ([Add a turret](https://crossbotics.com/ftc-helper/docs/add-to-robot/06-turret/#actionsjava-and-autos-use-it-in-steps)). ### Tunables.java: its numbers **Where:** `Tunables.java`, a new section. The section's name is the camera's name in CamelCase: `"limelight"` reads `Tunables.Limelight`, and `"Webcam 1"` reads `Tunables.Webcam1`. ```java title="Tunables.java" public static class Limelight { // "limelight" in the configuration public static double pipeline = 0; // a Limelight: the pipeline to use (0) public static boolean autoLighting = true; // try a few settings at INIT, keep the best (true) public static double pitchDeg = DEFAULT; // its tilt up, degrees (0 = level) } ``` - `pipeline`: the pipeline to use when the lighting test is off. - `autoLighting`: `true` runs the lighting test at each INIT. At an event, you can set it to `false` ([Camera lighting: At an event](https://crossbotics.com/ftc-helper/docs/tuning/11-camera-lighting/#at-an-event)). - `pitchDeg`: the camera's tilt up, in degrees. Then the camera gives the direction and the distance along the floor. - The camera reads these numbers once, at INIT. They are not in the tuning menu. Change them in `Tunables.java` and install again. **Aiming numbers** are in a section with a fixed name, `Tunables.Aim`. They set how whole-robot aim turns, and the goal's place on the field for the odometry backup. Every line is optional ([Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/)). ### Controls.java: its buttons **Where:** `Controls.java`, inside `buttons(...)`. The camera itself needs no button. These lines use what it sees. The aim buzz: gamepad 2 buzzes while the aim is close. ```java title="Controls.java" // Gamepad 2 buzzes while the aim is close: the closer, the stronger (Tunables.Aim.rumbleDeg). // It works for a turret that follows the goal and for whole-robot aim. g2.rumbleWhenAimed(); ``` **With no turret:** the whole robot turns to face the goal while the driver holds RB. Do not use it with a turret that follows the goal: INIT stops. ```java title="Controls.java" // Hold RB: the robot turns to face the goal by itself; the driver keeps forward and sideways. g1.rb.hold(robot.aimMode()::on, robot.aimMode()::off).says("hold: aim the robot at the goal"); // Or a toggle. Careful: while it is on, the robot turns by itself, even after you let go. // g1.rb.toggle(robot.aimMode()).says("aim the robot at the goal on/off").rumble(); ``` **The driver still wins:** while aim mode is on, a push of the turn stick turns the robot as the stick says. Let go, and the aim takes over again. **Aim only when you shoot:** add `public static boolean aimOnFire = true;` to `Tunables.Aim`. Then, with aim mode off, RB with the goal in view turns the robot to the goal, fires, and gives the turn stick back. It waits at most `aimOnFireSec` (0.5 s), so a press always fires. Tune whole-robot aim first: it uses the same numbers ([Quick turn on fire](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#quick-turn-on-fire)). To run the lighting test again in a match, put `relight()` on a button ([Camera: Buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/#buttons-to-add)). ### Actions.java and autos: use it in steps **Where:** an autonomous in `autos/`, at the shooting spot. Three ready-made steps aim, get ready and fire, with nothing in `Actions.java`: ```java title="autos/YourAuto.java" .aimAtGoal("Aim", 4, 45) // turns the robot; goal not seen: looks 45 degrees each way .readyToLaunch("Ready", 3) // spins up, waits until at speed and aimed .action(robot.launcher.fireAllAction()) // fires every piece it holds, only when aimed ``` - `aimAtGoal` turns the whole robot to the goal (at most 4 s). When the camera does not see the goal, the robot turns slowly up to 45 degrees each way to find it. With a turret that follows the goal, it waits for the turret instead. - `readyToLaunch` waits until the wheel is at speed and every launcher check is true (at most 3 s). - With the "aimed" check, a robot that never found the goal fires nothing. - **Start where the camera sees the goal.** In BIOBUZZ, at the start, our HIVE's up CELL is on the HIVE's right side, seen from our wall ([Aim in an auto](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#aim-in-an-auto)). ## 3. Find its numbers 1. **Camera lighting** ([how](https://crossbotics.com/ftc-helper/docs/tuning/11-camera-lighting/)): for a Limelight, save 3 pipelines on a laptop (usual, bright and dim light). 2. **`pitchDeg`:** put a phone level app on the camera's face. Read the tilt up, in degrees. 3. **Aim Tuner** ([how](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/)): it finds `cameraOffset`, when the camera is beside the launcher. Do not measure it: the tuner finds it from test shots. 4. **Shot Tuner** ([how](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/)): the shot table, a speed for each distance. Do it again when you change `pitchDeg`. ## 4. Check it, then tune it **Check it:** 1. Turn the robot so that the camera sees a tag. Press INIT. 2. Read the lighting line, for example `limelight lighting : pipeline 2 (9 of 10 pictures saw tags)`. When the camera sees no tag, this line is a warning. 3. Look at the camera's picture ([See what the camera sees](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/#see-what-the-camera-sees)). The tags must be sharp, and not too dark or too bright. 4. Press ▶. Point the robot at your goal. The Goal line must say **seen**, then `Goal : LOCKED (camera, 52 in, 0.8 deg off)` when the robot (or the turret) points at it. **Tune it:** the aim numbers in `Tunables.Aim` (`turnKp`, `turnKd`) only change whole-robot aim. Change them with [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/). Then put the tuned numbers in `Tunables.java`. ## More for your camera ### When the camera loses the goal: the odometry An arm, another robot or a bad angle can hide the tags. A robot with odometry ([Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/)) knows where it is, so it can work out where the goal is too. Tell it where the goal is: **Where:** `Tunables.java`, in the `Tunables.Aim` section. ```java title="Tunables.java" public static class Aim { public static double goalX = 13; // the goal: inches right of the center line public static double goalY = -13; // the goal: inches from the center, - = our half public static boolean mirrorForRed = false; // BIOBUZZ: false } ``` - `goalX`, `goalY` are field numbers, seen from your own drivers' wall, as in `driveTo` ([Field numbers](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#field-numbers)). BIOBUZZ: the up CELL at the start is 13 in right of the center line and 13 in toward your wall. Put the point where the camera measures to (the tags), so the camera's distance and the odometry's agree. - `mirrorForRed`: BIOBUZZ is `false`, because the field looks the same from each wall. On a mirror-image field, write `true`. INIT shows the choice on its `Aim :` line. Check it before the match. - You need nothing more. The turret and the shot table use the camera while it sees the goal, and the odometry while it does not: `Turret : 12 deg AIMED following: odometry`. A robot with no camera uses `.followsOdometry()` on the turret and `.speedFromOdometry()` on the launcher. **The camera comes first,** because the odometry drifts a little in a match. The odometry needs a good start, so the backup stays off until the robot has its pose. It gets the pose when an autonomous ran first, or when the drivers parked on the reset spot and held gamepad 1 START for 1 s ([Add odometry: TeleOp starts where autonomous ended](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#teleop-starts-where-autonomous-ended)). The backup also stays off while it says the goal is farther than the field allows. Every setting: [Aim: The goal point](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#the-goal-point). ### Shooting while moving A piece shot from a moving robot keeps the robot's speed. At 30 in/s sideways, a piece in the air for 0.8 s lands 24 in to the side. So the robot aims that far the other way, at a "virtual goal". It needs odometry, for the robot's speed. **Where:** `Tunables.java`, in the `Tunables.Aim` section. ```java title="Tunables.java" public static boolean shootOnMove = false; // true only after testing it on the real robot public static double flightSec = 0.8; // seconds in the air: measure it public static double shooterForwardIn = -4; // the turret's pivot: inches ahead of the odometry's center public static double shooterLeftIn = 0; // the turret's pivot: inches left of the odometry's center ``` - **Measure `flightSec`** with a phone's slow-motion video (240 pictures a second). Film a shot from the side, count the pictures from the launcher to the goal, and divide by 240 (192 pictures = 0.8 s). - **The shooter's place:** do not measure from the robot's middle. Measure from the edges, in inches: `shooterForwardIn` = (half the robot's length) - (the pivot's distance from the FRONT edge). `shooterLeftIn` = (half the robot's width) - (the pivot's distance from the LEFT edge). Example: a robot 17 in long with the pivot 12.5 in from the front: 8.5 - 12.5 = -4 (4 in behind the middle). - **Test it:** first shoot standing still: the shots must land as before. Then drive slowly sideways past the goal and shoot. Misses toward the way the robot drives: `flightSec` is too short. Misses the other way: it is too long. - A button can switch it off in a match: `g2.a.toggle(robot.aim().movingShotMode()).says("shoot on the move on/off");`. Every setting, a camera on the body, longer flights: [Shooting on the move](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#shooting-on-the-move). ### Aim into the opening Some goals have their opening in front of their tags (BIOBUZZ: about 3 in in front of the tags under the CELL). From an angle, a shot aimed at the tags goes toward the back edge of the opening, and up close it can miss. Turn on the angle aim, and the robot aims at the opening instead: ```java title="Tunables.java" public static class Aim { public static boolean angleAim = true; // aim into the opening, not at the tags public static double goalFrontIn = 3; // the opening is 3 in in front of the tags (BIOBUZZ) } ``` Straight on, nothing changes. From an angle, the aim turns a few degrees toward the front of the goal. Put it on a button to compare shots with it on and off: `g1.a.toggle(robot.aim().angleAimMode());`. It needs a webcam ([Aim into the opening](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/#aim-into-the-opening)). ### Try it in the simulator The turret robot has a camera on a turret, and a shot table for each piece. Make its simulator file from its `Robot.java`, then run it. **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:fromRobot -PteamCode=none -ProbotClass=com.crossbotics.ftchelper.examples.turretbot.Robot -Pout=build/turretbot.properties ./gradlew :sim:run -PteamCode=none -Probot=build/turretbot.properties ``` Open http://localhost:8780. Choose "TurretBot TeleOp", pick the alliance in INIT (gamepad 1 X = BLUE, B = RED), and press ▶. Drive until the goal is in view. The turret follows it, and the speed changes with the distance. - **Where to stand:** the tags are under the up CELL, so the camera must be below and in front of them. RED: about x 57, y -13, facing the HIVE (heading 90). BLUE: about x -57, y 13 (heading -90). Drag the robot there on the map. - Spin up (LB) and fire (RB). The POLLEN table comes from tuning in the simulator, so POLLEN shots go in. The NECTAR table is example numbers, so expect misses. - **Whole-robot aim:** do the same with `flywheelbot` (`-ProbotClass=com.crossbotics.ftchelper.examples.flywheelbot.Robot -Pout=build/flywheelbot.properties`). Choose "FlywheelBot TeleOp", drive until the goal is in view, and press RB on gamepad 1. - Your own robot: [Simulator](https://crossbotics.com/ftc-helper/docs/simulator/). ## Fix a problem | Problem | Why, and the fix | | --- | --- | | `limelight: not found: no Limelight called "limelight"` | The name in the robot configuration is different (case counts), or the Limelight is not in it. The OpMode still runs, without the camera | | `limelight lighting: NO TAGS SEEN` (after ▶) | No pipeline saw a tag at INIT. Have a tag in view at INIT. Check each pipeline on the Limelight's page | | `limelight lighting: no pictures from pipeline 2 (missing?)` | That pipeline is not set up on the Limelight. Make it, or take it out of `autoPipelines(...)` | | `Goal : not seen (RED SCORING is upside down (a down CELL))` | The camera sees only a down CELL. Drive to see the up CELL | | Aim turns away from the goal, or aims at the down CELL (webcam) | The webcam is mounted upside down. Add `.upsideDown()` to its line in Robot.java | | The speed never changes with distance | No goal in view. Check `pipeline` and the `goal(...)` names | | INIT stops: `robot.aimMode() ... separate modes` | The turret follows the goal. Remove the `aimMode()` line, or `.follows(...)` on the turret | | Whole-robot aim stops a few degrees off | Raise `turnKp`, or set `minTurnPower` in `Tunables.Aim` | | It is aimed, but the shots go wide by the same angle | The camera is beside the launcher. Run the Aim Tuner | | `limelight lighting: trying 1 of 3: pipeline 0 (no tags yet: face a tag)` (INIT) | No pipeline saw a tag yet. Turn the robot toward a tag. The test goes on until ▶ | | `Aim: no goal` | Whole-robot aim is on, but the camera does not see the goal, and there is no odometry backup | | `following: odometry` points the wrong way | Check `goalX`, `goalY` (seen from your own wall), `mirrorForRed`, and that the pose started right | | `Aim odometry: the pose was never set` | TeleOp ran with no autonomous before it. Run the autonomous first, or park on the reset spot and hold gamepad 1 START 1 s | | `Aim odometry: ... more than the field allows` | The pose is wrong. The backup stays off until it is right | | `Aim: camera says 60 in, odometry 48 in` | The pose drifted, or `goalX`, `goalY` are not where the camera measures to | ## Done when - At INIT, facing a tag, the lighting line shows a setting and no warning. - Pointed at your goal, the Driver Station shows `Goal : LOCKED`. - A Limelight has its 3 pipelines saved. --- **Next:** [Add lights](https://crossbotics.com/ftc-helper/docs/add-to-robot/08-lights/). **Look it up:** [Camera](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/) and [Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/): every setting, number and command. --- # Add lights URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/08-lights/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). - On the robot, one of these two: - a goBILDA RGB Indicator Light on a servo port. In the robot configuration it is a "Servo". Call it `light`. - a REV Blinkin LED Driver with an LED strip. In the robot configuration it is a "REV Blinkin LED Driver". Call it `blinkin`. ## 1. What it is A **light** shows one color at a time. You write **rules** in `Controls.java`: "show this color when this is true". - **The drivers watch the robot, not the Driver Station.** A light tells them "ready" without a look at the screen. - **The first true rule wins.** Put the most important rule first. - **A flash beats every rule** while it lasts: one short flash for each piece fired, or from a button or an action. - **The alliance shows at INIT, with no code.** Before the drivers pick the alliance, the light blinks white once a second. After the pick, it is solid RED or BLUE. At ▶ it flashes the alliance for 1 s, then your rules start. **Keep your rules away from red and blue.** Then nobody reads "intake on" as "BLUE alliance". The examples use purple, orange, green, yellow and white. **Game rules:** the referees can switch off a light that flashes faster than about 5 times a second (R202 J). So the library never changes the light faster than every 0.1 s, and blinks at most 5 times a second. Do not shine a light onto the field (G302). ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`. The field `public Lights lights;` goes at the top of the class. The line goes in `define()`, after the drive. ```java title="Robot.java" // At the top of Robot.java: import com.crossbotics.ftchelper.robot.Lights; // A goBILDA RGB Indicator Light on a servo port ("Servo" in the robot configuration): lights = add(Lights.gobilda("light")); // Or a REV Blinkin LED Driver with an LED strip ("REV Blinkin LED Driver" in the configuration): // lights = add(Lights.blinkin("blinkin")); ``` - Use one of the two lines. The name in quotes is the name in the robot configuration. - When a name is red, click it and press Alt+Enter (Option+Enter on a Mac) to add the import. **When a Blinkin color looks wrong on your strip:** give that color another Blinkin pattern. Your rules still say `LightColor.BLUE`. A goBILDA light ignores this line. **Where:** `Robot.java`, in `define()`, below the lights line. ```java title="Robot.java" // At the top of Robot.java: import com.qualcomm.hardware.rev.RevBlinkinLedDriver; // A REV Blinkin LED Driver ("REV Blinkin LED Driver" in the robot configuration): lights = add(Lights.blinkin("blinkin")); // Plain blue too dark on your strip? Show another Blinkin pattern for BLUE. lights.blinkinPattern(LightColor.BLUE, RevBlinkinLedDriver.BlinkinPattern.BLUE_VIOLET); ``` The pattern names are on REV's Blinkin page. ### Two lights A robot can have two lights (or more). Pick one of these ways: | You want | Do this | | --- | --- | | Both lights show the same thing | One part that drives both: `.alsoLight(...)` | | Two goBILDA lights show the same thing, with no code | Plug both into one servo port with a servo Y-cable. Robot.java stays one light | | Each light shows something different | Two parts, each with its own rules | **Both lights show the same:** **Where:** `Robot.java`, in `define()`, in place of the lights line. ```java title="Robot.java" // "light" and "light_right" = the two lights' names in the robot configuration (the same kind). // Both show the same color, blinking and flashes. Write the rules once, for robot.lights. lights = add(Lights.gobilda("light").alsoLight("light_right")); ``` - Both lights must be the same kind: two goBILDA lights, or two Blinkins. - Write the rules once, for `robot.lights`. Both lights show the same color, blinking and flashes. **Each light shows something different:** **Where:** `Robot.java`. The two fields go at the top of the class. The lines go in `define()`, in place of the lights line. ```java title="Robot.java" // At the top of the class: public Lights leftLight, rightLight; Here in define(): leftLight = add(Lights.gobilda("light_left")); rightLight = add(Lights.gobilda("light_right")); ``` **Where:** `Controls.java`, inside `buttons(...)`. Each light has its own rules and its own `otherwise`. ```java title="Controls.java" // The left light: the launcher. The right light: the intake. robot.leftLight.show(LightColor.GREEN).when(robot.launcher::isReady); robot.leftLight.otherwise(LightColor.OFF); robot.rightLight.show(LightColor.YELLOW).when(robot.intake::isRunning); robot.rightLight.otherwise(LightColor.OFF); ``` **Why each light needs its own rules:** a rule, a flash and `otherwise` belong to one part. A flash on `robot.leftLight` does not show on `robot.rightLight`. ### Tunables.java: one switch **Where:** `Tunables.java`, a new section. You need it only to turn off the alliance at INIT. The section's name is the device's name in CamelCase: `"light"` reads `Tunables.Light`. ```java title="Tunables.java" public static class Light { // "light" in the configuration public static boolean allianceAtInit = true; // show the alliance in INIT, flash it at ▶ (true) } ``` `false`: no alliance color at INIT, and your rules show from INIT on. ### Controls.java: the rules **Where:** `Controls.java`, inside `buttons(...)`. Every file that names a color needs `import com.crossbotics.ftchelper.robot.LightColor;` at the top. Press Alt+Enter on a red `LightColor` to add it. Write the lines in this order: the flashes, then the endgame, then your rules. **1. A flash for each piece fired, and one from a button:** ```java title="Controls.java" // A flash beats every rule while it lasts (write it first: it reads that way). // A short white flash for each piece fired, and one from a button. robot.lights.show(LightColor.WHITE).forSeconds(0.2) .whenCountGoesUp(() -> robot.launcher.part().getShotsFired()); g2.a.press(() -> robot.lights.flash(LightColor.YELLOW)).says("flash the light (signal the partner)"); ``` The flash is 0.2 s, so two quick shots are two flashes, not one long one. **2. Yellow in the last 20 seconds:** ```java title="Controls.java" // Yellow, blinking, in the last 20 seconds of TeleOp: time to park (above the other rules: it wins). robot.lights.show(LightColor.YELLOW).blinking().inLastSeconds(20); ``` The time counts from ▶, like the gamepad buzzes. It is about 1 s off from the field clock. **3. Your rules, one per line:** ```java title="Controls.java" // One rule per line. The first true rule wins: put the most important first. // Red and blue are left for the alliance (shown at INIT), so no rule looks like one. robot.lights.show(LightColor.ORANGE).blinking().when(robot.intake::isPushingOut); // pushing out robot.lights.show(LightColor.GREEN).when(robot.launcher::isReady); // at speed: fire robot.lights.show(LightColor.PURPLE).when(robot.intake::isRunning); // intake on robot.lights.otherwise(LightColor.OFF); // none true ``` - Use the parts your robot has. Any true/false works as a rule: a part's method (`robot.intake::isRunning`), a mode (`() -> robot.turret.followMode().isOn()`), or your own test (`() -> robot.lift.position() > 1000`). - `otherwise(...)` is the color when no rule is true. **The alliance colors:** you add nothing, because it is on by default. When your light shows red badly, pick other colors for it: ```java title="Controls.java" // On by default: the alliance at INIT (solid RED or BLUE), flashed for 1 s at ▶. // Your light shows red badly? Other colors for the alliance at INIT (BLUE, and PURPLE for RED): robot.lights.allianceColors(LightColor.BLUE, LightColor.PURPLE); // No alliance color at INIT at all? Delete the line above and write: // robot.lights.allianceAtInit(false); ``` A line in `Controls.java` wins over `Tunables.Light.allianceAtInit`. ### Actions.java and autos: a flash when an action is done You need no line here for the light alone. An action can flash the light as its last step. No action "claims" the light, so any action may flash it. **Where:** `Actions.java`, one method per action. ```java title="Actions.java" // In Actions.java (it needs import com.crossbotics.ftchelper.robot.LightColor; at the top). // The last step: a 1 s white flash says "done" to the drivers. Pick a color your rules do not use. public static Action shootTwo(Robot r) { return Action.named("Shoot two") .then(r.launcher::spinUp) .waitUntil("at speed", r.launcher::isReady, 3.0) .then(() -> r.launcher.fire(2)) .waitUntil("both gone", () -> !r.launcher.isShooting(), 3.0) .then(() -> r.lights.flash(LightColor.WHITE, 1.0)); } ``` A GREEN flash over the GREEN "ready" rule cannot be seen. Pick another color, or a longer time. ## 3. Find its numbers A light has no numbers to find. The colors come from your rules. ## 4. Check it, then tune it **Check it:** 1. Press INIT. Before you pick the alliance, the light must blink white once a second. 2. Pick the alliance. The light must be solid RED or BLUE. 3. Press ▶. The light must flash the alliance for 1 s, then show your rules. 4. Make each rule true, one at a time (for example, turn on the intake). The light must show that rule's color. 5. Press the flash button (gamepad 2 A). The light must flash yellow. **Tune it:** nothing to tune. To change a color, change the rule and send the code again. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: no device with that name | The name in `Robot.java` must match the robot configuration exactly | | The light shows the wrong rule | The first true rule wins. Move the most important rule up | | A flash does not show | It is the same color as the rule under it. Pick another color | | Two quick shots give one long flash | Put `.forSeconds(0.2)` before `whenCountGoesUp(...)` | | Your light shows red or blue badly | Pick other alliance colors: `robot.lights.allianceColors(LightColor.BLUE, LightColor.PURPLE);` | | A Blinkin color looks wrong | `lights.blinkinPattern(...)` in `Robot.java` | | The light blinks white in INIT | No alliance is picked yet. TeleOp: press gamepad 1 X or B. Autonomous: pick it in the INIT menu | | INIT stops: no device named the second light's name | That name is in `.alsoLight(...)` or a second `add(...)` line. Add it to the robot configuration, or remove it | | One of two lights shows nothing | With a Y-cable: check the cable. With `.alsoLight(...)`: both must be the same kind | | INIT stops on `blinking(...)` | More than 5 times a second is not allowed (R202 J) | ## Done when - INIT shows the alliance color on the light. - Each rule shows its color when it is true. - No rule uses red or blue. --- **Next:** [Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/). **Look it up:** [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/): every rule, color and command. --- # Add odometry URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/ **You need:** - A robot that drives, with its five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). The drive is calibrated (`Tunables.Drive.calibrated = true`, [Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/)). - For `driveTo`: a mecanum drive. A tank robot can still use odometry for `robot.pose()`. - On the robot, one of these three: - **a goBILDA Pinpoint and two pods** (recommended). The Pinpoint goes on an I2C port. In the robot configuration it is a "goBILDA® Pinpoint Odometry Computer". Call it `pinpoint`. - **a SparkFun OTOS** on an I2C port, 10 to 12 mm above the tiles. In the robot configuration it is a "SparkFun OTOS". Call it `otos`. - **dead wheels:** three pods (or two and the Control Hub's IMU), each in a motor port's encoder connector. Which one to get, and how to mount and wire it: step 1. ## 1. What it is **Odometry** tells the robot its **pose** every loop: where it is (x, y) and which way it faces (heading). - **Pods** are small free-turning wheels with encoders. Springs press them onto the tiles. One rolls forward and back (the **X pod**), one rolls sideways (the **Y pod**). - **Field numbers are inches, seen from your own drivers' wall**, whatever your alliance. x = inches right of the center line. y = inches away from your wall (negative = your half). Heading 0 = facing away from you, and a turn to the left is +. See the [field numbers](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#field-numbers). - **It must know where its pods sit.** When the robot turns in place, a pod away from the turn point rolls too. The library takes that roll away. - **You must check it before it drives.** `driveTo` steps do nothing on the robot until `Tunables.Odometry.checked = true`. **Why:** a pod that counts the wrong way would send the robot the wrong way at speed. With odometry, `driveTo` goes to a field point and ends on it, even after a bump or a wheel slip. TeleOp starts where autonomous ended. ### Why odometry The drive wheels slip: they spin when another robot pushes yours, and they skid when the robot speeds up. After a bump, a drive by distance (`forward(...)`) is off, and every later step is off too. The robot does not know it. The pods carry no weight and drive nothing, so they do not slip. They only roll and count. The robot adds up every small move, many times a second. So it knows its real pose. **Why not AprilTags in BIOBUZZ:** the tags are on the HIVE cells, and the cells move. A tag tells you where you are compared with the tag, not with the field. So in BIOBUZZ, odometry says where the robot is, and the camera is for aiming. ### Which one to get | Choice | What it is | Parts and price (checked 2026-10-21) | | --- | --- | --- | | **goBILDA Pinpoint + 2 pods** (recommended) | a small odometry computer with its own IMU. Two pods plug into it, and it plugs into an I2C port | Pinpoint Odometry Computer V2, goBILDA 3110-0002-0002, $79.99. Two 4-bar odometry pods, goBILDA 3110-0001-0002, about $99.99 each (not checked on goBILDA's page: check it before you order) | | **SparkFun OTOS** | an optical sensor under the robot that watches the floor, like a computer mouse. No pods | SparkFun SEN-24904, $84.95 | | **Dead wheels** | three pods (or two and the Control Hub's IMU), each plugged into a motor port's encoder connector. No extra computer | the pods only. They use three (or two) encoder ports | - **I2C port:** the small 4-pin ports on the Control Hub (I2C 0 to 3). Sensors that send numbers, like the Pinpoint and the OTOS, plug in there. - **4-bar and swingarm pods:** goBILDA's two pod designs. They give a different number of encoder counts per mm. The library expects 4-bar pods. Swingarm pods need `.podsSwingarm()` in the odometry line. - **Why we recommend the Pinpoint:** it does the math itself about 1500 times a second, and the robot reads the answer once per loop. So the loop speed does not change how good the pose is. It also uses no encoder ports. ### Mount it, wire it, name it 1. **Mount the two pods** under the robot, with the springs pressing the wheels onto the tiles. One rolls **forward and back** (the X pod). One rolls **sideways** (the Y pod). They can sit anywhere: step 2 says how to give their places, and the tuner measures them. 2. **Mount the Pinpoint** flat, anywhere on the robot. 3. **Plug the X pod into the Pinpoint's X port, and the Y pod into its Y port.** **Why:** the Pinpoint takes X as forward. With the pods swapped, the robot takes forward as sideways. 4. **Plug the Pinpoint into an I2C port** on the Control Hub. Port 0 has the hub's own IMU, so use port 1. 5. **Add it to the robot configuration** on the Driver Hub: Configure Robot, edit your configuration, Control Hub, the I2C bus you used (for example I2C Bus 1), Add. Choose the type **goBILDA® Pinpoint Odometry Computer** and name it `pinpoint`. Save, and restart the robot. An OTOS goes on an I2C port the same way: type **SparkFun OTOS**, name `otos`. Mount it 10 to 12 mm above the tiles. For dead wheels, plug each pod's encoder cable into a motor port's encoder connector. The pod's name is that motor port's configuration name. ## 2. Add it to the five files ### Robot.java: one line **Where:** `Robot.java`, in `define()`, right after the `drive(...)` line. Add `import com.crossbotics.ftchelper.robot.Odometry;` at the top (Alt+Enter on the red name). Use the line for your kind. Measure with a tape from the robot's **edges**, with the bumpers off. The library works out the robot's center from the size. The Odometry Tuner then measures the exact numbers. **A Pinpoint:** ```java title="Robot.java" // After drive(...). The robot's length and width, then where each pod's wheel is, mm: // the forward pod from the LEFT edge, the sideways pod from the FRONT edge. odometry(Odometry.pinpoint("pinpoint").robotSizeMm(430, 400).podsFromEdgesMm(284, 383)); ``` ![A robot seen from above: the X pod 284 mm from the left edge, the Y pod 383 mm from the front edge](https://crossbotics.com/ftc-helper/docs/images/odometry-pods-from-edges.svg) | Number | What it is | Measure | | --- | --- | --- | | `robotSizeMm(430, …)` | the robot's length | front edge to back edge | | `robotSizeMm(…, 400)` | the robot's width | left edge to right edge | | `podsFromEdgesMm(284, …)` | the **X pod**: the pod that rolls when the robot drives **forward** | LEFT edge to the middle of its wheel | | `podsFromEdgesMm(…, 383)` | the **Y pod**: the pod that rolls when the robot drives **sideways** | FRONT edge to the middle of its wheel | - Plug the X pod (forward) into the Pinpoint's X port, and the Y pod (sideways) into its Y port. - goBILDA swingarm pods need `.podsSwingarm()` at the end of the line. The default is 4-bar pods. **An OTOS:** ```java title="Robot.java" // The robot's length and width, then the OTOS's middle from the FRONT and LEFT edges (mm), and its turn. odometry(Odometry.otos("otos").robotSizeMm(430, 400).mountFromEdgesMm(126, 200, 0)); ``` | Number | What it is | Measure | | --- | --- | --- | | `robotSizeMm(430, 400)` | length, then width | as for the Pinpoint | | `mountFromEdgesMm(126, …, …)` | where the OTOS is, front to back | FRONT edge to the middle of the OTOS | | `mountFromEdgesMm(…, 200, …)` | where the OTOS is, side to side | LEFT edge to the middle of the OTOS | | `mountFromEdgesMm(…, …, 0)` | the way its arrow points | degrees, see below | **Careful:** the OTOS line gives FRONT first, then LEFT. The Pinpoint line is the other way around. The last number is the way the OTOS's arrow points, in degrees (0 = forward, a turn to the left is +). The tuner cannot measure where an OTOS sits, so these tape numbers stay. **Dead wheels:** ```java title="Robot.java" // The configuration names of the motor ports the pods plug into: left, right, sideways pod. // trackWidthIn: left pod to right pod. perpForwardIn: the sideways pod, 6 in BEHIND the center. odometry(Odometry.threeWheels("par_left", "par_right", "perp") .trackWidthIn(13.2).perpForwardIn(-6)); ``` | Number or name | What it is | Measure | | --- | --- | --- | | `"par_left"` | the LEFT pod that rolls when the robot drives forward | its motor port's configuration name | | `"par_right"` | the RIGHT pod that rolls when the robot drives forward | its motor port's configuration name | | `"perp"` | the pod that rolls when the robot drives sideways | its motor port's configuration name | | `trackWidthIn(13.2)` | the distance between the two forward pods | the left pod's wheel to the right pod's wheel, inches | | `perpForwardIn(-6)` | how far the sideways pod is ahead of the robot's middle: **+** = ahead, **−** = behind | do not measure it from the middle (see below) | **A first `perpForwardIn` from the edges:** (half the robot's length) − (the sideways pod's wheel from the FRONT edge), in inches. Example: a robot 17 in long with the pod 14.5 in from the front: 8.5 − 14.5 = −6. The Odometry Tuner then measures the exact number. - Two pods and the IMU: `Odometry.twoWheels(parallel, perp)` with `.parallelLeftIn(...)` and `.perpForwardIn(...)` ([Odometry](https://crossbotics.com/ftc-helper/docs/reference/parts/odometry/#in-robotjava)). **Dead wheels and the OTOS need the IMU in the drive line** (`.imu(...)` in `drive(...)`). The tuner's Spin test uses it. The Pinpoint has its own. ### Tunables.java: the check and the reset spot **Where:** `Tunables.java`, a new section. Its name is always `Odometry`. ```java title="Tunables.java" public static class Odometry { // a fixed name: always Odometry public static boolean checked = false; // true after the Odometry Tuner's Loop test // "Set pose here" (TeleOp: hold gamepad 1 START 1 s on this spot), written for BLUE. public static double resetX = -56; // inches right of center, - = left public static double resetY = -61; // inches from center, - = our half public static double resetHeading = 0; // degrees, 0 = facing the field // RED: false = the same numbers from the red wall; true (or left out) = mirrored left-right. public static boolean mirrorForRed = false; // BIOBUZZ: false } ``` - `checked`: you set it to `true` by hand, after the tuner's Loop test passes (step 3). - `resetX`, `resetY`, `resetHeading`: the **reset spot**. When autonomous did not run, TeleOp does not know where the robot is. Put the robot on this spot, let go of the sticks, and hold gamepad 1 **START** for 1 s. Here the spot is your left corner tile, facing the field. - `mirrorForRed = false` is for BIOBUZZ: its field is turned half a turn, so RED uses the same numbers from its own wall. ### TeleOp starts where autonomous ended You write nothing for this: - When autonomous ends, its pose goes to TeleOp. TeleOp's INIT starts the odometry there, if autonomous ran in the last 5 minutes. A Pinpoint still calibrates right after INIT: the library keeps the pose and gives it to the Pinpoint when it is ready. - Field-centric "forward" comes from the odometry's heading. Hold BACK to make "forward" the way the robot faces now. This is for the driver only: the pose does not change, so aiming at a field point stays right. **With no autonomous, or one stopped early,** set the pose with the reset spot. Put the robot on it, let go of the sticks, and hold gamepad 1 **START** (OPTIONS on a PlayStation gamepad) for 1 s. Do it in INIT if you can. Gamepad 1 buzzes twice, and the Driver Station says `Pose set: x -56, y -61 in, heading 0 (BLUE)`. While the robot drives, it says `Pose NOT set: stop first`. START held with A or B pairs a gamepad, so it never sets the pose. From code or an action: `robot.resetPose()` (the reset spot) or `robot.resetPose(x, y, heading)`. To move the button: `lib.setPose(...)` ([Move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/)). **One mirror setting for the whole robot.** The autos' start spots, the reset spot and the aim's goal point all use one answer to "is RED a mirror image of BLUE?". The robot takes the first one it finds: `Tunables.Aim.mirrorForRed`, then `Tunables.Odometry.mirrorForRed`, then the autonomous's `mirrorForRed()`, else `true`. Write it in `Tunables.Odometry`, so a TeleOp with no autonomous before it gets it right too. INIT shows the one it uses: `Reset spot for RED: ...`. **The autonomous ran with the wrong alliance:** with the alliance switch in `Controls.java` (`lib.switchAlliance(g1.start, g1.back)`), hold START, then BACK, for 1.5 s. On a mirrored field, the library mirrors the pose too. On BIOBUZZ's turned field it cannot: set the pose here again ([Switching the alliance in TeleOp](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/#switching-the-alliance-in-teleop)). ### Controls.java: show the pose **Where:** `Controls.java`, inside `buttons(...)`. The reset spot on START works with no line. To check the odometry, show the pose on the Driver Station: ```java title="Controls.java" show("Where", () -> String.format(Locale.US, "x %.0f, y %.0f in, heading %.0f", robot.pose().x, robot.pose().y, robot.pose().headingDeg)); ``` For a second reset spot, or a reset from an action: [How do I set the pose when autonomous did not run?](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-set-the-pose-when-autonomous-did-not-run). #### A button that drives to a spot in TeleOp With odometry, a button can drive the robot to a field spot by itself, for example to park at the end. **Any drive stick stops it at once**, and the driver has the robot again. It needs a mecanum drive and a field map, so that it goes around the field parts. **Where:** `Robot.java`, in `define()`, after the `odometry(...)` line: the field map. ```java title="Robot.java" // After odometry(...). The margin: half the robot's corner to corner size, plus some for drift. // Each box: two opposite corners, like driveTo's numbers. These are BIOBUZZ's two HIVE frames. fieldMap(FieldMap.margin(13) .keepOut("HIVE frame, near", -19.5, -24.8, 19.5, -15.4) .keepOut("HIVE frame, far", -19.5, 15.4, 19.5, 24.8)); ``` **Where:** `Controls.java`, inside `buttons(...)`: the button, and a time when it starts by itself. ```java title="Controls.java" // route(...) makes the job. It starts when the button or the time says so. Runnable park = route("Park", -56, -36, 0, 0.8); g1.dpadLeft.tap(park).says("drive to the park spot (a drive stick stops it)"); atSecondsLeft(10, park); ``` - `route("Park", -56, -36, 0, 0.8)`: the spot's x, y and heading (field numbers, as in `driveTo`), then the top power. - `atSecondsLeft(10, park)`: it starts with 10 s left. When a driver pushes a stick at that time, it waits until the sticks are let go (at most 5 s). - It drives only after the Drive Tuner and the Odometry Tuner (`calibrated` and `checked` are `true`). More: [Keep-out boxes and routes](https://crossbotics.com/ftc-helper/docs/modules/odometry/#keep-out-boxes-and-routes). ### Actions.java and autos: drive to field points **Where:** a file in `autos/`, inside `steps(...)`. It needs a mecanum drive. ```java title="autos/YourAuto.java" // The start spot (x, y, heading) must be where the robot really stands: the pose starts there. s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) .driveTo("To the goal", -30, -30, 45, 0.6) .parkWithSeconds(4) // The last number: "close enough", in inches (default 1). .driveTo("Park", -56, -36, 0, 0.7, 2.0); ``` - `driveTo(label, x, y, heading, power)`: a place on the field, not a distance. - The numbers in `start(...)` must be where the robot stands. The pose starts there. An action can also use the pose. **Where:** `Actions.java`, one method per action. ```java title="Actions.java" /** Runs the intake while the robot is on our half of the field (y below 0). */ public static Action intakeOnOurHalf(Robot r) { return Action.named("Intake on our half") .then(r.intake::in) .waitUntil("past the center line", () -> r.pose().y > 0, 10.0) .then(r.intake::stop); } ``` To drive around field elements (`routeTo`), see [keep-out boxes and routes](https://crossbotics.com/ftc-helper/docs/modules/odometry/#keep-out-boxes-and-routes). ## 3. Find its numbers The **Odometry Tuner** is in the **Tune and check** OpMode ([how](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/)). You need a 48 in strip of tape on the floor, with a mark at its start. 1. **Forward 48 in:** it says which way the X pod counts. For "counted BACKWARD", add `.reversed("x")` to the odometry line (dead wheels: that pod's port name). 2. **Left 24 in:** it says which way the Y pod counts. For "counted RIGHT", add `.reversed("y")`. 3. **Spin 3+ turns:** it measures where the pods sit, and shows the line to change, for example `.offsetsMm(-84.2, -167.5)`. The 1st number is the X pod: mm LEFT of the robot's middle (− = right). The 2nd is the Y pod: mm AHEAD of the middle (− = behind). With a Pinpoint, write `.offsetsMm(...)` in place of `.robotSizeMm(...).podsFromEdgesMm(...)`. Dead wheels get `.trackWidthIn(..).perpForwardIn(..)`. 4. Send the code again. 5. **Loop and back:** drive away at least 24 in and come back onto the mark. Within 1 in and 2 degrees, the screen says `Tunables.Odometry: checked = true`. Write it in `Tunables.java`. An OTOS gets `Tunables.Odometry: linearScalar = ...` from the Forward test. ## 4. Check it, then tune it **Check it:** 1. Run your TeleOp. Push the robot by hand and watch the `Where` line. 2. Forward must make y go up. Left must make x go down. A turn to the left must make the heading go up. 3. In an autonomous with a `driveTo`, set `Tunables.Drive.maxPower` low (0.4) for the first runs. Put the robot exactly on the start spot, and keep a hand on STOP. 4. In INIT, check for `Odometry: Pinpoint ready` (or your kind). Run it. The robot must end within about 1 in of the point. 5. Run it again, and push the robot gently sideways while it drives. It must come back on course. 6. Set `maxPower` back to `DEFAULT`. **Tune it** with the [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/). It makes moves stop where they should and turns end on their heading. `driveTo` and routes use the same numbers (`moveMinPower`, `slowDownIn`, `turnMinPower`). With an odometry line, the Move Tuner measures with the odometry, so it sees a skid. Run its tests in order: Creep, Stops, Turns, Drift, then Move and turn on a mecanum. Put the `Tunables.Drive:` lines it shows in `Tunables.Drive`. To try a turn number without a new build, use [Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/). The drive's turn numbers change at the next INIT. Then write the number in `Tunables.Drive`. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | `skipped: Tunables.Odometry.checked is false` in the report | Run the tuner's Loop test, then `checked = true` | | INIT stops: no `GoBildaPinpointDriver` named `"pinpoint"` | The configuration name and type must match `Robot.java` | | `Pinpoint: X pod not found: check its cable` | A pod cable is out of the Pinpoint | | `Pinpoint: calibrating (keep the robot still)` stays | The robot moved in INIT. Keep it still, and INIT again | | The pose goes the wrong way | A pod is reversed. Forward and Left tests, then `.reversed("x")` or `("y")` | | x and y look swapped | The X and Y pods are in each other's ports | | The pose drifts when the robot only turns | The offsets. Run the Spin test | | INIT stops: `driveTo(...) needs a mecanum drive` | `driveTo` drives sideways. A tank robot uses `turnTo` and `move` | | It drives to the mirror spot on RED | BIOBUZZ: `mirrorForRed = false` | | It circles the point or stops just short | Run the [Move Tuner](https://crossbotics.com/ftc-helper/docs/tuning/10-move-tuner/) | | The report says `NO_ODOMETRY` | The odometry stopped during a `driveTo`. Check the pod and I2C cables | | `OTOS: not answering` | The I2C cable, or the configuration name or type | | INIT stops: `odometry .reversed("...")` | A name in `.reversed(...)` that is not a pod. A Pinpoint's pods are `"x"` and `"y"` | | The tuner stops at INIT: `needs the IMU` | Dead wheels or an OTOS: add `.imu(...)` to `drive(...)` | | TeleOp's field-centric is wrong after autonomous | The heading in `s.start(...)` is wrong | | `No reset spot: add resetX, resetY, resetHeading to Tunables.Odometry` | The reset spot is missing in `Tunables.Odometry` | | After "set pose here", the pose is mirrored the wrong way on RED | BIOBUZZ: add `mirrorForRed = false` to `Tunables.Odometry`. INIT's `Reset spot for RED` line shows which is used | | `Pose NOT set: stop first` | The robot was driving (or aiming by itself). Stop, then hold START 1 s again | More, for `driveTo` reports (`STALLED`, `TIMED_OUT`): [Drive to points: problems](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/#problems). ## Done when - Pushed by hand, the `Where` line goes the right way. - The Loop test passed, and `Tunables.Odometry.checked = true`. - A `driveTo` ends within about 1 in of its point. --- **Next:** [Make parts work together](https://crossbotics.com/ftc-helper/docs/add-to-robot/10-parts-together/). For curved paths in autos: [Add Pedro paths](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/). **Look it up:** [Odometry](https://crossbotics.com/ftc-helper/docs/reference/parts/odometry/): every setting, number and command. --- # Make parts work together URL: https://crossbotics.com/ftc-helper/docs/add-to-robot/10-parts-together/ **You need:** - A lift, an arm and a claw, each added and checked on its own: [Add a lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/), [Add an arm](https://crossbotics.com/ftc-helper/docs/add-to-robot/02-arm/), [Add a claw](https://crossbotics.com/ftc-helper/docs/add-to-robot/03-claw/). - Their named positions measured: lift `down` and `high`, arm `stowed` and `score`, claw `open` and `closed`. Use your own names in place of these. ## 1. What it is Two things join the parts: - **An action** puts the moves in order: lift up, arm out, claw open, arm in, lift down. Each move waits until the part before it is there. One button starts it, and the same button cancels it. - **A safety rule** (an **interlock**: a rule that keeps two parts apart) stops the arm from swinging out while the lift is low. The action has the right order. The rule also covers a driver who moves one part by hand, and an action that you cancel half way. **Why both:** the action makes the score fast and the same each time. The rule makes a crash impossible, whoever moves the parts. ## 2. Add it to the five files ### Robot.java: the safety rule **Where:** `Robot.java`, in `define()`, after the lift's, the arm's and the claw's lines. ```java title="Robot.java" // The arm stays below its line while the lift is low, and the lift stays up while the arm is out. keepApart("ArmLift", arm.zoneAbove(), lift.zoneBelow()); ``` - `arm.zoneAbove()` is the arm's zone: from an angle up to the top of its swing (the arm is out). - `lift.zoneBelow()` is the lift's zone: from a height down to the bottom (the lift is low). - The two parts are never in their zones at the same time. **The part that is in its zone first keeps it. The other part waits outside its own zone**, with its target kept. It goes on when the first part leaves. For comparison, the cookbook's rule for a turret and a lift has the same shape: ```java title="Robot.java" // AFTER the parts' add lines: the turret stays out of its zone while the lift is in its // zone, and the other way round. Whoever is in its zone first keeps it. keepApart("TurretLift", turret.zone(), lift.zoneAbove()); ``` ### Tunables.java: where each zone starts **Where:** `Tunables.java`, a new section. Its name is the rule's name, `"ArmLift"`. ```java title="Tunables.java" public static class ArmLift { // keepApart("ArmLift", ...) in Robot.java public static double armAbove = MEASURE; // degrees: the arm is out from here up public static double liftBelow = MEASURE; // counts: the lift is low from here down public static double armStopSec = 0.15; // how long the arm takes to stop public static double liftStopSec = 0.2; // a heavy slide takes longer to stop } ``` - The field names come from the part's section name with a small first letter: `Arm` -> `armAbove`, `Lift` -> `liftBelow`. A lift called `lift_left` gives `liftLeftBelow`. INIT stops on a wrong name. - Each zone is in its part's own units: degrees for the arm, counts for the lift. - The rule reads these numbers once, at INIT. They are never in the tuning menu. **Why:** a zone that changes while the parts move could let them hit. The cookbook's section for the turret and lift rule: ```java title="Tunables.java" // The rule's own section, named like the rule in Robot.java. Each zone in its part's units. public static class TurretLift { // keepApart("TurretLift", ...) in Robot.java public static double turretFrom = MEASURE; // degrees: where the turret's zone starts public static double turretTo = MEASURE; // degrees: where it ends (robot's back) public static double liftAbove = MEASURE; // counts: the slide is up from here public static double liftStopSec = 0.2; // a heavy slide takes longer to stop (0.15) } ``` **Find the two numbers with the Motor Finder** ([Motor Finder](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/)). Keep a hand near STOP: 1. Choose `lift`. Raise the slide slowly until the arm can swing out with room to spare. Press **A** there. That count is `liftBelow`. 2. Put the lift at the bottom. Choose `arm`. Swing the arm out slowly until it almost touches the slide or the frame. Press **A** there. Change that count to degrees, as in [Add an arm, step 3](https://crossbotics.com/ftc-helper/docs/add-to-robot/02-arm/#3-find-its-numbers). A number a little below it is `armAbove`. ### Actions.java: the score action **Where:** `Actions.java`, one method per action. ```java title="Actions.java" /** Lift up, arm out, claw open, arm in, lift down: each move waits for the one before it. */ public static Action scoreHigh(Robot r) { return Action.named("Score high") .then(() -> r.lift.goTo("high")) .waitUntil("lift at the top", r.lift::isAtTarget, 2.0) // at most 2 s .then(() -> r.arm.goTo("score")) .waitUntil("arm out", r.arm::isAtTarget, 1.5) .then(r.claw::open) .waitUntil("claw open", r.claw::isDone, 1.0) .waitSeconds(0.3) // let the piece drop .then(() -> r.arm.goTo("stowed")) .waitUntil("arm in", r.arm::isAtTarget, 1.5) .then(() -> r.lift.goTo("down")); } ``` - `waitUntil(words, check, seconds)` waits until the check is true, at most that many seconds. When the time runs out, the action stops, and the Driver Station says `timed out waiting for` and the words. **Why:** a lift that never reached the top must not open the claw. - `isAtTarget` is true when a motor part (lift, arm) is at its named position. `isDone` is true when a servo part (claw) has had the time to get there. - The safety rule still works inside the action. If the arm is sent out too early, it waits at its line. ### Controls.java: the buttons **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Press Y: the action starts. Press Y again while it runs: it is canceled, safely. g2.y.press(Actions.scoreHigh(robot)).says("score high"); ``` Add a button that stops every action at once: ```java title="Controls.java" // Stop every running action at once (each stops what it started, safely). g2.back.press(robot::cancelAll).says("stop all actions"); ``` A canceled action stops what it started, safely: the lift holds its height and the arm holds its angle. The safety rule still holds. Move the parts back with their own buttons. **Use free buttons.** The part pages put the lift's heights on A, X and Y. Move one of them, or use another button for the action. INIT lists the free buttons (`G2 free: ...`). ### Autos: the same action as one step **Where:** your autonomous file in `autos/`, in its steps. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .forward("To the goal", 24, 0.5) .action(Actions.scoreHigh(robot), 5) // waits until it is done (at most 5 s) .back("Back up", 12, 0.5); ``` `.action(action, seconds)` starts the action and waits until it is done. When it takes too long, the autonomous cancels it, and goes on with the next step. ## 3. Check it 1. Lift the wheels off the floor, and keep a hand near STOP. Put the lift at the bottom and the arm in. 2. Press INIT. Check that no warning names `ArmLift`. Press ▶. 3. **Check the rule first, by hand:** with the lift at the bottom, send the arm out with its own button. The arm must stop below its line and wait. The Driver Station says which part waits, and why. 4. Raise the lift. The arm must go on to its position by itself. 5. With the arm out, send the lift down. The lift must wait until the arm comes back in. 6. **Then the action:** put the parts back. Press Y once and watch each move. Press Y again during a move: everything must stop where it is. 7. Press Y and let it run to the end. Each move must start only when the one before it is done. **Slow first:** for the first runs, lower `maxPower` in `Tunables.Lift` and `Tunables.Arm`. Put it back when the order is right. ## 4. Tune it - **Wait times:** each `waitUntil` has a time limit. Set it a little longer than the move takes on the robot. A limit that runs out stops the action. Watch the Driver Station for the wait's name. - **The drop time:** `waitSeconds(0.3)` gives the piece time to leave the claw. Make it longer if the arm pulls the piece back in. - **Order:** some moves can start before the one before them ends. For example, the arm can start out when the lift is above `liftBelow`. Change one wait at a time, and check again. - **The rule's stop time:** if a part still goes past its waiting point, raise its `StopSec` ([Interlock](https://crossbotics.com/ftc-helper/docs/reference/parts/interlock/)). If it waits too far out, lower it. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | INIT stops: `Tunables.ArmLift.armAbove = MEASURE` | Not measured yet. Find the two numbers (step 2) | | INIT stops on a field name | The name does not match the part. INIT says "did you mean ...?". Use that name | | The arm never swings out | The lift never leaves its zone: `liftBelow` is above the `high` height. Lower `liftBelow` | | The lift never goes down after a score | The arm is still in its zone: `armAbove` is below the `stowed` angle. Raise `armAbove` | | The action stops half way | A `waitUntil` ran out of time: `timed out waiting for ...`. Give it more time, or tune that part | | The claw opens before the arm is out | The arm's wait is missing or too short. Wait on `r.arm::isAtTarget` | | The parts still touch | The zones are too small. Move `armAbove` down or `liftBelow` up, or add a margin ([Interlock](https://crossbotics.com/ftc-helper/docs/reference/parts/interlock/)) | ## Done when - With the lift low, the arm will not swing out, from any button. - With the arm out, the lift will not go down. - One press of the button scores, in order, and a second press stops it. - The autonomous runs the same action as one step. --- **Next:** [Controls](https://crossbotics.com/ftc-helper/docs/controls/): more ways to use the buttons. **Look it up:** [Actions.java](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/) for every action step, and [Interlock](https://crossbotics.com/ftc-helper/docs/reference/parts/interlock/) for every rule setting. Examples: [Two parts that must not collide](https://crossbotics.com/ftc-helper/docs/guides/interlocks/). --- # The basics URL: https://crossbotics.com/ftc-helper/docs/cookbook/01-the-basics/ **The questions on this page:** - [Coming from Blocks: where did my blocks go?](#coming-from-blocks-where-did-my-blocks-go) - [Where does each line go? The files, whole](#where-does-each-line-go-the-files-whole) - [Words you will meet](#words-you-will-meet) ## Coming from Blocks: where did my blocks go? | In Blocks you used | Here you write | In which file | | --- | --- | --- | | a `repeat while opModeIsActive` loop | nothing: the library runs the loop for you, many times a second | - | | drive forward, turn (in autonomous) | `.move("Forward", 24, 0, 0.5)`, `.turn("Left", 90, 0.4)` ([moves](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-drive-forward-sideways-and-turn)) | a file in `autos/` | | `if` a sensor or part says something, then ... | `.waitUntil(...)`: wait until it is true, then go on ([wait until](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-wait-until-something-is-true)) | `Actions.java` or an autonomous | | `if` the drivers chose something before the match | `onlyIf(...)` with a menu choice ([choices](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-let-the-drivers-choose-before-the-match)) | an autonomous | | `repeat 3 times` | a `for` loop that adds the steps 3 times to an action ([repeat](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-repeat-steps-several-times)) | `Actions.java` | | set servo position | a named position: `robot.claw.open()`, `robot.intakeDeploy.goTo("deployed")` ([servo positions](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-any-servo-with-named-positions-a-gate-a-fold-out)) | `Controls.java`, `Actions.java` | | `waitForStart` | nothing: the library waits for ▶ (start on the Driver Hub). For something right after ▶: `atStart(...)` ([at ▶](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-run-an-action-when-the-opmode-starts)) | `Robot.java` | | blocks before `waitForStart`, or after the loop | `atInit(...)`, `duringInit(...)`, `atStop(...)` ([your own code](https://crossbotics.com/ftc-helper/docs/guides/your-own-code/)) | `Robot.java` | | `if gamepad2.y then ...` inside the loop | one line, once: `g2.y.press(...)` ([buttons](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-make-a-button-do-something-once)) | `Controls.java` | | `if` the button is held | `g1.a.hold(...)` ([hold](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-run-something-only-while-a-button-is-held)) | `Controls.java` | | `sleep 500` | `.waitSeconds(0.5)` ([wait](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-wait-half-a-second-like-sleep-in-blocks)) | `Actions.java` or an autonomous | | a loop that waits until something is true | `.waitUntil(...)` ([wait until](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-wait-until-something-is-true)) | `Actions.java` or an autonomous | | set motor direction REVERSE | drive motors: `.reversed("front_right", ...)` ([drive](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#a-wheel-turns-the-wrong-way-how-do-i-fix-it)); a lift: `.reversed()` ([lift](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#my-lift-goes-down-when-it-should-go-up-how-do-i-fix-it)) | `Robot.java` | | set motor power | a command of the part: `robot.intake.in()`, `robot.lift.goTo("high")` ([parts](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-send-a-part-to-a-position-from-a-button)) | `Controls.java`, `Actions.java` | | a variable for a number (a speed, a position) | a number in `Tunables.java` ([numbers](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#where-do-the-numbers-go)) | `Tunables.java` | | `telemetry.addData` | `show("Label", ...)` ([show](https://crossbotics.com/ftc-helper/docs/cookbook/13-telemetry/#how-do-i-show-a-value-on-the-driver-station-screen)) | `Controls.java` | | drive blocks (sticks to motor powers) | nothing: driving is built in ([driving](https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/#driving-that-is-already-built-in)) | - | **Why there is no loop:** in Blocks, your code ran again and again in the loop. Here `buttons(...)` runs **once**, at INIT, and each line plugs a job into a button. Then the library's loop runs the job each time the driver presses the button. So you never write `if`, `while` or `sleep` for buttons. More: [From Blocks to Java](https://crossbotics.com/ftc-helper/docs/blocks-to-java/). ## Where does each line go? The files, whole Each recipe gives a few lines. Put them INSIDE one of these files, at the spot the comment shows. Keep every other line of the file. Your files also start with a `package` line and some `import` lines. The recipes leave them out. They stay at the very top, above `public class`. An import tells Java where a word like `Lift` comes from. When Android Studio shows a word in red, click it and press **Alt+Enter** (Mac: **Option+Enter**) to add its import. **`Robot.java`**: the parts. Fields at the top, one line per part inside `define()`: ```java title="Robot.java" public class Robot extends RobotDefinition { public Intake intake; // one field per part: "public", the kind of part, a name public Lift lift; public Claw claw; public Camera camera; public Launcher launcher; @Override protected void define() { // the drive line, then one line per part drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") .motor("gobilda-5203-312").wheelMm(96) .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); odometry(Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)); // .part(...) = which motor or servo it is: the id on its label (optional, recommended). (1)! intake = add(Intake.motor("intake").part("gobilda-5203-1150")); lift = add(Lift.slide("lift").part("gobilda-5203-435").bottomSwitch("lift_bottom")); claw = add(Claw.servo("claw").part("gobilda-2000-torque")); camera = add(Camera.limelight("limelight").goal("BLUE SCORING", "RED SCORING")); launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .speedFromDistance(camera)); } } ``` 1. `.part(...)` says which motor or servo it is. It is optional, but we recommend it: with it, the library takes better starting values from the part's numbers, and the simulator moves like the real part. The ids here are examples. Write the ids of your parts, from the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). An arm, a turret and a launcher need the motor's id, and take it in their brackets instead. Every recipe below has the same `.part(...)` comment, with this meaning. **`Controls.java`**: the buttons, and your TeleOp. Button lines go inside `buttons(...)`: ```java title="Controls.java" @TeleOp(name = "Cookbook TeleOp", group = "Cookbook") // the name on the Driver Station @Disabled // delete this line in your copy public class Controls extends ControlMap { public static boolean oneDriver = false; @Override protected void buttons(Robot robot, Pad g1, Pad g2) { // robot = your Robot.java, g1 = gamepad 1, g2 = gamepad 2. Button lines go here: g2.y.press(Actions.scoreHigh(robot)).says("score high"); show("Lift ticks", robot.lift::position); } } ``` **`Actions.java`**: one method per action: ```java title="Actions.java" public class Actions { // One method per action. r = your robot. Use it in Controls.java and in autos. public static Action scoreHigh(Robot r) { return Action.named("Score high") .then(() -> r.lift.goTo("high")) .waitUntil("lift at the top", r.lift::isAtTarget, 2.0) .then(r.claw::open) .waitSeconds(0.5) // wait half a second (this is "sleep", done safely) .then(() -> r.lift.goTo("down")); } } ``` An autonomous file: see [your first autonomous](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-make-my-first-autonomous-drive-2-feet). The numbers file: see [Tunables.java](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#where-do-the-numbers-go). **`Tunables.java`**: one section per part, inside `public class Tunables { ... }`. When a recipe adds a new part, it shows the part's whole section (`public static class Lift { ... }`). Put it inside `Tunables`, next to the other sections. If your file **already has** a section with that name, do not add a second one. Two sections with one name do not compile. Copy only the lines inside it into yours, and change the lines you already have. A recipe that adds to a section you already have says so ("In your `Tunables.Launcher` section") and shows only the lines. **How a recipe's section reads:** one number per line, with a short comment. - `MEASURE`: a number that only your robot can give (a lift's top, a servo's positions). INIT stops and names the tool that finds it. Write the number in its place. - `DEFAULT`: the library's starting value, shown in brackets in the comment. Change it only when you see the problem it fixes ([Find a setting by what you want](https://crossbotics.com/ftc-helper/docs/reference/tunables/#find-a-setting-by-what-you-want)). - A real number: the point of the recipe (a slower robot, a spot on the field). - These words need one line at the top of `Tunables.java`: `import static com.crossbotics.ftchelper.robot.Starting.*;` **Names:** the name in quotes in `Robot.java` (`Lift.slide("lift")`) is exactly the device's name in the robot configuration on the Driver Station. The section's name is that name in CamelCase (each word starts with a capital letter, no spaces or `_`): `"lift"` reads `Lift`, `"intake_deploy"` reads `IntakeDeploy`. ## Words you will meet | Word | Means | | --- | --- | | `Robot.java` | the file that says WHAT is on the robot: the drive and one line per part, inside `define()` | | `Tunables.java` | the file with every number (speeds, positions), one section per part | | `Controls.java` | the file that says which button does what, inside `buttons(...)`. It is also your TeleOp | | `Actions.java` | moves that use several steps or parts (score, grab) | | `autos/` | the folder with your autonomous programs, one file each | | configuration name | the name of a motor or servo you typed on the Driver Station (`"lift"`). The code must use the same name | | `robot.lift::position` | `::` hands over a method without running it. The library runs it later (when the driver presses the button) | | `() -> robot.lift.goTo("high")` | a **lambda**: a small piece of code the library runs later. Use `::` when the job is one method with nothing in its brackets (`robot.claw::open`); use `() ->` when the brackets hold something (`goTo("high")`) or for several commands | | `g1`, `g2` | gamepad 1 (the driver) and gamepad 2 (the operator) | | operator | the second driver, on gamepad 2: runs the mechanisms while the driver drives | | GUIDE | the center button of the gamepad. **Tap:** the button map (what each button does). **Hold 1 s** (PRACTICE profile): the tuning menu (change numbers while the robot runs) | | "every loop" | the library's loop runs many times a second: it reads the gamepads, runs the jobs and updates every part. You never write it | | power | from 0 (stopped) to 1 (full). A negative power runs the other way | | `robot`, `g1`, `g2`, `s` | names the library hands you: `buttons(Robot robot, Pad g1, Pad g2)` and `steps(Steps s, Robot robot)` (see [the files, whole](#where-does-each-line-go-the-files-whole)) | | `;` | ends a line of Java. A chain of steps (`.move(...)` then `.turn(...)`) is ONE line split over several lines: only its last line has `;` | | `"lift"` (in quotes) | a name. Capitals and spelling must match exactly | | class | one Java file's main block: `public class Robot ... { ... }`. "Inside the class" = between its `{` and `}` | | method | a named piece of code, like `define()` or `scoreHigh(...)`. Its lines go between its `{` and `}` | | `@TeleOp(...)`, `@Autonomous(...)` | puts the program in the Driver Station's list, with this name | | `@Disabled` | hides the program from the list. The cookbook's programs have it. Delete it in your copy | | `@Override`, `public`, `static`, `protected` | Java words the file needs. Copy them as they are | | INIT, ▶ | the Driver Station's two buttons: INIT gets ready (the library moves nothing then), and ▶ (start) runs the program | | PRACTICE, COMPETITION | the two profiles (ways to run): PRACTICE is slower and has the tuning menu | | ticks (counts) | how far a motor has turned, from its encoder (a sensor in the motor) | | `kP`, `kI`, `kD`, `kF` | the PID numbers: how hard a lift pushes toward its target. Start with the defaults | | catalog id (`"gobilda-5203-312"`) | a motor's or servo's name in the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/): 5203 is goBILDA's motor series, 312 its RPM (on the motor's label) | | `.part("gobilda-5203-435")` | which motor or servo a part uses. Optional, but recommended: with it, the library takes better starting values from the part's numbers, and the simulator moves like the real part. An arm, a turret and a launcher need the id, and take it in their brackets instead | | tuning menu | a menu where you change numbers while the robot runs. The INIT choice menu of an autonomous is a different menu | | terminal | a window where you type commands. In Android Studio: the **Terminal** tab at the bottom ([how](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/)) | **One rule for every recipe:** a job never waits. A `sleep(...)` or a `while` loop in a button job or an action freezes the whole robot, so never write one there. To wait, see [how do I wait half a second (like sleep)?](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-wait-half-a-second-like-sleep-in-blocks). --- # Driving URL: https://crossbotics.com/ftc-helper/docs/cookbook/02-driving/ **The questions on this page:** - [How do I set up a mecanum drive?](#how-do-i-set-up-a-mecanum-drive) - [How do I set up a tank (standard) drive?](#how-do-i-set-up-a-tank-standard-drive) - [A wheel turns the wrong way. How do I fix it?](#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-tell-the-robot-how-the-control-hub-is-mounted) - [How do I make the robot slower (or faster)?](#how-do-i-make-the-robot-slower-or-faster) - [How do I let one driver do everything?](#how-do-i-let-one-driver-do-everything) - [How do I put slow mode on a trigger?](#how-do-i-put-slow-mode-on-a-trigger) - [Driving that is already built in](#driving-that-is-already-built-in) ## How do I set up a mecanum drive? **Where:** `Robot.java`, inside `define()`. ```java title="Robot.java" // The four motor names, in this order: front left, front right, back left, back right. drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") .motor("gobilda-5203-312").wheelMm(96) // the motor (catalog id) and wheel size .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); ``` **Why:** the names must match the configuration, and the wheel size makes autonomous distances right. **More:** [Robot.java](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/), [Drive](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/). ## How do I set up a tank (standard) drive? **Where:** `Robot.java`, inside `define()` (in place of the mecanum line). ```java title="Robot.java" drive(Drive.tank("left_drive", "right_drive") .motor("gobilda-5203-312").wheelMm(96) .reversed("right_drive") // only the motors that run backward .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); ``` **Why:** the motors on the two sides face opposite ways, so one side runs backward. List that side's motors in `.reversed(...)`. With two motors per side, name all four: `Drive.tank("front_left", "front_right", "back_left", "back_right")`. **More:** [Robot.java](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#your-motor-names), [Drive](https://crossbotics.com/ftc-helper/docs/reference/parts/drive/). ## A wheel turns the wrong way. How do I fix it? **Where:** `Robot.java`, in the drive line, before `.imu(...)`. ```java title="Robot.java" drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") .motor("gobilda-5203-312").wheelMm(96) // List EVERY reversed drive motor. Without this line the left side is reversed. .reversed("front_right", "back_right") .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD)); ``` **Why:** the motors on the two sides face opposite ways. So one side must run reversed, or the robot does not go straight. **More:** [Wiring checks: check the motor directions](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#motor-direction-check-each-wheel-rolls-forward), [Troubleshooting](https://crossbotics.com/ftc-helper/docs/troubleshooting/#robot-behavior). ## How do I tell the robot how the Control Hub is mounted? **Where:** `Robot.java`, the `.imu(...)` part of the drive line. ```java title="Robot.java" drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right") .motor("gobilda-5203-312").wheelMm(96) // Which way the hub's LOGO faces, then which way its USB PORTS face, on the robot. .imu("imu", LogoFacingDirection.LEFT, UsbFacingDirection.UP)); ``` **Why:** the IMU (the hub's turn sensor) must know which way is up. If it does not, turns and field-centric driving go wrong. **More:** [Robot.java: the IMU](https://crossbotics.com/ftc-helper/docs/five-files/01-robot-java/#how-your-control-hub-is-mounted). ## How do I make the robot slower (or faster)? **Where:** `Tunables.java`, section `Drive`. ```java title="Tunables.java" public static class Drive { // a fixed name: always Drive public static double maxPower = 0.6; // top wheel power: slow for first drives (1.0) public static double practiceMaxPower = DEFAULT; // top wheel power in PRACTICE (same as maxPower) public static double slowSpeed = DEFAULT; // top power with the slow trigger held (0.3) public static double strafeCorrection = DEFAULT; // sideways moves: Drive Tuner (1.15) public static double turnKp = DEFAULT; // auto turns: push per degree off (0.012) public static double turnKd = DEFAULT; // auto turns: brake near the end (0.003) public static double moveMinPower = DEFAULT; // auto: least power that moves it (0.30) public static boolean calibrated = false; // true after the Drive Tuner: auto runs then } ``` **Why:** `maxPower` is the top power in both profiles, so the drivers practice at match speed. Lower it for the first drives, then set it back. To set a lower top power for PRACTICE only, use `practiceMaxPower`, for example on a new driver's first day. **More:** [Tunables.java: the numbers](https://crossbotics.com/ftc-helper/docs/five-files/02-tunables-java/#the-drives-numbers), [Profiles](https://crossbotics.com/ftc-helper/docs/guides/profiles/). ## How do I let one driver do everything? **Where:** `Controls.java`, at the top of the class. ```java title="Controls.java" // true: every button is on gamepad 1 (the operator's buttons move there). public static boolean oneDriver = true; ``` **Why:** with one driver, the operator's buttons move to gamepad 1, and the stick clicks switch slow mode and field-centric. **More:** [How buttons work: one driver or two](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#one-gamepad-and-a-second-one-when-you-want-it). ## How do I put slow mode on a trigger? **Where:** `Controls.java`, inside `buttons(...)`. This is for one driver. With two drivers, LT on gamepad 1 is already slow mode. ```java title="Controls.java" // One driver: slow on LT. The further it is pulled, the slower (down to slowSpeed). g1.lt.slow().says("slow"); ``` **Why:** a trigger gives fine control: a small squeeze makes the robot a little slower. **More:** [ControlMap: one driver](https://crossbotics.com/ftc-helper/docs/reference/controls/#controlmap). ## Driving that is already built in You write no code for these. With `Controls.java` (two drivers): - **Drive:** the gamepad 1 left stick drives (and strafes), and right stick X turns. LT gives slow mode: the further you pull it, the slower the robot. - **Field-centric** (mecanum): double-tap gamepad 1 **Y** to switch it on and off. Then "forward" is away from the drivers, whichever way the robot faces. - **Pause:** tap gamepad 1 **BACK**, and everything stops on brake. Tap again to go on. - **Reset "forward":** turn the robot to face away from you, then hold gamepad 1 **BACK** for 1 second. **More:** [How buttons work: the driving you get for free](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#the-librarys-own-buttons), [the standard map](https://crossbotics.com/ftc-helper/docs/reference/controls/#controlmap). --- # Buttons and gestures URL: https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/ **Pick a free button.** Each part's usual buttons are lines in `Controls.java` too (see each part's "buttons to add" in the [reference](https://crossbotics.com/ftc-helper/docs/reference/robot-java/)). For example, the claw is on operator **B**, and the lift is on **A**, **X** and **Y**. When two jobs are on one button, INIT stops and names the button. INIT also lists the free buttons ([move a button](#how-do-i-move-a-parts-button-to-another-button)). **The questions on this page:** - [How do I make a button do something once?](#how-do-i-make-a-button-do-something-once) - [How do I run something only while a button is held?](#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-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-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-make-a-button-safe-hold-for-1-second) - [How do I use two buttons together (like a shift key)?](#how-do-i-use-two-buttons-together-like-a-shift-key) - [How do I make the gamepad buzz?](#how-do-i-make-the-gamepad-buzz) - [How do I control a part with a stick?](#how-do-i-control-a-part-with-a-stick) - [How do I move a part's button to another button?](#how-do-i-move-a-parts-button-to-another-button) - [How do I put the launcher's fire button on another button?](#how-do-i-put-the-launchers-fire-button-on-another-button) - [How do I let the parts add their usual buttons by themselves?](#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-move-the-librarys-own-buttons-slow-field-centric-pause) - [How do I change the double-tap and hold times?](#how-do-i-change-the-double-tap-and-hold-times) - [How do I switch the alliance during TeleOp?](#how-do-i-switch-the-alliance-during-teleop) - [Buttons that are already built in](#buttons-that-are-already-built-in) ## How do I make a button do something once? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Once per press. "::" hands over the method; the button runs it later. g2.y.press(robot.claw::open).says("open the claw"); // Several commands: "() ->" starts a small piece of code (a lambda). g2.x.press(() -> robot.lift.goTo("low")).says("lift to low"); ``` **Why:** `press` runs the job once per press, the moment the button goes down. **More:** [Controls.java: add your own jobs](https://crossbotics.com/ftc-helper/docs/five-files/03-controls-java/#add-your-own-button), [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#every-press-type). ## How do I run something only while a button is held? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Runs every loop while held; the second job runs once when it is let go. g1.a.hold(robot.intake::in, robot.intake::stop).says("intake in (hold)"); ``` **Why:** the second job stops the intake when you let go. Without it, the intake keeps running. **More:** [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#every-press-type). ## How do I switch something on and off with one button? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Each press switches the intake on or off. rumble(): 2 buzzes = on, 1 buzz = off. g1.x.toggle(robot.intake).rumble().says("intake on/off"); ``` **Why:** `toggle` remembers on or off for you. The buzz tells the driver which one it is, so the driver does not have to look. **More:** [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#every-press-type). ## How do I put a tap, a hold and a double-tap on one button? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Three gestures on one button: tap, hold, double-tap. g2.rb.tap(robot.launcher::fire).says("fire one") .hold(robot.launcher::fireWhileHeld, robot.launcher::ceaseFire).says("keep firing") .doubleTap(() -> robot.launcher.fire(3)).says("fire three"); ``` **Why:** one button can do several jobs, so the drivers need fewer buttons to remember. **More:** [Controls: gestures](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#several-press-types-on-one-button). ## How do I make a button safe ("hold for 1 second")? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Runs once, after the button is held for 1 second: a safe "are you sure?". g2.dpadLeft.heldFor(1.0, robot.launcher::stop).says("hold 1 s: flywheel off"); ``` **Why:** a quick bump of the button does nothing, so nobody starts a big job by accident. **More:** [Controls: gestures](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#several-press-types-on-one-button). ## How do I use two buttons together (like a shift key)? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Hold RB (the "shift key"), then press D-pad up: for a job that must not run by accident. g1.rb.with(g1.dpadUp, () -> robot.lift.goTo("high")).says("lift to high"); ``` **Why:** a pair is a safe place for a big job that you use only once or twice a match, like a climb. D-pad up alone still does its own job. **More:** [Controls: two buttons together](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#two-buttons-together). ## How do I make the gamepad buzz? **Where:** `Controls.java`, inside `buttons(...)`. Add `.rumble()` after a job (see [the toggle recipe](#how-do-i-switch-something-on-and-off-with-one-button)). Or make the gamepad buzz when the robot gets ready: ```java title="Controls.java" // A buzz on gamepad 2 each time the flywheel gets to its speed. g2.rumbleWhen(robot.launcher::isReady); ``` **Why:** the drivers watch the robot, not the Driver Station. A buzz tells them "ready", so they do not have to look away. **More:** [Controls: feedback](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/#feedback-on-a-button). ## How do I control a part with a stick? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // A stick is a number from -1 to 1 (up and right are +). Its value goes to the job every loop. g2.rightStickY.use(robot.lift::manual).says("lift by hand"); ``` **Why:** a stick gives a number every loop, so the part moves as far as you push the stick. When you let go, the part holds. **More:** [Controls: sticks](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#every-press-type). ## How do I move a part's button to another button? **Where:** `Controls.java`, inside `buttons(...)`. A part's buttons are lines in `Controls.java`. For example, the intake's usual buttons are operator RT and LT. To move them, change the button in their lines: ```java title="Controls.java" // The intake's usual lines are on RT and LT: here the same jobs are on the bumpers. g2.lb.hold(robot.intake::holdIn, robot.intake::stop).says("intake in (hold)"); g2.rb.hold(robot.intake::out, robot.intake::stop).says("intake out (hold)"); ``` **Why:** a part's buttons are your own lines. Put its jobs on the buttons you want, and leave its usual buttons free. **More:** [How buttons work: the buttons the parts bring](https://crossbotics.com/ftc-helper/docs/controls/01-how-buttons-work/#a-parts-buttons). ## How do I put the launcher's fire button on another button? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" robot.launcher.fireOn(g2.y); // all of RB's firing moves to Y robot.launcher.spinOn(g2.x); // LB's spin up / down moves to X ``` **Why:** the fire button does more than one job. A tap fires one piece, quick taps line up more shots, a hold keeps firing, and a tap then a hold sprays. `fireOn` moves all of these jobs in one line, and RB is then free for something else. `fireOn(null)` leaves no fire button at all. **More:** [Firing](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#firing-shot-modes-feed-stop-piece-path). ## How do I let the parts add their usual buttons by themselves? **Where:** `Controls.java`, inside the class, as a method of its own: below the `}` that ends `buttons(...)`, above the class's last `}`. ```java title="Controls.java" // true: each part adds its usual buttons by itself. A line in buttons(...) on one of them replaces it. @Override protected boolean useStandardButtons() { return true; } ``` **Why:** code written before v0.39.0 needs it. In that code, each part put its usual buttons on the gamepads with no line in `Controls.java`. Since v0.39.0, a part has no buttons until you write its lines (see each part's "buttons to add" in the [reference](https://crossbotics.com/ftc-helper/docs/reference/robot-java/)). So you can read every button as a line. **More:** [ControlMap](https://crossbotics.com/ftc-helper/docs/reference/controls/#controlmap). ## How do I move the library's own buttons (slow, field-centric, pause)? **Where:** `Controls.java`, inside the class, as a method of its own: below the `}` that ends `buttons(...)`, above the class's last `}`. At the top of the file, with the other imports: `import com.crossbotics.ftchelper.teleop.LibraryButtons;` ```java title="Controls.java" // The library's own buttons (driving, pause, menus...): move them here; null = no button. @Override protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2) { lib.fieldCentric(g1.x); // field-centric on/off: X instead of Y lib.slow(g1.rt); // slow on the right trigger: LT is free now lib.switchAlliance(g1.start, g1.back); // optional, off by default: hold START, then BACK, 1.5 s } ``` **Why:** the old button is then free for your own jobs in `buttons(...)`. When two library jobs are on one button, INIT stops and names the button. A file has only one `libraryButtons(...)` method, so put every `lib.` line in it. **More:** [Controls: move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/). ## How do I change the double-tap and hold times? **Where:** `Tunables.java` (optional: leave the section out for the defaults). ```java title="Tunables.java" /** Optional: slower gestures, e.g. for new drivers. Leave the section out for the defaults (in brackets). */ public static class Buttons { // a fixed name: always Buttons public static double tapGapSec = 0.45; // most time between the taps of a double-tap (0.35) public static double holdSec = 0.4; // a press this long is a hold, not a tap (0.3) } ``` **Why:** some drivers tap slower. These times are in the tuning menu too. When you tune a value there, copy it back into `Tunables.java`, because the file is the record. **More:** [Press types](https://crossbotics.com/ftc-helper/docs/controls/02-press-types/#several-press-types-on-one-button). ## How do I switch the alliance during TeleOp? The drivers choose the alliance in INIT (gamepad 1: X = BLUE, B = RED). When they picked the wrong one and the match has started, this switch fixes it. Turn it on first. It is off by default, so nobody switches by accident. **Where:** `Controls.java`, inside the class, as a method of its own (below the `}` that ends `buttons(...)`). If you already have a `libraryButtons(...)` method, add only the `lib.switchAlliance` line to it. ```java title="Controls.java" // Controls.java, inside the class, next to buttons(...) (import // com.crossbotics.ftchelper.teleop.LibraryButtons at the top). Off by default. @Override protected void libraryButtons(LibraryButtons lib, Pad g1, Pad g2) { // Gamepad 1: hold START, then press and hold BACK too, for 1.5 s: BLUE <-> RED. lib.switchAlliance(g1.start, g1.back); } ``` **Why:** the alliance sets the goal that the camera and the turret aim at, and the light's color. With the wrong alliance, the robot aims at the other alliance's goal all match. Press START first, then BACK. BACK alone is the pause, so BACK first only pauses the robot. The 1.5 s hold means a bump does nothing. **More:** [Controls: move the library's buttons](https://crossbotics.com/ftc-helper/docs/controls/04-move-library-buttons/). ## Buttons that are already built in - **The button map:** INIT shows every button and what it does. During the match, tap **GUIDE**. - **The tuning menu:** hold **GUIDE** for 1 second (PRACTICE profile). A tap shows the map, a hold opens the menu. Copy each number you change there into `Tunables.java` ([Live tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/)). - **Two jobs on one button:** INIT stops and names the button, so you find the mistake before the match. - **Pause:** press gamepad 1 **BACK** (the small button left of the center), and everything stops at once. Tap it again to go on. - **Alliance:** choose it in INIT (gamepad 1: X = BLUE, B = RED). Switching during TeleOp is optional. [Turn it on](#how-do-i-switch-the-alliance-during-teleop). Then, on gamepad 1, hold the small **START** button, then press and hold **BACK** too, for 1.5 s. If you let go sooner, the alliance stays the same and the debug lines turn on or off. - **Set pose here** (robots with odometry): put the robot on the reset spot, let go of the sticks, and hold gamepad 1 **START** for 1 s. This works in INIT or in the match ([how](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-set-the-pose-when-autonomous-did-not-run)). **More:** [What the drivers see and feel: the button map](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/#the-button-map-and-the-teleops-init-screen). --- # Mechanisms URL: https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/ Each part is one line in `Robot.java`'s `define()`. It also needs a field at the top of the class (for example `public Lift lift;`) and a section with its numbers in `Tunables.java`. The section's name is the configuration name in CamelCase: `intake_deploy` reads `IntakeDeploy`. For its buttons, copy its lines into `Controls.java` (see "buttons to add" in the [reference](https://crossbotics.com/ftc-helper/docs/reference/robot-java/)). **The questions on this page:** - [How do I add an intake on a motor?](#how-do-i-add-an-intake-on-a-motor) - [How do I add an intake on CR servos?](#how-do-i-add-an-intake-on-cr-servos) - [How do I make the intake run from the start?](#how-do-i-make-the-intake-run-from-the-start) - [How do I add a lift with set heights?](#how-do-i-add-a-lift-with-set-heights) - [My lift goes down when it should go up. How do I fix it?](#my-lift-goes-down-when-it-should-go-up-how-do-i-fix-it) - [My motor isn't in the catalog](#my-motor-isnt-in-the-catalog) - [How do I run one lift on two motors?](#how-do-i-run-one-lift-on-two-motors) - [How do I add an arm that moves in degrees?](#how-do-i-add-an-arm-that-moves-in-degrees) - [How do I add a claw?](#how-do-i-add-a-claw) - [How do I run a claw on two servos?](#how-do-i-run-a-claw-on-two-servos) - [How do I add a wrist?](#how-do-i-add-a-wrist) - [How do I add any servo with named positions (a gate, a fold-out)?](#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-get-my-servos-full-range) - [How do I send a part to a position from a button?](#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?](#my-robot-doesnt-have-this-part-yet-how-do-i-keep-its-code) - [How do I add a launcher (flywheel and feeder)?](#how-do-i-add-a-launcher-flywheel-and-feeder) - [How do I add a turret that follows the goal?](#how-do-i-add-a-turret-that-follows-the-goal) - [How do I fire only when aimed, at the right speed?](#how-do-i-fire-only-when-aimed-at-the-right-speed) ## How do I add an intake on a motor? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // At the top of the class: public Intake intake; Here in define(): // "intake" = the motor's name in the robot configuration. Its numbers: Tunables.Intake. // .part(...): which motor it is (optional, recommended). intake = add(Intake.motor("intake").part("gobilda-5203-1150")); ``` ```java title="Tunables.java" public static class Intake { // "intake" in the configuration public static double inPower = DEFAULT; // power taking pieces in, 0 to 1 (1.0) public static double outPower = DEFAULT; // power pushing pieces out (0.7) } ``` **Why:** the intake reads its numbers from `Tunables.Intake`. Its buttons are lines in `Controls.java`: [Intake: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/#buttons-to-add). **More:** [Add a lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#robotjava-one-line), [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/). ## How do I add an intake on CR servos? A CR (continuous rotation) servo spins all the way round, like a small motor, instead of going to a position. **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // Two continuous-rotation (CR) servos. The one that spins the wrong way is reversed. (1)! // "intake", "intake_right" = the servos' names in the robot configuration. Numbers: Tunables.Intake (the 1st name). // .part(...): which servo it is (optional, recommended). intake = add(Intake.crServos("intake", "intake_right").part("gobilda-2000-speed") .reversed("intake_right")); ``` 1. Also add the field at the top of the class: `public Intake intake;`. The two servos face each other, so one must turn the other way. `.reversed(...)` names that servo. **Why:** two servos that face each other must turn opposite ways to pull a piece in. The numbers are in `Tunables.Intake` too (`inPower`, `outPower`). **More:** [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/). ## How do I make the intake run from the start? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // Runs in from ▶ until stopped. Its button (operator RT) then switches it on/off. // .part(...): which motor it is (optional, recommended). add(Intake.motor("intake").part("gobilda-5203-1150").onAtStart()); ``` **Why:** many robots collect pieces all match. With this line, the driver does not have to switch the intake on. **More:** [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/). ## How do I add a lift with set heights? **Where:** `Robot.java` (the part) and `Tunables.java` (its numbers). ```java title="Robot.java" // At the top of the class: public Lift lift; Here in define(): // "lift", "lift_bottom" = the motor's and the bottom switch's names in the robot configuration. (1)! // .part(...): which motor it is (optional, recommended). lift = add(Lift.slide("lift").part("gobilda-5203-435").bottomSwitch("lift_bottom")); ``` 1. Each time the lift presses the bottom switch, the switch sets the lift's 0. With no switch, delete `.bottomSwitch(...)`. ```java title="Tunables.java" public static class Lift { // "lift" in the configuration public static double min = MEASURE; // lowest safe point, counts (Motor Finder) public static double max = MEASURE; // highest safe point, counts (Motor Finder) public static double kP = DEFAULT; // push toward the target (from the motor) public static double kI = DEFAULT; // fix a small steady miss (0) public static double kD = DEFAULT; // brake near the target (from the motor) public static double kF = DEFAULT; // hold up against gravity (0.05) public static double down = MEASURE; // a named height, counts: any name you like public static double low = MEASURE; // a named height (Motor Finder) public static double high = MEASURE; // a named height (Motor Finder) } ``` **Why:** the lift never goes past `min` and `max`, so it cannot break itself. INIT stops if they are missing. `MEASURE` stops INIT until you write the real number. Find yours with the [Motor Finder](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-find-a-lifts-limits-and-heights). `"lift"` must be the motor's name in your configuration. To send the lift to a height, see [from a button](#how-do-i-send-a-part-to-a-position-from-a-button). **More:** [Add a lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#tunablesjava-its-numbers), [Lift](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/), [why the bottom switch matters](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#1-what-it-is). ## My lift goes down when it should go up. How do I fix it? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // The lift goes DOWN on positive power (the Motor Finder says "add .reversed()"): flip it. // .part(...): which motor it is (optional, recommended). add(Lift.slide("lift").part("gobilda-5203-435").reversed()); ``` **Why:** the lift's limits and heights count up as it goes up, so positive power must move it up. **More:** [Motor Finder](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/), [Troubleshooting](https://crossbotics.com/ftc-helper/docs/troubleshooting/#robot-behavior). ## My motor isn't in the catalog **Where:** `Robot.java`, inside `define()`. ```java title="Robot.java" // A motor that is not in the catalog: its encoder counts per output turn, then its free speed (RPM). (1)! launcher = add(Launcher.flywheel("launcher", Motors.custom("my-flywheel-motor", 28, 5800))); // A servo: how far it turns (degrees), then its speed (seconds per 60 degrees, at 4.8 V). (2)! claw = add(Claw.servo("claw").part(Parts.customServo("my-claw-servo", 270, 0.16))); // Motors.unknown(...): "I know neither number" (a single unknown number: Double.NaN). (3)! lift = add(Lift.slide("lift").part(Motors.unknown("old-lift-motor"))); ``` 1. Find the two numbers on the seller's page. goBILDA: "Encoder Resolution" (the number "at the Output Shaft") and "No-Load Speed". REV: "Encoder Counts per Revolution" (at the output) and "Free Speed". The name (`"my-flywheel-motor"`) then works like a catalog id, here and in `.part(...)`. 2. When the seller lists 4.8 V and 6 V, use the 4.8 V speed, because the hub gives a servo about 5 V. 3. `Double.NaN` means "I don't know this one". The part then uses general defaults, and INIT says so. A launcher or an arm needs at least the counts per turn: `Motors.custom("...", 28, Double.NaN)`. **Why:** the library works out a part's defaults (a launcher's gains and speed, a lift's kP, a servo's move time) from its motor's or servo's numbers. When you describe yours with the seller's numbers, it works like a catalog part. INIT says `defaults from my-flywheel-motor (custom)`, and `:sim:fromRobot` writes its numbers into the simulator's robot file. For a number you do not know, write `Double.NaN` ("I don't know this one"). Or write the whole part as `Motors.unknown` / `Parts.unknownServo`. The part then uses general defaults, and INIT says so. Do not use a catalog motor that is "close": its numbers would be wrong, and nothing would warn you. **More:** [Parts not in the catalog](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-in-the-catalog), [Parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). ## How do I run one lift on two motors? **Where:** `Robot.java`, inside `define()`, and `Tunables.java`. ```java title="Robot.java" // "lift_left", "lift_right" = the motors' names in the robot configuration. Numbers: Tunables.LiftLeft. (1)! // Plug the encoder cable into the FIRST motor: only its encoder is read. (2)! // The motors face each other, so the second turns the other way: alsoMotorReversed. (3)! lift = add(Lift.slide("lift_left").part("gobilda-5203-435").alsoMotorReversed("lift_right")); ``` 1. The numbers are in `Tunables.LiftLeft` (the FIRST motor's name in CamelCase), not in `Tunables.Lift`. 2. Both motors always get the same power, also when the lift stops or pauses. So one encoder is enough. 3. When both motors turn the same way for "up", use `.alsoMotor("lift_right")` instead. ```java title="Tunables.java" // A lift on two motors, Lift.slide("lift_left").part("gobilda-5203-435").alsoMotorReversed("lift_right"): // its section is the FIRST motor's name in CamelCase. public static class LiftLeft { // "lift_left" in the configuration public static double min = MEASURE; // lowest safe point, counts (first motor) public static double max = MEASURE; // highest safe point, counts (first motor) public static double kP = DEFAULT; // push toward the target (from the motor) public static double kI = DEFAULT; // fix a small steady miss (0) public static double kD = DEFAULT; // brake near the target (from the motor) public static double kF = 0.06; // a heavier slide needs more hold (0.05) public static double down = MEASURE; // a named height (Motor Finder) public static double low = MEASURE; // a named height (Motor Finder) public static double high = MEASURE; // a named height (Motor Finder) } ``` **Why:** two motors on one slide must never fight. The library sends both the very same power in the same loop. It does this also when the lift stops or pauses (BACK). It does it also when an interlock rule (a rule that stops two parts from hitting each other) holds the lift. Your own code that copies the power every loop would miss pause and STOP. **Check the directions before the chain goes on.** With the chain or belt off, each motor must turn the way that lifts. If one is wrong, swap `alsoMotorReversed` and `alsoMotor`. Two motors that push against each other get hot and can break a gearbox. An arm works the same way: `Arm.motor("arm_left", "gobilda-5203-117").alsoMotorReversed("arm_right")`. The simulator ties both motors to one slide (`:sim:fromRobot` writes the second motor's line). **More:** [Two motors on one lift or arm](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#two-motors-on-one-lift-or-arm), [Tunables names](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#in-tunablesjava). ## How do I add an arm that moves in degrees? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // "arm" = the motor's name in the robot configuration. Its numbers: Tunables.Arm. // "gobilda-5203-117" = the motor's catalog id (needed: it works in degrees). (1)! // gearRatio: motor turns per arm turn. 0 degrees = where it is at INIT. arm = add(Arm.motor("arm", "gobilda-5203-117").gearRatio(2)); ``` 1. The arm needs the motor's counts per turn to work in degrees. So, as for a turret or a launcher, the arm's motor id is required. ```java title="Tunables.java" public static class Arm { // "arm" in the configuration public static double min = MEASURE; // lowest safe angle, degrees, 0 = at INIT public static double max = MEASURE; // highest safe angle, degrees (Motor Finder) public static double kP = DEFAULT; // push toward the target (0.02) public static double kI = DEFAULT; // fix a small steady miss (0) public static double kD = DEFAULT; // brake near the target (0.001) public static double kF = 0.1; // hold up against gravity (0) public static double stowed = MEASURE; // a named angle, degrees: any name you like public static double pickup = MEASURE; // a named angle (Motor Finder) public static double score = MEASURE; // a named angle (Motor Finder) } ``` **Why:** degrees are easier to think about than encoder counts. Put the arm at its 0 before you press INIT. **More:** [Arm](https://crossbotics.com/ftc-helper/docs/reference/parts/arm/). ## How do I add a claw? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // At the top of the class: public Claw claw; Here in define(): // "claw" = the servo's name in the robot configuration. Its numbers: Tunables.Claw. // .part(...): which servo it is (optional, recommended). claw = add(Claw.servo("claw").part("gobilda-2000-torque")); ``` ```java title="Tunables.java" public static class Claw { // "claw" in the configuration // The Servo Finder shows "Tunables.Claw: P1 = 0.210, P2 = 0.770": write P1 as open, P2 as closed. public static double open = MEASURE; // servo position, open (Servo Finder) public static double closed = MEASURE; // servo position, closed (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) } ``` **Why:** a claw needs two numbers, open and closed, and the Servo Finder gives them. Its button is a line in `Controls.java`: [Claw: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#buttons-to-add). **More:** [Add a lift](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#robotjava-one-line), [Claw](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/). ## How do I run a claw on two servos? **Where:** `Robot.java`, inside `define()`, and `Tunables.java`. ```java title="Robot.java" // "claw_left", "claw_right" = the servos' names in the robot configuration. Numbers: Tunables.ClawLeft. // Find open and closed in Tune and check > Servo Finder on the FIRST servo: the second moves with it. // The servos face each other, so the second turns the other way: alsoServoReversed. claw = add(Claw.servo("claw_left").part("gobilda-2000-torque").alsoServoReversed("claw_right")); ``` ```java title="Tunables.java" // A claw on two servos, Claw.servo("claw_left").alsoServoReversed("claw_right"): its section is the // FIRST servo's name in CamelCase. public static class ClawLeft { // "claw_left" in the configuration public static double open = MEASURE; // servo position, open (Servo Finder on claw_left) public static double closed = MEASURE; // servo position, closed (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) public static double alsoTrim = DEFAULT; // the second servo: raw position added so the two meet (0; used at the next move) } ``` **Why:** two servos on one part must never fight. The library sends both the same position at the same moment, also when the robot pauses (BACK) or stops. Your own code that copies the position would miss some of these moments. **Reversed or not:** servos that face each other (mirror images, the usual way) turn opposite ways, so use `alsoServoReversed`. When both face the same way, use `.alsoServo("claw_right")`. **When the fingers do not quite meet:** the horns may sit a spline tooth apart. Set `alsoTrim` (a small raw position, like 0.02) for the second servo. The same line works on a Wrist, a Positioner and a servo feeder: `Indexer.servo("feeder_left").alsoServoReversed("feeder_right")` (two arms that pinch a piece into a launcher). On a CR servo feeder, it adds a second wheel that spins the other way: `Indexer.crServo("feeder_left").alsoServoReversed("feeder_right")`. **More:** [Two servos on one part](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/), [Tunables names](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/#in-tunablesjava). ## How do I add a wrist? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // At the top of the class: public Wrist wrist; Here in define(): // "wrist" = the servo's name in the robot configuration. Its numbers: Tunables.Wrist. // .part(...): which servo it is (optional, recommended). wrist = add(Wrist.servo("wrist").part("gobilda-2000-speed")); ``` ```java title="Tunables.java" public static class Wrist { // "wrist" in the configuration public static double down = MEASURE; // servo position: any name you like public static double level = MEASURE; // servo position (Servo Finder) public static double up = MEASURE; // servo position (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) } ``` **Why:** a wrist steps through its named positions. Its buttons are lines in `Controls.java`: [Wrist: buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/wrist/#buttons-to-add). **More:** [Wrist](https://crossbotics.com/ftc-helper/docs/reference/parts/wrist/). ## How do I add any servo with named positions (a gate, a fold-out)? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // Any servo with named positions: a gate, a kicker, a fold-out intake. // "intake_deploy" = the servo's name in the robot configuration. Numbers: Tunables.IntakeDeploy. // .part(...): which servo it is (optional, recommended). intakeDeploy = add(Positioner.servo("intake_deploy").part("gobilda-2000-torque")); // Right after ▶ (autonomous and TeleOp): fold the intake out. atStart(() -> Action.named("Deploy").then(() -> intakeDeploy.goTo("deployed"))); ``` ```java title="Tunables.java" public static class IntakeDeploy { // "intake_deploy" in the configuration public static double stowed = MEASURE; // servo position, folded (Servo Finder) public static double deployed = MEASURE; // servo position, folded out (Servo Finder) public static double travelSec = DEFAULT; // time for a full 0-to-1 move (0.3, or the servo's) } ``` **Why:** a `Positioner` has no usual buttons, so you choose when it moves. Here it moves at ▶. **More:** [Positioner](https://crossbotics.com/ftc-helper/docs/reference/parts/positioner/), [an action at ▶](https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/#how-do-i-run-an-action-when-the-opmode-starts). ## How do I get my servo's full range? **Where:** `Robot.java`, inside `define()`: add `.fullRange()` to the servo part. ```java title="Robot.java" // fullRange(): positions 0 to 1 = the servo's whole turn (300 degrees on a goBILDA 2000). (1)! // Turn it on FIRST, then find the positions (Servo Finder: press Y while choosing the servo). wrist = add(Wrist.servo("wrist").part("gobilda-2000-speed").fullRange()); ``` 1. For positions 0 to 1, the hub normally sends 600-2400 us (microseconds). With that signal, a goBILDA 2000 servo turns only 270 of its 300 degrees. `fullRange()` sends the whole 500-2500 us. **Why:** the FTC SDK's normal servo signal (600 to 2400 microseconds) is narrower than what most servos take (500 to 2500). So the servos turn less than the seller says: 270 degrees for a goBILDA 2000, 243 for a REV Smart Robot Servo. Add it only when you need the extra turn. It works the same on a Claw, a Positioner, `Hood.servo`, `Turret.servo` and `Indexer.servo`. After the change, the positions you measured before point somewhere else, so measure them again. Without `.fullRange()`, nothing changes. **More:** [Full range](https://crossbotics.com/ftc-helper/docs/modules/hardware/#full-range) (a table per servo), [Claw, Wrist, Positioner](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/). ## How do I send a part to a position from a button? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // The names are the ones in Tunables.java (capitals do not matter). g2.y.press(() -> robot.arm.goTo("score")).says("arm to score"); g2.a.press(() -> robot.arm.goTo("pickup")).says("arm to pick up"); g2.x.press(() -> robot.lift.goTo("high")).says("lift to high"); g2.b.press(robot.claw::toggle).says("claw open/close"); g2.back.press(() -> robot.intakeDeploy.goTo("stowed")).says("fold the intake in"); ``` **Why:** `goTo("name")` uses the position by its name, so the number is only in `Tunables.java`. These lines use Y, A, X and B. The lift's and the claw's usual lines use the same buttons, so write one or the other. See [pick a free button](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/). **More:** [Lift](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/), [Claw](https://crossbotics.com/ftc-helper/docs/reference/parts/claw/). ## My robot doesn't have this part yet. How do I keep its code? You change three places: the part's line in `Robot.java`, the action in `Actions.java`, and its button in `Controls.java`. **`Robot.java`**, inside `define()`: add `.optional()` to the part's `add` line. Here the part is a deploy servo that folds the intake out. The `atStart` line runs the action below at ▶. ```java title="Robot.java" // optional(): while "intake_deploy" is not in the robot configuration, the part is off (INIT goes on). (1)! // .part(...): which motor or servo it is (optional, recommended). intakeDeploy = add(Positioner.servo("intake_deploy").part("gobilda-2000-torque").optional()); intake = add(Intake.motor("intake").part("gobilda-5203-1150")); // At ▶: fold the intake out, then run it (the action is in Actions.java, below). (2)! atStart(() -> Actions.deployIntake(this)); ``` 1. The deploy servo is not on the robot yet. INIT shows a note and goes on (see **Why**, below). 2. With no deploy servo, the action skips the servo and the wait for it, and only starts the intake. **`Actions.java`**, inside `public class Actions { ... }`: the action. In your file the brackets say `(Robot r)`. ```java title="Actions.java" /** Folds the intake out with the deploy servo, then runs the intake. */ public static Action deployIntake(NotOnTheRobotYet r) { // in your Actions.java: (Robot r) return Action.named("Deploy intake") .then(() -> r.intakeDeploy.goTo("deployed")) .waitUntil("the deploy servo", r.intakeDeploy::isDone, 2.0) .then(r.intake::in, () -> r.intakeDeploy.goTo("stowed")); } ``` **`Controls.java`**, inside `buttons(...)`: the button, with `.needs(...)` at the end. ```java title="Controls.java" // needs(...): while the deploy servo is not on the robot, X does nothing and the // button map at INIT says "off: IntakeDeploy not on the robot". g2.x.press(Actions.deployIntake(robot)).says("deploy intake").needs(robot.intakeDeploy); ``` **Why:** teams build robots in steps. Without `optional()`, INIT stops when the part's device is not in the configuration (`No Servo named "intake_deploy" ...`). With it, INIT shows a note and goes on: `"intake_deploy" not in the configuration: IntakeDeploy is off (optional part)`. In the COMPETITION profile, the note is a warning at the top of the screen (`!! COMPETITION: ... IntakeDeploy is OFF ...`). So nobody plays a match without a part by mistake. Everything that uses the part skips it: - its commands - its buttons (the button map says `G2 X: deploy intake - off: IntakeDeploy not on the robot`) - the action steps (an autonomous keeps going, and its report says `skipped IntakeDeploy (not on the robot)`) When you wire the servo and add it to the configuration, it works, with no code to change. You need no `if (HAS_DEPLOY_SERVO)` switches. To try it in the simulator without the part, write `missing = intake_deploy` in the robot file. **More:** [Parts not on the robot yet](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-on-the-robot-yet). ## How do I add a launcher (flywheel and feeder)? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // A flywheel (in RPM) and the indexer that feeds it one piece at a time. // "launcher", "indexer" = names in the robot configuration. Numbers: Tunables.Launcher, .Indexer. // The motor's catalog id is in the brackets (needed). The indexer's .part(...) is optional, recommended. (1)! launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed"))); ``` 1. The launcher needs its motor's id for its speed control. The indexer's `.part(...)` is optional ([what it does](https://crossbotics.com/ftc-helper/docs/cookbook/01-the-basics/#words-you-will-meet)). ```java title="Tunables.java" public static class Launcher { // "launcher" in the configuration public static double speedRpm = DEFAULT; // shot speed without the table (60% of top) public static double stepRpm = DEFAULT; // speed change per D-pad press (100) public static double readyBandRpm = DEFAULT; // "at speed" = this close to the target (60) public static double idleRpm = 1500; // spins between shots: quicker first shot (0) public static double shotIntervalSec = DEFAULT; // least time between two pieces (0.25) // The hub's speed control: the defaults for the motor until the Flywheel Finder (INIT shows them). // Then write the Finder's numbers in their place. public static double kP = DEFAULT; // push per speed error (kF / 10) public static double kI = DEFAULT; // fix a steady error (kP / 10) public static double kD = DEFAULT; // brake changes (0) public static double kF = DEFAULT; // steady power for a speed (from the motor) // {inches to the goal, RPM}, blended between rows. Example rows: write the Shot Tuner's instead. public static double[][] speedByDistance = {{24, 2200}, {48, 2550}, {72, 2900}, {96, 3250}}; } ``` ```java title="Tunables.java" public static class Indexer { // "indexer" in the configuration public static double rest = MEASURE; // servo position, out of the way (Servo Finder) public static double push = MEASURE; // servo position, piece pushed (Servo Finder) public static double pushSec = DEFAULT; // time to push (0.25, or the servo's speed) public static double returnSec = DEFAULT; // time to come back (the same as pushSec) } ``` **Why:** the launcher feeds a piece only when the wheel is at speed, so every shot flies the same way. **More:** [Add a launcher](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#robotjava-one-line), [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/). ## How do I feed with two wheels, one on each side? **Where:** `Robot.java`, inside `define()`. Add the intake before the launcher. ```java title="Robot.java" // Two CR servo wheels squeeze each piece into the flywheel. They face each other, so the // second spins the other way: alsoServoReversed. Numbers: Tunables.FeederLeft (power, feedSec). // feedWheelOutWith: the intake pushing out turns both wheels backward too. launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.crServo("feeder_left").alsoServoReversed("feeder_right").part("gobilda-2000-speed")) .feedWheelOutWith(intake)); ``` **Why:** two wheels that squeeze the piece push it in straight. One power (`Tunables.FeederLeft`) runs both, so they can never fight. When the intake pushes pieces out, the wheels turn backward, so a piece in the feeder comes out too. A shot always wins. **Test the direction first:** set `feedSec` to 2, fire with no piece, and watch both wheels pull in. Both pull out: add `.reversed()` to the feeder. One pulls out: use `.alsoServo(...)` in place of `.alsoServoReversed(...)`. **Stop on the shot:** `stopOnShot = true` in `Tunables.FeederLeft` stops both wheels when the flywheel sees the shot, so they do not push the next piece in behind. `feedSec` is then only the time limit. It is `boolean`, not `double`: ```java title="Tunables.java" public static class FeederLeft { // "feeder_left" in the configuration: it runs both wheels public static double power = DEFAULT; // wheel power (1) public static double feedSec = DEFAULT; // the most time the wheels run per shot (0.4) public static boolean stopOnShot = true; // stop when the flywheel sees the shot: true or false } ``` **More:** [Indexer](https://crossbotics.com/ftc-helper/docs/reference/parts/indexer/), [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/). ## How do I add a turret that follows the goal? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // The camera knows the goal of each alliance (BLUE first, then RED). camera = add(Camera.limelight("limelight").goal("BLUE SCORING", "RED SCORING")); // "turret" = the motor's name in the robot configuration. 5 motor turns per turret turn. // follows(camera): it follows the goal from ▶, but never past Tunables.Turret min and max. turret = add(Turret.motor("turret", "gobilda-5203-117").gearRatio(5).follows(camera)); ``` ```java title="Tunables.java" public static class Turret { // "turret" in the configuration public static double min = MEASURE; // furthest right, degrees (Motor Finder) public static double max = MEASURE; // furthest left, degrees: 0 = forward, + = left public static double startAngle = DEFAULT; // where you set it by hand before INIT (0) public static double kP = DEFAULT; // push per degree off (0.02) public static double kD = DEFAULT; // brake near the target (0.001) public static double maxPower = DEFAULT; // the most power (0.8) public static double tolerance = DEFAULT; // "aimed" within this, degrees (1.0) public static double cameraOffset = DEFAULT; // aims a little to one side: Aim Tuner (0) } ``` **Why:** the turret aims for the driver, and its limits keep the wires from twisting. **More:** [Add a turret: the turret](https://crossbotics.com/ftc-helper/docs/add-to-robot/06-turret/), [Turret](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/), [Camera](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/). ## How do I fire only when aimed, at the right speed? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // The speed comes from the distance to the goal (Tunables.Launcher.speedByDistance), // and a piece is only fed when the turret points at the goal. // .part(...): which servo it is (optional, recommended). launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .speedFromDistance(camera) .requireReady("turret aimed", () -> turret.isAimed())); ``` **Why:** a shot fired before the turret is on target, or at the wrong speed, is a lost piece. For a turret that follows the goal, `isAimed()` means on the goal NOW. When the camera loses the goal, it is false. **More:** [Add a camera](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/#robotjava-one-line). --- # Game pieces URL: https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/ A `Pieces` line in `Robot.java` counts the pieces the robot holds, and knows which kind fires next. It uses a sensor at the intake, and (optional) one at the "ready to fire" slot. Measure each kind's color (or size) with the Piece Tuner, and write it in `Tunables.java`. The full details: [Pieces and PieceSensor](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/). **The questions on this page:** - [How do I know which piece is in the robot, and how many?](#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-stop-the-intake-when-the-robot-is-full) - [How do I tell pieces apart by size, or with a second camera?](#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-use-the-count-buzz-leds-the-shot-table) - [How do I let the next piece pick the shot table?](#how-do-i-let-the-next-piece-pick-the-shot-table) - [How do I tune the piece sensors?](#how-do-i-tune-the-piece-sensors) ## How do I know which piece is in the robot, and how many? **Where:** `Robot.java`, inside `define()`. ```java title="Robot.java" // At the top of the class: public Pieces pieces; Here in define(), ABOVE the intake line. (1)! // The kinds of piece, a sensor where they come in, one at the "ready to fire" slot (optional). (2)! pieces = add(Pieces.kinds("POLLEN", "RED_NECTAR", "BLUE_NECTAR") .comingIn(PieceSensor.color("intake_color")) // a REV Color Sensor V3 .readyToFire(PieceSensor.color("ready_color")) // another one .max(4) // BIOBUZZ G407: no more than 4 .startsWith(4, "POLLEN")); // the 4 POLLEN preload ``` 1. Put it above the intake line. Then, in each loop, the count is up to date before the intake asks "full?". 2. BIOBUZZ has yellow POLLEN, and red and blue NECTAR. Then come the most pieces the rules allow (`max`) and the preload (`startsWith`). **Why:** each piece the intake sensor sees counts one in. Each feed of the indexer counts one out, the oldest first, once the piece has gone. A jammed feed counts nothing. Until you tune a kind with the Piece Tuner, it reads `"UNKNOWN"`. `robot.pieces.count()`, `robot.pieces.next()` ("POLLEN", "UNKNOWN" or "NONE") and `robot.pieces.isFull()` work anywhere in your code. **More:** [Pieces and PieceSensor](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/). ## How do I stop the intake when the robot is full? **Where:** `Robot.java`, inside `define()`. ```java title="Robot.java" // ADD .stopsWhen(...) to your intake line (no second intake line); the Pieces line goes above it. (1)! // .part(...): which motor it is (optional, recommended). intake = add(Intake.motor("intake").part("gobilda-5203-1150").stopsWhen(() -> pieces.isFull())); ``` 1. The intake then does not pull in a 5th piece. `() ->` means that the intake asks the test in every loop. Pushing out still works. ```java title="Robot.java" // Each feed counts one piece out. requireReady: no feed with nothing to fire. // .part(...): the indexer's servo (optional, recommended). launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .requireReady("a piece to fire", () -> !pieces.isEmpty())); ``` **Why:** BIOBUZZ rule G407 says that a robot may not control more than 4 pieces. The rules ask for "systems to prevent active pickup" of a 5th, and this is one. Put the intake sensor where the robot already holds a piece, so the intake does not stop with a piece half in. The count can be wrong (two pieces can read as one). So the drivers are responsible for G407, not the count. When the count says full and the robot is not, hold RT for 1 s to pull in anyway. The Driver Station warns when the intake is held back for more than 2 s. **More:** [Intake](https://crossbotics.com/ftc-helper/docs/reference/parts/intake/). ## How do I tell pieces apart by size, or with a second camera? **Where:** `Robot.java`, inside `define()`. ```java title="Robot.java" // A REV 2m Distance Sensor across the intake tells the sizes apart (not the colors). (1)! // A second webcam on the ready slot: colors. (2)! pieces = add(Pieces.kinds("POLLEN", "NECTAR") .comingIn(PieceSensor.distance("intake_distance")) .readyToFire(PieceSensor.camera("Webcam 2")) .max(4)); ``` 1. A NECTAR (3.6 in) comes closer to the sensor than a POLLEN (2.8 in). It sees size only, so it cannot tell a red NECTAR from a blue one. 2. The webcam reads the main color in a box of its picture. **Why:** a distance sensor reads 20 mm closer with a NECTAR than with a POLLEN, but it sees no color. Rule G408 forbids controlling the other alliance's NECTAR. A webcam sees colors from farther away, but it cannot tell how far the piece is. **More:** [the sensors compared](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/). ## How do I use the count (buzz, LEDs, the shot table)? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // A buzz on gamepad 2 when the robot holds the most it may. g2.rumbleWhen(robot.pieces::isFull); // Two buzzes when a NECTAR (red or blue) is next to fire. For one kind only: // robot.pieces.whenNextIs("RED_NECTAR"). g2.rumbleWhen(() -> robot.pieces.next().endsWith("NECTAR"), 2); // A light the drivers see: green = full, orange = empty (needs a Lights line in Robot.java, and // import com.crossbotics.ftchelper.robot.LightColor; at the top of this file). robot.lights.show(LightColor.GREEN).when(robot.pieces.whenFull()); robot.lights.show(LightColor.ORANGE).when(robot.pieces.whenEmpty()); // Pieces shows "3/4, next POLLEN" by itself; this adds what the intake sees now. show("At the intake", robot.pieces::atIntake); // The count went wrong? Hold G2's left stick button 1 s = count 0 (its line: below), // and hold the intake's RT 1 s to pull in although the count says full. ``` **Why:** `whenFull()`, `whenEmpty()` and `whenNextIs("POLLEN")` (one kind) are conditions that any part can watch: a buzz, a light (the [Lights](https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/) recipes), or an action that waits. For "either NECTAR", the recipe asks `next()` (the next kind's name) whether it ends with `NECTAR`. When the count is wrong (for example, after you take pieces out by hand), a button sets it to 0. Add this line to `Controls.java`, inside `buttons(...)`. Then hold G2's left stick button for 1 s: ```java title="Controls.java" g2.leftStickButton.heldFor(1.0, robot.pieces::clear).says("piece count = 0"); ``` **More:** [hooks for other parts](https://crossbotics.com/ftc-helper/docs/reference/parts/pieces/). ## How do I let the next piece pick the shot table? **Where:** `Robot.java`, inside `define()`, on your launcher line (the Pieces line must be above it). Also two tables in your `Tunables.Launcher` section ([one table per piece](https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/#how-do-i-use-one-shot-table-per-game-piece)). ```java title="Robot.java" // In define(), BELOW the Pieces line: your launcher line with three more lines. The tables // are Tunables.Launcher.speedByDistancePollen and speedByDistanceNectar. launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .speedFromDistance(camera) .startTable("pollen") // before a piece is known .tableFrom(pieces.nextKind()) // the next piece picks the table .tableFor("nectar", "RED_NECTAR", "BLUE_NECTAR")); // both NECTAR colors use "nectar" ``` **Why:** POLLEN and NECTAR fly differently. With these lines, the drivers never switch tables by hand. Each time the next piece changes, the launcher uses that piece's table. A kind with the same name as a table needs no line (`POLLEN` uses `pollen`). `tableFor` puts both NECTAR colors on the `nectar` table. `NONE` and `UNKNOWN` (a kind not tuned yet) never change the table. `startTable` is the table before the robot knows the first piece. A button (D-pad right) can still pick another table until the next piece changes. **More:** [Launcher: shot tables](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/), [Add a launcher: the next piece picks the table](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#know-which-piece-fires-next). ## How do I tune the piece sensors? **Where:** a new file next to `Robot.java`, `PieceTuner.java`. Below is the whole file. Its first line is `package org.firstinspires.ftc.teamcode;` (Android Studio writes it when you make the file), then: ```java title="PieceTuner.java" import com.crossbotics.ftchelper.finders.PieceTunerOpMode; import com.crossbotics.ftchelper.robot.RobotDefinition; import com.qualcomm.robotcore.eventloop.opmode.Disabled; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; // The Piece Tuner: each sensor's readings, and the numbers for Tunables.java. @TeleOp(name = "Cookbook Piece Tuner", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class PieceTuner extends PieceTunerOpMode { @Override protected RobotDefinition robot() { return new Robot(); // your Robot.java: the tuner finds its piece sensors } } ``` **Why:** each sensor and each robot reads colors a little differently. Hold each kind in front of the sensor and press A. Then copy the lines that the tuner shows into `Tunables.java`. **More:** [Piece Tuner](https://crossbotics.com/ftc-helper/docs/modules/finders/#piecetuneropmode). --- # Aiming and shooting URL: https://crossbotics.com/ftc-helper/docs/cookbook/06-aiming-and-shooting/ **The questions on this page:** - [How do I make the whole robot aim at the goal (no turret)?](#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-make-the-gamepad-buzz-when-the-aim-is-on-target) - [How do I keep aiming when the camera loses the goal?](#how-do-i-keep-aiming-when-the-camera-loses-the-goal) - [How do I aim with the odometry only (no camera)?](#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-make-the-camera-work-in-any-venues-light) - [How do I find game pieces with a HuskyLens?](#how-do-i-find-game-pieces-with-a-huskylens) - [How do I shoot while the robot is driving?](#how-do-i-shoot-while-the-robot-is-driving) - [How do I use one shot table per game piece?](#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)?](#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?](#how-do-i-add-a-hood-to-my-launcher) ## How do I make the whole robot aim at the goal (no turret)? **Where:** `Controls.java`, inside `buttons(...)` (and `Tunables.java` for the numbers, below). The robot needs a camera with a [`goal(...)`](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/) (or odometry with a goal point). Do not use it with a turret that follows the goal. Turret-following and whole-robot aim are separate modes, so INIT stops with a message if both are there. ```java title="Controls.java" // Hold RB: the robot turns to face the goal by itself; the driver keeps forward and sideways. (1)! g1.rb.hold(robot.aimMode()::on, robot.aimMode()::off).says("hold: aim the robot at the goal"); // Or a toggle. Careful: while it is on, the robot turns by itself, even after you let go. (2)! // g1.rb.toggle(robot.aimMode()).says("aim the robot at the goal on/off").rumble(); ``` 1. When you let go, the aim is off, and the driver turns again. To turn by hand while you hold RB, move the turn stick. Do not use it with a turret that follows the goal: these are separate modes (INIT stops with a message). 2. A press switches it on, and the next press switches it off. Two buzzes = on. **Why:** the driver drives, and the robot keeps itself pointed at the goal. Start with hold-to-aim. When you let go, the robot stops turning by itself, so it never surprises anyone. The stick always wins, so the driver can take over at once. The toggle (commented out) keeps aiming after you let go. **More:** [Add a camera: aim the whole robot](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/#controlsjava-its-buttons). ## How do I make the gamepad buzz when the aim is on target? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Gamepad 2 buzzes while the aim is close: the closer, the stronger (Tunables.Aim.rumbleDeg). // It works for a turret that follows the goal and for whole-robot aim. g2.rumbleWhenAimed(); ``` **Why:** the driver who fires watches the field, not the screen. The buzz tells the driver "now". **More:** [Add a camera: feel the aim](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/#controlsjava-its-buttons). ## How do I keep aiming when the camera loses the goal? **Where:** `Robot.java`, inside `define()`, and the goal's place in `Tunables.java`. ```java title="Robot.java" // With an odometry line and Tunables.Aim goalX, goalY, the turret and the speed keep // working when the camera loses the goal: from where the robot is on the field. odometry(Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)); camera = add(Camera.limelight("limelight").goal("BLUE SCORING", "RED SCORING")); turret = add(Turret.motor("turret", "gobilda-5203-117").gearRatio(5).follows(camera)); // .part(...): the indexer's servo (optional, recommended). launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .speedFromDistance(camera) .startTable("pollen")); // the table to start with ``` ```java title="Tunables.java" /** Aiming (every line is optional; leave out what you do not use). */ public static class Aim { // a fixed name: always Aim // The goal on the field, in inches, seen from your drivers' wall (the same numbers as driveTo). (1)! public static double goalX = 13; // inches right of center (BIOBUZZ) public static double goalY = -13; // inches from center, - = our half (BIOBUZZ) public static boolean mirrorForRed = false; // BIOBUZZ: turned, not mirrored (true) public static double turnKp = DEFAULT; // whole-robot aim: push per degree off (0.02) public static double turnKd = DEFAULT; // brake near the goal (0.002) public static double maxTurnPower = DEFAULT; // the most it turns by itself (0.5) public static double toleranceDeg = DEFAULT; // "aimed" within this, degrees (2) public static double aimDriveSpeed = DEFAULT; // aim mode on: forward and strafe at this share (0.5) public static double rumbleDeg = DEFAULT; // rumbleWhenAimed(): buzz within this (4) public static boolean aimOnFire = false; // no turret: a fire press turns to the goal first (2)! } ``` 1. With odometry, the aim goes on when the camera loses the goal. In BIOBUZZ, the goal is your HIVE's CELL that is up at the start, 13 in right of the center line and 13 in toward you. 2. Quick turn on fire, for a robot with no turret: with aim mode off and the goal in view, RB turns the robot to the goal, then fires (at most 0.5 s later: `aimOnFireSec`). It is off unless you set it to `true`, because it turns the robot. **Why:** a robot or a game piece can block a tag, but the odometry still knows where the goal is. The Driver Station says which one aims (`following: camera` or `following: odometry`). The backup needs the pose (the robot's position and heading) from autonomous, or from [set pose here](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-set-the-pose-when-autonomous-did-not-run). Without it, the backup stays off, and the Driver Station says so. You write `goalX`, `goalY` from your own drivers' wall, like every field number in your code. Only the simulator's map and its scenario checks use the red wall. `mirrorForRed` is ONE setting for the whole robot (the routes, the start and reset spots, this goal point). The library takes the first one it finds of `Tunables.Aim.mirrorForRed`, `Tunables.Odometry.mirrorForRed` and your autonomous's `mirrorForRed()`. If it finds none, it uses `true` (a mirrored field). BIOBUZZ's turned field needs `false`: write it once, here. INIT shows the alliance and this choice. The numbers in `Tunables.Aim` are in the tuning menu too, so copy tuned values back into `Tunables.java`. **More:** [Add a camera: when the camera loses the goal](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/#when-the-camera-loses-the-goal-the-odometry), [Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/). ## How do I aim with the odometry only (no camera)? **Where:** `Robot.java`, inside `define()` (the odometry, turret and launcher lines), and a section `Aim` in `Tunables.java`. ```java title="Robot.java" // No camera: the odometry says where the robot is, Tunables.Aim where the goal is. The // turret follows that direction and the launcher's speed comes from that distance. odometry(Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)); turret = add(Turret.motor("turret", "gobilda-5203-117").gearRatio(5).followsOdometry()); // .part(...): the indexer's servo (optional, recommended). launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .speedFromOdometry() .requireReady("turret aimed", () -> turret.isAimed())); ``` ```java title="Tunables.java" public static class Aim { // a fixed name: always Aim // Where the goal is, seen from YOUR drivers' wall (inches; the same numbers as driveTo). // BIOBUZZ: your HIVE's CELL that is up at the start. public static double goalX = 13; // inches right of center (BIOBUZZ) public static double goalY = -13; // inches from center, - = our half (BIOBUZZ) public static boolean mirrorForRed = false; // BIOBUZZ's field is turned, not mirrored } ``` **Why:** you have no camera to buy, mount or tune. But the aim is only as good as the pose. It needs the start spot from autonomous (or [set pose here](https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/#how-do-i-set-the-pose-when-autonomous-did-not-run)). A bump that slips the wheels moves the aim off a little. When you have a camera too, use [the camera first, the odometry as backup](#how-do-i-keep-aiming-when-the-camera-loses-the-goal). The library takes it that the turret turns about the robot's center. Whole-robot aim (no turret) works from the odometry in the same way. **More:** [Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/), [Turret](https://crossbotics.com/ftc-helper/docs/reference/parts/turret/). ## How do I make the camera work in any venue's light? **Where:** `Robot.java`, inside `define()`: the camera line. ```java title="Robot.java" // In INIT the Limelight tries these pipelines (your usual one FIRST) and keeps the best one. (1)! camera = add(Camera.limelight("limelight").autoPipelines(0, 1, 2).goal("BLUE SCORING", "RED SCORING")); // A webcam: Camera.webcam("Webcam 1").autoExposure().goal(...) tries the camera's own // exposure, then 3, 6 and 12 ms. ``` 1. Each venue's lights are different. Set up each pipeline on the Limelight's web page for one kind of light. The Limelight keeps the pipeline that sees the most AprilTags, and the Driver Station says which one. **Why:** bright stage lights or a dark corner can make a camera miss the AprilTags it saw in your shop. The test runs in INIT (nothing moves) and takes about a second per setting. The Driver Station says which setting it kept. Point the robot at the tags in INIT. Its numbers are optional. In `Tunables.Limelight`, `autoLighting = false` skips the test and uses `pipeline`. **For a camera tilted up:** add its tilt to the same section: `public static double pitchDeg = 35;` (degrees up, measured on the robot). Then a goal off to the side reads the right angle, and distances are along the floor. **More:** [Vision: venue lighting](https://crossbotics.com/ftc-helper/docs/modules/vision/#venue-lighting), [CameraTilt](https://crossbotics.com/ftc-helper/docs/modules/vision/#cameratilt), [Camera](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/). ## How do I find game pieces with a HuskyLens? **Where:** `Robot.java`, inside `define()`. First teach the camera, on the camera itself: dial to Color Recognition, turn on Learn Multiple, point the `+` at a piece, and press the learning button. ```java title="Robot.java" // At the top of the class: public Camera pieceCamera; Colors you taught it: ID1, ID2. (1)! pieceCamera = add(Camera.huskyLens("huskylens").colors().label(1, "POLLEN").label(2, "NECTAR")); // Or AprilTags: list which real tag each taught number is, and add goal(...). (2)! // camera = add(Camera.huskyLens("huskylens").tag(1, 34).tag(2, 35).goal("BLUE SCORING", "RED SCORING")); ``` 1. A HuskyLens does one job at a time: colors or tags, not both. 2. It says the number you taught it, never the tag's real number. **Why:** the camera finds the piece itself, so the hub does no picture work. Then `pieceCamera.target("POLLEN")` gives the bearing to the nearest box, or null. In `Tunables`, set `hfovDeg` (the camera's side-to-side view angle: measure it). For a rough distance, also set `sizeIn` (the longest side of the piece it sees). Nobody has tested it on a real robot yet. **More:** [HuskyLensCamera](https://crossbotics.com/ftc-helper/docs/modules/vision/#huskylenscamera), [Camera](https://crossbotics.com/ftc-helper/docs/reference/parts/camera/). ## How do I shoot while the robot is driving? **Where:** `Tunables.java` (the numbers, in your `Aim` section), and a button in `Controls.java` (inside `buttons(...)`) to switch it on and off. The robot needs [odometry](https://crossbotics.com/ftc-helper/docs/reference/parts/odometry/), because the odometry gives the robot's speed. **It stays off until you tune it on the real robot** (`shootOnMove = false`). Measure `flightSec` with a slow-motion video, and test shots while driving. Only then write `true`. ```java title="Tunables.java" // ADD these lines to your Tunables.Aim section (keep goalX, goalY and the others). public static boolean shootOnMove = false; // true only after testing on the real robot public static double flightSec = MEASURE; // seconds in the air (slow-motion video) (1)! public static double flightSecPerIn = DEFAULT; // longer shots fly longer: per inch (0) public static double maxLeadIn = DEFAULT; // never lead more than this, inches (24) // Where the shooter (a turret's pivot) and a camera on the body are from the robot's center. (2)! public static double shooterForwardIn = MEASURE; // inches forward of the center (from the edges) public static double shooterLeftIn = MEASURE; // inches left of the center (from the edges) public static double cameraForwardIn = MEASURE; // inches forward of the center (from the edges) public static double cameraLeftIn = MEASURE; // inches left of the center (from the edges) ``` 1. Film a shot in slow motion. Count the frames from when the piece leaves the launcher to when it reaches the goal. Divide by the video's frames per second. 2. In inches: forward (+) and left (+). Measure from the robot's edges, not its middle: forward = length / 2 - (from the front edge), left = width / 2 - (from the left edge). A camera on the turret sits at the turret's pivot. Then a button, in `Controls.java` inside `buttons(...)`: ```java title="Controls.java" // Shooting on the move on/off (on from ▶ when Tunables.Aim.shootOnMove = true): if // the shots go wide while driving, switch it off and shoot standing still. g2.a.toggle(robot.aim().movingShotMode()).says("shoot on the move on/off").rumble(); ``` **Why:** a piece shot from a moving robot keeps the robot's speed, so it lands to the side (30 in/s for 0.8 s: 24 in). With `shootOnMove`, the turret (or the whole robot) aims at a point that far the other way. The launcher takes its speed from that point's distance. It also brings the camera's picture forward to now, because the robot turned and moved since the camera took it. It works with a turret or whole-robot aim, with a camera on the turret or on the body, or with the odometry alone. Tell it where the shooter and the camera are. The Driver Station says `Aim : moving shot: lead 12.3 deg, 18 in` while it leads. **More:** [Add a camera: shooting while moving](https://crossbotics.com/ftc-helper/docs/add-to-robot/07-camera/#shooting-while-moving), [Aim](https://crossbotics.com/ftc-helper/docs/reference/parts/aim/). ## How do I use one shot table per game piece? **Where:** `Tunables.java` (the tables, in your `Launcher` section), then `Controls.java` (inside `buttons(...)`) or `Actions.java` (inside the class) to switch. ```java title="Tunables.java" // IN PLACE OF the speedByDistance line: one table per game piece, {inches to the goal, RPM}. (1)! // The POLLEN table (example rows: write the Shot Tuner's). public static double[][] speedByDistancePollen = {{24, 2200}, {48, 2550}, {72, 2900}}; // The NECTAR table. public static double[][] speedByDistanceNectar = {{24, 2400}, {48, 2800}, {72, 3200}}; ``` 1. Write this in your `Tunables.Launcher` section. The name after `speedByDistance` is the table's name: `"pollen"` and `"nectar"`. Fill both from the Shot Tuner. ```java title="Controls.java" // One button per game piece (the launcher's D-pad right already picks the next table). g2.x.press(() -> robot.launcher.useTable("pollen")).says("POLLEN shot table"); g2.b.press(() -> robot.launcher.useTable("nectar")).says("NECTAR shot table"); ``` ```java title="Actions.java" /** An action that picks the NECTAR table, then fires one (Actions.java). */ public static Action fireNectar(Robot r) { return Action.named("Fire NECTAR") .then(() -> r.launcher.useTable("nectar")) .then(r.launcher::fire); } ``` **Why:** POLLEN (2.8 in) and NECTAR (3.6 in) fly differently, so each needs its own speeds. **The table at ▶:** a plain `speedByDistance` table (named `main`) if there is one. If not, the first by name: here `nectar` (n before p). To start on POLLEN, add `.startTable("pollen")` to the launcher line in `Robot.java` ([like here](#how-do-i-keep-aiming-when-the-camera-loses-the-goal)). The Driver Station's `Shot table` line says which one is in use. Fill each table with the [Shot Tuner](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/) ([its file](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-build-a-shot-table-speed-for-each-distance)). Press Y until `> Table`, then pick the table you tune with the D-pad. Then copy its line into `Tunables.java`. To let the robot pick the table by itself, see [the next piece picks it](https://crossbotics.com/ftc-helper/docs/cookbook/05-game-pieces/#how-do-i-let-the-next-piece-pick-the-shot-table). **More:** [Add a launcher: two shot tables](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#two-kinds-of-pieces-two-shot-tables), [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/). ## Every shot is a bit short today. How do I trim the speed (a low battery)? **Where:** the D-pad trim is the launcher's usual line in `Controls.java`: `robot.launcher.speedOn(g2.dpadUp, g2.dpadDown);` ([Buttons to add](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#buttons-to-add)). The numbers go in your `Tunables.Launcher` section. Your own buttons go in `Controls.java`, inside `buttons(...)`. ```java title="Tunables.java" // In your Tunables.Launcher section (change the lines you already have, add the others). public static double kP = MEASURE; // speed control (Flywheel Finder) public static double kI = MEASURE; // speed control (Flywheel Finder) public static double kD = DEFAULT; // speed control (0) public static double kF = MEASURE; // steady power (Flywheel Finder) public static double nominalVolts = MEASURE; // battery volts for kF (Flywheel Finder) public static double trimStepPercent = DEFAULT; // one D-pad press (1%) public static double trimMaxPercent = DEFAULT; // never more than this each way (15%) // Battery compensation: true = F follows the battery. Try it on a real robot and tell us. public static boolean batteryCompensation = false; // (off until proven on a real robot) ``` ```java title="Controls.java" // The launcher's usual line trims too: speedOn(g2.dpadUp, g2.dpadDown) = +/- 1% a press. // Your own: a bigger step on a button, and a far shot that sets the trim first. g2.y.press(() -> robot.launcher.trimBy(+3)).says("speed trim +3%"); g2.a.press(Action.named("Far shot +5%") .then(() -> robot.launcher.setTrim(+5), robot.launcher::fire) // The launcher fires or gives up within 3 s, so 4 s is always enough. .waitUntil("fired", () -> !robot.launcher.isShooting(), 4.0) .then(robot.launcher::resetTrim)); // Last match's trim (INIT offers it as "Trim last time"): from your own button too. g2.x.press(robot.launcher::useLastTrim).says("use last match's trim"); ``` 1. Hold the D-pad for 4 steps a second. Double-tap D-pad down to go back to 0. The launcher's first line on the Driver Station shows the trim: `Speed trim : +3% READY`. **Why:** a worn wheel or softer balls make every shot a little short. The trim fixes it for this match, for every table. It moves +/- 1% a press, at most 15%, and never past the motor's top speed. It goes back to 0 at every INIT. At INIT, the Driver Station offers last time's trim (`Trim last time : +3%`). To use it, double-tap D-pad up after ▶ (or use your own button: `useLastTrim`, in the recipe). The library never applies it by itself. Battery compensation scales the F gain by `nominalVolts` / the battery (tuned at 12.6 V, at 11.5 V: F x 1.10). Nobody has proven it on a real robot yet, so it is off: the box writes `batteryCompensation = false`. Change it to `true` only when you want to test it. It needs the `kF` and `nominalVolts` that the Flywheel Finder found together. That is why the box writes the gains as `MEASURE`. Without battery compensation, `DEFAULT` gains (from the motor) are a good start. When you need a trim every match, with a charged battery, the cause is the wheel or the balls, not the battery. The table is off. Make the trim part of the table (+3%: every speed x 1.03, `{48, 2550}` becomes `{48, 2627}`). Copy the lines into `Tunables.java`, and trim back to 0. **More:** [Add a launcher: speed trim and a low battery](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#speed-trim-and-a-low-battery), [Launcher](https://crossbotics.com/ftc-helper/docs/reference/parts/launcher/#speed-trim-and-battery-compensation). ## How do I add a hood to my launcher? **Where:** `Robot.java`, inside `define()`: add `.hood(...)` to your launcher line. In `Tunables.java`, add a new section `Hood` (its stops), and a third number in each row of your `Launcher` section's shot table. ```java title="Robot.java" // The hood goes on the launcher; its numbers are in Tunables.Hood. // .part(...): which servos they are (optional, recommended). launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .feeder(Indexer.servo("indexer").part("gobilda-2000-speed")) .hood(Hood.servo("hood").part("gobilda-2000-torque")) .speedFromDistance(camera)); ``` A new section in `Tunables.java`: ```java title="Tunables.java" public static class Hood { // "hood" in the configuration // posA and posB: the servo positions a hair off the hood's two hard stops. Never past them. public static double posA = MEASURE; // servo position at stop A (Hood Finder) public static double posB = MEASURE; // servo position at stop B (Hood Finder) // Optional: the hood's angle at each stop (any scale, e.g. 0 = steep end, 30 = flat end). public static double angleA = MEASURE; // the angle at stop A (an angle app) public static double angleB = MEASURE; // the angle at stop B (an angle app) public static double travelSec = DEFAULT; // stop to stop, seconds (0.5, or the servo's) public static double startAngle = DEFAULT; // where it goes at ▶ (angle A) } ``` Then the shot table: ```java title="Tunables.java" // IN PLACE OF your speedByDistance line: {inches to the goal, RPM, hood angle}, blended between rows. (1)! public static double[][] speedByDistance = {{24, 2200, 3}, {48, 2550, 12}, {72, 2900, 20}}; ``` 1. This goes in your `Tunables.Launcher` section. The launcher blends the hood angle between rows, like the speed. **With no measured angles:** leave out `angleA`, `angleB`. The hood then works in servo positions, and the table's third number is a servo position. ```java title="Tunables.java" // Tunables.Hood: only posA and posB (delete angleA, angleB). Tunables.Launcher, IN PLACE OF // your speedByDistance line, {inches, RPM, servo position}: the Shot Tuner writes these for you. public static double[][] speedByDistance = {{24, 2200, 0.24}, {48, 2550, 0.38}, {72, 2900, 0.50}}; ``` **A hood on a linkage or cam:** equal servo steps do not make equal angles. Use this `Hood` section in place of the one above. It has a calibration table instead of `posA`, `posB`, `angleA`, `angleB`. ```java title="Tunables.java" public static class Hood { // "hood" in the configuration // {servo position, hood angle} rows, blended. The first and last rows are the stops (no posA / posB). (1)! // Example rows: write the Hood Finder's in their place. public static double[][] calibration = {{0.20, 0}, {0.32, 8}, {0.45, 18}, {0.65, 30}}; } ``` 1. The angles must keep going one way: in servo-position order, the angles all go up, or all go down. **A hood on a motor with an encoder** (it knows where it is): write `Hood.motor` in the launcher line, and use this `Hood` section in place of the one above. ```java title="Robot.java" add(Launcher.flywheel("launcher", "gobilda-5203-6000") .hood(Hood.motor("hood", "gobilda-5203-117")) // a motor with an encoder .speedFromDistance(camera)); ``` ```java title="Tunables.java" public static class Hood { // "hood" in the configuration // Encoder ticks at the two stops, counted from where the hood sits at INIT (start the robot // with the hood on stop A), and the angles there. public static double posA = MEASURE; // ticks at stop A, usually 0 (Hood Finder) public static double posB = MEASURE; // ticks at stop B (Hood Finder) public static double angleA = MEASURE; // the angle at stop A (an angle app) public static double angleB = MEASURE; // the angle at stop B (an angle app) public static double kP = DEFAULT; // power per tick off (0.005) public static double maxPower = DEFAULT; // the most power (0.5) public static double tolerance = DEFAULT; // ready within this (1/50 of the range) } ``` Your own hood buttons, in `Controls.java` inside `buttons(...)`: ```java title="Controls.java" // The launcher's hood already has gamepad 2's left stick Y (up = a bigger angle): a trim // while the table sets the angle, else the angle itself. Your own: steps and the start angle. g2.y.press(() -> robot.launcher.hood().step(+1)).says("hood +1 step"); g2.a.press(() -> robot.launcher.hood().step(-1)).says("hood -1 step"); g2.x.press(() -> robot.launcher.hood().goToStart()).says("hood to its start angle"); ``` **Why:** close shots need a steep angle, and far ones a flatter one. So each distance gets a speed AND a hood angle, blended between rows. `posA`, `posB` are hard limits: nothing sends the hood past a stop. The launcher waits for the hood before it fires. For a servo hood, it waits a share of `travelSec`. For a motor hood, it reads the encoder. While the camera sees a goal, the table sets the angle, and the stick (gamepad 2 left Y) is a hood trim. With no goal seen, the stick moves the hood itself, so you always see what it does. Double-tap D-pad down to clear both trims. A lift brings the same stick (gamepad 2 left Y). With a hood AND a lift, give one of them another stick ([move a button](https://crossbotics.com/ftc-helper/docs/cookbook/03-buttons/#how-do-i-move-a-parts-button-to-another-button)). INIT says which part has it. Find the stops with the [Hood Finder](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-find-my-hoods-stops-and-angles), then fill the table with the [Shot Tuner](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-build-a-shot-table-speed-for-each-distance) (press Y until `> Hood`). **More:** [Add a launcher: a hood](https://crossbotics.com/ftc-helper/docs/add-to-robot/05-launcher/#a-hood-the-shot-angle), [Hood](https://crossbotics.com/ftc-helper/docs/reference/parts/hood/). --- # Turrets and interlocks URL: https://crossbotics.com/ftc-helper/docs/cookbook/07-turrets-and-interlocks/ Every kind of turret has its own lines: motor, servo or CR servo, with a switch or not, with any range. See [Setting up a turret](https://crossbotics.com/ftc-helper/docs/guides/turret-setup/). An interlock is a rule that stops two parts from hitting each other. Code: [`InterlockRecipes.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/cookbook/InterlockRecipes.java). **The questions on this page:** - [How do I home my turret with a switch?](#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-turret-on-a-servo) - [How do I set up a slip-ring turret (round and round)?](#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-stop-two-parts-from-hitting-each-other) - [How do I pick up and score with a lift, a wrist and a claw?](#how-do-i-pick-up-and-score-with-a-lift-a-wrist-and-a-claw) ## How do I home my turret with a switch? **Where:** `Robot.java`, inside `define()` (the turret line), and a section `Turret` in `Tunables.java`. ```java title="Robot.java" // "turret", "turret_home" = the motor's and the home switch's names in the robot configuration. (1)! // At ▶ the turret turns slowly until it finds the switch. (2)! turret = add(Turret.motor("turret", "gobilda-5203-312").gearRatio(2.75) .homeSwitch("turret_home") .follows(camera)); ``` 1. The home switch is a touch sensor ("REV Touch Sensor" in the configuration) or a magnetic switch ("Digital Device", for example the REV Magnetic Limit Switch). 2. After that, each time the turret passes the switch, the switch sets its angle right again. ```java title="Tunables.java" public static class Turret { // "turret" in the configuration public static double min = MEASURE; // furthest right, degrees (Motor Finder) public static double max = MEASURE; // furthest left, degrees: 0 = forward, + = left public static double homeAngle = MEASURE; // where the switch closes (turret-setup.md) public static double homingPower = DEFAULT; // how slowly it looks for the switch (0.2) public static double homingTimeout = DEFAULT; // the most seconds it looks (5) } ``` **Why:** a motor's encoder counts from where the turret was at INIT. With a switch, the turret finds its real angle at ▶ by itself. It never does this during INIT, because nothing moves before ▶. Every time the turret passes the switch, the switch fixes the error from a slipping belt. Until the turret is homed (has found its real angle), it does not follow the goal and is never "aimed". You must write `homeAngle`, or INIT stops. `min`, `max` default to -90 and 90. With no switch, put the turret at `startAngle` (default 0, straight forward) by hand before INIT. **More:** [Setting up a turret: how it knows its angle](https://crossbotics.com/ftc-helper/docs/guides/turret-setup/#2-how-does-it-know-its-angle). ## How do I set up a turret on a servo? **Where:** `Robot.java`, inside `define()` (the turret line), and a section `Turret` in `Tunables.java`. ```java title="Robot.java" // "turret" = the servo's name in the robot configuration. Numbers: Tunables.Turret. (1)! // fullRange(): the servo's whole turn. Turn it on BEFORE you measure posA and posB. (2)! turret = add(Turret.servo("turret").part("gobilda-2000-speed").fullRange().follows(camera)); ``` 1. A standard servo turns the turret to an angle by itself. It needs no encoder, no PID and no homing. 2. With it, a goBILDA 2000 servo turns 300 degrees, not 270. Find posA and posB with the Servo Finder: press Y while you choose the servo. ```java title="Tunables.java" public static class Turret { // "turret" in the configuration // Two servo positions and the turret's angle at each: 0 = straight forward, counterclockwise // (left) +. Its range is between the two angles. public static double posA = MEASURE; // servo position at one end (Servo Finder) public static double angleA = MEASURE; // the turret's angle there (an angle app) public static double posB = MEASURE; // servo position, other end (Servo Finder) public static double angleB = MEASURE; // the turret's angle there (an angle app) public static double travelSec = DEFAULT; // posA to posB, seconds (0.6, or the servo's) public static double startAngle = DEFAULT; // sent here at ▶ (0) } ``` **Why:** a servo knows how to go to a position, so the turret needs no encoder, no PID and no homing. It is the cheapest turret. But a servo cannot say where it is. So at ▶, the library sends it to `startAngle` (or the middle of its range), and "aimed" waits `travelSec` for it. You must write `posA`, `angleA`, `posB`, `angleB`, or INIT stops. Find the positions with the [Servo Finder](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-find-a-servos-open-and-closed-numbers), and measure the angle at each with a phone angle app. Its range is between `angleA` and `angleB`. Put hard stops a little past them. **More:** [Setting up a turret](https://crossbotics.com/ftc-helper/docs/guides/turret-setup/#1-what-turns-it), [Full range](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-get-my-servos-full-range). ## How do I set up a slip-ring turret (round and round)? **Where:** `Robot.java`, inside `define()` (the turret line), and a section `Turret` in `Tunables.java`. ```java title="Robot.java" // A CR servo turns it, an absolute encoder says where it points, continuous(): no limits. (1)! // "turret", "turret_pos" = the servo's and the encoder's names in the robot configuration. // .part(...): which servo it is (optional, recommended). turret = add(Turret.crServo("turret").part("axon-max-mk2").analogEncoder("turret_pos").continuous() .follows(camera)); ``` 1. The encoder is on an analog port and knows the angle at once, so the turret needs no homing. A slip ring (a turning joint that carries the wires) lets the turret turn with no limits. With no limits, the turret always takes the shortest way. ```java title="Tunables.java" public static class Turret { // "turret" in the configuration // No min and max: it turns round and round. public static double kP = 0.015; // push per degree off, CR servo (0.02) public static double kD = DEFAULT; // brake near the target (0.001) public static double maxPower = 1.0; // a CR servo's full speed (0.8) public static double tolerance = DEFAULT; // "aimed" within this, degrees (1.0) public static double encoderOffset = MEASURE; // encoder reading, pointing forward } ``` **Why:** with a slip ring, the wires never wind up. So the turret can always take the shortest way to the goal, and is never "out of range". A motor turret can be `continuous()` too. **More:** [Setting up a turret: how far can it turn?](https://crossbotics.com/ftc-helper/docs/guides/turret-setup/#3-how-far-can-it-turn). ## How do I stop two parts from hitting each other? **Where:** `Robot.java`, inside `define()`, one line below the parts' `add` lines. Also a new section in `Tunables.java` for the zones, with the same name as the rule. ```java title="Robot.java" // AFTER the parts' add lines: the turret stays out of its zone while the lift is in its // zone, and the other way round. Whoever is in its zone first keeps it. keepApart("TurretLift", turret.zone(), lift.zoneAbove()); ``` ```java title="Tunables.java" // The rule's own section, named like the rule in Robot.java. Each zone in its part's units. public static class TurretLift { // keepApart("TurretLift", ...) in Robot.java public static double turretFrom = MEASURE; // degrees: where the turret's zone starts public static double turretTo = MEASURE; // degrees: where it ends (robot's back) public static double liftAbove = MEASURE; // counts: the slide is up from here public static double liftStopSec = 0.2; // a heavy slide takes longer to stop (0.15) } ``` **Why:** each part is safe inside its own limits, but a turret over the back and a lift at the back can still meet. The library keeps the rule every loop, whatever moves the parts: buttons, sticks, actions, a following turret or autonomous steps. The part that is in its zone first keeps it. The other part waits at the edge of its own zone, and the Driver Station says so (`TurretLift : Lift held at 216 counts: Turret is between 130 and 218 deg`). The rule slows a fast part down as it comes near, so it brakes in time, even with slow loops. To do this, the rule measures the part's speed every loop. The library reads the zones at INIT only, so change them in `Tunables.java`. **More:** [Two parts that must not collide](https://crossbotics.com/ftc-helper/docs/guides/interlocks/), [Interlock](https://crossbotics.com/ftc-helper/docs/reference/parts/interlock/). ## How do I pick up and score with a lift, a wrist and a claw? **Where:** `Actions.java`, inside the class; then a button in `Controls.java`, inside `buttons(...)`: `g2.y.press(Actions.scoreInFlower(robot)).says("score in a FLOWER");` ```java title="Actions.java" /** Lifts a held ball over a FLOWER, lets it go and comes back folded (Actions.java). */ public static Action scoreInFlower(Robot r) { return Action.named("Score in FLOWER") .then(() -> r.wrist.goTo("carry")) // 1. swing the claw out first .waitUntil("wrist out", r.wrist::isDone, 1.0) .then(() -> r.lift.goTo("flower")) // 2. lift (the interlock may make it wait) .waitUntil("lift up", r.lift::isAtTarget, 4.0) .then(() -> r.wrist.goTo("flower")) // 3. tip it over the FLOWER .waitUntil("over the FLOWER", r.wrist::isDone, 1.0) .then(r.claw::open) // 4. let go .waitUntil("let go", r.claw::isDone, 1.0) .then(() -> r.wrist.goTo("carry")) // 5. back the same way .waitUntil("wrist back", r.wrist::isDone, 1.0) .then(() -> r.lift.goTo("stowed")) .waitUntil("lift down", r.lift::isAtTarget, 3.0) .then(() -> r.wrist.goTo("folded"), r.claw::close); } ``` **Why:** the order keeps the parts out of each other's way. The claw swings out before the lift rises, and folds only after the lift is down. Each wait has a time limit, so a stuck part ends the action instead of stopping the robot. With an interlock rule, the lift waits by itself while the turret is in the way. **More:** the whole robot: [`v2bot`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/v2bot/Actions.java). --- # Actions URL: https://crossbotics.com/ftc-helper/docs/cookbook/08-actions/ **The questions on this page:** - [How do I do several things one after the other?](#how-do-i-do-several-things-one-after-the-other) - [How do I repeat steps several times?](#how-do-i-repeat-steps-several-times) - [How do I move two parts at the same time?](#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-half-a-second-like-sleep-in-blocks) - [How do I wait until something is true?](#how-do-i-wait-until-something-is-true) - [How do I start an action from a button?](#how-do-i-start-an-action-from-a-button) - [How do I stop every running action?](#how-do-i-stop-every-running-action) - [How do I run an action when the OpMode starts?](#how-do-i-run-an-action-when-the-opmode-starts) - [How do I use the same action in an autonomous?](#how-do-i-use-the-same-action-in-an-autonomous) ## How do I do several things one after the other? **Where:** `Actions.java`, inside the class. ```java title="Actions.java" /** Lift up, open the claw, lift down: one step after the other. */ public static Action scoreHigh(Robot r) { return Action.named("Score high") .then(() -> r.lift.goTo("high")) .waitUntil("lift at the top", r.lift::isAtTarget, 2.0) // at most 2 s .then(r.claw::open) .waitSeconds(0.3) // let the piece drop .then(() -> r.lift.goTo("down")); } ``` **Why:** each step starts when the one before it is done, and the driver can still drive the whole time. **More:** [Actions.java: scoreHigh](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#your-first-action), [Action](https://crossbotics.com/ftc-helper/docs/reference/steps/#action). ## How do I repeat steps several times? **Where:** `Actions.java`, inside the class. ```java title="Actions.java" /** Pulses the intake 3 times: the for loop adds the same steps 3 times to the action. */ public static Action pulseThree(Robot r) { Action a = Action.named("Pulse three"); for (int i = 0; i < 3; i++) { // runs once, when the action is made: it never waits a.then(r.intake::in) .waitSeconds(0.4) .then(r.intake::stop) .waitSeconds(0.3); } return a; } ``` **Why:** the `for` loop runs once, while Java makes the action, and writes the steps 3 times. Then the action does them one after the other, and the robot does not wait. **More:** [Action](https://crossbotics.com/ftc-helper/docs/reference/steps/#action). ## How do I move two parts at the same time? **Where:** `Actions.java`, inside the class. ```java title="Actions.java" /** Two parts at once: then(a, b) starts both in the same loop. */ public static Action grabAndLift(Robot r) { return Action.named("Grab and lift") .then(r.claw::close, r.intake::stop) // both at once .waitUntil("claw closed", r.claw::isDone, 1.0) // isDone: it should be there .then(() -> r.lift.goTo("low")); } ``` **Why:** `then(a, b)` starts both parts in the same loop, so neither waits for the other. **More:** [Actions.java: grabAndLift](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#the-steps). ## How do I wait half a second (like sleep in Blocks)? Search words: sleep, wait, pause, delay. **In an action** (`Actions.java`): ```java title="Actions.java" /** Opens the claw, waits half a second, then lowers the lift. */ public static Action dropAndLower(Robot r) { return Action.named("Drop and lower") .then(r.claw::open) .waitSeconds(0.5) // half a second; the robot keeps running .then(() -> r.lift.goTo("down")); } ``` **In an autonomous** (inside `steps(...)`), give the step a name first, for the report: ```java title="autos/YourAuto.java" s.run("Open the claw", robot.claw::open) .waitSeconds("Let the piece drop", 0.5) // a name for the report, then the seconds .run("Lift down", () -> robot.lift.goTo("down")); ``` **Why:** `sleep()` stops the whole robot: no driving, and no other part moves. `waitSeconds` waits while everything keeps running. **More:** [Actions.java: the rules](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#the-rules-every-action-follows), [Non-blocking code](https://crossbotics.com/ftc-helper/docs/guides/non-blocking/). ## How do I wait until something is true? **Where:** `Actions.java`, inside the class. ```java title="Actions.java" /** Lowers the lift, and opens the claw only once the lift is down. */ public static Action lowerAndRelease(Robot r) { return Action.named("Lower and release") .then(() -> r.lift.goTo("down")) // Waits until the test is true. If 2 s pass first, the action STOPS here and says why. .waitUntil("lift down", () -> r.lift.isAt("down"), 2.0) .then(r.claw::open); } ``` **Why:** every wait has a time limit, so a stuck part cannot freeze the action forever. **More:** [Actions.java: the rules](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#the-rules-every-action-follows). ## How do I start an action from a button? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Press Y: the action starts. Press Y again while it runs: it is canceled, safely. g2.y.press(Actions.scoreHigh(robot)).says("score high"); g2.x.press(Actions.grabAndLift(robot)).says("grab and lift"); ``` **Why:** the same button cancels it. A stick or button that moves the same part also stops it, so the driver always wins. **More:** [Actions.java: start it from a button](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#start-it-from-a-button). ## How do I stop every running action? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Stop every running action at once (each stops what it started, safely). g2.back.press(robot::cancelAll).says("stop all actions"); ``` **Why:** a stopped action leaves each part safe: a lift holds its height, and an intake stops. **More:** [RobotDefinition: for your code](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#robotdefinition). ## How do I run an action when the OpMode starts? **Where:** `Robot.java`, inside `define()`. ```java title="Robot.java" // In Robot.java's define(): this action runs once, right after ▶ (autonomous and TeleOp). atStart(() -> Actions.deployIntake(this)); ``` The action it runs, in `Actions.java` inside the class (`intakeDeploy` is a [servo with named positions](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-any-servo-with-named-positions-a-gate-a-fold-out)): ```java title="Actions.java" /** Folds the intake out (the atStart line in Robot.java runs it). */ public static Action deployIntake(Robot r) { return Action.named("Deploy intake").then(() -> r.intakeDeploy.goTo("deployed")); } ``` **Why:** the library never moves anything in INIT, so a fold-out waits for ▶. This is the library's safety choice, because people are still next to the robot. The game rules would allow it (R103.B), but the robot must be still once INIT is done (G304.H). **More:** [Actions.java: an action at ▶](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#an-action-when-the-opmode-starts). ## How do I use the same action in an autonomous? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .forward("To the goal", 24, 0.5) .action(Actions.scoreHigh(robot), 5) // waits until it is done (at most 5 s) .back("Back up", 12, 0.5); ``` **Why:** you write the move once, and use it in TeleOp and autonomous. The report says if it timed out. **More:** [Actions.java: in an autonomous](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/#use-it-in-an-autonomous). --- # Autonomous URL: https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/ > **One rule for every angle:** angles count counterclockwise, like the IMU: 0 = forward, **90 = left**, > 180 = back, -90 = right. The rule is for a move (`.move("Left", 12, 90, 0.5)`), a turn > (`.turn("Left", 90, 0.4)`), `turnTo(...)`, and the heading in `start(...)` and `driveTo(...)`. Straight > moves and turns can use words instead: `.forward`, `.back`, `.left`, `.right`, `.turnLeft`, `.turnRight`. **The robot drives only after you run the Drive Tuner.** Until then, the autonomous shows "AUTONOMOUS IS OFF". Run the [Drive Tuner](https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/#how-do-i-tune-the-drive-for-autonomous) and copy its lines. Then set `calibrated = true` in `Tunables.java`, section `Drive`. The simulator runs the autonomous anyway, so you can try a route before tuning. **The questions on this page:** - [How do I make my first autonomous (drive 2 feet)?](#how-do-i-make-my-first-autonomous-drive-2-feet) - [How do I drive forward, sideways and turn?](#how-do-i-drive-forward-sideways-and-turn) - [Does my autonomous need a RED version?](#does-my-autonomous-need-a-red-version) - [How do I let the drivers choose before the match?](#how-do-i-let-the-drivers-choose-before-the-match) - [How do I make sure there is time to park?](#how-do-i-make-sure-there-is-time-to-park) - [How do I run a mechanism while the robot drives?](#how-do-i-run-a-mechanism-while-the-robot-drives) - [How do I wait for my alliance partner?](#how-do-i-wait-for-my-alliance-partner) - [How do I write a step the list cannot say?](#how-do-i-write-a-step-the-list-cannot-say) - [How do I change a distance in an autonomous?](#how-do-i-change-a-distance-in-an-autonomous) - [How do I share the same first steps in several autos?](#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?](#how-do-i-make-the-start-delay-shorter-or-use-a-different-number-on-red) ## How do I make my first autonomous (drive 2 feet)? **Where:** a new file in `autos/`. In Android Studio, right-click the `autos` folder, then New, Java Class, and name it `LeaveTheStart`. Below is the whole file. Change the `package` and `import ...Robot` lines as the comment says: ```java title="autos/LeaveTheStart.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first import below to: import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; // The name on the Driver Station, and the TeleOp it picks next (use YOUR TeleOp's name). @Autonomous(name = "Cookbook Leave the Start", group = "Cookbook", preselectTeleOp = "Cookbook TeleOp") @Disabled // delete this line in your copy, or the Driver Station will not list it public class LeaveTheStart extends Auto { @Override protected void steps(Steps s, Robot robot) { // s = the list of steps, robot = your Robot.java. Step lines go here: s.start("Against our wall, facing the field", 0) // the note the drive team reads .forward("Leave the start", 24, 0.4); // 24 inches = 2 feet, forward, 0.4 power } } ``` **Why:** `preselectTeleOp` makes the Driver Station pick your TeleOp next, so the drivers only have to press INIT. **More:** [Red and blue](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue). ## How do I drive forward, sideways and turn? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .forward("Forward", 24, 0.5) // inches, max power .right("Sideways to the right", 12, 0.5) // mecanum only; also back(...), left(...) .turnLeft("Turn left 90", 90, 0.4) // also turnRight(...) .move("At an angle", 12, 45, 0.5) // angles count counterclockwise: 45 = forward and left .turn("Turn right 90", -90, 0.4) // the same rule: a right turn is minus .moveWithTurn("Back, turning", 12, 180, 90, 0.4) // mecanum only: drive and turn at once .turnTo("Face the start way", 0, 0.4); // to a heading: 0 = the way it faced at the start ``` **Why:** each move starts from where the robot is now, so the steps read like directions to a person. `moveWithTurn` is the one exception. It drives and turns at once, so its direction is fixed on the field. It counts like `turnTo`'s heading, from the way the robot faced at the start (180 = the opposite way). **More:** [Driving: move, turn, turnTo](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#drive). ## Does my autonomous need a RED version? No. Write it once, for BLUE. BIOBUZZ's field is turned half a turn between the alliances. For it, add this to the autonomous class: ```java title="autos/YourAuto.java" // BIOBUZZ's field is turned half a turn between the alliances: one route works for both. @Override protected boolean mirrorForRed() { return false; } ``` **Why:** RED then uses the same numbers, seen from the red wall. On a mirrored field (the default), the library flips RED for you. **More:** [Field numbers](https://crossbotics.com/ftc-helper/docs/building-autos/01-what-an-auto-can-do/#field-numbers). ## How do I let the drivers choose before the match? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .menuYesNo("Score", true) // the drivers choose in INIT with the D-pad .menuChoice("Park", "Near", "Far") .onlyIf("Score") // these steps run only if "Score" is yes .forward("To the goal", 30, 0.5) .action(Actions.scoreHigh(robot), 5) .end() // never forget end() ``` **Why:** one file covers several plans, and the drivers choose in INIT with the D-pad. The alliance and start delay choices come with it, with no code. **More:** [The INIT menu](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#add-choices-to-the-init-menu), [Branches: onlyIf](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#add-choices-to-the-init-menu). ## How do I make sure there is time to park? Add `parkWithSeconds` before the park steps. This code follows the menu recipe above: ```java title="autos/YourAuto.java" .parkWithSeconds(4) // the steps below always get the last 4 s .onlyIf("Park", "Near") .right("Park near", 20, 0.7) .end() .onlyIf("Park", "Far") .right("Park far", 40, 0.7) .end(); ``` **Why:** when 4 s are left, the main steps stop, so a slow step cannot cost you the parking points. **More:** [Keep time to park](https://crossbotics.com/ftc-helper/docs/reference/steps/#keep-time-to-park). ## How do I run a mechanism while the robot drives? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.start("Against our wall, facing the field", 0) .run("Intake on", robot.intake::in) // starts it and goes on at once .run("Lift up", () -> robot.lift.goTo("high")) .forward("To the pieces", 24, 0.4) // the intake and lift work while it drives .waitUntil("Lift at the top", robot.lift::isAtTarget, 2.0) .run("Intake off", robot.intake::stop); ``` **Why:** `run` starts a part and goes on at once. `waitUntil` waits only when the next step needs it. **More:** [Mechanisms: run and wait](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#start-something-or-wait-for-it). For whole actions while driving, use `alongside(...)` ([write each piece once](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes)). ## How do I wait for my alliance partner? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.menuYesNo("Wait for partner", false) .onlyIf("Wait for partner") .waitSeconds("Let our partner pass", 3) // the robot keeps running while it waits .end(); ``` **Why:** the drivers decide in INIT. For a wait before the first step, the menu already has a start delay. **More:** [Write each piece once](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes). ## How do I write a step the list cannot say? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" // Your own step, for anything the list cannot say. Wait with ctx, never sleep(). s.step("Clear the intake", ctx -> { robot.intake.out(); ctx.waitFor(0.3); // every part keeps working while it waits robot.intake.stop(); }); ``` **Why:** `ctx.waitFor` keeps every part updating and the timer working. `sleep()` would freeze them. **More:** [Your own steps](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#write-your-own-step). ## How do I change a distance in an autonomous? **Where:** the step itself, in your file in `autos/`. Change the number and build again. ```text title="autos/YourAuto.java" .forward("To the goal", 30, 0.5) // 30 = inches; change it here ``` **Why:** each autonomous keeps its own numbers, so a change to one auto does not change another. The simulator's auto builder can read the auto, change a number, and give you the new file. `Tunables.java` keeps the robot's numbers (speeds, positions, gains), which are the same in every auto. **More:** [The numbers are in the step](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#the-numbers-are-in-the-step). ## How do I share the same first steps in several autos? **Where:** your autonomous class (or a shared file), next to `steps(...)`. ```java title="autos/YourAuto.java" /** The same first steps for several autos: a method that adds them to the list. */ static Steps scorePreload(Steps s, Robot robot) { return s.forward("To the goal", 30, 0.5) .action(Actions.scoreHigh(robot), 5); } // in each autonomous: scorePreload(s.start("...", 0), robot).right("Park", 20, 0.7); ``` **Why:** when you fix the opening once, every autonomous gets the fix. **More:** [Write each piece once](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes). ## How do I make the start delay shorter, or use a different number on RED? Every autonomous's INIT menu already has `Alliance` and `Start delay` (0 to 10 s, D-pad left/right). **For a shorter menu line, where:** your autonomous class, as a method of its own next to `steps(...)`: ```java title="autos/YourAuto.java" // Inside your autonomous class, next to steps(...): the INIT menu's "Start delay" line // offers 0 to 5 s (the default is 0 to 10 s). @Override protected double maxStartDelaySec() { return 5; } ``` Most routes need no number that is different on RED, because the library mirrors or turns RED for you. **For one number that is different on RED, where:** inside `steps(...)`, above the steps. ```java title="autos/YourAuto.java" // Inside steps(...): alliance() is the alliance chosen in INIT. pick(blue, red) gives the // first value on BLUE and the second on RED (here: RED waits 2 s for its partner). double waitSec = alliance().pick(0.0, 2.0); s.start("Against our wall, facing the field", 0) .waitSeconds("Let our partner go first", waitSec) .forward("Leave the start", 24, 0.4); ``` **Why:** the start delay waits before the first step, so a partner can go first. 10 s is a lot to scroll through. `alliance().pick(blue, red)` works for any kind of value: a number, a name, an AprilTag id. **More:** [What the INIT menu can choose](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#add-choices-to-the-init-menu). --- # Several autos and choosing one URL: https://crossbotics.com/ftc-helper/docs/cookbook/10-several-autos/ You can have one autonomous per plan, or one autonomous with an INIT menu. Both use the same pieces. For the decision table, naming, simulator tests and a match-day checklist, see [Building autos 3: having multiple autos](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/). Each file below is whole. Copy it into `autos/`, and change the `package` and `import` lines as its comment says. The distances are plain numbers in the steps ([why](https://crossbotics.com/ftc-helper/docs/cookbook/09-autonomous/#how-do-i-change-a-distance-in-an-autonomous)). **The questions on this page:** - [How do I build several autos from the same pieces?](#how-do-i-build-several-autos-from-the-same-pieces) - [How do I make two autos that differ by one piece?](#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?](#how-do-i-let-the-drivers-choose-the-start-spot-and-the-plan-in-init) ## How do I build several autos from the same pieces? **Where:** a new file `Routes.java` in `autos/`. It has no `@Autonomous`, so it is not an OpMode (a program in the Driver Station's list). The autos below call its methods. ```java title="autos/Routes.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first two imports below to: import org.firstinspires.ftc.teamcode.Actions; // import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Actions; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Steps; /** The pieces every autonomous is made from. Write each piece once. No @Autonomous: not an OpMode. */ public class Routes { /** Score the piece the robot starts with: hold it, drive to the goal, score. */ public static Steps scorePreload(Steps s, Robot robot) { return s.run("Hold the preload", robot.claw::close) .forward("To the goal", 30, 0.6) .action(Actions.scoreHigh(robot), 5); } /** One more piece: back to the pieces, grab one, forward to the goal, score. */ public static Steps cycle(Steps s, Robot robot) { return s.back("To the pieces", 20, 0.6) .run("Grab", robot.claw::close) .waitSeconds("Let the claw close", 0.3) .forward("Back to the goal", 20, 0.6) .action(Actions.scoreHigh(robot), 5); } /** The park: back toward our wall. It keeps the last 3 seconds for itself, so it always runs. */ public static Steps park(Steps s) { return s.parkWithSeconds(3) .back("Park", 20, 0.7); } } ``` **Why:** you write each piece once, so a fix (or a new number in it) reaches every autonomous. `public static Steps scorePreload(Steps s, Robot robot)` is a method that any file can call (`public static`). It adds its steps to the list `s` and hands the list back (`return`). **More:** [Build them from shared steps](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes). ## How do I make two autos that differ by one piece? **Where:** two new files in `autos/`, `NearPreloadPark.java` and `NearCycle.java` (delete `@Disabled` in your copies, and write your TeleOp's name in `preselectTeleOp`). ```java title="autos/NearPreloadPark.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first import below to: import org.firstinspires.ftc.teamcode.Robot; // (Routes is in the same autos folder: no import needed for it.) import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; /** Score the preload, then park. preselectTeleOp: YOUR TeleOp's name. */ @Autonomous(name = "Near: Preload + Park", group = "Autos", preselectTeleOp = "Cookbook TeleOp") @Disabled // delete this line in your copy public class NearPreloadPark extends Auto { @Override protected boolean mirrorForRed() { return false; // BIOBUZZ: the field is turned half a turn, one route for both alliances } @Override protected void steps(Steps s, Robot robot) { s.start("NEAR: against our wall, 2nd tile left of center, facing the field", -36, -61, 0); Routes.scorePreload(s, robot); Routes.park(s); } } ``` ```java title="autos/NearCycle.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first import below to: import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; /** Score the preload, one more piece, then park. Only the Routes.cycle line is new. */ @Autonomous(name = "Near: Preload + Cycle + Park", group = "Autos", preselectTeleOp = "Cookbook TeleOp") @Disabled // delete this line in your copy public class NearCycle extends Auto { @Override protected boolean mirrorForRed() { return false; } @Override protected void steps(Steps s, Robot robot) { s.start("NEAR: against our wall, 2nd tile left of center, facing the field", -36, -61, 0); Routes.scorePreload(s, robot); Routes.cycle(s, robot); Routes.park(s); } } ``` **Why:** the Driver Station shows two lines, named after the start spot and the plan, so the drivers pick fast. Each line in `steps(...)` calls a piece, and the piece adds its steps to the same list `s`. **More:** [Write each piece once](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#routes), [names and groups](https://crossbotics.com/ftc-helper/docs/building-autos/03-multiple-autos/#names-on-the-driver-station). ## How do I let the drivers choose the start spot and the plan in INIT? **Where:** one new file in `autos/`, `ChooseInInit.java`. ```java title="autos/ChooseInInit.java" package com.crossbotics.ftchelper.examples.cookbook.autos; // In your TeamCode, change the line above to exactly: package org.firstinspires.ftc.teamcode.autos; // and the first import below to: import org.firstinspires.ftc.teamcode.Robot; import com.crossbotics.ftchelper.examples.cookbook.Robot; import com.crossbotics.ftchelper.robot.Auto; import com.crossbotics.ftchelper.robot.Steps; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; /** ONE autonomous: the drivers choose the start and the plan in INIT. */ @Autonomous(name = "Choose in INIT", group = "Autos", preselectTeleOp = "Cookbook TeleOp") @Disabled // delete this line in your copy public class ChooseInInit extends Auto { @Override protected boolean mirrorForRed() { return false; } @Override protected void steps(Steps s, Robot robot) { // Your menu lines (under the library's Alliance and Start delay lines). The FIRST option of // each is chosen at INIT: make it your safest plan. s.menuChoice("Start", "Near", "Far") .menuChoice("Plan", "Preload + Park", "Preload + Cycle + Park", "Park only"); // The start spot follows the "Start" line: the note and the simulator's robot change with it. s.onlyIf("Start", "Near") .start("NEAR: against our wall, 2nd tile left of center, facing the field", -36, -61, 0) .end() .onlyIf("Start", "Far") .start("FAR: against our wall, 2nd tile right of center, facing the field", 36, -61, 0) // Off the wall first: the FLOWER on our wall stands between the two start spots. .forward("Off the wall", 12, 0.5) .left("Across to the near side", 72, 0.7) .end(); // The plan: plain Java "if". choice(...) = the option chosen, as text. (1)! String plan = s.choice("Plan"); if (!plan.equals("Park only")) Routes.scorePreload(s, robot); if (plan.equals("Preload + Cycle + Park")) Routes.cycle(s, robot); Routes.park(s); } } ``` 1. The pieces are Java methods, so a plain `if` picks them. `choice(...)` gives the text of the option (a String). `equals(...)` tests whether two texts are the same. `!` means "not". **Why:** the library uses a `start(...)` inside an `onlyIf` only for its option. So the "Place robot" note (and the simulator's robot) changes as the drivers change the menu. The first option of each line is the default, so make it your safest plan. Your lines come after the library's two (`Alliance`, `Start delay`), so the drivers press D-pad down twice to reach `Start`. The FAR route drives off the wall first, because the FLOWER on your wall stands between the two start spots. A few Java words: `String plan` keeps a text. `plan.equals("Park only")` is true when the two texts are the same. `!` means "not". **More:** [One file, the drivers choose in INIT](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#a-whole-example-one-auto-the-drivers-choose), [what the menu can choose](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#add-choices-to-the-init-menu). --- # Odometry and driveTo URL: https://crossbotics.com/ftc-helper/docs/cookbook/11-odometry/ Odometry tells the robot where it is on the field. **Field numbers:** x = inches right of the center line, and y = inches away from your wall (negative = your half). Heading 0 = facing away from you, and counterclockwise (left) is +. **Every number in your code is seen from your own drivers' wall**, whatever your alliance: start spots, `driveTo`, the goal point, the reset spot. Only the simulator's map and its scenario checks (`expect robot x ...`) use one fixed view, from the red wall. See the [field map](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#why-odometry). **The questions on this page:** - [How do I add a goBILDA Pinpoint?](#how-do-i-add-a-gobilda-pinpoint) - [How do I add a SparkFun OTOS?](#how-do-i-add-a-sparkfun-otos) - [How do I add dead wheels?](#how-do-i-add-dead-wheels) - [How do I tune the odometry?](#how-do-i-tune-the-odometry) - [How do I drive to a point on the field?](#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-get-around-field-elements-on-the-way-to-a-spot) - [How do I show where the robot is?](#how-do-i-show-where-the-robot-is) - [How do I use the robot's position in an action?](#how-do-i-use-the-robots-position-in-an-action) - [How do I set the pose when autonomous did not run?](#how-do-i-set-the-pose-when-autonomous-did-not-run) ## How do I add a goBILDA Pinpoint? **Where:** `Robot.java`, inside `define()`, after the drive line. ```java title="Robot.java" // After drive(...). The robot's length and width, then where each pod's wheel is, mm: (1)! // the forward pod from the LEFT edge, the sideways pod from the FRONT edge. odometry(Odometry.pinpoint("pinpoint").robotSizeMm(430, 400).podsFromEdgesMm(284, 383)); ``` 1. Measure with a tape across the frame, bumpers off. The library finds the robot's center from the size. Here it works out `offsetsMm(-84, -168)`: the forward pod is 84 mm right of the center, and the sideways pod is 168 mm behind it. The Odometry Tuner then measures the exact offsets, and you write `.offsetsMm(...)` in place of `.podsFromEdgesMm(...)`. **Why:** the Pinpoint must know where the pods are, so a turn on the spot does not look like a move. **More:** [Add odometry: one line in Robot.java](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#robotjava-one-line), [Pinpoint](https://crossbotics.com/ftc-helper/docs/modules/odometry/#pinpoint). ## How do I add a SparkFun OTOS? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // The robot's length and width, then the OTOS's middle from the FRONT and LEFT edges (mm), and its turn. odometry(Odometry.otos("otos").robotSizeMm(430, 400).mountFromEdgesMm(126, 200, 0)); ``` **Why:** the OTOS measures at its own spot. To give the place of the robot's center, it must know where it sits. **More:** [OTOS](https://crossbotics.com/ftc-helper/docs/modules/odometry/#otos). ## How do I add dead wheels? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" // The configuration names of the motor ports the pods plug into: left, right, sideways pod. // trackWidthIn: left pod to right pod. perpForwardIn: the sideways pod, 6 in BEHIND the center. odometry(Odometry.threeWheels("par_left", "par_right", "perp") .trackWidthIn(13.2).perpForwardIn(-6)); ``` **Why:** each pod's encoder plugs into a motor port, so the names are those ports' configuration names. **More:** [Three dead wheels](https://crossbotics.com/ftc-helper/docs/modules/odometry/#three-dead-wheels). ## How do I tune the odometry? **Where:** a new file in TeamCode (one per robot). The whole file: ```java title="OdometryTuner.java" // The Odometry Tuner: which way each pod counts, the offsets, and a loop check. @TeleOp(name = "Cookbook Odometry Tuner", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class OdometryTuner extends OdometryTunerOpMode { @Override protected RobotDefinition robot() { return new Robot(); // your Robot.java: the tuner uses its parts and numbers } } ``` **Why:** the tuner checks which way each pod counts, and measures the offsets. Then set `Tunables.Odometry.checked = true`, or `driveTo` does nothing on the robot. It is its own small file, because each program in the Driver Station's list is one class. `robot()` makes it use your `Robot.java`, so it measures the same odometry line that autonomous uses. **More:** [Odometry Tuner: the Odometry Tuner](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/), [Finders](https://crossbotics.com/ftc-helper/docs/tuning/09-odometry-tuner/). ## How do I drive to a point on the field? **Where:** a file in `autos/`, inside `steps(...)`. It needs a mecanum drive. ```java title="autos/YourAuto.java" // The start spot (x, y, heading) must be where the robot really stands: the pose starts there. s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) .driveTo("To the goal", -30, -30, 45, 0.6) .parkWithSeconds(4) // The last number: "close enough", in inches (default 1). .driveTo("Park", -56, -36, 0, 0.7, 2.0); ``` It replaces `.move(...)`: you give a place on the field, not a distance. **Why:** `driveTo` keeps checking where the robot is. So a bump or a wheel slip does not matter, and the robot ends on the point. On the robot, it works only after the [Odometry Tuner](#how-do-i-tune-the-odometry) and `checked = true` in `Tunables.java`, section `Odometry`. **More:** [Drive to points on the field: drive to field points](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/#drive-to-a-point-driveto), [driveTo](https://crossbotics.com/ftc-helper/docs/building-autos/04-drive-to-points/#drive-to-a-point-driveto). ## How do I get around field elements on the way to a spot? **Where:** `Robot.java`, inside `define()`, then a file in `autos/`, or `Controls.java`. It needs odometry and a mecanum drive. ```java title="Robot.java" // After odometry(...). The margin: half the robot's corner to corner size, plus some for drift. // Each box: two opposite corners, like driveTo's numbers. These are BIOBUZZ's two HIVE frames. fieldMap(FieldMap.margin(13) .keepOut("HIVE frame, near", -19.5, -24.8, 19.5, -15.4) .keepOut("HIVE frame, far", -19.5, 15.4, 19.5, 24.8)); ``` In an autonomous, `routeTo` is `driveTo` with a way around the boxes (the keep-out areas in the field map). It starts from wherever the park time stopped the robot: ```java title="autos/YourAuto.java" s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) .driveTo("To the goal", -30, -30, 45, 0.6) .parkWithSeconds(6) // the route slows at each corner: give it more time than a straight line .routeTo("Park", -56, -36, 0, 0.8); ``` In TeleOp, a button or a time starts it, and any drive stick stops it: ```java title="Controls.java" // route(...) makes the job. It starts when the button or the time says so. Runnable park = route("Park", -56, -36, 0, 0.8); g1.dpadLeft.tap(park).says("drive to the park spot (a drive stick stops it)"); atSecondsLeft(10, park); ``` **Why:** a straight line from an unknown place can go through a field element. The robot works out the way when it sets off. It uses only its pose, so it cannot see another robot. Go slow the first time. **More:** [Keep-out boxes and routes](https://crossbotics.com/ftc-helper/docs/modules/odometry/#keep-out-boxes-and-routes). ## How do I show where the robot is? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" show("Where", () -> String.format(Locale.US, "x %.0f, y %.0f in, heading %.0f", robot.pose().x, robot.pose().y, robot.pose().headingDeg)); ``` **Why:** to check the odometry, push the robot by hand and watch the numbers. **More:** [robot.pose()](https://crossbotics.com/ftc-helper/docs/modules/odometry/#robotpose). (TeleOp also starts where autonomous ended: [Add odometry](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#teleop-starts-where-autonomous-ended).) ## How do I use the robot's position in an action? **Where:** `Actions.java`, inside the class. ```java title="Actions.java" /** Runs the intake while the robot is on our half of the field (y below 0). */ public static Action intakeOnOurHalf(Robot r) { return Action.named("Intake on our half") .then(r.intake::in) .waitUntil("past the center line", () -> r.pose().y > 0, 10.0) .then(r.intake::stop); } ``` **Why:** the library updates `robot.pose()` every loop, so a wait can test where the robot is. **More:** [robot.pose()](https://crossbotics.com/ftc-helper/docs/modules/odometry/#robotpose). ## How do I set the pose when autonomous did not run? **Where:** `Tunables.java`, section `Odometry` (and `Controls.java` for more spots). When autonomous stopped early or did not run, TeleOp does not know where the robot is. Park the robot on the reset spot and let go of the drive sticks. Then hold gamepad 1 **START** for 1 second ("set pose here"). This works in INIT or in the match. Write the spot for BLUE, like a start spot. Write `mirrorForRed = false` because BIOBUZZ's field is turned half a turn (RED uses the same numbers from its own wall). On a mirrored field, leave it out (default `true`, RED mirrored). INIT's `Reset spot for RED` line shows which one the library uses. ```java title="Tunables.java" public static class Odometry { // a fixed name: always Odometry public static boolean checked = false; // true after the Odometry Tuner's Loop test // "Set pose here" (TeleOp: hold gamepad 1 START 1 s on this spot), written for BLUE. (1)! public static double resetX = -56; // inches right of center, - = left public static double resetY = -61; // inches from center, - = our half public static double resetHeading = 0; // degrees, 0 = facing the field // RED: false = the same numbers from the red wall; true (or left out) = mirrored left-right. (2)! public static boolean mirrorForRed = false; // BIOBUZZ: false } ``` 1. Inches and degrees seen from your wall, like a start spot. Here the spot is our left corner tile, facing the field. 2. BIOBUZZ's field is turned half a turn between the alliances, so write `false`. `true` is for a mirrored field. For more spots, or to set the pose from an action, write this in `Controls.java`, inside `buttons(...)`: ```java title="Controls.java" // A second spot of your own: hold D-pad down 1 s with the robot in the right corner tile. (1)! g1.dpadDown.heldFor(1.0, () -> robot.resetPose(56, -61, 0)).says("hold 1 s: pose = right corner tile"); // An action can set it too (the action is in Actions.java, below). (2)! g1.dpadUp.heldFor(1.0, Actions.poseHereThenIntake(robot)).says("hold 1 s: pose here, intake on"); ``` 1. x, y and heading are written for BLUE. RED uses them like the reset spot in `Tunables.Odometry`. 2. Here the action sets the `Tunables.Odometry` spot, then runs the intake. The action, in `Actions.java` inside the class: ```java title="Actions.java" /** Sets the pose to the reset spot in Tunables.Odometry, then runs the intake. */ public static Action poseHereThenIntake(Robot r) { return Action.named("Pose here, intake on") .then(r::resetPose) // resetPose() with no numbers: the Tunables.Odometry spot .then(r.intake::in); } ``` **Why:** with a pose, the aim's odometry backup and field-centric "forward" work again. The 1 s hold means a bump of the button does nothing. Write all the spots from your own drivers' wall, like every field number in your code. **More:** [Add odometry: TeleOp starts where autonomous ended](https://crossbotics.com/ftc-helper/docs/add-to-robot/09-odometry/#teleop-starts-where-autonomous-ended), [resetPose()](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#robotdefinition). --- # Pedro paths URL: https://crossbotics.com/ftc-helper/docs/cookbook/12-pedro-paths/ **The questions on this page:** - [How do I add Pedro Pathing to Robot.java?](#how-do-i-add-pedro-pathing-to-robotjava) - [How do I make a straight path and a curve?](#how-do-i-make-a-straight-path-and-a-curve) - [How do I follow a path in an autonomous?](#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-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-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-drive-first-and-turn-at-the-end-of-a-path-or-turn-first) - [How do I start something partway along a path?](#how-do-i-start-something-partway-along-a-path) ## How do I add Pedro Pathing to Robot.java? **Where:** `Robot.java`, inside `define()` (and `Tunables.java` for the numbers). ```java title="Robot.java" odometry(Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)); // Pedro needs odometry // Pedro drives the paths with the drive and odometry lines above. PedroConstants holds the // numbers from Pedro's Foresight tuner (docs/modules/pedro.md#tuning-pedro). follower(Pedro.follower(PedroConstants.foresight)); ``` **Why:** Pedro uses your drive and odometry lines, so you describe the robot only once. **More:** [Add Pedro paths: Robot.java](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/#robotjava-one-line-and-pedros-numbers-file), [Tuning Pedro](https://crossbotics.com/ftc-helper/docs/modules/pedro/#tuning-pedro). ## How do I make a straight path and a curve? **Where:** your autonomous class, above `steps(...)`. ```java title="autos/YourAuto.java" // Make each path once. A line: from (x1, y1) to (x2, y2). A curve: start, a control point // that pulls the curve toward it (the robot does not drive through it), end. static final PedroPath OUT = PedroPath.line(-56, -61, -56, -36).keepHeading(0); static final PedroPath TO_GOAL = PedroPath.curve(-56, -36, -44, -36, -30, -30).turnTo(0, 45); ``` **Why:** Java makes a path once (`static final`), because it is the same every match. **More:** [PedroPath](https://crossbotics.com/ftc-helper/docs/modules/pedro/#pedropath-paths-in-our-field-numbers). ## How do I follow a path in an autonomous? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) .follow("Out", OUT) // brakes to a stop at its end .follow("To the goal", TO_GOAL) .run("Intake on", robot.intake::in) .follow("Back", WATCH_GOAL) .parkWithSeconds(4) .driveTo("Park", -56, -36, 0, 0.7); // driveTo works too (it ends any hold first) ``` **Why:** each `follow` brakes to a stop at its end. Start the next path where the last one ended. **More:** [Add Pedro paths: your first path](https://crossbotics.com/ftc-helper/docs/building-autos/05-pedro-paths/#actionsjava-and-autos-make-paths-then-follow-them), [follow](https://crossbotics.com/ftc-helper/docs/modules/pedro/#follow-the-autonomous-step). ## How do I drive two paths with no stop, slow down, or hold at the end? **Where:** your autonomous class, above `steps(...)`. ```java title="autos/YourAuto.java" // Two parts with NO stop between them (then), a slow part near the goal (maxSpeed), // and hold the end point while it scores (holdEnd: at most 5 s). static final PedroPath IN_ONE_GO = PedroPath.line(-56, -61, -48, -50).keepHeading(0) .then(PedroPath.curve(-48, -50, -44, -36, -30, -30)).turnTo(0, 45) .maxSpeed(0.6) .holdEnd(); ``` **Why:** `then` saves the time of a stop, and `holdEnd` pushes back if another robot bumps yours while it scores. **More:** [PedroPath](https://crossbotics.com/ftc-helper/docs/modules/pedro/#pedropath-paths-in-our-field-numbers), [Hold the end point](https://crossbotics.com/ftc-helper/docs/modules/pedro/#hold-the-end-point). ## How do I keep facing the goal along a path? **Where:** your autonomous class, above `steps(...)`. ```java title="autos/YourAuto.java" // Keep facing one field point the whole way (here x -60, y 60: put your goal's x and y). static final PedroPath WATCH_GOAL = PedroPath.line(-30, -30, -56, -36).facePoint(-60, 60); ``` **Why:** the robot can slide along the path while it keeps the camera or launcher on the goal. **More:** [PedroPath: the heading](https://crossbotics.com/ftc-helper/docs/modules/pedro/#pedropath-paths-in-our-field-numbers). ## How do I drive first and turn at the end of a path (or turn first)? **Where:** your autonomous class, above `steps(...)`. ```java title="autos/YourAuto.java" // Turn from 0 to 90 only in the last 30% of the line (0.7 to 1): drive first, then turn. static final PedroPath DRIVE_THEN_TURN = PedroPath.line(-56, -61, -30, -30).turnTo(0, 90, 0.7, 1); ``` **Why:** `turnTo(a, b)` turns all along the part. The two extra numbers say on which stretch it turns (0 = the part's start, 1 = its end). `0, 0.3` turns first, then drives. `0.7, 1` drives first, then turns. **More:** [PedroPath: the heading](https://crossbotics.com/ftc-helper/docs/modules/pedro/#pedropath-paths-in-our-field-numbers). ## How do I start something partway along a path? **Where:** your autonomous, `steps(...)`. Android Studio shows `PathAt` in red. Press Alt+Enter to add the import. ```java title="autos/YourAuto.java" s.start("Against our wall, in the left corner tile, facing the field", -56, -61, 0) // PathAt: start things ALONG the path, once each, while the robot keeps driving. .follow("To the goal", Paths.IN_ONE_GO, PathAt.part(2, "Intake on", robot.intake::in), // where part 2 starts PathAt.inchesLeft(6, "Intake off", robot.intake::stop)) // 6 in before the end .waitSeconds("Score (the robot holds still)", 0.5); ``` You can also use `PathAt.fraction(0.5, ...)` (halfway along the whole path), `PathAt.inchesDone(10, ...)` and `PathAt.near(x, y, 6, ...)`, for example `PathAt.inchesLeft(12, "Spin up", robot.launcher::spinUp)`. In place of a name and a command, you can give an action from your `Actions.java` (`PathAt.inchesLeft(12, Actions.scoreHigh(robot))`: any action you wrote). **Why:** the robot does not stop to start a mechanism, and Pedro has no "do this here" of its own. If the path ends early, the report says which ones did not start (`STALLED, not fired: Intake off`). **More:** [Do things along the path](https://crossbotics.com/ftc-helper/docs/modules/pedro/#do-things-along-the-path). --- # Telemetry URL: https://crossbotics.com/ftc-helper/docs/cookbook/13-telemetry/ **The questions on this page:** - [How do I show a value on the Driver Station screen?](#how-do-i-show-a-value-on-the-driver-station-screen) - [How do I round a number on the Driver Station?](#how-do-i-round-a-number-on-the-driver-station) - [How do I show lines from my own autonomous step?](#how-do-i-show-lines-from-my-own-autonomous-step) ## How do I show a value on the Driver Station screen? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // A line of its own in buttons(...). The value is read again every loop. show("Lift ticks", robot.lift::position); show("Intake on", robot.intake::isRunning); // shows "Intake on : true" show("Flywheel ready", () -> robot.launcher.isReady()); ``` **Why:** you see what the robot "thinks" while you drive. The value must be quick to read, with no waiting. **More:** [Controls: feedback](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/#feedback-on-a-button). For debug lines (loop time and more), hold gamepad 1 START, then press BACK. The lines turn on or off when you let go. BACK first only pauses the robot. When the alliance switch is on, let go before 1.5 s: a 1.5 s hold switches the alliance and does not change the debug lines. ## How do I round a number on the Driver Station? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // Round a number: %.0f = no decimals, %.1f = one decimal. Locale.US keeps the dot (not a comma). show("Target RPM", () -> String.format(Locale.US, "%.0f", robot.launcher.targetRpm())); ``` **Why:** `%.0f` means "a number with 0 decimals", and `%.2f` gives 2. **More:** [Controls: feedback](https://crossbotics.com/ftc-helper/docs/controls/03-see-and-feel/#feedback-on-a-button). ## How do I show lines from my own autonomous step? **Where:** a file in `autos/`, inside `steps(...)`. ```java title="autos/YourAuto.java" // In your own step: lines on the Driver Station while it runs, and a note in the report. s.step("Spin up", ctx -> { robot.launcher.spinUp(); double giveUpAt = ctx.secondsLeft() - 3; // a time limit: at most 3 s while (ctx.isActive() && !robot.launcher.isReady() && ctx.secondsLeft() > giveUpAt) { ctx.telemetry().line("Flywheel", "spinning up to %.0f RPM", robot.launcher.targetRpm()); ctx.loop(); // updates every part once: the robot keeps running } ctx.note(robot.launcher.isReady() ? "at speed" : "not at speed after 3 s"); }); ``` **Why:** `ctx.loop()` keeps the robot running inside your loop. The time limit makes sure that the loop ends. **More:** [Your own steps](https://crossbotics.com/ftc-helper/docs/building-autos/08-advanced-autos/#write-your-own-step), [The report](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#after-the-match-read-the-report). --- # Lights URL: https://crossbotics.com/ftc-helper/docs/cookbook/14-lights/ A colored light on the robot tells the drivers what the robot "knows" (full, ready, a mode on), so they do not have to look at the Driver Station. The color names need `import com.crossbotics.ftchelper.robot.LightColor;` at the top of each file that uses them: `Controls.java`, and `Actions.java` if an action flashes the light. To add it, press Alt+Enter on a red `LightColor`. The full details: [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/). **The questions on this page:** - [How do I add a colored light for the drivers?](#how-do-i-add-a-colored-light-for-the-drivers) - [How do I change a color on a REV Blinkin?](#how-do-i-change-a-color-on-a-rev-blinkin) - [How do I show a color when something is true?](#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-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-something-happens) - [How do I flash the light when an action is done?](#how-do-i-flash-the-light-when-an-action-is-done) - [How do I blink the light in the last 20 seconds?](#how-do-i-blink-the-light-in-the-last-20-seconds) ## How do I add a colored light for the drivers? **Where:** `Robot.java`, inside `define()` (and a field `public Lights lights;`). ```java title="Robot.java" // At the top of Robot.java: import com.crossbotics.ftchelper.robot.Lights; (1)! // A goBILDA RGB Indicator Light on a servo port ("Servo" in the robot configuration): lights = add(Lights.gobilda("light")); // Or a REV Blinkin LED Driver with an LED strip ("REV Blinkin LED Driver" in the configuration): // lights = add(Lights.blinkin("blinkin")); ``` 1. `Controls.java` needs `import com.crossbotics.ftchelper.robot.LightColor;` for the colors. To add it, press Alt+Enter on a red `LightColor`. **Why:** the light is one line, like any part. It has no numbers and no buttons of its own: the colors come from your rules. **More:** [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/) (the parts and their color tables). ## How do I change a color on a REV Blinkin? **Where:** `Robot.java`, inside `define()`, below the lights line. ```java title="Robot.java" // At the top of Robot.java: import com.qualcomm.hardware.rev.RevBlinkinLedDriver; // A REV Blinkin LED Driver ("REV Blinkin LED Driver" in the robot configuration): lights = add(Lights.blinkin("blinkin")); // Plain blue too dark on your strip? Show another Blinkin pattern for BLUE. (1)! lights.blinkinPattern(LightColor.BLUE, RevBlinkinLedDriver.BlinkinPattern.BLUE_VIOLET); ``` 1. The pattern names are on REV's Blinkin page. Other lights ignore this line. **Why:** each `LightColor` is one of the Blinkin's patterns (`BLUE` is its plain blue). LED strips differ. When one color looks wrong on yours, give that color another pattern. Your rules still say `LightColor.BLUE`. A goBILDA light ignores the line. ## How do I show a color when something is true? **Where:** `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // One rule per line. The first true rule wins: put the most important first. // Red and blue are left for the alliance (shown at INIT), so no rule looks like one. robot.lights.show(LightColor.ORANGE).blinking().when(robot.intake::isPushingOut); // pushing out robot.lights.show(LightColor.GREEN).when(robot.launcher::isReady); // at speed: fire robot.lights.show(LightColor.PURPLE).when(robot.intake::isRunning); // intake on robot.lights.otherwise(LightColor.OFF); // none true ``` **Why:** any true/false works as a rule: - a part's method (`robot.intake::isRunning`) - a mode: `() -> robot.turret.followMode().isOn()` (the turret follows the goal), or on a robot without a turret, `() -> robot.aimMode().isOn()` (whole-robot aim is on) - your own test (`() -> robot.lift.position() > 1000`, if your robot has a lift) Blinking is at most 5 times a second, and the light never changes faster than every 0.1 s (FTC rule R202 J). **More:** [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/), [lambdas](https://crossbotics.com/ftc-helper/docs/five-files/04-actions-java/). ## How do I show the alliance on the light before the match? **Where:** you add nothing, because it is on by default. To change its colors or turn it off, write in `Controls.java`, inside `buttons(...)`. ```java title="Controls.java" // On by default: the alliance at INIT (solid RED or BLUE), flashed for 1 s at ▶. (1)! // Your light shows red badly? Other colors for the alliance at INIT (BLUE, and PURPLE for RED): robot.lights.allianceColors(LightColor.BLUE, LightColor.PURPLE); // No alliance color at INIT at all? Delete the line above and write: (2)! // robot.lights.allianceAtInit(false); ``` 1. Until the drivers choose an alliance, the light blinks white. You do not write anything for this. 2. Your rules then show from INIT on. Or, in `Tunables.java`, write this in the light's section: `public static class Light { public static boolean allianceAtInit = false; }`. The line in `Controls.java` wins. **Why:** with a wrong alliance pick in INIT, the robot aims at the other alliance's goal all match. The light is solid RED or BLUE before ▶ (white, blinking once a second, until the drivers pick). So the drive team sees a wrong pick from the field. The game manual has no rule against a light in your alliance color, but the ROBOT SIGNS are still required (R401, R402). Keep your own rules' colors away from red and blue. **More:** [Lights](https://crossbotics.com/ftc-helper/docs/reference/parts/lights/#the-alliance-at-init). ## How do I flash the light when something happens? **Where:** `Controls.java`, inside `buttons(...)`, above your other light rules. ```java title="Controls.java" // A flash beats every rule while it lasts (write it first: it reads that way). (1)! // A short white flash for each piece fired, and one from a button. robot.lights.show(LightColor.WHITE).forSeconds(0.2) .whenCountGoesUp(() -> robot.launcher.part().getShotsFired()); g2.a.press(() -> robot.lights.flash(LightColor.YELLOW)).says("flash the light (signal the partner)"); ``` 1. A flash wins, wherever you write it. The launcher counts the pieces it feeds. The flash is 0.2 s, so two quick shots are two flashes, not one long one. **Why:** `whenCountGoesUp` flashes each time the number goes up, so each flash is a real shot. `whenStarts(test)` flashes when a true/false turns from false to true (`whenStarts(robot.intake::isRunning)`: the intake has started). A flash lasts 0.5 s. `.forSeconds(...)` before `when...` changes it. Here it is shorter, so two shots a quarter second apart are two flashes, not one long one. `flash(color)` from a button or an action flashes once. ## How do I flash the light when an action is done? **Where:** `Actions.java`, inside the class. ```java title="Actions.java" // In Actions.java (it needs import com.crossbotics.ftchelper.robot.LightColor; at the top). // The last step: a 1 s white flash says "done" to the drivers. Pick a color your rules do not use. (1)! public static Action shootTwo(Robot r) { return Action.named("Shoot two") .then(r.launcher::spinUp) .waitUntil("at speed", r.launcher::isReady, 3.0) .then(() -> r.launcher.fire(2)) .waitUntil("both gone", () -> !r.launcher.isShooting(), 3.0) .then(() -> r.lights.flash(LightColor.WHITE, 1.0)); } ``` 1. A GREEN flash over the GREEN "ready" rule cannot be seen. Pick another color, or a longer time. **Why:** no action "claims" the light, so any action (or button) may flash it. A flash beats every rule. But you cannot see a flash in the same color as the rule under it, so pick another color, or a longer time. ## How do I blink the light in the last 20 seconds? **Where:** `Controls.java`, inside `buttons(...)`, before the other rules. ```java title="Controls.java" // Yellow, blinking, in the last 20 seconds of TeleOp: time to park (above the other rules: it wins). robot.lights.show(LightColor.YELLOW).blinking().inLastSeconds(20); ``` **Why:** the time counts from ▶ (TeleOp's 2:00), like the gamepad buzzes. It is about a second off from the field clock, which is good enough for a reminder. --- # Tuning and finders URL: https://crossbotics.com/ftc-helper/docs/cookbook/15-tuning/ **The questions on this page:** - [Where do the numbers go?](#where-do-the-numbers-go) - [How do I find a servo's open and closed numbers?](#how-do-i-find-a-servos-open-and-closed-numbers) - [How do I find a lift's limits and heights?](#how-do-i-find-a-lifts-limits-and-heights) - [How do I change a number while the robot runs?](#how-do-i-change-a-number-while-the-robot-runs) - [How do I tune the drive for autonomous?](#how-do-i-tune-the-drive-for-autonomous) - [How do I set the flywheel numbers?](#how-do-i-set-the-flywheel-numbers) - [How do I build a shot table (speed for each distance)?](#how-do-i-build-a-shot-table-speed-for-each-distance) - [How do I find my hood's stops and angles?](#how-do-i-find-my-hoods-stops-and-angles) ## Where do the numbers go? In `Tunables.java`, one section per part (see [the lift recipe](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-lift-with-set-heights)). A finder (a program that measures a number on the robot) shows lines like `Tunables.Claw: P1 = 0.210, P2 = 0.770`. Copy them into that section, keep the other lines, and give P1 and P2 real names. A number you leave out uses the library's default (INIT says which). The exception is a lift's or arm's `min` and `max`: you must write those. **More:** [Tunables.java](https://crossbotics.com/ftc-helper/docs/reference/tunables/), [Finding your numbers](https://crossbotics.com/ftc-helper/docs/tuning/). ## How do I find a servo's open and closed numbers? **With the five files:** you add nothing. Run **Tune and check** (the library puts it on the Driver Hub) and pick the Servo Finder ([Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/)). **Without the five files:** a new file in TeamCode (also in the [starter kit](https://crossbotics.com/ftc-helper/docs/starter-kit/)). The whole file: ```java title="ServoFinder.java" // The Servo Finder: lists every servo in the configuration. No robot needed. @TeleOp(name = "Cookbook Servo Finder", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class ServoFinder extends ServoFinderOpMode { } ``` **Use it:** put the robot on a block. Run the Servo Finder. Choose the servo (D-pad, A). A servo cannot say where it is, so choose a start number close to where it sits now (D-pad, A). Nudge it with the D-pad. At each end of its safe travel (right before it pushes on the frame), press X, then B. Then move it to each position you need and press A. For example: fully open, A (that is P1); closed, A (P2). Copy the line it shows (`Tunables.Claw: P1 = 0.210, P2 = 0.770`) into `Tunables.java` and rename P1, P2 (`open`, `closed`). For a part with [`.fullRange()`](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-get-my-servos-full-range) in Robot.java, press Y first, while you choose the servo. **Why:** a servo pushed past its end hums, gets hot and breaks. The finder finds the safe numbers. **More:** [Servo Finder](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/), [the order](https://crossbotics.com/ftc-helper/docs/tuning/#the-tuning-order). ## How do I find a lift's limits and heights? **With the five files:** you add nothing. Run **Tune and check** (the library puts it on the Driver Hub) and pick the Motor Finder ([Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/)). **Without the five files:** a new file in TeamCode (also in the [starter kit](https://crossbotics.com/ftc-helper/docs/starter-kit/)). The whole file: ```java title="MotorFinder.java" // The Motor Finder: lists every motor in the configuration. No robot needed. @TeleOp(name = "Cookbook Motor Finder", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class MotorFinder extends MotorFinderOpMode { } ``` **Use it:** first put the lift all the way down, because the count starts at 0 there. Choose the motor (D-pad, A). Move it slowly with the right stick. Press X a little above the bottom and B a little below the top. Then press A at each height you need. Copy the line it shows (`Tunables.Lift: min = 0, max = 2580, P1 = 1200`) into `Tunables.java` and rename P1 (`low`). **Why:** a wrong top limit drives the lift into its hard stop. Measured limits keep it safe. **More:** [Motor Finder](https://crossbotics.com/ftc-helper/docs/tuning/05-motor-finder/). ## How do I change a number while the robot runs? With the five files, you write no code for this. In the TeleOp (PRACTICE profile), after ▶, **hold GUIDE for 1 second**, and the tuning menu opens. D-pad up/down chooses a number, and right/left changes it. **A** saves it on the hub, and **B** lists the changed values. **Then copy each good value into `Tunables.java`.** With a new Control Hub, you lose a value that you saved only on the hub. Also, your teammates cannot see it. **Why:** you see the effect at once, and you do not have to build and install again. **More:** [Tuning](https://crossbotics.com/ftc-helper/docs/tuning/16-live-tuning/#open-it-and-change-a-number), [Add a lift: tune the lift live](https://crossbotics.com/ftc-helper/docs/add-to-robot/01-lift/#4-check-it-then-tune-it). ## How do I tune the drive for autonomous? **With the five files:** you add nothing. Run **Tune and check** (the library puts it on the Driver Hub) and pick the Drive Tuner ([Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/)). **Without the five files:** a new file in TeamCode. The whole file: ```java title="DriveTuner.java" // The Drive Tuner: wheel size and strafe correction, for the drive in your Robot.java. @TeleOp(name = "Cookbook Drive Tuner", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class DriveTuner extends DriveTunerOpMode { @Override protected RobotDefinition robot() { return new Robot(); // your Robot.java: the tuner uses its parts and numbers } } ``` **Why:** the tuner measures the real wheel size and strafe correction. Copy its lines, then set `Tunables.Drive.calibrated = true`. **More:** [Tune the drive first](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#tune-the-drive-first), [Drive Tuner](https://crossbotics.com/ftc-helper/docs/tuning/08-drive-tuner/). ## How do I set the flywheel numbers? Before you have them, write `DEFAULT` in their place, or leave the lines out. The launcher then starts from the parts catalog's numbers for its motor, and INIT says so. For a goBILDA 6000 RPM motor, these are kF 11.7, kP 1.17, kI 0.117, and 60% of its top speed, 3600 RPM. Then run the **Flywheel Finder** (in the [starter kit](https://crossbotics.com/ftc-helper/docs/starter-kit/)) and copy its line into `Tunables.Launcher` (see [the launcher recipe](https://crossbotics.com/ftc-helper/docs/cookbook/04-mechanisms/#how-do-i-add-a-launcher-flywheel-and-feeder)). Do not copy another robot's gains, because its team found them for its own wheel. **Why:** the right `kP`..`kF` (the gains: how hard the motor pushes toward the target speed) make the wheel get back to speed fast after each shot. **More:** [Flywheel Finder](https://crossbotics.com/ftc-helper/docs/tuning/06-flywheel-finder/). ## How do I build a shot table (speed for each distance)? **With the five files:** you add nothing. Run **Tune and check** (the library puts it on the Driver Hub) and pick the Shot Tuner ([Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/)). **Without the five files:** a new file in TeamCode, `ShotTuner.java`. Run the [Aim Tuner](https://crossbotics.com/ftc-helper/docs/tuning/12-aim-tuner/) first. Below is the whole file. Its first line is `package org.firstinspires.ftc.teamcode;` (Android Studio writes it when you make the file), then: ```java title="ShotTuner.java" import com.crossbotics.ftchelper.finders.ShotTunerOpMode; import com.crossbotics.ftchelper.robot.RobotDefinition; import com.qualcomm.robotcore.eventloop.opmode.Disabled; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; // The Shot Tuner: fills Tunables.Launcher.speedByDistance from shots you mark HIT or MISS. @TeleOp(name = "Cookbook Shot Tuner", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class ShotTuner extends ShotTunerOpMode { @Override protected RobotDefinition robot() { return new Robot(); // your Robot.java: the tuner uses its parts and numbers } } ``` **Why:** the launcher needs a speed for each distance. At each distance, you shoot 3-5 times per speed and mark each HIT (A) or MISS (B), all on gamepad 1. A left stick click takes the last mark back. X keeps the speed with the best hit ratio (hits out of shots). The tuner fills `Tunables.Launcher.speedByDistance` (one line per table to copy), so the launcher picks the speed for each distance. **More:** [Shot Tuner](https://crossbotics.com/ftc-helper/docs/tuning/13-shot-tuner/). ## How do I find my hood's stops and angles? **With the five files:** you add nothing. Run **Tune and check** (the library puts it on the Driver Hub) and pick the Hood Finder ([Tune and check](https://crossbotics.com/ftc-helper/docs/tuning/01-tune-and-check/)). **Without the five files:** a new file in TeamCode, `HoodFinder.java` (first line `package org.firstinspires.ftc.teamcode;`): ```java title="HoodFinder.java" import com.crossbotics.ftchelper.finders.HoodFinderOpMode; import com.crossbotics.ftchelper.robot.RobotDefinition; import com.qualcomm.robotcore.eventloop.opmode.Disabled; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; // The Hood Finder: the hood's two stops (and its angles) for Tunables.Hood. It reads the hood // from Robot.java (servo or motor), so it works before Tunables.Hood has numbers. @TeleOp(name = "Cookbook Hood Finder", group = "Finders") @Disabled // delete this line in your copy, or you will not see it public class HoodFinder extends HoodFinderOpMode { @Override protected RobotDefinition robot() { return new Robot(); // your Robot.java: the finder finds its hood } } ``` **Why:** the hood needs its stops and angles. Nudge the hood to each stop, back off a hair, and press X and B. The finder writes `Tunables.Hood: posA = ..., posB = ...`. Before X / B, hold LB + D-pad to type in the angle you measured (or press A for a point in between, for a linkage). Copy the lines into `Tunables.java`. **More:** [Hood Finder](https://crossbotics.com/ftc-helper/docs/tuning/04-hood-finder/). --- # Simulator URL: https://crossbotics.com/ftc-helper/docs/cookbook/16-simulator/ The simulator runs your real code on a laptop, with the field in 3D. The easy way to start it is a button in Android Studio (below). Or type the commands in a terminal: in Android Studio, the **Terminal** tab at the bottom ([how](https://crossbotics.com/ftc-helper/docs/setup/09-the-terminal/)). First go into the `ftc-helper-lib` folder by typing `cd ftc-helper-lib`. It is the library's folder inside your robot project, next to `TeamCode` in Android Studio's Project panel. If it is not there, ask your mentor, or see [Add the library](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/). `./gradlew` runs Gradle, the tool that builds the code, and `-P...` gives it a setting. **The questions on this page:** - [How do I start the simulator?](#how-do-i-start-the-simulator) - [How do I see my own robot in the simulator?](#how-do-i-see-my-own-robot-in-the-simulator) - [How do I make the simulator draw my part?](#how-do-i-make-the-simulator-draw-my-part) - [How do I test my code with a script?](#how-do-i-test-my-code-with-a-script) ## How do I start the simulator? In Android Studio, pick **Simulator** in the list next to the green Run button, and click Run. If **Simulator** is not in the list, close the project and open it again ([the buttons](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/#the-simulator-buttons-you-do-nothing)). Or, in the terminal: **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ```bash ./gradlew :sim:run ``` Then open **http://localhost:8780** in a browser. Choose an OpMode, press INIT, then ▶. To stop the simulator, click the red **Stop** button (or press Ctrl+C in the terminal). **Why:** you can try buttons and autonomous routes before the robot is built. **More:** [Simulator: start it](https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/). ## How do I see my own robot in the simulator? Start the simulator (the **Simulator** button, or `./gradlew :sim:run`). It runs your TeamCode. When it starts, it makes the simulator's robot file from your `Robot.java`, and prints `Robot file made from Robot.java: simulator/robot.properties`. **Why:** the robot file then always matches your code. The simulator keeps your own lines in it. When you change the code, stop the simulator and start it again. **More:** [A robot file from Robot.java](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/#2-the-simulator-makes-it-from-robotjava), [Your own robot code](https://crossbotics.com/ftc-helper/docs/reference/robot-file/#the-commands). ## How do I make the simulator draw my part? **Where:** `Robot.java`: add `.looks(...)` to the part's line (optional). ```java title="Robot.java" // For the simulator only. All in mm. atMm(forward, left, up): from the middle of the chassis, on the tiles. (1)! // sizeMm(front to back, side to side, up). chassisMm(400, 400, 100); // the chassis box heightMm(380); // the whole robot, folded // TWO shapes on one part: name each shape, then looks(intakeArm, intakeRoller). // passive(): nothing in the code moves the arm. range: its two hard stops, degrees. (2)! Shape intakeArm = Shape.arm().name("intake_arm").atMm(150, 0, 80).sizeMm(80, 300, 20) .passive().range(-20, 0).startAt(0); Shape intakeRoller = Shape.roller("gobilda-gecko-72").on("intake_arm").atMm(80, 0, 0).lengthMm(300); intake = add(Intake.motor("intake").part("gobilda-5203-1150").looks(intakeArm, intakeRoller)); // ONE shape: write it inside looks(...). A slide at the back; travelMm: how far it rises. lift = add(Lift.slide("lift").part("gobilda-5203-435") .looks(Shape.slide().atMm(-170, 0, 20).sizeMm(40, 40, 300).travelMm(600))); // A claw on top of the slide: on(lift) makes it go up with the slide. claw = add(Claw.servo("claw").part("gobilda-2000-torque") .looks(Shape.claw().on(lift).atMm(60, 0, 300).sizeMm(80, 120, 50))); // A flywheel: its size comes from the wheel's catalog id. Only its place is yours. launcher = add(Launcher.flywheel("launcher", "gobilda-5203-6000") .looks(Shape.flywheel("gobilda-hogback-96").atMm(-40, 0, 200))); ``` 1. The real robot never reads `.looks(...)`. Measure with a tape, or shape the part in the simulator's Edit robot mode and copy the lines it shows. 2. The arm hinges at the front and rests on its stop. The roller rides on the arm's end: `on("intake_arm")`. **One shape or several:** one shape goes inside `looks(...)` on the part's line. For two or more (an arm and its roller), give each a name first (`Shape intakeArm = ...;`), then write `looks(intakeArm, intakeRoller)` ([how](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#shapes-and-parts)). **Why:** without `.looks(...)`, the simulator still runs, with a guessed box for each part (marked `TODO measure` in the robot file). With it, the 3D view shows your robot, and the size check (18 in start cube, 29 in tall) is right. Pieces also touch the intake where the real one is. Name the part (`.part(...)`) too, so a roller's or a wheel's size comes from the parts catalog. **The easy way:** use the simulator's **Edit robot** mode. Drag and size each part on the 3D robot, then copy the `.looks(...)` lines it shows into `Robot.java`. After a change, stop the simulator and start it again. **More:** [Shapes and parts](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#shapes-and-parts) (every shape and setting), [A robot file from Robot.java](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/#2-the-simulator-makes-it-from-robotjava). ## How do I test my code with a script? A script (a scenario file) presses buttons and checks the robot for you. The easy way is to **record** it. In the simulator, click **Tests > Record a test**, drive, and click **Stop recording**. Keep the ticked checks and click **Save**. The simulator then writes `simulator/scenarios/NAME.sim` for you ([Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/)). Or write one by hand, for example `simulator/scenarios/intake.sim` (the library runs this same file as a test: `sim/scenarios/cookbook-intake.sim`): ```text init "Quick Start TeleOp" # your TeleOp's name start hold g2.rt 1 # hold RT (the intake runs while it is held) expect within 1 motor intake power > 0.5 release g2.rt expect within 1 motor intake power = 0 0.01 expect error none ``` To run every test in the folder, click **Tests > Run all tests** on the simulator page, or the **Simulator tests** button in Android Studio. Or use the terminal (leave out `-Pfile` for every test): **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ```bash ./gradlew :sim:scenario -Pfile=../simulator/scenarios/intake.sim ``` It runs your own code (`../TeamCode`, next to the library in your robot project). **Why:** a script checks the same things every time, with no clicking, and catches a mistake before a meeting. A scenario uses the FTC button names, which can differ from the Java names. `g2.rt`, `g2.lb`, `g2.a` are the same, but `g2.dpadUp` is `g2.dpad_up` and `g2.leftStickY` is `g2.left_stick_y`. **More:** [Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/), [Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/) (every command and button name). --- # Start it and drive URL: https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/ **You need:** - A laptop with Android Studio ([Install Android Studio](https://crossbotics.com/ftc-helper/docs/setup/02-android-studio/)). - Your robot project with the library in it ([Add the library](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/)). - No project yet? You can start the simulator from the `ftc-helper-lib` folder alone, with the library's example robots ([step 2](#2-or-start-it-in-the-terminal)). It works on Windows, macOS and Linux, and on a Chromebook with Linux turned on. ## 1. Start it with the Simulator button The library adds two buttons to Android Studio when it syncs your project. 1. In the list next to the green Run button, pick **Simulator**. 2. Click Run. 3. When the simulator is ready, the page http://localhost:8780 opens in your browser. No browser opens? Find `Open http://localhost:8780` in the Run window. It is a blue link: click it. The red square **Stop** button stops the simulator. **Simulator tests**, in the same list, runs your tests ([Tests](https://crossbotics.com/ftc-helper/docs/tests/)). The buttons are not in the list? Close the project (**File > Close Project**) and open it again. The buttons need no laptop setup. ## 2. Or start it in the terminal **Why:** the terminal shows every message, and it takes options (for example, another robot file). The first time on a laptop, do the [laptop setup](#laptop-setup-once) below. **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ```bash ./gradlew :sim:run ``` `./gradlew` runs Gradle, the tool that builds the code. `:sim:run` is the job: the `run` job of the `sim` (simulator) part. It builds your code, makes the robot file from your `Robot.java` ([Your robot file](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/)), and starts the simulator. Open **http://localhost:8780** in a browser. Press Ctrl+C in the terminal to stop it. **Windows:** type `gradlew.bat` (or `.\gradlew` in PowerShell) instead of `./gradlew`. **With no robot project:** add `-PteamCode=none`. The simulator then runs the library's own examples. ### Laptop setup (once) The library is its own Gradle build, apart from your robot project. So the terminal needs two things, even when the robot project already builds. - **Java.** Gradle needs `JAVA_HOME`: the folder where Java is. Android Studio has its own Java, in its `jbr` folder. Check that the folder exists, then set it. It lasts until you close that terminal. - Mac: `export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"` - Windows PowerShell: `$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jbr"` No such folder? In Android Studio, open **Settings > Build, Execution, Deployment > Build Tools > Gradle**. The **Gradle JDK** line names the Java that Android Studio uses, with its folder. Use that folder. Still none? Install a JDK 17 or 21 (a **JDK** is Java with the tools that build code), for example Eclipse Temurin from [adoptium.net](https://adoptium.net). You do not need the Java from java.com. - **The Android SDK.** The first command stops with `SDK location not found`? Make a file `ftc-helper-lib/local.properties` with one line: - Mac: `sdk.dir=/Users//Library/Android/sdk` - Windows: `sdk.dir=C\:\\Users\\\\AppData\\Local\\Android\\Sdk` Put your user name in place of ``. Android Studio shows the SDK folder in **Settings > Languages & Frameworks > Android SDK**. **Why:** the library is its own build, so your robot project's `local.properties` does not count. **Warnings you can ignore:** `source value 8 is obsolete`, `SDK processing. This version only understands SDK XML versions up to 3`, `Deprecated Gradle features were used`, `[Incubating] Problems report`. **Android Studio's "Start AGP Upgrade Assistant" note: do not click it.** The FTC SDK sets its own Android build version. An upgrade can break the robot build. Close the note. ## 3. Read the page ![The simulator page: the Driver Hub on the left, the field in 3D in the middle with the gamepads under it, and the Control Hub's panels on the right](https://crossbotics.com/ftc-helper/docs/images/simulator.png) The page has three parts. It fits one laptop screen. On a narrow screen, the parts stack and the page scrolls. - **Left: the Driver Hub.** It looks like the Driver Station app: the battery, gamepad 1 and 2 (lit while used), the **Auto** and **TeleOp** lists, one big button (INIT, then ▶, then STOP), the match time and the telemetry. - **Middle: the field in 3D,** with the gamepads under it. The buttons over it are **View** and **Layers** (how to look), then **Tests**, **Edit robot** and **Auto builder** (what to do). - **Right: the Control Hub.** Its panels show the robot on the field from above, the motors, the servos and switches, the cameras, and the match. Each button at the top shows or hides one panel. The page remembers your choices in this browser: the panels, the view, and whether the gamepads show. ## 4. Run an OpMode 1. Pick an OpMode with the **TeleOp** button (or **Auto**). 2. Press **INIT**. The telemetry shows the OpMode's INIT screen. 3. Press **▶** (the same big button). 4. Press **STOP** when you are done. ![The simulator page while goBILDA's starter bot runs its TeleOp: the Driver Hub shows the running OpMode and its telemetry (time, drive, intake, launcher READY), gamepad 1 is set to Keyboard, and the robot is on the field in 3D and on the map](https://crossbotics.com/ftc-helper/docs/images/sim-teleop-running.png) Like the real Driver Station: - An autonomous stops by itself after 30 s, and a TeleOp after 2:00. A box under the clock turns each timer off. - An error shows in red, with the line where it happened. The same OpMode stays picked, so you can fix the code and press INIT again. - OpModes marked "(hidden on robot)" have `@Disabled`. The simulator shows them anyway. ## 5. Drive Each gamepad has its own source, picked in its list under the 3D view. | Source | How | | --- | --- | | Keyboard | Set the gamepad's list to **Keyboard**. Left stick: W A S D. Right stick: the arrows. D-pad: T F G H. A, B, X, Y: K, L, J, I. LB, RB: Q, E. LT, RT: Z, C. BACK: Backspace. START: Enter. GUIDE: M. Left and right stick click: X, V | | Controller | Plug in a USB or Bluetooth controller and press one of its buttons (a browser rule). Gamepad 1 takes it, or gamepad 2 when gamepad 1 already has one. Xbox, PS4 and PS5 controllers work everywhere. A Logitech F310 works on Windows (on a Mac, set its back switch to "D"). Chrome and Edge work best | | On-screen | Click the buttons, drag the sticks, slide the triggers. **Sticky buttons** (the box under the gamepads): a click holds a button until the next click, so you can hold two things with one mouse | | Phone | Start the simulator with `-Plan` ([options](https://crossbotics.com/ftc-helper/docs/reference/robot-file/#the-commands)). On a phone on the same WiFi, open the address that the page shows, with `?phone=2` at the end. The phone is then gamepad 2 (`?phone=1`: gamepad 1). Set that gamepad's list to **Phone / other page** | **Keep the simulator tab in front while you drive.** A browser tab in the background sends gamepad updates only once a second. After 2.5 s with no news, the simulator lets go of every button, like a pulled cable. **The GUIDE (PS) button** often does not reach the browser, because Windows and macOS keep it. Use the on-screen GUIDE, the M key, or hold START (Enter) for 1 second. The library accepts that too. **`-Plan` on open WiFi:** anyone on that WiFi can open the page and run OpModes. Use it on a team or home network, not on open school WiFi. ## 6. Look around and move the robot **The 3D view:** drag to turn the view, scroll to zoom, and right-drag (or use two fingers) to slide. The **View** menu, or the keys 1 to 8, look from fixed places: | Key | View | | --- | --- | | 1 | Drivers: your alliance's wall (the alliance that the running program uses; red until a program says) | | 2 | Red wall | | 3 | Blue wall | | 4 | Audience side | | 5 | Far side, across from the audience | | 6 | From above, your alliance's wall at the bottom | | 7 | Follow robot, from behind it | | 8 | HIVE close-up: your alliance's HIVE (on a field with no HIVEs: the goal nearest the robot) | ![The View menu open over the 3D field: keys 1 to 8 (Drivers, Red wall, Blue wall, Audience side, Far side, From above, Follow robot, HIVE close-up), then the Show the 3D view and Field CAD model boxes](https://crossbotics.com/ftc-helper/docs/images/sim-view-menu.png) **The robot:** a gray box with a white arrow at the front, plus its parts. It turns red when it bumps into something. A roller glows green while it takes pieces in, and orange while it pushes them out. A flywheel glows yellow while it spins. **Move it by hand:** while no program runs (or in INIT), drag the robot on the field map (Control Hub, **Robot** panel). Turn it with the mouse wheel over it. In the 3D view, double-click the robot, then drag it, or drag its yellow ring to turn it. Under the map, the page shows the spot in the numbers that an autonomous's `s.start(...)` takes. **Push the robot** (Robot panel) rolls it like a hand push, also while a program runs. **Back to start** puts the robot and every game piece back where the match starts them. **Where the robot starts:** INIT of an autonomous starts a new match. The robot goes to the autonomous's start spot, and every piece goes back. A TeleOp's INIT keeps the field as it is, so it goes on from the autonomous. More: [Watch an autonomous](https://crossbotics.com/ftc-helper/docs/simulator/04-watch-an-autonomous/#2-run-it). ## 7. After a code change Stop the simulator and start it again (the **Simulator** button, or `./gradlew :sim:run`). **Why:** the simulator builds your code and makes the robot file only when it starts. The page connects again by itself, so you do not need to reload it. While the simulator is off, a red bar across the top of the page says so. ## Problems | What you see | Why, and the fix | | --- | --- | | No **Simulator** in the Run list | Android Studio has not synced the project since the library came in. Close the project and open it again | | `SDK location not found` | The library's build cannot find the Android SDK. Make `ftc-helper-lib/local.properties` ([laptop setup](#laptop-setup-once)) | | `JAVA_HOME is not set` | Set it in this terminal ([laptop setup](#laptop-setup-once)) | | The page says the simulator stopped | The simulator program ended: you clicked Stop, or closed Android Studio. Start it again | | "press INIT to run it again" under the Driver Hub | The OpMode ended. Press INIT | | The robot does not move with the keyboard | The gamepad's list is not set to **Keyboard**, or the page is not in front. Click the page once, then try again | | The robot drives backward or spins | A motor direction in your code, or the robot file's `drive.mirrored`. See [Your robot file](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/#problems) | | The page is slow | Untick **Show the 3D view** in the View menu | ## Done when - The simulator starts, and the page shows your OpModes. - You can INIT and run your TeleOp, and drive the robot with a gamepad or the keyboard. --- **Next:** [Your robot file](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/). **Look it up:** [The commands and their options](https://crossbotics.com/ftc-helper/docs/reference/robot-file/#the-commands). --- # Your robot file URL: https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/ **You need:** - The simulator running ([Start it and drive](https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/)). - A robot in five files ([The five files](https://crossbotics.com/ftc-helper/docs/five-files/)). No five files? See [section 6](#6-a-robot-without-the-five-files). ## 1. What the robot file is The simulator cannot read your robot. It needs to know the device names, the motors and servos, the size of the robot, and where each part sits. The **robot file** holds that, as plain `name = value` lines (a "properties" file). Text after `#` is a note for people. Your robot file is `simulator/robot.properties` in your robot project. The simulator uses it by itself. Commit it with your code. ## 2. The simulator makes it from Robot.java Each time the simulator starts (the **Simulator** button, `./gradlew :sim:run`, or a test run), it first writes the robot file from your Robot class. It prints one line: ```text Robot file made from Robot.java: simulator/robot.properties ``` ![Each start, Robot.java and Tunables.java make simulator/robot.properties, and the simulator reads it. The file has three kinds of lines: from Robot.java (written again at every start), TODO measure (a guess to replace), and your own lines (kept)](https://crossbotics.com/ftc-helper/docs/images/sim-robot-file-flow.svg) It takes these from `Robot.java` and `Tunables.java`: - every device name, as in the robot configuration. - the drive: tank or mecanum, the motors, the wheel, and which side the code reverses. - the motors' and servos' catalog parts (`.part(...)`): speed, encoder counts, range. - each part's limits and positions: a lift's stops, a claw's open and closed. - the odometry and the cameras. - one shape per part, and where game pieces go in and out (the intake, the launcher, the claw). To make the file alone, with no simulator: **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ```bash ./gradlew :sim:fromRobot ``` **Why it helps:** it builds your TeamCode first. So it also tells you, with no Control Hub, whether your code builds. ## 3. Read what it guessed Open `simulator/robot.properties`. The top of a small robot's file looks like this: ```properties # The simulator's robot, made from org.firstinspires.ftc.teamcode.Robot (again at each start of the simulator). battery = 12.8 field = biobuzz-2026 # ---- from Robot.java ---- drive.type = mecanum # from Robot.java drive.motors = front_left, front_right, back_left, back_right # from Robot.java drive.part = gobilda-5203-312 # from Robot.java shape.lift = slide, at=-7,0,4, size=2x2x12, axis=up, motor=lift # from Robot.java. TODO measure: place, size and travel (at the back; ...) ``` - **`# from Robot.java`:** the simulator wrote this line, and it writes it again at every start. - **`TODO measure`** after it: a guess. Your code does not say where this part sits. So the simulator put it in a typical place: the intake across the front, a lift at the back, a turret on top in the middle, a claw on the end of the lift or arm. The guesses fit the size rules (the 18 in start cube, 29 in tall). The robot drives and its parts move with the guesses. But the size checks, and where game pieces touch the robot, are guesses too. [Make it match your robot](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/) replaces them. ## 4. Your own lines stay yours You can add lines, or change the simulator's lines. - A line with no `# from Robot.java` note is yours. The simulator keeps it, even for the same setting. - To keep your own number on a simulator line, delete its `# from Robot.java` note. - A `TODO` line keeps a number that you write on it. - When the code changes a marked line, the simulator prints the change and keeps the old file as `robot.properties.bak`. - It removes the lines for parts that are no longer in the code. **Better:** put sizes and places in `Robot.java` (`looks(...)`), not in the robot file. Then `Robot.java` stays the one record of your robot ([Make it match your robot](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/)). ## 5. MEASURE numbers and missing parts **A Tunables number written `MEASURE`** ([DEFAULT and MEASURE](https://crossbotics.com/ftc-helper/docs/reference/tunables/#default-and-measure)) stops INIT on the robot until you measure it. In the simulator, the robot file gets a **stand-in** for it: ```properties tunable.IntakeDeploy.deployed = 0.5 # from Robot.java. Simulator only: a stand-in for MEASURE (the library's default). ... ``` - INIT in the simulator uses 0.5, and says so under the Driver Hub. - The real robot never reads the robot file, so it still stops at INIT. Safety on the robot does not change. - When you write the real number in `Tunables.java`, the code's number wins, and the stand-in line goes. **A part not on the robot yet:** a part marked `optional()` in Robot.java ([parts not on the robot yet](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-on-the-robot-yet)) is in the robot file anyway. To try the robot as it is today, without the part, add a line of your own: ```properties missing = intake_deploy ``` The simulator then acts like a robot whose configuration does not have that device: INIT says `IntakeDeploy is off`, its buttons are off, and actions skip it. ## 6. A robot without the five files The simulator still runs your OpModes. It needs a robot file that you start in one of these ways: - **A starter bot:** the library has a robot file for each season's starter bot, in `ftc-helper-lib/sim/robots/` ([Starter bots](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/)). Copy the one for your robot to `simulator/robot.properties`. - **From your robot configuration:** copy the configuration file from the Control Hub, then: **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ```bash ./gradlew :sim:fromConfig -Pconfig=../my-config.xml -Pout=../simulator/robot.properties ``` It writes every device name, and guesses the rest. - **With an AI coding agent:** the [robot-file skill](https://crossbotics.com/ftc-helper/docs/guides/robot-file-skill/) writes most of it from your configuration, your code and a tape measure. A robot file that you wrote by hand (no "made from" line at the top) does not change when the simulator starts. ## Problems | What you see | Why, and the fix | | --- | --- | | The simulator prints why it wrote nothing, and uses the file as it is | The file describes a device in another way than the code (`motor.claw` in the file, a claw servo in the code), or names other drive motors. Fix one of them, or delete the line from the file | | Stick forward drives the robot backward, or the robot spins | The file's `drive.mirrored` names the wrong side. It must name the side that your code reverses. The simulator writes it from `Robot.java`, so check the drive line there first | | INIT says a Tunables field is not read by any part | A name in `Tunables.java` has a typo. The simulator runs the same name checks as INIT, and prints them after it writes the file, with a "did you mean" | | A part sits in a strange place | It is a guess (`TODO measure`). [Make it match your robot](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/) | | Your number on a line went away | The line had `# from Robot.java`. Delete that note to keep your number, or put the number in `Robot.java` | | No robot file is made | The simulator found no Robot class. It looks for the class that the file names, then `org.firstinspires.ftc.teamcode.Robot`, then any class in TeamCode that extends `RobotDefinition`. Name yours with `-ProbotClass=...` | ## Done when - `simulator/robot.properties` exists in your robot project, and you committed it. - INIT of your TeleOp works in the simulator. - You know which lines say `TODO measure`. --- **Next:** [Make it match your robot](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/). **Look it up:** [The robot file](https://crossbotics.com/ftc-helper/docs/reference/robot-file/): every line, with its default. --- # Make it match your robot URL: https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/ **You need:** - Your robot file, made from `Robot.java` ([Your robot file](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/)). - A tape measure, or your robot's CAD. ## 1. Why match it With guesses, the robot still drives and its parts still move. But three things depend on the real shapes: - **The size rules.** The simulator checks the 18 in start cube and the 29 in height limit, now and with every part out. A guessed lift can pass when the real one does not. - **Game pieces.** A piece goes in where it touches the intake roller, and leaves the launcher at its angle. A roller in the wrong place takes no pieces. - **Bumps.** The robot's parts hit the field. A tall lift can hit an overhead bar. Work in this order. Each step makes the next one count. | Step | What you give | Where | | --- | --- | --- | | [2. Size and wheels](#2-size-and-wheels) | the chassis box, the robot's height, the wheels | `Robot.java` | | [3. The parts](#3-shape-the-parts-with-edit-robot) | where each part sits, and how big it is | **Edit robot**, then `Robot.java` | | [4. Pieces in and out](#4-where-pieces-go-in-and-out) | the intake roller, the launcher's shot angle, the claw | **Edit robot**, then `Robot.java` | | [5. CAD (optional)](#5-cad-models-optional) | your CAD parts in place of the boxes | the robot file | | [6. Real speeds (optional)](#6-real-speeds-optional) | how your motors move | the robot file, from the Characterizer | **Or let an AI coding agent do steps 2 to 5 with you.** The **robot-file skill** is a set of written steps for an agent such as Claude Code or Codex. Give it what you have: - **Photos** of the robot from the side, the top and the front, and of each moving part at both ends of its travel. Put a field tile or a tape measure in each photo, so the agent can read sizes. - **A tape measure.** The agent asks for the few numbers that decide a rule, always from the robot's edges and the floor. - **CAD of the robot,** if you have it. Then the agent reads the exact sizes and draws your real parts. The agent writes the sizes and shapes into `Robot.java`, runs the simulator's checks, and then checks its 3D robot against your photos with you. It marks each number it estimated, so you know what to measure. Your photos stay on your computer. Set it up: [The robot-file skill](https://crossbotics.com/ftc-helper/docs/guides/robot-file-skill/). Check what it wrote the same way as your own work: open **Edit robot** and look at every pose ([step 3](#3-shape-the-parts-with-edit-robot)). ## 2. Size and wheels **How to measure:** measure from the robot's edges and the floor, never from its middle. Take the bumpers off, or measure the frame without them. Put these lines in `define()` in `Robot.java`, after the drive: ```java chassisMm(400, 400, 100); // the chassis box: length front to back, width side to side, height from the tiles heightMm(300); // the whole robot: the tallest part that does not move ``` **The wheels:** give the drive its wheel by catalog id, and where the wheels sit. The simulator then turns the robot like yours. ```java drive(Drive.tank("left_drive", "right_drive").motor("gobilda-5203-312").wheel("gobilda-hogback-96") .wheelsAtMm(380, 290) // wheel centers: side to side, then front to back .reversed("right_drive")); ``` Measure the wheel centers from wheel edge to wheel edge, then add one wheel width: that is center to center. The wheel ids are in the [parts catalog](https://crossbotics.com/ftc-helper/docs/guides/parts-catalog/). ## 3. Shape the parts with Edit robot Typing where each part sits, in mm, is hard. **Edit robot** lets you shape the robot with the mouse. Then it gives you the Java lines for `Robot.java`. The editor writes no file: `Robot.java` stays the one record of your robot. ![Edit robot: the 3D view shows the robot close up inside the see-through 18 in start cube, with a yellow arrow where the launcher's shots leave. The panel lists the shapes (hood, intake, launcher, wheels, tower); launcher is picked, with its place (forward -40, left -5, up 172 mm), its size (length 24, diameter 96 mm), its axis and tilt.](https://crossbotics.com/ftc-helper/docs/images/edit-robot.png) 1. Click **Edit robot** (over the 3D view). The simulator holds still, the field goes away, and the view turns round your robot, close. 2. See-through guides show the size rules: the **18 in start cube**, and the 18 x 24 in box with the **29 in** line. A part that sticks out turns red. The panel says how far, and which way. ![Edit robot with the tower made 520 mm tall: the tower shows red through the top of the dashed 18 in start cube, and the panel says "tower is 103 mm too tall (more than 18 in)" and gives the new robot file line to copy](https://crossbotics.com/ftc-helper/docs/images/sim-edit-robot-red.png) 3. Click a shape to pick it. The panel shows its numbers in mm: its place (`atMm`), its size (`sizeMm`, or length and diameter for a roller), and its angles. 4. Move it to where the part is on your robot: - **Drag** the shape to move it flat. **Shift + drag** moves it up and down. With **Size** on, a drag makes it bigger or smaller. - **Arrow keys** move it forward, back, left and right. **Page Up / Page Down** move it up and down. Each press moves it 1 mm, or 10 mm with Shift. - Or type the numbers. 5. **Check every pose.** Each moving part has buttons for its named positions (`stowed`, `deployed`...) and its hard stops. **Every part out** puts each part at its farthest pose. The panel says whether every pose fits. 6. **Copy into Robot.java.** The panel shows the Java for each part you changed, and where it goes. Click **Copy** (or **Copy all**) and paste it there. Then stop the simulator and start it again. **From your tape measure to the numbers:** the numbers are from the middle of the chassis, on the floor (forward, left, up). Measure each part from the edges, then work them out: - forward = (chassis length / 2) - (part from the front edge) - left = (chassis width / 2) - (part from the left edge) - up = part from the floor ![A 400 x 400 mm chassis from above. The intake roller is 30 mm from the front edge, so forward = 200 - 30 = 170. The flywheel is 250 mm from the front edge and 140 mm from the left edge, so forward = -50 and left = 60](https://crossbotics.com/ftc-helper/docs/images/sim-measure-from-edges.svg) **Try it** puts the changed shapes into the running simulator, in memory only. Click **Back to driving**, and game pieces hit the new shapes. **Undo all** goes back to the robot file's shapes. **Where the lines go in Robot.java:** - **One short shape:** inside `looks(...)` on the line that adds the part: `.looks(Shape.flywheel("gobilda-hogback-96").atMm(-40, 0, 200))`. - **Two or more shapes:** one `Shape` line each, above the line that adds the part. That line then ends with `.looks(intakeArm, roller)`. - **A part that does not move** (a tower, a ramp): `fixed(Shape.box("tower").atMm(...).sizeMm(...));`. Every shape and setting: [Shapes and parts](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#shapes-and-parts). ## 4. Where pieces go in and out The simulator takes these from your parts, so you only check that they sit right. - **The intake:** a piece comes in where it touches the intake's roller while the roller turns inward. Put the roller where it touches the pieces: across the front, low. `holds(n)` sets how many pieces the robot holds. More rollers on one intake (`looks(arm, roller1, roller2)`): a piece comes in at any of them. - **The launcher:** a shot leaves its flywheel shape at the **shot angle**: degrees up from the robot's front (90 = straight up, more than 90 = out of the back). Edit robot shows it as a yellow arrow. Put it in `Robot.java` with `.shotAngle(...)`. A ramp or hood shape does not change the angle: the arrow does. A launcher with a hood takes its angle from the hood. - **The claw:** it holds a piece in its fingers while it is closed, and drops it when it opens. After a change, run your autonomous again ([Watch an autonomous](https://crossbotics.com/ftc-helper/docs/simulator/04-watch-an-autonomous/)) and watch the pieces. ## Worked examples Each common setup has a robot that already matches. Open its file and copy what fits your robot. | Setup | Look at | It shows | | --- | --- | --- | | A season's starter bot (goBILDA, REV, AndyMark, Studica) | its robot file in `ftc-helper-lib/sim/robots/starter-bot-*.properties` | a robot file written from the seller's CAD: size, wheels, intake rollers and spinners, launcher, a fixed hood and tower. For teams with no five files ([Starter bots](https://crossbotics.com/ftc-helper/docs/guides/starter-bots/)) | | An intake on a folding arm, and a flywheel launcher | [`flywheelbot/Robot.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/flywheelbot/Robot.java) | `chassisMm`, `heightMm`, a servo that pushes the intake arm over at ▶ (`dropsWhen`), a roller on the arm, a flywheel and its `shotAngle` | | A lift with a wrist and a claw | [`v2bot/Robot.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/main/java/com/crossbotics/ftchelper/examples/v2bot/Robot.java) | a slide in a back corner, the wrist riding on the lift (`on(lift)`), the claw on the wrist | | A drive only (odometry, Pedro, the quick start) | `chassisMm` and `heightMm`, and the drive's `wheel(...)` and `wheelsAtMm(...)` | [step 2](#2-size-and-wheels) is all it needs | ## 5. CAD models (optional) A team with CAD (Onshape, Fusion, SolidWorks) can draw its real parts in place of the boxes. The size rules then use the CAD's shape too. The physics and the game pieces still use the boxes, so do steps 2 to 4 first. 1. **Put the CAD robot in its start pose:** each lift and arm where the simulator shows it when it opens, and each servo part at its start position. 2. **Make the robot's center on the floor easy to find.** In the assembly, place the drive frame so the CAD origin is the middle of the drive frame, at the bottom of the wheels. Then write `cad.origin = 0,0,0`. Otherwise, measure that point from the origin and write it in CAD units. 3. **Export each group of parts that move together as one STL file,** in the assembly's positions. The chassis and everything fixed to it is one group. The lift's moving stage and what rides on it is another. - **Onshape:** work in the **Assembly** tab, not a Part Studio. Select every part of the group, then right-click > Export. Choose STL, and untick "Export unique parts as individual files". - **Fusion:** hide every part that is not in the group. Right-click the top component > Save As Mesh, STL, one file. 4. **Name the files in the robot file.** Put them in a `cad` folder next to it: ```properties cad.units = mm # the unit in the export window: mm, cm, m or in cad.axes = y,-x,z # the CAD axes that point the robot's forward, left and up cad.origin = 0,0,0 # the robot's center on the floor, in CAD units robot.model = cad/chassis.stl # drawn in place of the chassis box shape.lift = slide, ..., model=cad/lift-stage.stl, baseModel=cad/lift-base.stl ``` `cad.axes`: Onshape and SolidWorks have up = z (front along +y: `y,-x,z`). Fusion usually has up = y (front along +x: `x,-z,y`). 5. **Check it:** run a scenario with `print cad` ([Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/)). It lists each model next to the box it covers. "FAR from its box" means `cad.origin`, `cad.axes` or the shape's place is wrong. "25 times smaller" means `cad.units` is wrong. Every CAD setting: [The robot file: CAD](https://crossbotics.com/ftc-helper/docs/reference/robot-file/#cad-models). CAD from a seller belongs to the seller: keep it in your team's own repository, not a public one, unless the seller allows it. ## 6. Real speeds (optional) The simulator moves each motor from the catalog's numbers. To make it move like YOUR robot, measure it: 1. Run the **Characterizer** on the real robot ([Characterizer](https://crossbotics.com/ftc-helper/docs/tuning/15-characterizer/)). 2. Copy its logs from the Control Hub (`/sdcard/FIRST/ftc-helper/characterizer/*.csv`) into a folder on the laptop. 3. Fit them: **Where:** Android Studio's **Terminal** tab, in the **`ftc-helper-lib` folder** (type `cd ftc-helper-lib` first). ```bash ./gradlew :sim:fit -Plog=../characterizer-logs -Pwrite ``` It writes the numbers into your robot file, and keeps the old file as `robot.properties.bak`. It leaves out a poor fit, and says so. Check the file and commit it. ## Problems | What you see | Why, and the fix | | --- | --- | | A part is red in Edit robot | It sticks out of the size box. Move it, or make it smaller. On the real robot, it would fail inspection too | | "Nothing may go below the tiles" | A shape or a hard stop reaches under the floor. The shape's place or the part's range is wrong | | The intake takes no pieces | The roller does not reach the pieces. Move it lower and farther forward, and check that it turns inward | | Shots go the wrong way | The shot angle. 90 is straight up. A launcher that shoots over the back needs more than 90 | | The pasted Java does not build | A line went in the wrong place. One shape goes inside `looks(...)`; named shapes go above the part's line | | Your shapes went away after a restart | You did not paste them into `Robot.java`. **Try it** is in memory only | | The CAD robot is mirrored or on its side | `cad.axes` is wrong. The simulator refuses a choice that draws the robot mirrored | ## Done when - No line in your robot file says `TODO measure`. - Edit robot shows every pose inside the size box. - Your intake takes pieces, and your launcher's shots go toward the goal. --- **Next:** [Watch an autonomous](https://crossbotics.com/ftc-helper/docs/simulator/04-watch-an-autonomous/). **Look it up:** [Shapes and parts](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#shapes-and-parts) in Robot.java. [The robot-file skill](https://crossbotics.com/ftc-helper/docs/guides/robot-file-skill/): an AI agent that does this with you. [The robot file](https://crossbotics.com/ftc-helper/docs/reference/robot-file/): every line. --- # Watch an autonomous URL: https://crossbotics.com/ftc-helper/docs/simulator/04-watch-an-autonomous/ **You need:** - An autonomous in your code ([The autos](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/)). - The simulator running your code ([Start it and drive](https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/)). - Your robot's size and parts in the robot file. Guesses work for a first look ([Make it match your robot](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/)). ## 1. Why watch it in the simulator A practice field is busy, and a bad route can hit a wall at full speed. In the simulator, you see the whole route, the score and the report in 30 seconds, and nothing breaks. Fix what you see, then try it on the real field. The simulator is not the real robot. Its speeds and shots are a model. A route that works here is a route worth trying, not a route that is done. ## 2. Run it 1. Pick your autonomous with the **Auto** button on the Driver Hub. 2. Press **INIT**. The simulator starts a new match: every game piece goes back to its start, the preload goes into the robot, and the robot goes to its start spot. 3. Choose the alliance in the INIT menu (X for BLUE, B for RED, as the screen says). 4. Press **▶**. The autonomous runs, and stops after 30 s. ![The Driver Hub in INIT of goBILDA's starter bot autonomous: the place-the-robot note, the INIT menu with Alliance RED, start delay and profile, and "X = BLUE B = RED"](https://crossbotics.com/ftc-helper/docs/images/sim-auto-init.png) **Where the robot starts:** - An autonomous that gives its start in inches (`s.start(note, x, y, heading)`) puts the robot there, for the alliance you chose. - An autonomous that gives its start only in words (`s.start(note, heading)`) puts the robot on your alliance's side. The Driver Hub asks you to drag the robot to the exact spot. At ▶, the simulator remembers that spot for this autonomous, so the next INIT puts the robot there. **Then TeleOp:** pick your TeleOp and press INIT. The robot stays where the autonomous left it, and the score goes on, like a match. ## 3. Watch the route - **The green line** is where the robot actually went, in its last 30 seconds of driving. - **The orange dashed line** is the path that a Pedro `follow` step plans. It stays, faded, after the step ends, so you can compare the plan with the green line. - The robot turns **red** when it bumps into something. The Control Hub's Robot panel names what it hit. **Clear lines** (Robot panel) clears both lines. The **Layers** button over the 3D view adds more: | Layer | What it shows | | --- | --- | | Path lines | the Pedro plan and the green trail | | Shot arc | where the launcher would send its next piece now, with its peak height | | Ball trails | the last half second of each loose ball's path | | Camera sight lines | which tags the camera sees now, and why it does not see the others | | Robot size box | everything the robot has out now: green while it fits, red when not | ![The Layers menu open over the 3D field, with a box for each layer and the color key for the camera sight lines](https://crossbotics.com/ftc-helper/docs/images/sim-layers-menu.png) Every layer: [How the simulator works: Layers](https://crossbotics.com/ftc-helper/docs/guides/how-the-simulator-works/#layers). ## 4. Watch the score The **score bar** over the 3D view shows RED and BLUE, the period (AUTO, TELEOP, FINAL) and the time left. Click it to open the **Match** panel. - **The score counts like a referee.** Points that change all match long (pieces in goals, parking) show gray, as "+N", until the end. The gray number shows what those points would add if the match ended now. - **Click a side** to see where its points come from, grouped like FIRST's score calculator. - **Shots** lists each shot's verdict: clean, rim, other HIVE, frame or miss. - **Fouls** lists each foul that the simulator can see. ![The Match panel after goBILDA's starter bot autonomous: RED 3 (+10), AUTO done, BLUE 0 (+10); the four FLOWERs with their pieces; Shots: 4 of 4 shots were a miss; no fouls](https://crossbotics.com/ftc-helper/docs/images/sim-match-panel.png) In this run, all 4 shots missed: the starter bot's numbers are not tuned. That is what the panel is for. The simulator is not a referee. It counts what it can see, and it plays without the other three robots. What it counts: [Game rules and the score](https://crossbotics.com/ftc-helper/docs/guides/how-the-simulator-works/#game-rules-and-the-score). ## 5. Read the report When the autonomous ends, the Driver Hub shows `Autonomous finished` and one line per step: ```text Start: done To the goal: done Score high: timed out Park: done ``` ![The Driver Hub after the autonomous: Autonomous finished, then Start: done, Fire all: done (4 fired), Away from the wall: done](https://crossbotics.com/ftc-helper/docs/images/sim-auto-report.png) Write down each step that does not say `done`, and fix it: | The report says | Look in the simulator | The fix | | --- | --- | --- | | `STALLED` | where the robot turned red | the route hits a field part. Move the route away from it | | `timed out` on an action | the part on the robot: did it get there? | the part is slow, or its numbers are off. Check the part's Tunables | | `cut short (time for park)` | the clock | the autonomous is too long. Remove a step, or drive faster | | `not seen` | the Camera sight lines layer | the camera does not see the goal from there. Aim from another spot | | `done`, but the robot ends in the wrong place | the green line against your plan | the numbers in the steps. On the real robot: tune the drive first | Every word in the report: [Match day: read the report](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#after-the-match-read-the-report). ## 6. Change it, run it again 1. Change the steps in your autonomous. 2. Stop the simulator and start it again. **Why:** it builds your code only when it starts. 3. Run the autonomous again, and compare. **Faster for routes:** the [auto builder](https://crossbotics.com/ftc-helper/docs/building-autos/06-auto-builder-steps/) runs a plan with your real code with one click, and shows each step's result next to the plan. Copy its Java into your code when the route is right. **Keep it working:** when the autonomous does what you want, record a test of it ([Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/)). The test then checks it after every change. ## Problems | What you see | Why, and the fix | | --- | --- | | The robot does not move at ▶ | The INIT screen has an error, or the INIT menu still waits for a choice. Read the Driver Hub | | The robot starts in the wrong place | The autonomous gives its start in words only. Drag the robot to the spot in INIT, or give the start in inches | | The robot drives a mirror route on RED | Autos are written for BLUE, and the library changes them for RED. Check `mirrorForRed()` ([Red and blue](https://crossbotics.com/ftc-helper/docs/building-autos/02-put-steps-together/#red-and-blue)) | | The score stays at 0 | The field has no rules file, or the pieces did not reach a goal. Watch the Shot arc layer | | A shot falls short in the simulator but not on the robot | The simulator's shots are a model. Make a shot table ([How shots fly](https://crossbotics.com/ftc-helper/docs/guides/how-the-simulator-works/#how-shots-fly-and-shot-tables)), or trust the real robot | | The route is right here, but wrong on the real robot | The real robot's numbers differ. Tune it ([Tuning](https://crossbotics.com/ftc-helper/docs/tuning/)), and measure its speeds for the simulator ([Real speeds](https://crossbotics.com/ftc-helper/docs/simulator/03-make-it-match-your-robot/#6-real-speeds-optional)) | ## Done when - Each of your autonomous programs runs in the simulator, and every step says `done`. - You know what each one scores. - Each one has a test ([Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/)). --- **Next:** [Tuning](https://crossbotics.com/ftc-helper/docs/tuning/). **Look it up:** [Steps](https://crossbotics.com/ftc-helper/docs/reference/steps/): every step an autonomous can use. **Go deeper:** [How the simulator works](https://crossbotics.com/ftc-helper/docs/guides/how-the-simulator-works/). --- # Record a test URL: https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/ **You need:** - A robot that drives and has an autonomous ([The autos](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/)). - Your robot project with the simulator running your code: the **Simulator** button in Android Studio, or `./gradlew :sim:run` ([the simulator guide](https://crossbotics.com/ftc-helper/docs/simulator/01-start-and-drive/)). - No project yet? Try it first with goBILDA's starter bot ([Run all your tests: try it](https://crossbotics.com/ftc-helper/docs/tests/02-run-all-your-tests/#try-it-with-gobildas-starter-bot)). ## 1. Why tests? You change one number for the lift, and the autonomous stops scoring. You find out at the next event. A **test** finds it on your laptop, before the robot does. It does what a driver does (INIT, ▶ on the Driver Hub, sticks, buttons), then checks the result ("the autonomous finished", "4 pieces were shot"). A test does not prove that the robot is good. It proves that **what worked yesterday still works today**. It finds the break you did not mean to make: a typo, a wrong button, a number changed in the wrong section. ![Record once, choose checks, save, then run after each change. PASSED: go on. FAILED: if you changed it on purpose, update the test; if not, fix the code](https://crossbotics.com/ftc-helper/docs/images/tests-cycle.svg) ## 2. Record a test 1. Start the simulator with your code and open http://localhost:8780. 2. Open **Tests** (in the row of buttons above the 3D field, next to **View** and **Layers**) and choose **Record a test**. A red bar says `Recording`. The field starts fresh: the robot on its start spot, every game piece back, your numbers as in `Tunables.java`. **Why fresh:** the test always starts this way, so you must record it this way too. ![The Tests menu, open: Record a test, Record from now, Open a test, Run all tests](https://crossbotics.com/ftc-helper/docs/images/tests-menu.png) 3. Choose your OpMode and press **INIT**. In the INIT menu, choose the alliance (gamepad 1 **B** for RED, **X** for BLUE). On the keyboard (set gamepad 1's list to "Keyboard"), B is the **L** key and X is the **J** key. Or click B or X on the on-screen gamepad 1. ![Recording: the red bar with Recording 0:25, Stop recording and Cancel. The Driver Hub is in INIT with the alliance menu (X = BLUE, B = RED)](https://crossbotics.com/ftc-helper/docs/images/tests-recording.png) 4. Press **▶** and do the job, as in a match: drive to a piece, pick it up, shoot. For an autonomous, do nothing, and let it run to its end. 5. Press **Stop recording** in the red bar. A window opens: **Your test: choose the checks**. ![Your test: choose the checks. Goal checks are ticked (the autonomous finishes, steps done, pieces shot, points, no error, not pushing a wall). Details are not ticked (the end spot, the heading, screen lines). Then the name and Save (here Download, with no robot project) and Run it now](https://crossbotics.com/ftc-helper/docs/images/tests-choose-checks.png) 6. Leave the ticked checks ticked ([section 5](#5-check-goals-not-details) says why). Type a name, for example `main-teleop`, and press **Save**. The test is now `simulator/scenarios/main-teleop.sim` in your robot project. To find it in Android Studio's Project panel, open the top folder (the one that holds `TeamCode`), then `simulator`, then `scenarios`. Commit it with your code ([Every practice: pull, change, commit, push](https://crossbotics.com/ftc-helper/docs/setup/08-every-practice/)). 7. Press **Run it now**. The simulator plays your test back from a fresh field and shows **PASSED**, or **FAILED** with the line that failed. Keep your hands off, because the test drives. ![PASSED, with the report line by line: each step and each check says ok](https://crossbotics.com/ftc-helper/docs/images/tests-passed.png) The recorder writes down every gamepad button and stick (from the keyboard, a real controller or the on-screen gamepad). It also writes down how long you waited, INIT, ▶, STOP, and the robot or a piece moved by hand. - A quick tap becomes a `press`. - A button held down becomes `hold` and `release`. - A stick becomes `hold g1.left_stick_y -0.5`, in steps of 0.25. **Why:** nobody holds a stick at exactly 0.53 twice. **Record from now** (in the same menu) starts from where the robot is, without a fresh field. Use it for a quick try. A test that starts from INIT is more reliable. ## 3. Read the test, line by line A test is a short text file that you can read and change. The recorder made this test for goBILDA's starter bot's autonomous ([`sim/scenarios/recorded-gobilda-auto.sim`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/sim/scenarios/recorded-gobilda-auto.sim)): ```text # recorded-gobilda-auto.sim: made by the simulator's test recorder on 2026-10-22, from "goBILDA Bot Launch and Back Up". init "goBILDA Bot Launch and Back Up" wait 1 press g1.b wait 0.92 start # The checks expect within 6 phase STOPPED expect within 3 launched >= 4 expect within 3 points "red" >= 13 expect step 1 done expect step 2 done expect error none expect bumped none ``` | Line | What it does | | --- | --- | | `# ...` | a note for people; the test skips it | | `init "goBILDA Bot Launch and Back Up"` | INIT this OpMode (the name exactly as on the Driver Station) | | `wait 1` | wait 1 second (the recorder cuts waits before ▶ to 1 s, because they change nothing) | | `press g1.b` | press and let go of gamepad 1's B: RED in the INIT menu | | `start` | press ▶ | | `expect within 6 phase STOPPED` | **a check:** within 6 s, the OpMode stops by itself (the autonomous ends). The **phase** is where the OpMode is: `IDLE` before INIT, then `INIT`, `RUNNING` (after ▶) or `STOPPED` | | `expect within 3 launched >= 4` | within 3 s, at least 4 pieces were shot | | `expect within 3 points "red" >= 13` | RED has at least 13 points | | `expect step 1 done` | the first step of the autonomous's report says `done` ([the report](https://crossbotics.com/ftc-helper/docs/five-files/05-autos/#what-you-get-with-no-extra-code)) | | `expect error none` | no error on the Driver Station | | `expect bumped none` | the robot does not push against a wall or a field element at the end | Every `expect` line is a check. The test **passes** when every check passes. The report shows each line as `ok` or `FAIL`, with the value it saw: `FAIL 13 expect within 3 launched >= 4 -> was 2`. ## 4. How close is close enough? Tolerances A robot never stops at exactly the same spot twice, not even in the simulator. So a check says how close is close enough: | Check | What it checks | Use it for | | --- | --- | --- | | `expect robot y = -36 3` | y is -36, give or take 3 inches (from -39 to -33) | where the robot ends | | `expect robot heading = 90 5` | 90 degrees, give or take 5 | which way it faces | | `expect launched >= 4` | 4 or more | counts: pieces, points | | `expect time < 25` | less than 25 s since ▶ | "fast enough" | | `expect within 4 stored >= 1` | wait up to 4 s for it to become true | anything that takes time | The number after `=` is the value. The next number is the **tolerance**: how far off it may be. Without a tolerance, `=` means exactly, and that almost never works for a measured number. ![A number line for expect robot y = -36 3: from -39 to -33 is close enough. A robot that ends at -34.5 passes; one that ends at -40.5 fails](https://crossbotics.com/ftc-helper/docs/images/tests-tolerance.svg) The recorder picks loose numbers: 3 inches, 5 degrees, `>=` for counts, and `within` 1.5 times the time it took. - **A test that is too strict** fails for no reason, and soon nobody trusts it. - **A test that is too loose** never fails, even when the robot is broken. If a test fails now and then for no reason, make the tolerance a little bigger: in the window before you save, or in the file. ## 5. Check goals, not details The window shows two lists: - **Goal checks** (ticked): what the test is for. The autonomous finishes, its steps are done, the pieces are shot or scored, and there is no error. For a driving test with no pieces: where the robot ends. - **Details** (not ticked): the exact spot after an autonomous, the time, lines on the Driver Station screen. Tick one only if it is what you want to test. **Why:** a detail changes every time you improve something. A test that checks "the screen says `Launcher : 2600 rpm`" fails when you tune the speed, but nothing is broken. A test that checks "4 pieces were shot" fails only when the shooting is broken. Fewer, better checks make a test you trust. ## 6. A few good tests You do not need many tests. Start with these: - **One test per autonomous.** Its goal: it finishes, every step is `done`, and it scores. - **TeleOp basics:** drive forward and turn (the robot ends near the spot). Add one test for each job the drivers use most (pick up a piece: `stored >= 1`; shoot: `launched >= 1`). That is 3 to 5 tests. When a bug surprises you, add a test for it. Then it cannot come back without a warning. ## 7. After a planned change: update the test Say you made the robot faster on purpose. Now the TeleOp test fails, because the robot ends 12 inches further than the test says. The robot is right, and the test is out of date. 1. Choose **Tests > Open a test**, choose the test, and press **Run it now**. It shows FAILED. 2. Read the failed lines, and decide whether you meant to change this. - **Not on purpose:** the test caught a break. Fix the code, not the test. - **On purpose:** press **The change was on purpose: update the test**. ![FAILED: 1 check. The red line: expect within 3 points "red" >= 30, was 13.00. Below: The change was on purpose: update the test, and Run it again](https://crossbotics.com/ftc-helper/docs/images/tests-failed.png) 3. The simulator runs the test once more and measures. It shows each failed check with its old and its new number. Only the failed checks change. The steps, the tolerances and the other checks stay. 4. Press **Save the update**, then **Run it again**. It shows PASSED. A check of words (`phase`, `step`, `screen`) cannot take a new number. The window lists it, and you change it or delete it by hand. The file gets a note with the date and the lines that changed. The old numbers are in git. ## 8. Write or change a line by hand (optional) A test is plain text, so you can add a line the recorder did not write. Open the file in Android Studio (`simulator/scenarios/`) and type it. For example, check that the claw is closed: ```text expect servo claw target = 0.75 0.01 ``` **A number you have not measured yet.** A `MEASURE` in `Tunables.java` stops INIT on the robot, but not in the simulator. When the simulator starts, it puts a stand-in for it in the robot file (`tunable.IntakeDeploy.deployed = 0.5`), and the simulator uses that ([MEASURE in the simulator](https://crossbotics.com/ftc-helper/docs/simulator/02-your-robot-file/#5-measure-numbers-and-missing-parts)). So most tests need nothing for it. For another number, put this line before `init`. The test then uses 0.6, for this file only, and your code does not change: ```text set tunable IntakeDeploy.deployed 0.6 ``` **Button names in a test are the FTC names, not the Java names:** `g2.dpadLeft` in `Controls.java` is `g2.dpad_left` in a test. ## Fix a problem | What you see | Why, and the fix | | --- | --- | | The test fails on the first run after recording | Something in the run was not the same: a check is too strict ([section 4](#4-how-close-is-close-enough-tolerances)), or the robot still moved when you stopped recording. Loosen the tolerance, or record again and wait a moment before **Stop recording** | | `FAIL ... robot y = ... 3 -> was ...`, a little more than 3 off | A fast robot ends a few inches off from run to run. Make the tolerance 5 | | It fails now and then, then passes | The same cause: the check is too strict. A test you cannot trust is worse than no test | | `true only after 5.3 s` | It happens, but later than `within` allows. If the robot is slower on purpose, update the test ([section 7](#7-after-a-planned-change-update-the-test)) | | `waited 3 s: the OpMode shows nothing in INIT` | The OpMode sends no telemetry in INIT, so the test cannot count its loops. It still runs | | `unknown command`, or a check says `too short` | A line typed by hand has a mistake. The report names it. See [Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/) | | The page says `a test is running` | A test drives the robot. Wait for it, or press **Stop the test** in the blue bar | | Save says `no robot project` | The simulator was started with `-PteamCode=none`. Press **Download**, and put the file in your robot project's `simulator/scenarios` folder | | The auto builder's Run is not in the test | A test runs your own OpModes. Copy the builder's plan into your code (its Code tab), then record that autonomous | ## Done when - Each autonomous has a test, and it passes. - One TeleOp test drives and does the drivers' main job, and it passes. - The tests are in `simulator/scenarios`, committed with your code. --- **Next:** [Run all your tests](https://crossbotics.com/ftc-helper/docs/tests/02-run-all-your-tests/). **Look it up:** [Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/): every command and check. [Record a test](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/#the-recorder): the recorder. --- # Run all your tests URL: https://crossbotics.com/ftc-helper/docs/tests/02-run-all-your-tests/ **You need:** - At least one test in your robot project's `simulator/scenarios` folder ([Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/)). - Or no project yet: [try it with goBILDA's starter bot](#try-it-with-gobildas-starter-bot). ## 1. Run them all Each of these three ways runs every test in your `simulator/scenarios` folder: - **On the simulator page:** **Tests > Run all tests**. The page shows passed or failed for each test, with the failed lines. Click a test's name to open it. ![The Tests menu, open, with Run all tests at the bottom](https://crossbotics.com/ftc-helper/docs/images/tests-menu.png) - **In Android Studio:** pick **Simulator tests** in the list next to the green Run button, and click Run. If the list has no such button, close the project and open it again ([the simulator buttons](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/#the-simulator-buttons-you-do-nothing)). - **In the Terminal:** **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:scenario ``` Each test starts from a fresh robot, so nothing carries over from one test to the next. The button and the command end with a list (paths shortened here): ```text == 3 of 3 passed PASSED ../simulator/scenarios/launch-and-back-up.sim PASSED ../simulator/scenarios/main-teleop.sim PASSED ../simulator/scenarios/pick-up.sim ``` - **The button and the command build your code first,** and make the robot file from `Robot.java`. - **The page runs the code that the simulator started with.** So after a code change, stop the simulator and start it again before you press **Run all tests**. ## 2. Run one test **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:scenario -Pfile=../simulator/scenarios/main-teleop.sim ``` For several files, put commas between them: `-Pfile=a.sim,b.sim`. A folder runs every `.sim` file in it. ## 3. When to run them - **Before you commit:** a failed test means the change broke something. - **Before every event:** run them all on the code you will take. - **After you change a number in `Tunables.java`:** a test that fails tells you which job the number changed. The simulator's own automatic tests (`./gradlew :sim:testDebugUnitTest`) also run every file in your `simulator/scenarios` folder. ## 4. For programmers: laptop tests in Java (optional) A simulator test drives the whole robot, in real time. A **JUnit test** checks one piece of your code in a fraction of a second, with pretend motors and servos. For example: "after `Actions.scoreHigh`, the lift was sent to 2400 counts". **Where:** the Terminal, in your robot project's folder (the one that holds `TeamCode`). ```bash ./gradlew :TeamCode:testDebugUnitTest ``` - **It can check:** INIT's checks (a misspelled Tunables field, a missing safety number, a device used twice), which power or position each command sends, limits, interlock rules, pause and STOP, and your own `Actions.java` steps that do not wait. - **It cannot check:** how the real robot moves (gravity, a heavy lift, a slipping belt), anything that waits for time to pass (an action's `waitSeconds`), or cameras. Use a simulator test for those, and the [checks on the real robot](https://crossbotics.com/ftc-helper/docs/tests/03-checks-before-practice-and-matches/). JUnit tests need a little Java. How to set up TeamCode once, and a first test of your robot in five files: [Tutorial 13: Testing](https://crossbotics.com/ftc-helper/docs/tutorials/13-testing/#7-test-your-robot-in-five-files). The pretend devices: [the test kit](https://crossbotics.com/ftc-helper/docs/modules/testkit/). A complete example: [`V2botTest.java`](https://github.com/crossbotics/ftc-helper-lib/blob/v0.47.0/examples/src/test/java/com/crossbotics/ftchelper/examples/v2bot/V2botTest.java). ## Try it with goBILDA's starter bot With no robot project yet, try the recorder and the runner with goBILDA's starter bot. **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:run -PteamCode=none -Probot=sim/robots/starter-bot-gobilda.properties ``` 1. Open http://localhost:8780. Choose **Tests > Record a test**. 2. Choose "goBILDA Bot Launch and Back Up", press INIT, press gamepad 1 **B** (RED; the **L** key on the keyboard), then ▶. Wait until the Driver Station says `Autonomous finished`. 3. Press **Stop recording**. Look at the goal checks: it finishes, steps 1 and 2 are done, and 4 pieces are shot. 4. With `-PteamCode=none` there is no robot project, so **Download** saves the file in your browser's downloads. Press **Run it now**, and it shows PASSED. 5. Run the same test without the page. This runs the library's own copy of the test (in `sim/scenarios`), not the file you downloaded. **Where:** the Terminal, in the `ftc-helper-lib` folder. ```bash ./gradlew :sim:scenario -PteamCode=none -Pfile=sim/scenarios/recorded-gobilda-auto.sim ``` 6. Record a TeleOp test the same way: "goBILDA Bot TeleOp", B, ▶. Hold the left stick forward for a second, let go, and press **Stop recording**. The goal is where the robot ends. ## Fix a problem | What you see | Why, and the fix | | --- | --- | | A test passes on the page but fails with the button or the command | The page runs the code the simulator started with. Stop the simulator, start it again, and run the test on the page again | | `No scenario file. Use: ./gradlew :sim:scenario -Pfile=...` | The command found no `simulator/scenarios` folder. Check that it is in the folder that holds `TeamCode`, and that it has a test | | `PROBLEM: no such file: ...` | A wrong `-Pfile` path. Paths start from the `ftc-helper-lib` folder: `../simulator/scenarios/...` | | **Simulator tests** is not in the Run list | Close the project and open it again ([the simulator buttons](https://crossbotics.com/ftc-helper/docs/setup/04-add-the-library/#the-simulator-buttons-you-do-nothing)) | | A test failed, and you did not change that part | Read the failed line: it names the check and the value it saw. Fix the code, or update the test if the change was on purpose ([Record a test, section 7](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/#7-after-a-planned-change-update-the-test)) | | More problems with one test | [Record a test: fix a problem](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/#fix-a-problem) | ## Done when - One button or one command runs all your tests, and they pass. - You run them before each commit, and before each event. --- **Next:** [Checks before practice and matches](https://crossbotics.com/ftc-helper/docs/tests/03-checks-before-practice-and-matches/). **Look it up:** [Scenario files](https://crossbotics.com/ftc-helper/docs/reference/scenario-files/): every command, check and flag. **Go deeper:** [Tutorial 13: Testing](https://crossbotics.com/ftc-helper/docs/tutorials/13-testing/): JUnit tests on the laptop. --- # Checks before practice and matches URL: https://crossbotics.com/ftc-helper/docs/tests/03-checks-before-practice-and-matches/ **You need:** - A robot that runs your code, and the **Tune and check** OpMode on it (its Hardware Check: [Wiring checks](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/)). - A block to put the robot on, so the wheels are off the floor. - The whole team: programmers, builders and drivers. ## 1. A fixed order
flowchart LR
    A["Laptop tests"] --> B["Hardware Check<br/>robot on a block"]
    B --> C["Mechanism checks"]
    C --> D["Floor check<br/>low power"]
    D --> E["Autonomous runs<br/>read the report"]
    E --> F["Event: before every match"]
Do the steps in this order. Each step finds problems that would be dangerous or confusing in the next step. For example, the Hardware Check finds a reversed drive motor at once. On the floor, the same motor looks like "the robot spins for no reason". | Step | When | | --- | --- | | 2. Laptop tests | after every code change | | 3. Hardware Check | after any change to the wiring or the robot configuration | | 4. Mechanism checks | after you build or change a mechanism | | 5. Floor check | before practice runs | | 6. Autonomous check | after a change to an autonomous | | 7. Before every match | at an event | ## 2. Laptop tests (every code change) Run all your simulator tests, and your JUnit tests if you have them ([Run all your tests](https://crossbotics.com/ftc-helper/docs/tests/02-run-all-your-tests/)). They need no robot. **Without tests:** run the OpMode in the [simulator](https://crossbotics.com/ftc-helper/docs/simulator/) first. It shows many problems before you touch the robot: a crash at INIT, a wrong button, a screen that does not fit. The simulator builds its robot from your code, so it cannot find a wrong wire or a motor that turns the wrong way. Only the real robot can. ## 3. Hardware Check (after a wiring or configuration change) Run the **Hardware Check** in Tune and check, with the robot on a block ([how to get there](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#get-to-the-checks)). It lists every device in the active configuration and the battery voltage. Check each device: | Device | Check | If wrong | | --- | --- | --- | | every motor | moves with positive power the way you expect, and its encoder counts UP | `.reversed()` on its part in `Robot.java`; check the encoder cable port | | drive motors | each wheel rolls FORWARD with positive power ([Motor Direction Check](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#motor-direction-check-each-wheel-rolls-forward)) | `Drive.mecanum(...).reversed("front_left", ...)` in `Robot.java` | | every motor with an encoder | its own port counts, up ([Encoder Check](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#encoder-check-each-encoder-cable-in-its-own-port)) | the encoder cable in its own motor's port, plugged in | | a lift or arm on two motors | with the chain or belt OFF, both turn the way that lifts | `alsoMotor` / `alsoMotorReversed` ([two motors](https://crossbotics.com/ftc-helper/docs/reference/parts/lift/#two-motors-on-one-lift-or-arm)) | | servos | find and write down each position you need ([Servo Finder](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/)) | the named positions in `Tunables.java` | | CR servos | spin both ways | the configuration must say "Continuous Rotation Servo" | | touch and magnetic switches | change when pressed, or with a magnet near | wiring; magnetic: false = near | | IMU | yaw (the heading) goes UP when the robot turns LEFT | the logo and USB directions in the drive's `.imu(...)` in `Robot.java` | | distance and color sensors | sensible numbers | wiring, I2C port, configuration type | | camera | listed; Limelight "connected"; HuskyLens `Answers: yes` and a `Sees` line per box | USB, Ethernet or I2C cable, configuration name; a HuskyLens's Protocol Type | | battery | 12.5 V or more when charged | charge or replace it. Never play a match under 12.0 V | | `Robot.java`'s devices | `Robot.java: every device is in the configuration`, or only the parts you know are not built yet (`optional, so the part is off`) | add the device to the configuration, or fix its name ([parts not on the robot yet](https://crossbotics.com/ftc-helper/docs/reference/robot-java/#parts-not-on-the-robot-yet)) | **On a lift or an arm:** the Hardware Check has no limits, and RB gives full power. Use short, gentle taps. Know where its hard stop is, and keep hands clear. ## 4. Mechanism checks (after you build or change a mechanism) | Mechanism | Procedure | Pass | | --- | --- | --- | | Lift or arm | the steps under this table | stops before the hard stops; reaches each position in about 1 s; holds | | Intake | in, out, stop; block it by hand (with jam detection) | backs out and goes on; the jam count goes up | | Servo parts | each named position; toggle; slow move | no buzzing at the ends (a buzz means the range is too wide) | | Flywheel | spin to 3 speeds; compare the RPM on the screen with a tachometer or a slow-motion video | the numbers agree within about 3%; READY within about 1 s | | Launcher | shoot 1, then 3 | each piece only when READY; `whyNotReady` names what is missing | | Turret | home; aim at 0, 90, -90, 180 and back; turn it by hand to each limit | the short way around; never past a limit; cables slack | | Camera | point it at a tag; read the bearing (positive = left), and the distance against a tape measure | the bearing sign is right; the distance is within about 5% | **Lift or arm steps:** 1. Put the hard stops in place. 2. Set a low `maxPower` in `Tunables.java`. 3. Home it (push it down to the switch). 4. Drive it by hand to each end. It slows and stops before the hard stop. 5. Try each named position. 6. Pause (gamepad 1 BACK) while it moves. It stops (both motors, if it has two). ## 5. Floor check (before practice runs) 1. Set the PRACTICE profile, and a low `Tunables.Drive.maxPower` (for example 0.4) for the first runs. 2. Drive: forward, sideways, turn, field-centric. 3. Every button on the drivers' sheet does what it says. 4. The match timer buzzes 20 s before the end of TeleOp. Run a whole TeleOp once to hear it (the simulator works too). ## 6. Autonomous check (after a change to an autonomous) 1. Run it at low speed, and read the step report. 2. Run it as RED once. 3. Run it with a start delay once. 4. Run it at full speed: it ends in less than 28 s, and parks. 5. Put a box in the way: the move ends `STALLED`, and the robot stops pushing. More: [Match day: before the event](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#before-the-event). ## 7. Before every match (print it) The drive team's auto checklist (the partner talk, the auto, the alliance, the profile, where to place the robot) is on [Match day: before each match](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/#before-each-match). Add these checks on the robot: - [ ] Battery 12.5 V or more (the Hardware Check shows it), and a spare on the cart - [ ] The robot starts inside its size limit, with everything folded and the hard stops tight - [ ] The lift and the turret are at their start positions (the home switches in reach) - [ ] No `!! COMPETITION: ... is OFF (optional part)` warning at INIT for a part that IS on the robot (a renamed or unplugged device) - [ ] No "tuned values differ" warning at INIT - [ ] After the autonomous, TeleOp's INIT screen says "Forward: from autonomous" - [ ] Gamepads: 1 = driver (Start+A), 2 = operator (Start+B) ## 8. When something breaks ![Five steps: write it down, repeat it on the bench, find where it lives, fix it (in code: add a test), note it in the team log. The new test warns you if the problem comes back](https://crossbotics.com/ftc-helper/docs/images/tests-when-it-breaks.svg) 1. **Write it down:** what you did, what you expected, what happened. Turn the debug lines on and take a photo of the screen. 2. **Make it happen again** on the bench, before you change code. You can fix a problem for sure only when you can repeat it. 3. **Find where it lives:** the hardware (the Hardware Check shows it), the configuration (names), your code, or the library. 4. **Fix it.** When the problem was in the code, also **add a test** ([Record a test](https://crossbotics.com/ftc-helper/docs/tests/01-record-a-test/)). Then it cannot come back without a warning. When it is a library bug, tell us ([Contributing](https://crossbotics.com/ftc-helper/docs/contributing/)). 5. **Note it** in the team's log. The next driver or programmer will meet it again. ## Fix a problem | Problem | Why, and the fix | | --- | --- | | The robot spins on the floor when it should drive straight | A drive motor is reversed. Go back to the Hardware Check (step 3) | | A motor turns, but its encoder stays at 0 | The encoder cable is not plugged in, or is in another motor's port ([Encoder Check](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/#encoder-check-each-encoder-cable-in-its-own-port)) | | A servo buzzes at one end | The position is past what the servo can reach. Find the end again with the [Servo Finder](https://crossbotics.com/ftc-helper/docs/tuning/03-servo-finder/) | | INIT says a part is OFF, but the part is on the robot | Its device name in the configuration is wrong, or the cable is out | | The battery drops under 12 V in a run | Charge it or replace it. Low voltage changes how far and how fast parts move | | A problem shows on the robot, but not in the simulator | The simulator cannot see wiring. Use the Hardware Check | ## Done when - The Hardware Check passes for every device. - Each mechanism passes its check. - The team has a printed copy of the before-every-match list, and of the Match day checklist. --- **Next:** the road ends here. Before an event, read [Match day](https://crossbotics.com/ftc-helper/docs/building-autos/09-match-day/). To look something up: [Reference](https://crossbotics.com/ftc-helper/docs/reference/) and the [Cookbook](https://crossbotics.com/ftc-helper/docs/cookbook/). To learn how it works inside: [Build it by hand](https://crossbotics.com/ftc-helper/docs/tutorials/). **Look it up:** [Wiring checks](https://crossbotics.com/ftc-helper/docs/tuning/02-wiring-checks/): the Hardware, Motor Direction and Encoder Checks. [The testing module](https://crossbotics.com/ftc-helper/docs/modules/testing/): the Hardware Check OpMode. **Go deeper:** [Tutorial 19: Hardware Check](https://crossbotics.com/ftc-helper/docs/tutorials/19-testing-procedures/): the Hardware Check in your own 3-line OpMode, and what each button does.