3.8 Conditions
A Condition starts a hook (a command attached to a
waypoint) at a point along the drive, at a match time, in a field zone or on a sensor reading.
Some conditions are moments that happen once, like progress or entered. The others are
states that hold or don’t on each loop, like inside or when. All of them are listed in the
Condition reference.
This drive raises the elevator with 1 m of path left and lights the LEDs red 1 s into the
auto. It lights them green while the robot is within 1.5 m of REEF_KR and holding a coral.
The poses are from Routes & waypoints,
plus REEF_G from Write the first auto.
import static edu.wpi.first.units.Units.Meters;
import static edu.wpi.first.units.Units.Seconds;
import com.tempo.Condition;
route.to(REEF_KR)
.run(Condition.remaining(Meters.of(1)), superstructure.prepareL4())
// seconds since the auto started
.run(Condition.matchTime(Seconds.of(1)), leds.solidCommand(Color.kRed))
.runWhile(Condition.near(REEF_KR, Meters.of(1.5)).and(intake::hasPiece),
leds.solidCommand(Color.kGreen));from tempo import Condition
(route.to(REEF_KR)
.run(Condition.remaining(1.0), superstructure.prepare_l4())
# seconds since the auto started
.run(Condition.match_time(1.0), leds.solid_command(Color.kRed))
.run_while(Condition.near(REEF_KR, 1.5) & Condition.when(intake.has_piece),
leds.solid_command(Color.kGreen)))#include <tempo/Condition.h>
// prepare_, red_ and green_ are stored frc2::CommandPtr members.
route.to(REEF_KR)
.run(tempo::Condition::remaining(1.0), prepare_.get())
// seconds since the auto started
.run(tempo::Condition::match_time(1.0), red_.get())
.run_while(tempo::Condition::near(REEF_KR, 1.5_m) && tempo::Condition::when(
[this] { return intake.HasPiece(); }),
green_.get());Python and C++ take meters and seconds.
Where a condition goes
run(condition, cmd) after a to(...) watches the condition while the robot drives to that
waypoint and starts the command the first time it holds. A matchTime condition
is watched for the whole route.
runWhile(condition, cmd) takes states only. It watches from the start of that drive until the
route ends. It starts the command each time the state comes to hold and interrupts it when the
state stops holding.
Conditions also start an aim with aimTarget, a hook on a whole
Setlist run, and a Setlist when(...) branch.
Each one accepts a different set of conditions, listed in
Accepted by, and throws if you pass one it doesn’t
take.
Distance and progress
route.to(REEF_KR)
.run(Condition.progress(0.2), superstructure.stow()) // 20% of the path
.run(Condition.remaining(Meters.of(1)), superstructure.prepareL4()); // 1 m of path left(route.to(REEF_KR)
.run(Condition.progress(0.2), superstructure.stow()) # 20% of the path
.run(Condition.remaining(1.0), superstructure.prepare_l4())) # 1 m of path leftroute.to(REEF_KR)
.run(tempo::Condition::progress(0.2), stow_.get()) // 20% of the path
.run(tempo::Condition::remaining(1.0), prepare_.get()); // 1 m of path leftprogress(f) is the fraction of the planned path to the waypoint that the robot has covered.
It’s measured at the robot’s nearest point on the current plan. run(f, cmd) is shorthand for
run(Condition.progress(f), cmd).
remaining(d) fires when the planned path left to the target is d or less. That distance is
the length of the path, so on a detour around the reef it’s longer than the straight line.
After a replan that rejoins the planned path, which is the default,
progress keeps reading along that path. With ReplanMode.NEW_PATH it reads against the new
path and keeps the distance already covered.
Position triggers are progress (with its shorthand run(f, ...)), remaining, the start of a
run(from, to, ...) window and passed.
They all fire by the time the robot arrives. The ones that haven’t fired yet fire on that loop
in the order they were written, before runAfter.
If the drive ends without arriving, its unreached positions don’t fire and they don’t carry
over to the next waypoint. That covers giveUpAfter, endWhen, a
stall and a
missed arrival.
Distances and zones are measured from the robot’s center.
Match time
matchTime(t) holds from t seconds after the auto started. It counts up and doesn’t read the
Driver Station countdown. In a Setlist every route counts from the auto’s first loop, and a
route run on its own counts from its own first loop.
A matchTime trigger fires on whichever drive of its route is running when the time comes,
whether the robot is moving or stopped at a waypoint. A time that has already passed fires on
the route’s first loop. A route that ends first never fires it. A time late in the auto
needs a route that’s still running then, or a
Setlist run that lasts that long.
Field zones
The zone conditions need a region in the pack. The REEFSCAPE 2025 pack has none, so the
examples on this page add a stationApproach region at the left coral station:
[[regions]]
id = "stationApproach"
shape = "rectangle"
minM = [0.0, 6.60]
maxM = [1.70, 8.052]route.to(REEF_G)
.to(STATION_LEFT)
.run(Condition.passed("reef"), superstructure.stow()) // level with the reef
.run(Condition.entered("stationApproach"), intake.intakeCommand()); // crossing in(route.to(REEF_G)
.to(STATION_LEFT)
.run(Condition.passed("reef"), superstructure.stow()) # level with the reef
.run(Condition.entered("stationApproach"), intake.intake_command())) # crossing inroute.to(REEF_G)
.to(STATION_LEFT)
.run(tempo::Condition::passed("reef"), stow_.get()) // level with the reef
.run(tempo::Condition::entered("stationApproach"), intakeCommand_.get()); // crossing inentered(id) and exited(id) fire on the loop the robot’s center crosses into or out of a
region. inside(id) holds on every loop the center is in the region. If the drive starts inside a
region, inside holds from the first loop and entered fires only if the robot leaves and
comes back in. Conditions are checked once per loop, so the robot can cross a zone narrower
than one loop of travel without it registering.
These three take a region that isn’t an
avoid zone, which in the pack file is a [[regions]] entry with no effect. An avoid zone,
obstacle or terrain id throws when the hook is added, and so does an id the pack doesn’t have.
passed(id) takes any element in the pack. It fires when the robot is level with the center of
the element, measured along the straight line from where the drive started to its target. It
also fires at arrival if that comes first. An element at or past the target only fires at
arrival, and Tempo prints a warning for it when it plans the route.
Sensors
route.to(STATION_LEFT)
.run(Condition.when(intake::hasPiece), superstructure.stow()); // the loop a coral lands(route.to(STATION_LEFT)
.run(Condition.when(intake.has_piece), superstructure.stow())) # the loop a coral landsroute.to(STATION_LEFT)
.run(tempo::Condition::when([this] { return intake.HasPiece(); }), stow_.get());when(check) calls the check once per loop and uses the result as it is, with no debounce. If
your sensor is noisy, filter it in your own code.
Combining conditions
Condition readyToScore = Condition.near(REEF_KR, Meters.of(1.5)).and(intake::hasPiece);
Condition nearReef = Condition.near(REEF_IR, Meters.of(1.5)).or(Condition.near(REEF_KR, Meters.of(1.5)));
Condition atStation = Condition.inside("stationApproach");
Condition awayFromStation = atStation.not();ready_to_score = Condition.near(REEF_KR, 1.5) & Condition.when(intake.has_piece)
near_reef = Condition.near(REEF_IR, 1.5) | Condition.near(REEF_KR, 1.5)
at_station = Condition.inside("stationApproach")
away_from_station = ~at_stationtempo::Condition ready_to_score = tempo::Condition::near(REEF_KR, 1.5_m)
&& tempo::Condition::when([this] { return intake.HasPiece(); });
tempo::Condition near_reef = tempo::Condition::near(REEF_IR, 1.5_m)
|| tempo::Condition::near(REEF_KR, 1.5_m);
tempo::Condition at_station = tempo::Condition::inside("stationApproach");
tempo::Condition away_from_station = !at_station;near(point, d) holds while the robot is within d of the point. The point is mirrored with
the route for the other alliance.
and, or and not combine states, which are near, inside, matchTime, when and
their combinations. and and or also take a plain check in place of a
Condition.when(...), as in Java’s .and(intake::hasPiece). A moment (progress,
remaining, passed, entered or exited) or always throws in a combination, so put a
moment on its own run.
Python spells them &, | and ~ (or and_, or_, not_). A Condition can’t be used
with the and, or and not keywords or in an if, and those raise a TypeError.
C++ spells them &&, || and ! (or and_, or_, not_). Only and_ and or_ take a
plain check.
If it fails…
Check the id against the loaded pack first. An entered on a leg that starts inside the zone doesn’t fire unless the robot leaves and comes back in, so use inside there. A zone narrower than one loop of travel can also be missed, and it needs to be wider.
The condition may have first held after the robot passed that waypoint. Attach it to the leg where it becomes true. A state (near, inside, matchTime, when) that should be watched across later legs can go on runWhile, which doesn’t take moments.
The element projects at or past the target. Pass an element that lies between the leg’s start and its target.
With ReplanMode.NEW_PATH, progress reads against the new path. For a fixed place on the field use near, a zone or a sensor.