Class RobotDefinition

java.lang.Object
com.crossbotics.ftchelper.robot.RobotDefinition

public abstract class RobotDefinition extends Object
What is on the robot, written once in the team's Robot.java: the drive and one line per mechanism, with each part's name in the robot configuration. TeleOp (ControlMap) and every autonomous (Auto) use it, so a renamed motor is changed in one place.

 public class Robot extends RobotDefinition {
     public Intake intake;
     public Lift lift;
     public Claw claw;

     @Override protected void define() {
         drive(Drive.mecanum("front_left", "front_right", "back_left", "back_right")
                 .motor("gobilda-5203-312").wheelMm(96)
                 .imu("imu", LogoFacingDirection.UP, UsbFacingDirection.FORWARD));
         intake = add(Intake.motor("intake"));
         lift = add(Lift.slide("lift").bottomSwitch("lift_bottom"));
         claw = add(Claw.servo("claw"));
     }
 }
 

The numbers live in Tunables.java next to this file (one section per module), the buttons in Controls.java, steps that use several parts in Actions.java.

Nothing moves in INIT: the modules make their hardware then, and move only after START. Docs: docs/modules/robot.md. Tutorial: docs/tutorials/start/01-robot-in-five-files.md

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final <T extends Module<?>>
    T
    add(T module)
    Adds a mechanism and hands it back, so it can go in a field: lift = add(Lift.slide("lift"));
    all()
    Every part, for one update() per loop (the OpMode classes do this).
    final Alliance
    The alliance for this match (chosen in autonomous; TeleOp remembers it).
    protected final void
    An action that runs once, right after START, in autonomous and in TeleOp (for example a servo that pushes the intake into place).
    final void
    cancel(Action action)
    Stops an action.
    final void
    Stops every running action.
    static List<String>
    The Tunables values changed on this robot (tuning menu) that differ from Tunables.java, as lines to copy back into the code: "Tunables.Lift.kP = 0.0050 (code 0.004)".
    protected final void
    chassisMm(double length, double width, double height)
    The chassis box for the simulator (it bumps into the field and the game pieces): length front to back, width side to side, height from the tiles to its top, in mm.
    protected abstract void
    Describe the robot here: one drive line and one add(T) line per mechanism.
    Runs define() once (no hardware).
    final Drive
    The drivetrain as written in define().
    protected final void
    The drivetrain.
    protected final void
    fixed(Shape... shapes)
    Parts the code does not move, for the simulator: fixed(Shape.box("ramp")...), and Shape.passive parts that belong to no module.
    The path follower as running (null before setup, or with no follower(...) line).
    protected final void
    A path follower from another library, e.g.
    final boolean
    True if Robot.java has a follower(...) line.
    protected final void
    heightMm(double height)
    The whole robot's height in mm (the tallest fixed part), for the simulator.
    final boolean
    True while paused.
    makeOdometry(HardwareMap) with any Devices (tests use pretend ones).
    makeOdometry(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap)
    Makes only the odometry from the odometry(...) line, for a tool that runs without the rest of the robot (e.g.
    final List<Module<?>>
    The mechanisms, in the order they were added (read only).
    final List<String>
    Notes for INIT: missing Tunables sections or fields (the library's defaults are used).
    The odometry as running (null before setup, or with no odometry(...) line).
    protected final void
    The odometry: what tells the robot where it is on the field (see Odometry).
    final boolean
    True once Tunables.Odometry.checked = true: the odometry's directions and offsets were checked with the Odometry Tuner.
    final Odometry
    The odometry as written in define() (null if none).
    final void
    Pauses the whole robot: every part stops now with its motors on brake (actions wait), and remembers what it was doing.
    final FieldPose
    Where the robot is now, from the odometry: x inches right, y inches away from your drivers' wall, heading 0 = facing away, counterclockwise + (the same as autonomous start spots).
    final void
    Ends pauseAll(): every part goes back to what it was doing.
    The drivetrain's settings (motor names, IMU, autonomous tuning) for EasyTeleOp and EasyAuto.
    final void
    run(Action action)
    Starts an action (from its first step if it was running).
    static String
    sectionName(String deviceName)
    The Tunables section a device's module reads: its name in CamelCase ("intake_deploy" -> "IntakeDeploy", "Webcam 1" -> "Webcam1").
    final void
    Sets the alliance (the OpMode classes do this).
    setup(Devices devices)
    setup(HardwareMap) with any Devices (tests use pretend ones).
    setup(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap)
    Makes every module's hardware (INIT).
    final List<String>
    The simulator robot file's lines from the code: the drive, then each module's (see ./gradlew :sim:fromRobot).
    final void
    Pauses if running, resumes if paused.
    protected final void
    tunables(Class<?> tunables)
    The Tunables class, if it is not called Tunables in the same folder as Robot.java.
    final Class<?>
    The Tunables class in use, or null if there is none.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RobotDefinition

      public RobotDefinition()
  • Method Details

    • define

      protected abstract void define()
      Describe the robot here: one drive line and one add(T) line per mechanism. Only describe: do not move anything (it runs in INIT, and also without a robot, to write the simulator file).
    • drive

      protected final void drive(Drive d)
      The drivetrain.
      Parameters:
      d - e.g. Drive.mecanum("front_left", "front_right", "back_left", "back_right")
    • odometry

      protected final void odometry(Odometry o)
      The odometry: what tells the robot where it is on the field (see Odometry).
      Parameters:
      o - e.g. Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)
    • follower

      protected final void follower(PathFollower.Maker maker)
      A path follower from another library, e.g. follower(Pedro.follower(Constants.foresight)) with the ftc-helper-lib "pedro" module. It needs an odometry(com.crossbotics.ftchelper.robot.Odometry) line too (it uses the same pose).
    • add

      protected final <T extends Module<?>> T add(T module)
      Adds a mechanism and hands it back, so it can go in a field: lift = add(Lift.slide("lift"));
      Parameters:
      module - the module, e.g. Intake.motor("intake")
      Returns:
      the same module
    • tunables

      protected final void tunables(Class<?> tunables)
      The Tunables class, if it is not called Tunables in the same folder as Robot.java.
      Parameters:
      tunables - e.g. MyNumbers.class
    • atStart

      protected final void atStart(Supplier<Action> action)
      An action that runs once, right after START, in autonomous and in TeleOp (for example a servo that pushes the intake into place). Never in INIT: a robot must not move before START.
      Parameters:
      action - e.g. () -> Actions.deployIntake(this)
    • chassisMm

      protected final void chassisMm(double length, double width, double height)
      The chassis box for the simulator (it bumps into the field and the game pieces): length front to back, width side to side, height from the tiles to its top, in mm.
    • heightMm

      protected final void heightMm(double height)
      The whole robot's height in mm (the tallest fixed part), for the simulator.
    • fixed

      protected final void fixed(Shape... shapes)
      Parts the code does not move, for the simulator: fixed(Shape.box("ramp")...), and Shape.passive parts that belong to no module.
      Parameters:
      shapes - one or more Shape.box(java.lang.String) or passive shapes
    • describe

      public final RobotDefinition describe()
      Runs define() once (no hardware). Used by setup and by the simulator file generator.
    • setup

      public final RobotDefinition setup(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap)
      Makes every module's hardware (INIT). The OpMode classes call this for you.
      Parameters:
      hardwareMap - the OpMode's hardwareMap
    • setup

      public final RobotDefinition setup(Devices devices)
      setup(HardwareMap) with any Devices (tests use pretend ones).
    • all

      public final Subsystems all()
      Every part, for one update() per loop (the OpMode classes do this). Null before setup(com.qualcomm.robotcore.hardware.HardwareMap).
    • robotConfig

      public final RobotConfig robotConfig()
      The drivetrain's settings (motor names, IMU, autonomous tuning) for EasyTeleOp and EasyAuto.
    • odometry

      public final PoseTracker odometry()
      The odometry as running (null before setup, or with no odometry(...) line).
    • follower

      public final PathFollower follower()
      The path follower as running (null before setup, or with no follower(...) line).
    • hasFollower

      public final boolean hasFollower()
      True if Robot.java has a follower(...) line.
    • makeOdometry

      public final PoseTracker makeOdometry(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap)
      Makes only the odometry from the odometry(...) line, for a tool that runs without the rest of the robot (e.g. Pedro's tuners through the pedro module). Your code calls update() on it each loop.
    • makeOdometry

      public final PoseTracker makeOdometry(Devices devices)
      makeOdometry(HardwareMap) with any Devices (tests use pretend ones).
    • odometrySpec

      public final Odometry odometrySpec()
      The odometry as written in define() (null if none).
    • pose

      public final FieldPose pose()
      Where the robot is now, from the odometry: x inches right, y inches away from your drivers' wall, heading 0 = facing away, counterclockwise + (the same as autonomous start spots). Null if the robot has no odometry. A copy: changing it does not move anything.
    • odometryChecked

      public final boolean odometryChecked()
      True once Tunables.Odometry.checked = true: the odometry's directions and offsets were checked with the Odometry Tuner. Until then, driveTo steps do not run on a real robot.
    • drive

      public final Drive drive()
      The drivetrain as written in define().
    • modules

      public final List<Module<?>> modules()
      The mechanisms, in the order they were added (read only).
    • pauseAll

      public final void pauseAll()
      Pauses the whole robot: every part stops now with its motors on brake (actions wait), and remembers what it was doing. resume() goes on from there. TeleOp's BACK does it.
    • resume

      public final void resume()
      Ends pauseAll(): every part goes back to what it was doing.
    • togglePause

      public final void togglePause()
      Pauses if running, resumes if paused.
    • isPaused

      public final boolean isPaused()
      True while paused.
    • run

      public final void run(Action action)
      Starts an action (from its first step if it was running). It runs a little every loop.
    • cancel

      public final void cancel(Action action)
      Stops an action. Its parts stop safely (a lift holds its height, waiting shots are dropped).
    • cancelAll

      public final void cancelAll()
      Stops every running action.
    • alliance

      public final Alliance alliance()
      The alliance for this match (chosen in autonomous; TeleOp remembers it).
    • setAlliance

      public final void setAlliance(Alliance a)
      Sets the alliance (the OpMode classes do this).
    • notes

      public final List<String> notes()
      Notes for INIT: missing Tunables sections or fields (the library's defaults are used).
    • tunablesClass

      public final Class<?> tunablesClass()
      The Tunables class in use, or null if there is none.
    • simLines

      public final List<String> simLines()
      The simulator robot file's lines from the code: the drive, then each module's (see ./gradlew :sim:fromRobot). Works without a robot.
    • changedTunables

      public static List<String> changedTunables()
      The Tunables values changed on this robot (tuning menu) that differ from Tunables.java, as lines to copy back into the code: "Tunables.Lift.kP = 0.0050 (code 0.004)". Empty if none.
    • sectionName

      public static String sectionName(String deviceName)
      The Tunables section a device's module reads: its name in CamelCase ("intake_deploy" -> "IntakeDeploy", "Webcam 1" -> "Webcam1").
      Parameters:
      deviceName - the configuration name