Scripts

The Scripts tab builds reusable scripts: behaviours like "shoot" or "intake for 1.5 s" that autons, camera zones, gamepad bindings and other scripts run by name.

Scripts are the .json files in <TeamCode>/src/main/java/org/firstinspires/ftc/teamcode/autons/Scripts. Every edit saves at once.

The Scripts tab: scripts on the left, the open script in the middle, the palette on the right.
The Scripts tab: scripts on the left, the open script in the middle, the palette on the right.

The tab

PartWhat it does
Scripts listYour scripts, sorted into folders (see below), with a Filter. New, Duplicate, Rename, Delete. Rename updates every place the script is used. Delete is refused while anything uses it.
EditorThe script's steps as a tree.
PaletteCommands and scripts to add: drag an entry into the script, double-click it, or use Add inside and Add after. Robot commands are grouped by the subsystems they use (see below).
FilterShows only palette entries containing every word you type, in any order.
Used inHow many files use each palette entry (autons, scripts, bindings, camera zones). Point at the number to see which. An entry nothing uses may not be needed.
ProblemsWhat is wrong with the script. Click a problem to select its step. Shrinks to one line when there is nothing to fix.

Reading a script: a script opens with its groups open and each command closed. A closed command reads in a line in its Value column: its custom name, then what it's set to. A script's name, a position or a condition shows as is; any other value shows only when it isn't the command's usual one (timeout 6.0 s), at most three. Open a command to edit it.

Colours: a command shows the subsystems it uses as a thin coloured bar down the left of its rows, in the colour of the subsystem's devices on the Design tab. Recolour a device there and its commands follow. A command that uses several subsystems shows a stripe for each, up to three, and the palette's subsystem headings show their own colour. A RunScript, and a script in the palette, shows the subsystems its script uses, including those of the scripts it runs. Groups, other built-in steps and commands that use no subsystem have no bar.

A problem inside a group names the path to it, such as SequentialCommandGroup > If > Then > Spin. 2nd Spin means the second step of that name.

The palette, Filter and Used in work the same on the Auton and Controls tabs.

Under Robot commands, each command is listed under every subsystem it uses, so EjectCommand is under both Indexer and Intake, and commands that use no subsystem are under No subsystem. A command the robot's config.json gives a heading of its own in PaletteGroups (the library's Shooter commands are under Shooter, and its driving commands, SetInitialPoseCommand, ResetHeadingCommand and SetPIDFollowingCommand among them, under Drive) is listed under that heading only, not under its subsystems. The groups come from Requires in the robot's config.json; if it names no subsystems, the commands are listed in one flat list.

Add steps from the palette

Drag an entry from the palette into the script and drop it where the drop line shows, with the same rules as moving a step (below). Or double-click it: it goes inside the selected group or Do / Then / Else, otherwise after the selected step.

Select, cut, copy and paste

Shift-click or Ctrl/Cmd-click to select several steps, anywhere in the script. Then use the keys or right-click one of them:

EditKeysWhat it does
CutCmd+X (Ctrl+X)Copies the steps and takes them out.
CopyCmd+C (Ctrl+C)Copies the steps, to paste here, into another script or auton, or as text.
PasteCmd+V (Ctrl+V)Puts the copied steps inside the selected group or Do / Then / Else, otherwise after the selected step. Into an empty script, several steps go in a SequentialCommandGroup.
DeleteDelete or BackspaceTakes the steps out.
Undo / RedoCmd+Z (Ctrl+Z) / Shift+Cmd+Z (Ctrl+Y)Takes back the last edit, or makes it again.

Steps are copied as the script file writes them, so text like {"WaitCommand": {"WaitTimeMs": 500}} pasted from anywhere becomes a step.

A robot command's parameter that takes a number, a whole number or true or false refuses other text where you type it: fast or 20 deg in a speed's cell is not saved, and a note beside the cell says what it takes. A parameter whose command gives it a range refuses a number outside it the same way, and the note names the range. Problems lists what the robot refuses in a robot command's step: a parameter it needs left out, one of the wrong type or outside its range, or a step whose value isn't an object. It warns of a key the command doesn't take, such as a misspelt parameter, which the robot ignores, using the parameter's default instead.

