Package com.crossbotics.ftchelper.robot
Class RobotDefinition
java.lang.Object
com.crossbotics.ftchelper.robot.RobotDefinition
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected final <T extends Module<?>>
Tadd(T module) Adds a mechanism and hands it back, so it can go in a field:lift = add(Lift.slide("lift"));final Subsystemsall()Every part, for one update() per loop (the OpMode classes do this).final Alliancealliance()The alliance for this match (chosen in autonomous; TeleOp remembers it).protected final voidAn action that runs once, right after START, in autonomous and in TeleOp (for example a servo that pushes the intake into place).final voidStops an action.final voidStops every running action.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 voidchassisMm(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 voiddefine()Describe the robot here: onedriveline and oneadd(T)line per mechanism.final RobotDefinitiondescribe()Runs define() once (no hardware).final Drivedrive()The drivetrain as written in define().protected final voidThe drivetrain.protected final voidParts the code does not move, for the simulator:fixed(Shape.box("ramp")...), andShape.passiveparts that belong to no module.final PathFollowerfollower()The path follower as running (null before setup, or with no follower(...) line).protected final voidfollower(PathFollower.Maker maker) A path follower from another library, e.g.final booleanTrue if Robot.java has a follower(...) line.protected final voidheightMm(double height) The whole robot's height in mm (the tallest fixed part), for the simulator.final booleanisPaused()True while paused.final PoseTrackermakeOdometry(Devices devices) makeOdometry(HardwareMap)with anyDevices(tests use pretend ones).final PoseTrackermakeOdometry(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.modules()The mechanisms, in the order they were added (read only).notes()Notes for INIT: missing Tunables sections or fields (the library's defaults are used).final PoseTrackerodometry()The odometry as running (null before setup, or with no odometry(...) line).protected final voidThe odometry: what tells the robot where it is on the field (seeOdometry).final booleanTrue onceTunables.Odometry.checked = true: the odometry's directions and offsets were checked with the Odometry Tuner.final OdometryThe odometry as written in define() (null if none).final voidpauseAll()Pauses the whole robot: every part stops now with its motors on brake (actions wait), and remembers what it was doing.final FieldPosepose()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 voidresume()EndspauseAll(): every part goes back to what it was doing.final RobotConfigThe drivetrain's settings (motor names, IMU, autonomous tuning) for EasyTeleOp and EasyAuto.final voidStarts an action (from its first step if it was running).static StringsectionName(String deviceName) The Tunables section a device's module reads: its name in CamelCase ("intake_deploy" -> "IntakeDeploy", "Webcam 1" -> "Webcam1").final voidSets the alliance (the OpMode classes do this).final RobotDefinitionsetup(HardwareMap)with anyDevices(tests use pretend ones).final RobotDefinitionsetup(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap) Makes every module's hardware (INIT).simLines()The simulator robot file's lines from the code: the drive, then each module's (see./gradlew :sim:fromRobot).final voidPauses if running, resumes if paused.protected final voidThe Tunables class, if it is not calledTunablesin the same folder as Robot.java.final Class<?> The Tunables class in use, or null if there is none.
-
Constructor Details
-
RobotDefinition
public RobotDefinition()
-
-
Method Details
-
define
protected abstract void define()Describe the robot here: onedriveline and oneadd(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
The drivetrain.- Parameters:
d- e.g.Drive.mecanum("front_left", "front_right", "back_left", "back_right")
-
odometry
The odometry: what tells the robot where it is on the field (seeOdometry).- Parameters:
o- e.g.Odometry.pinpoint("pinpoint").offsetsMm(-84, -168)
-
follower
A path follower from another library, e.g.follower(Pedro.follower(Constants.foresight))with the ftc-helper-lib "pedro" module. It needs anodometry(com.crossbotics.ftchelper.robot.Odometry)line too (it uses the same pose). -
add
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
The Tunables class, if it is not calledTunablesin the same folder as Robot.java.- Parameters:
tunables- e.g.MyNumbers.class
-
atStart
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
Parts the code does not move, for the simulator:fixed(Shape.box("ramp")...), andShape.passiveparts that belong to no module.- Parameters:
shapes- one or moreShape.box(java.lang.String)or passive shapes
-
describe
Runs define() once (no hardware). Used by setup and by the simulator file generator. -
setup
Makes every module's hardware (INIT). The OpMode classes call this for you.- Parameters:
hardwareMap- the OpMode'shardwareMap
-
setup
setup(HardwareMap)with anyDevices(tests use pretend ones). -
all
Every part, for one update() per loop (the OpMode classes do this). Null beforesetup(com.qualcomm.robotcore.hardware.HardwareMap). -
robotConfig
The drivetrain's settings (motor names, IMU, autonomous tuning) for EasyTeleOp and EasyAuto. -
odometry
The odometry as running (null before setup, or with no odometry(...) line). -
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
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
makeOdometry(HardwareMap)with anyDevices(tests use pretend ones). -
odometrySpec
The odometry as written in define() (null if none). -
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 onceTunables.Odometry.checked = true: the odometry's directions and offsets were checked with the Odometry Tuner. Until then,driveTosteps do not run on a real robot. -
drive
The drivetrain as written in define(). -
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()EndspauseAll(): 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
Starts an action (from its first step if it was running). It runs a little every loop. -
cancel
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
The alliance for this match (chosen in autonomous; TeleOp remembers it). -
setAlliance
Sets the alliance (the OpMode classes do this). -
notes
Notes for INIT: missing Tunables sections or fields (the library's defaults are used). -
tunablesClass
The Tunables class in use, or null if there is none. -
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
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
The Tunables section a device's module reads: its name in CamelCase ("intake_deploy" -> "IntakeDeploy", "Webcam 1" -> "Webcam1").- Parameters:
deviceName- the configuration name
-