Simulate Robot

The Simulate Robot tab runs an autonomous routine on your robot's own code, with simulated hardware, and plays it back on the field.

An auton played back part way: the robot on the field, its subsystems on the right, its commands on the timeline.
An auton played back part way: the robot on the field, its subsystems on the right, its commands on the timeline.

Before you start

  • Install the robot library (see Setting up Robot Designer). It adds RobotSimulation.java to TeamCode/src/test/java/org/firstinspires/ftc/teamcode/, and never overwrites it.
  • The robot project needs a working JDK and Gradle. If ./gradlew works in a terminal, this tab works too.

An empty RobotSimulation simulates the robot your @RobotSubsystem annotations describe. To simulate more, see "Simulating the whole robot" in the library's docs/simulation.md.

Run a simulation

  1. Pick a routine. Autonomous (robot code) is first. Any @RobotSimulationTest test in the robot project is listed after it.
  2. Set the start: drag the amber start marker of the routine's alliance (see "Choose where the robot starts").
  3. Click Simulate Robot.
  4. Press Play, or drag the playhead along the timeline.

The run shows the robot's position, its subsystems, and a timeline of its commands.

What the simulated robot does:

  • It stays on the field. When its drive's Respect forbidden areas setting is on, it also stays out of forbidden areas for both alliances and for its own, sliding along their edges as the real robot does; with it off, the default, it drives through them.
  • Its cameras see the game elements and AprilTags on the field layout you are showing.
  • A camera zone that sees an element runs its script. That script shows on the timeline.
  • AprilTags in view correct where the robot thinks it is.
  • AllianceTagSeen looks for the alliance's tags. A routine name with no alliance has none to see, so it waits.

What it does not simulate:

  • Sensors. A touch sensor reads not pressed, a distance sensor out of range and a colour sensor black for the whole run, so code that waits on a sensor waits as it would for one that never sees anything, until its timeout if it has one. The simulator's output, in the terminal Robot Designer was started from, names each such sensor. A robot's RobotSimulation can set a sensor's reading itself: see "When a robot needs more" in the library's docs/simulation.md.

The run uses the field as it was when you simulated. After you move an element or the start, simulate again.

Choose where the robot starts

The routine's alliance comes from its name: blueLeft_… is blue, redLeft_… is red. A name with neither is blue.

  • The field has two amber start markers, one per alliance, labelled in the alliance's colour.
  • Drag a marker to move it. Turn it by the knob in front of its nose. Click it to type exact values.
  • The marker can't go inside a forbidden area or past the field's edge. It stops at the nearest clear place. A typed X or Y that would put the robot over the wall turns red with the range allowed, and is not kept.
  • A saved start that is now inside an area shows a warning above the field, such as "⚠ Inside Blue goal: starting at (0.00, 0.53)".
  • A routine with a SetInitialPoseCommand starts where that command says, as on the robot.
  • These are the same starts as on Live Robot. They are saved for the robot (see "The start" under "Named positions on the field").

The run receives the start in the environment variables START_X_M, START_Y_M (metres) and START_HEADING_DEG (degrees).

Compare with the planned path

Tick routines in the Planned Routes list on the left. Each one is drawn as a faded "ghost" of its planned path, with its own row on the timeline. The ghost moves on the same clock as the robot, so you can see where the robot falls behind the plan.

The plan covers the routine's paths and its drive-to steps, each drive timed as Play on the Paths page times it. A drive that goes where the robot decides, such as to what its camera sees, isn't drawn; a note under the list says which one and why.

Use the timeline

Later in the same run.
Later in the same run.
The Motors sub-tab, the same on Simulate Robot, Live Robot and Recordings: here only the flywheel motors are shown, through a replayed match.
The Motors sub-tab, the same on Simulate Robot, Live Robot and Recordings: here only the flywheel motors are shown, through a replayed match.

The timeline runs across the bottom of Simulate Robot and Live Robot. Play, the speed (1x, 2x, 4x) and the time are at its left end.

  • Each command's bar is in the colour of the subsystem it uses, as in the script editors, with a band for each when it uses several; one that uses none is grey.
  • A command that runs the whole run, such as TeleOp, is a thin strip along the top rather than a row of its own.
  • Point at a command to see what it is and when it ran. Very short commands are thin slivers; pointing near one is enough.
  • Drag to move the playhead.
  • To zoom in, Shift+drag across a stretch, use ⌘/Ctrl+scroll, or pinch on a trackpad. Esc cancels a Shift+drag.
  • Right-click for Zoom In, Zoom Out and Show Whole Run.
  • When zoomed in, the timeline scrolls sideways and follows the playhead.
  • The Motors tab shows the same stretch of the run as the timeline, zooming and scrolling with it, in Simulate Robot and Recordings. Its speed, power and battery scales stay the whole run's.

