Skip to content
Tempo on GitHub (opens in a new tab)

5.1 Export robot code

The Code screen, the last tab in the bottom bar, has everything the GUI generates for your robot project.

The Code screen in the desktop app: RobotContainer.java with Tempo's imports and Tempo's autos block highlighted, and a list on the right with RobotContainer.java and Spots.java up to date, Robot config with no file and game.toml not live
View full size (opens in a new tab) ↗

The GUI generates three pieces of code:

  • Autos and paths: a Composer for each path and a Setlist for each auto. A path in the GUI is what these docs call a route.
  • Robot config: the config from the Robot screen, as a CONFIG constant (kConfig in C++).
  • Waypoints: the saved poses from Waypoints, as constants.

The Code screen also has the Configure call, which is the Tempo.configure(...) call you paste into your robot code once, and the game pack.

A piece has no file until you give it one, and until then the Code screen shows its code with a Copy button. In the desktop app you can give a piece a file in the robot project, and the GUI writes the piece there. Apart from the imports it adds, the GUI doesn’t change code outside its own files and blocks.

Browser and desktop

Only the desktop app writes into the robot project. In the browser, pick a piece on the Code screen, click Copy and paste the code into your robot project. The game pack has Export TOML, which saves the pack as a file for the deploy folder.

The configure call passes the config as CONFIG, so add the name of the class you pasted the config into in front of it.

On the Paths and Autos screens, the open path or auto also has its code on the panel’s Code tab, next to Properties. You can edit the code in that tab, and a valid edit updates the path or auto.

The browser keeps the workspace for one browser profile at one web address, so a different profile, port or host starts empty. Clearing the site’s data deletes the workspace. The desktop app saves to files on the computer. To move a workspace, open settings with the gear at the right of the bottom bar and go to Workspace. Export downloads the whole workspace as one file, and Import replaces the workspace with that file.

1. Connect the robot project

In the desktop app, click Setup guide on the Code screen.

  1. On Project, pick the folder you deploy from. The GUI reads the language and WPILib year from it and checks that the Tempo library is installed. If the step offers Add it, clicking it installs the library.
  2. On Files, give each piece its file with Create a file… or Add to a file…, or leave it without one and copy its code. Giving a piece a file describes both buttons. The Add autos to the chooser option makes each auto register itself under its name.
  3. On Drivetrain, click Copy and paste the Tempo.configure(...) call into your robot code where it runs once at startup. The first four arguments are example names, so change them to your own methods for the pose, the pose reset, the measured robot-relative speeds and the robot-relative drive (Connect the drivetrain). The fifth argument is the config the GUI generates. While the robot config has no file it’s CONFIG alone, and you add the class name in front. You can go on to the next step and paste the call later.
  4. On Field & sensors, turn on the field copy and, in Java, add Tempo’s annotation processor to build.gradle (see below).
  5. On Review, check the list of every file and block the GUI will touch. Finishing the guide writes them.

The project folder, the language and the WPILib year can be changed later in Settings, under Robot code.

The Checks tab on the right of the Code screen lists the project’s checks. Click Run checks again after you change something outside the GUI. The Drivetrain connected check shows where the call is in the project.

Giving a piece a file

With a robot project open in the desktop app, a piece that has no file shows a card on the Code screen with two buttons.

Click Create a file… to make a new file for the piece. You choose the file’s name and folder, and the GUI writes the whole file from then on. A C++ file has to be a header. An existing file is replaced only if you confirm it in the save dialog, and the GUI keeps a backup of it.

Click Add to a file… to keep the piece in one of your own files. Pick the file, and a dialog shows the file’s outline with the spots the block can take. Click a spot, then Add it here. The GUI backs the file up, writes one block at that spot, and from then on rewrites only that block.

The robot config is kept between tempo:begin config and tempo:end config comments, and the waypoints between tempo:begin poses and tempo:end poses. In C++ both have to go in a header. The autos go in a constructor. In Java they can also go in the class as fields or in a new method that the constructor calls.

If the file already has the block or the same code, the dialog offers Use that block, Use that code or Use those autos, and the code isn’t written twice. If the file’s code is different from what the GUI would write, the dialog lists the differences. Keep the file’s version imports the file’s code into the GUI, and Write Tempo’s version replaces it and keeps a backup of the file.

One file can hold more than one piece, and the GUI rewrites each block separately. To move a block, click another spot in the file’s Place view and click Done.

To take a file away from a piece, select the piece on the Code screen and click Stop next to Stop writing this file in its settings on the right. The file keeps its code and the piece has no file again.

Projects with an old setup block