A parameter with a unit shows it after its value and at the end of its field: a WaitCommand's WaitTimeMs reads 500 ms, since a wait is in milliseconds while other times in a script are in seconds. A robot command's parameter that a step must give has its name in bold. Hover over a parameter's name to see its default, its unit, its range and whether it is required.

The build lists each command's parameters, with their types, units and ranges, in config.json's ParamTypes; a config.json built by an older library has none, and only the numbers in a command's template are checked as you type.

Every edit is one undo step. Opening another script clears the history. An undo that would overwrite a file changed outside Robot Designer (by hand or by a git pull) is refused.

Sort scripts into folders

  • New folder: click the folder button beside Scripts, or right-click → New Folder. It goes in the folder selected.
  • Move: drag a script or a folder onto a folder. Drop it on a script to put it beside that script, or on the empty space below to move it to the top. Right-click → Move to Top does the same.
  • Rename and Delete act on a folder when one is selected. Deleting a folder deletes no script: what was in it moves up a level.
  • A new script goes in the folder selected; a duplicate stays beside the original.
  • Several at once: Shift-click or Ctrl/Cmd-click to select several scripts and folders. Drag them, or right-click → Move to a folder, to move them all. Duplicate and Delete take them all (a script something else still uses is kept, and you're told what uses it); Rename takes one.
  • Cut, copy, paste: Cmd/Ctrl+X, C and V, or right-click. A copy pastes as new scripts in the folder selected, each under its own name or the next free one (shoot2); a copied folder brings its folders and scripts. A cut pastes as a move. Copied scripts paste into another project too.
  • Filter shows only the scripts whose names contain every word you type, with their folders open. Enter or ↓ picks the first match; Esc clears it.

Folders are Robot Designer's only: the script files stay in the Scripts folder, and a RunScript still names a script alone, so script names stay unique. The folders are saved in autons/script_folders.json; commit it with the scripts. The palette's Scripts section shows the same folders, on every tab.

Move steps

  • Within its group: select the step, then Move Up / Move Down, Option/Alt+Up/Down, or right-click → Move Up / Move Down.
  • Anywhere else: drag it. Drag one of several selected steps to move them all: they land together, in the order they were in.
    • Drop near the top or bottom of a step to put it before or after that step.
    • Drop onto a group, a RepeatUntil's Do, or an If's Then / Else to add it at the end.
    • Drop just below an open group's row to make it the group's first step.
    • Below a group's last row, point further left to drop after the group, or further right to drop inside it at the end. The drop line shows the level.
  • You can't drop onto a parameter or condition, into the step itself, or beside the script's top step.

A ParallelDeadlineGroup ends when its first step ends. A move, drop or paste that changes the first step asks first, naming the new deadline.

Other step edits

  • Comment: double-click a step's Comment cell and type a note. The robot ignores it. Groups can't have comments. Simulate Robot's timeline shows a comment when you point at the bar.
  • Use default: a parameter that comes from the robot's Defaults on the Design tab, such as FlywheelOnCommand's targetRpm (shown there as targetRpm (FlywheelOnCommand)), reads Use default (3250), with the active robot's value, or Use default (3000, the code's) when it has none. A new step starts there, and the robot reads the value when the step runs. Type a number in its place to use that instead; pick Use default to go back.
  • Change a group's kind: right-click it → Change To. Its steps stay.
  • Empty script: drag or double-click a group from the palette, click Add inside, paste, or right-click the empty list.

Make a script from steps

  1. Select steps that are next to each other in one group, Do, Then or Else (Shift-click the first and last, or Ctrl/Cmd-click each).
  2. Right-click one → Make Script from Steps….
  3. Name the script.

The new script replaces the steps with one RunScript, and runs them as before. Steps from a parallel group become a group of the same kind. This works on the Auton tab too. If the steps drive the auton's own paths, you're asked first: renaming or deleting the auton later would leave the script driving the wrong paths.

A step that might never end is only a warning here, because a script for a held button or a race is meant to run until stopped.

Conditions

A script that waits on a reported value: run the intake, and unjam it whenever the motor stalls.
A script that waits on a reported value: run the intake, and unjam it whenever the motor stalls.
StepUses its condition to
WaitUntilWait until it is true.
RepeatUntilStop repeating. It checks all the time, so a pass is cut short when it comes true.
IfChoose Then or Else, once, when the If starts.