What the field shows

Use Show ▾ in the field's corner (or Show in the right-click menu) to hide things:

ItemWhat it is
Tile GridA line along each seam between the field's 2 ft tiles, for lining a robot or a position up with the tiles
Game ElementsBalls and other scoring elements
AprilTagsThe tags around the field
Forbidden AreasPlaces the robot must not drive
Field PositionsNamed places scripts drive to
Start PositionsNamed places routines start from
Robot TrackThe line the robot has driven
Device ActivityA glow on each motor that is running and each servo that is moving
Device LabelsThe label beside each glowing device, with its power or position
Planned PathsThe ghost routes from Planned Routes

Show Everything brings them all back. Each tab remembers its choice.

Hiding only stops drawing. The robot still avoids a hidden area, and cameras still see hidden elements. Hidden things can't be clicked, so you can reach what is under them.

Click a bare spot on the field to see its position in metres.

Find something on the field

Find in the field's corner opens a list of everything on the field, beside it, each under its own heading: the positions, start positions, game elements, AprilTags and forbidden areas you can pick, then the run's Planned paths, the Robot, what its cameras see now (Seen by cameras, which changes as the run plays) and its Devices.

  • Type in Find… to keep only the names holding those words.
  • Point at a row to outline its item on the field.
  • Select a row to select its item and open its form, as clicking it does. An item the Show menu hides is greyed in the list; selecting it shows its layer again.
  • The run's rows have nothing to edit: selecting one rings it on the field until something else is selected. A planned path is drawn bold, with a ring round its ghost robot.
  • Selecting something on the field selects its row.
  • ◀ at the list's top, or Find again, closes it. Closed, it takes no room. Opened, it takes its width from the read-outs beside the field, so the field keeps its size.

A game element's form sets which element it is and exactly where it sits.

Motors and servos at work

The robot is small on the field, so each motor that is running gets a glow ring on its device and a label beside the robot, joined to it by a line:

  • A motor's label shows its power as a signed percentage, such as intakeMotor +65%, with a bar under the text. The ring grows with the power. A motor below 2% counts as stopped.
  • A servo's label shows its position from 0 to 1, such as flowerBarServo 0.80. It shows while the servo moves and for a moment after, since a servo reports a position all the time.
  • The label uses the device's name, or the label you gave it on the Design tab.
  • A device whose Motion box is unchecked on the Design tab gets no glow and no label.
  • Labels stay one size however far the field is zoomed.
  • To clear the labels off the field but still see what is moving, right-click the field and untick Device Labels (it is also in Show). The glow rings stay. Untick Device Activity in Show to hide the rings too.

It works the same on Live Robot.

Game elements on the field

Game elements are what a simulated camera looks for.

  • Add one: choose + Add → Element in a corner of the field, or right-click the field.
  • Field layouts: the right-click menu switches between saved layouts and makes new ones.
  • Move: drag (5 mm steps). Option/Alt drags freely. Shift keeps to one direction.
  • Keys: click the field first. Arrow keys nudge, Delete removes, ⌘Z / Ctrl+Z undoes.

Changes save at once and show on both Simulate Robot and Live Robot. Switching layouts clears undo.

Picking up elements. A simulated robot picks up an element when the element's centre is under the robot. The element then shows as a dashed outline, and no camera sees it. An element already under the robot at the start stays loaded.

On Live Robot, changing the layout or pressing Clear puts every element back. With a simulated robot connected, right-click an element for Pick Up or Put Back. A real robot refuses these.

Camera panes

The Camera sub-tab.
The Camera sub-tab.

The panes beside the field show every camera in the active robot design, with its zones.

An AprilTag camera's pane shows what the robot reported, for a simulated or a real camera:

  • Each seen tag's outline and id, and a line such as "Tag 20 · 1.82 m · 14.2° left". Distance is from the robot's centre. Bearing is which way the tag is from the robot's front.
  • "no distance" for a tag seen without a position.
  • "Camera not connected" in red, with the robot's error, when the camera isn't working.
  • Hover a tag for its elevation and its angles in the image.

The same numbers are on the Subsystems tab, under the camera's subsystem → tags → the tag's id:

ValueMeaning
distancemetres
bearingdegrees, left is positive
elevationdegrees
tx, tydegrees from the image centre, right and up positive
corners_pxthe tag's corners in pixels (hover "4 points")

On the field, a cyan line runs from the camera to each tag it sees, and the tag is outlined in cyan. A tag missing from apriltags.json is drawn as a cyan diamond with its id.