Earlier versions of the GUI wrote the config and the Tempo.configure(...) call as one block. A project that still has one gets an Old setup block check, and the robot config’s card names the file the block is in. Click Split the block… on either one and confirm with Split it. That replaces the old block with the call alone and keeps the config in the same file as a block of its own (in C++, in the header of that name). Each file it replaces keeps a backup.

If the block was edited by hand, the GUI can’t replace it and changes nothing. Click Copy the call, paste the call over the old block, and click I pasted the call.

2. Write the files

The Write N changes button in the header writes every file with waiting changes. A file marked Needs you has a card that says what’s wrong, and writes skip it until you deal with the card. The field copy is written from its own card with Copy field.

Pick a file in the list on the Code tab to look at it. The Changes view shows what the next write adds and removes, Whole file shows the file as it will be, and Place shows where an autos block sits in a file of yours.

Before each write the GUI backs up the file, and it keeps the last three backups of each file. Click Restore… in the file’s settings to list them, each with a diff against the file now.

With Add autos to the chooser on, each auto is registered under its name. Auto chooser shows how to pick one and run it.

Live update

With Live update on, the GUI writes a file one second after the last change to the paths, autos or settings it comes from. Each file has its own switch in its settings. The Live update switch in Settings, under Robot code, turns it on and off for all of them and keeps each file’s choice. If no file is switched on, turning it on turns on every piece that has a file. The field copy’s switch is separate and starts off.

Changing the robot project, the language or a piece’s file pauses Live update. The file’s card then asks you to check where the code goes now and turn it on again.

Edits in the robot code

The GUI reads its files back before it writes them. If you change a path or an auto inside Tempo’s block, or a value in the robot config, the change is imported into the workspace. The file’s card says what was imported, with Undo import. The GUI doesn’t read your Tempo.configure(...) call or a piece that has no file.

When the same path or auto changed in the file and in the GUI, that file stops and its card shows both changes. Pick Use the file’s version or Use Tempo’s version, which backs up the file first. Always use my code sets When both change in Settings, under Robot code, to My code wins.

Editing the robot config by hand

Values the Robot screen has a field for are imported, and the next write keeps them. A line the GUI doesn’t know stays as you wrote it and is listed on the Robot screen under From your code. A tunable value, like .maxVelocity(kMaxV), shows as Set in code.

A save changes only the values you edited. Comments, order, imports and your own code stay as written.

A config that isn’t one TempoConfig chain, or that has a value the GUI can’t use, is marked Needs you. The card says what couldn’t be read, and the GUI doesn’t write the file until you pick one of these:

  • Click Keep my code and the GUI stops writing the file and leaves it as it is. The robot config then has no file.
  • Click Use Tempo’s version and the GUI replaces your edit, backing the file up first.

If the Robot screen and the file both changed since the last write, the card lists each setting that differs with the GUI’s value and the file’s.

With Read edits back turned off in the file’s settings, the next write replaces your edits with the GUI’s version and keeps a backup.

You can also pass your own config in the call and leave the GUI’s unused.

Commands and sensors from your code

Mark commands and sensors in the robot code and the desktop app lists them in Library under Found in robot code, with Add and Add all. Java uses annotations, Python decorators and C++ macros. In Python the decorators go on module-level functions that take no arguments, and they don’t work on methods.

Java
import com.tempo.TempoCommand;
import com.tempo.TempoSensor;
import edu.wpi.first.wpilibj2.command.Command;

@TempoCommand
private Command score() {
    return superstructure.scoreL4();
}

@TempoSensor
private boolean hasPiece() {
    return intakeSubsystem.hasPiece();
}
Python
from tempo import tempo_command, tempo_sensor

@tempo_command
def score():
    return superstructure.score_l4()

@tempo_sensor
def has_piece() -> bool:
    return intake_subsystem.has_piece()
C++
#include <tempo/wpi/Bindings.h>

TEMPO_COMMAND Score() {
    return superstructure.ScoreL4();
}

TEMPO_SENSOR hasPiece = [this] { return intakeSubsystem.HasPiece(); };

The annotation is com.tempo.TempoCommand. com.tempo.wpi has a class with the same name, so check that the import is the one from com.tempo.

The GUI reads the project again when the window gets focus and when you click Rescan code in Library.

The Java annotation processor

Python and C++ files are scanned directly. In Java, the GUI reads a list that Tempo’s annotation processor writes when the project compiles. The build.gradle file needs the processor, and the project has to be built once before anything shows up. The setup guide and the Checks tab offer to add the processor lines to build.gradle. To add them by hand, see Installation.

esc

Loading search...