A robot command can take a condition too, when its Java marks one (the library's conditions.md, "A condition as a command's parameter"): the library's ShooterFireOn fires only while its condition holds, say. Its Condition is chosen, held, timed out and combined exactly as a WaitUntil's, below, on the Scripts and Auton tabs alike, and checked the same way. The build lists these commands in config.json's ConditionParams.

Choose a condition

  1. Double-click the step's Condition value (or select it and press Return).
  2. Pick a condition. Hover an entry for its description.
  3. Fill in its Parameters, which start at their defaults.
  4. A parameter takes the type of its default: a number, text, or true or false. Hover it to see. A true-or-false parameter is a True / False dropdown; typing true or false in any case is accepted too.
  5. An unset condition reads "— choose a condition —".
  6. Conditions come from conditions.json in the Robot Designs folder. The robot's programmers write them in Java; the library's conditions.md says how.
  7. A project with no conditions.json offers its config.json's ValidConditions instead, without parameters or And/Or/Not.

If

  • Then or Else may be empty; an empty one shows a greyed "Do nothing" row. Both empty is an error.
  • To add a step, drop it on the Then / Else row, or select the row and click Add inside.
  • An If decides at once, so its conditions can't have Hold for (s), and Add Timeout… isn't offered.
  • Problems warns when the condition is sure to be one way when the If starts, so a branch never runs (for example a lone Deadline).
  • A RepeatUntil's Do can't be empty: that is an error.

Compare a reported value: ReportedValue

ReportedValue compares any value a subsystem reports, so "wait until the flywheel is above 3000 rpm" needs no new condition.

ParameterWhat to enter
AttributeThe value to check, such as flywheel.flywheelMotor1.speed (rpm). Pick from the list or type a path.
Comparison>, >=, <, <=, == or !=. Speeds are never exactly equal, so use >= or <=.
ValueThe number to compare with, in the value's unit. True and false are 1 and 0.
CompareToOptional. Another reported value to compare with instead of Value. — use Value — clears it.
ToleranceOptional. How close counts, in the value's unit. With 50, == means "within 50". 0 is exact; it can't be negative.
  • The Attribute list comes from the connected robot (Live Robot). With none connected, it comes from simulation reports (tests/reports/*-events.json). If both are missing, type the path or run a simulation on Simulate Robot.
  • An empty Attribute, a bad Comparison or a negative Tolerance is an error.
  • A path not in the list is a warning, in case it is misspelled.

Hold a condition for a time

Every condition has a Hold for (s) row: how long it must stay true, without a break, to count. Empty or 0 means no hold. Only a single condition can hold, not an And, Or or Not.

Example: the flywheel is at speed when it has stayed within 50 rpm of its target for 0.25 s, and its target isn't 0 (an off flywheel is "at its target"):

And — all of these
    ReportedValue (flywheel.flywheelMotor1.speed == flywheel.flywheelMotor1.targetSpeed ± 50 for 0.25 s)
    ReportedValue (flywheel.flywheelMotor1.targetSpeed > 0)

Add a timeout

Right-click the Condition → Add Timeout…, then type the seconds.

The condition becomes an Or of what it was and a Deadline, such as flywheel.flywheelMotor1.speed > 3000 or after 2 s. A Deadline is true once its Seconds (0 or more) have passed since the WaitUntil or RepeatUntil started. A step a Deadline is sure to end isn't warned about as one that might never end.

Combine conditions: And, Or, Not

Right-click the Condition → Wrap in And, Wrap in Or or Wrap in Not.

PartTrue when
And — all of theseEvery condition in it is true.
Or — any of theseAny condition in it is true.
NotThe one condition in it is false.
  • Right-click an And or Or to Add Condition, Add And, Add Or, Add Not, or Change To the other.
  • Right-click any part to wrap it, Unwrap it, or Remove it.
  • Drag a condition into an And or Or, or use Move Up / Move Down within one.
  • The Condition row reads the whole tree, such as not IntakeRunning and (HopperFull or FlywheelAtSpeed).
  • Problems lists an unknown condition, a wrong or missing parameter, an unchosen condition, an empty And or Or, and a Not without exactly one condition. Each says where, such as And[1] › Or[0].