AprilTags on the field

The field's AprilTags show on every layout as white squares with their number. The purple edge and arrow show which way the printed side faces.

  • Add one: + Add → AprilTag puts a tag on a wall, facing in, with the next free number. Right-click → Add AprilTag Here puts one where you clicked, facing the centre.
  • Move: drag (5 mm steps; Option/Alt freely; Shift one direction). Arrow keys nudge. [ and ] turn 1° (Shift: 15°). Delete removes. ⌘Z / Ctrl+Z undoes. A tag can sit up to 10 cm past the edge, on the wall.
  • Exact values: click a tag to open its form. Enter keeps changes, Esc cancels, Tab moves between boxes. A duplicate ID, or an X or Y more than 10 cm past the edge, turns red and must be fixed first.
  • Past the edge: a tag, area, position or element saved past the field's edge (say, after size_m in field.json was made smaller) is drawn at the edge and listed in the problem note at the top of the field. Its file keeps it where it is until you move it.
  • A size_m that can't be used: while field.json's size is wrong, the field is the default one and nothing on it is saved. The problem note says so.
  • Overlapping things: click the same spot again to pick the next thing under it.
FieldMeaning
IDThe tag's number
NameOptional
mmWidth of the tag's black square
X m, Y mPosition from the field's centre
Z mHeight above the floor
FaceWay the printed side looks: 0° right, 90° up the field, 180° left
Tilt0° on a wall, 90° lying face-up
Roll0° is top edge up

A tag with two poses

Some tags sit on something that rests two ways, such as a seesaw.

  1. Right-click the tag → Add Alternate Pose, or tick Alternate pose in its form.
  2. Type the second X, Y, Z, Face, Tilt and Roll.

The alternate pose is drawn faint and dashed, and can't be dragged. To remove it, untick the box or right-click → Remove Alternate Pose.

The robot uses the pose whose height (Z) is within 10 cm of the height it sees. If neither or both match, it doesn't use the tag to correct its position. That tag's line is faint and dashed; hover it to see why.

The tags file

Tags save to <TeamCode>/field_designs/apriltags.json, one file for the season. Positions are metres from the field's centre; angles are degrees. The second pose is the tag's "alternate". An entry Robot Designer can't read is kept, and noted on the field. If the whole file can't be read, fix it by hand first. Sync copies it to the robot.

Forbidden areas on the field

A forbidden area is a place the robot must not drive into, such as a structure. The robot's drive commands slide along its edge, as they do at the field's wall.

Areas are hatched rectangles: grey keeps out both alliances; blue or red keeps out only that alliance. One that doesn't keep out the alliance being played is faint, with a dashed edge. Hover one for its name.

  • Add one: + Add → Area puts a 60 cm square in the middle, for both alliances, and opens its form. Right-click → Add Forbidden Area Here puts one where you clicked.
  • Move: drag (5 mm steps; Option/Alt freely; Shift one direction). Arrow keys nudge.
  • Resize: click it, then drag the white squares on its corners and sides.
  • Turn: drag the knob beyond its front edge, or press [ and ] (1°; Shift: 15°).
  • Delete / undo: Delete removes; ⌘Z / Ctrl+Z undoes one change.
  • Right-click: Edit…, Alliance ▸ (Both, Blue, Red), Delete.
  • Exact values: click it for Name, For (Both, Blue, Red), X m, Y m (centre), Angle (counter-clockwise from pointing right), Length and Width. Each name must be unique; a blank or duplicate name turns red.

The areas file

Areas save to <TeamCode>/field_designs/forbidden_areas.json, one file for the season. It starts empty. An entry looks like this:

{"areas": [
  {"name": "Blue goal", "alliance": "both", "x_m": 0.0, "y_m": 0.6,
   "length_m": 0.5, "width_m": 0.3, "angle_deg": 0.0}
]}
  • An entry that can't be used (no name, bad alliance, missing number, zero size) is skipped, noted on the field, and kept in the file.
  • An area with no "alliance" keeps out both robots, and is noted until you choose one.
  • If the file changed since Robot Designer read it (a git pull, say), your edit isn't saved. The field reloads the file; make the edit again.
  • Sync copies it to the robot.

Named positions on the field

A named position is a place and heading on the field. Scripts drive to it or start at it by name, with the Position of DriveToFieldPositionCommand and SetInitialPoseCommand. Move it once and every routine that uses it follows.

  • A plain position is a white X with an arrow showing the heading. Its name goes beside it wherever it doesn't run over another name or mark, with a thin line back to it if it had to go further out.
  • A start position is an amber robot outline with its name on its alliance's colour.

Add and edit positions

  • Add one: + Add → Position, or right-click → Add Field Position Here. For a start position use + Add → Start or Add Start Position Here (named Start 1, Start 2, …).
  • Move: drag the X (5 mm steps; Option/Alt freely; Shift one direction). Arrow keys nudge. The X takes the press even under a start position's or a start marker's robot outline; press anywhere else in the outline to take the start.
  • Turn: drag the amber knob beyond the arrow, or press [ and ] (1°; Shift: 15°).
  • Delete / undo: Delete removes; ⌘Z / Ctrl+Z undoes.
  • Exact values: click it for Name, X m, Y m, Heading, Robot starts here and Alliance. Names must be unique and can't be start.

Renaming a position doesn't rename it in scripts. Their problem checks flag the old name.

The start

Every project has a start for each alliance: the two amber start markers. Each begins at the field centre, facing right.

  • Drag, turn or nudge it, or click it to type X m, Y m and Heading.
  • Moving a start on Simulate Robot also moves it on Live Robot.
  • A script's start means the start of the robot's alliance. It is never mirrored, so linked red and blue routines both say start.
  • A routine that names no position starts at its alliance's start.

Start positions

Use start positions when your routines start in different places, such as the left or right wall.

  1. Choose + Add → Start in your alliance's starting area.
  2. Name it.
  3. In the routine, set SetInitialPoseCommand's Position to that name.

A start position belongs to one alliance. Its mirror is drawn faintly on the other side. A routine for the other alliance keeps the same name and adds PositionMirror. Linking or copying a routine to the other alliance adds it for you, and Problems warns when it is missing.

Positions in a script

SetInitialPoseCommand and DriveToFieldPositionCommand each have a Position drop-down: start, then start positions, then other positions. Its first entry, Custom (X, Y, HeadingDeg), uses the typed numbers instead.

  • With a position chosen, X, Y and the heading show "(ignored: Position set)".
  • A routine using a position is checked and simulated as if its numbers were typed.
  • The Run row's parameters on Live Robot offer the same drop-down.
  • A Position that doesn't exist is a script problem, and the robot refuses the script.

Red and blue. A linked red routine keeps the blue Position name and adds "PositionMirror": "rotate_180", so it drives to the mirrored position. This comes from config.json's FieldFrameParams, where a parameter of kind "position" is a field position:

"FieldFrameParams": {
  "DriveToFieldPositionCommand": {"X": "x", "Y": "y", "HeadingDeg": "angle",
                                  "Position": "position"}
}

SetInitialPoseCommand's Position is mirrored without being listed. Mirroring again removes PositionMirror, so you can edit either side of a linked pair. Any command's parameter of kind "position" gets the same drop-down; one with no X and Y of its own starts with — none — instead of Custom.

Positions the robot works out

A position can also be one the robot's own Java code works out when the step runs: the goal nearest the robot, or where the camera last saw a tag. The robot project marks each with @ScriptPosition, and its build lists them in <TeamCode>/robot_designs/positions.json, beside conditions.json, in the same shape:

{"Positions": [{"Name": "NearestGoal", "Description": "The goal nearest the robot.",
                "Parameters": {"MaxDistanceM": 3.0}}]}

They follow the field's positions in every Position drop-down except SetInitialPoseCommand's (a start is a field position), as NearestGoal (worked out on the robot). Choosing one writes its name and parameters, and its parameters appear under the row to edit:

"Target": {"Position": "NearestGoal", "MaxDistanceM": 3.0}
  • Its own Position row switches back to a field position, or to another the robot works out.
  • It isn't drawn on the field: a drive to one ends wherever the robot decides.
  • It isn't mirrored for the other alliance: its code works it out for whichever alliance the robot plays.
  • A name positions.json doesn't list is a script problem.

The positions file

Positions save to <TeamCode>/field_designs/field_positions.json, beside the tags and areas:

{"starts": {"blue": {"x_m": -1.5, "y_m": -0.9, "heading_deg": 0.0},
            "red": {"x_m": 1.5, "y_m": 0.9, "heading_deg": 180.0}},
 "positions": [
  {"name": "Left", "x_m": -0.9, "y_m": 1.6, "heading_deg": -90.0, "start": true, "alliance": "blue"},
  {"name": "Launch", "x_m": 0.6, "y_m": -1.2, "heading_deg": 90.0}
]}
  • x_m, y_m: metres from the field's centre (+x right, +y up the field as drawn).
  • heading_deg: counter-clockwise from +x.
  • "start": true marks a start position; "alliance" is blue or red (blue if missing).
  • The file follows the same rules as the areas file. Sync copies it to the robot, which reads it when an OpMode initialises.