3.10 Failure handling
This drive to the station gives up after 2 s, ends early once a coral is in, and runs
superstructure.recover() if it fails. The poses are from
Routes & waypoints.
import static edu.wpi.first.units.Units.Seconds;
route.to(STATION_LEFT)
.giveUpAfter(Seconds.of(2.0)) // 2 s to drive and plan
.endWhen(intake::hasPiece) // stop short once loaded; not a failure
.runOnFailure(superstructure.recover());(route.to(STATION_LEFT)
.give_up_after(2.0) # 2 s to drive and plan
.end_when(intake.has_piece) # stop short once loaded; not a failure
.run_on_failure(superstructure.recover()))// recover_ is a stored frc2::CommandPtr from superstructure.Recover().
route.to(STATION_LEFT)
.give_up_after(2.0) // 2 s to drive and plan
.end_when([this] { return intake.HasPiece(); }) // stop short once loaded
.run_on_failure(recover_.get());Python and C++ spell these give_up_after, end_when and run_on_failure, and take the time in
seconds.
The drive to one waypoint is called a leg. A leg fails when it gives up, stalls,
misses a required crossing (a
crossing with a target it didn’t drive) or
can’t be planned. A failed leg skips its
runAfter commands and
waitUntil checks and starts its runOnFailure command. A leg that ends on endWhen or
outside the arrival tolerance (Missed arrivals) hasn’t failed, and its
runAfter commands run.
The same calls written after a Setlist’s drive(...) apply to that whole run and
follow different rules.
giveUpAfter
giveUpAfter limits how long the leg can spend driving, including the time spent waiting for
its plan. When the time runs out the leg fails and the route moves on to the next leg.
It doesn’t limit runBefore or runAfter commands, or a waitUntil between them. Give those
their own timeout, such as WPILib’s withTimeout or the waitUntil timeout.
endWhen
endWhen ends the leg on the first loop its check returns true. This doesn’t count as a failure,
so the leg’s runAfter commands still run even if the robot is short of the waypoint.
run(fraction, ...) commands at fractions the robot didn’t reach don’t start, and a required
crossing that wasn’t driven still fails the leg.
endWhen doesn’t limit the leg’s time, so add a giveUpAfter if the leg needs a limit.
runOnFailure
The runOnFailure command (the recovery) starts when the leg fails, and the route moves on
without waiting for it. It can also be a plain method, which is called once.
The recovery can’t require the drivetrain. If it does, the route throws when it freezes on its first use. Give the command an end condition or a timeout, because it keeps running after its route ends. If a later hook or step needs one of its subsystems, that command takes over and the recovery is interrupted.
To pick the recovery from a condition, build the command with WPILib’s Commands.either
(commands2.cmd.either in Python, frc2::cmd::Either in C++). The condition is then read
when the recovery starts.
Interrupting the auto while its steps are running ends its recoveries. If the steps finish while a recovery is still running, what happens depends on how the auto runs:
- When WPILib’s Commands v2 scheduler runs the auto, the auto ends and releases the
drivetrain. The recovery keeps running and holds only its own subsystems, until it
finishes, a driver command takes one of them or the robot is disabled. A recovery built
with WPILib’s
ignoringDisable(true)(IgnoringDisablein C++) keeps running through the disable, and one built to cancel incoming commands isn’t ended by a driver command. - An auto inside a command group or a decorator such as
withName, a Commands v3 auto and an auto started without the scheduler wait for their recoveries and hold the drivetrain until they end.
Stalls
A leg stalls when the robot is commanded faster than 0.15 m/s, but for 0.75 s its distance left along the path changes by no more than 5 cm and it gets no more than 5 cm closer to the path. That happens when the robot is pinned on a wall, hung up on a bump or caught on another robot. A leg also stalls when the robot has stopped after a failed replan and still has no path 0.75 s later.
A stalled leg fails and prints a console line. The check runs on every leg, with or without
giveUpAfter or runOnFailure, except while an
arriveWith command drives. Connecting drives use the same check.
A leg that ends stopped at a heading has a second check, the heading check. It starts once the
leg’s planned motion is done and the robot is within the replanning
threshold of the target with only the heading outside its tolerance. From then on the leg
stalls when its heading error hasn’t dropped by 1 degree for 2 s. That leg has failed, so its
runOnFailure runs, and it’s also counted as a missed arrival. The
console lines name the cause, with legs numbered from 1 in drive order:
[Tempo] leg 1 (target 10.50, 2.00) stalled 4.50 m from its target: commanded above 0.15 m/s with no more than 5 cm of progress along or toward the path for 0.75 s; the leg failed
[Tempo] leg 1 (target 2.60, 5.50) stopped 60.0 deg short of its heading and 0.0 cm from its target, with no heading progress for 2.0 s; the leg is missedA leg with a custom follower or output filter has a check of its own. While the robot is outside the arrival tolerance, the leg ends as missed and failed once its distance to the target hasn’t dropped by 1 cm for 1 s and its heading error hasn’t dropped by 1 degree for 2 s.
Time limit for the whole auto
import com.tempo.wpi.Setlist;
import edu.wpi.first.wpilibj2.command.Commands;
var bounded = Setlist.named("Bounded left coral")
.race(Commands.waitSeconds(14.5), leftCoral);import commands2.cmd
from tempo.wpi import Setlist
bounded = Setlist.named("Bounded left coral").race(
commands2.cmd.waitSeconds(14.5), left_coral)#include <frc2/command/Commands.h>
#include <tempo/wpi/Setlist.h>
auto bounded = tempo::Setlist::named("Bounded left coral")
.race(frc2::cmd::Wait(14.5_s), left_coral);leftCoral is the Setlist from Build an auto from routes.
A race group ends when either member ends, so the 14.5 s wait limits all of leftCoral, its
waits and commands included. A recovery that leftCoral started isn’t interrupted and keeps
running until it ends (runOnFailure).
Failure handling for one run in a Setlist
var cycle = Setlist.named("Cycle")
.drive(toStation)
.giveUpAfter(Seconds.of(4.0))
.runOnFailure(superstructure.recover());cycle = (Setlist.named("Cycle")
.drive(to_station)
.give_up_after(4.0)
.run_on_failure(superstructure.recover()))auto cycle = tempo::Setlist::named("Cycle")
.drive(to_station)
.give_up_after(4.0)
.run_on_failure(recover_.get());After drive(route), giveUpAfter limits that whole run, including the
connecting drive to the route’s start.
runOnFailure starts once, when any leg of the run fails or is
missed, when the run gives up or when its drive fails.
The run’s runAfter commands are skipped only when the run gives up or its drive fails. A
drive fails when it can’t be built or started, when a fault stops it partway through or when
its last leg fails. After a last waypoint that was only missed, they still run. A run’s
endWhen ends the run without failing it, so its runAfter commands run.
A connecting drive that stalls, can’t be planned or can’t be built also fails the run. The route isn’t driven, the robot is stopped, and the next step starts from there.
A fault ends that route and not the auto, and the Setlist goes on to its next step.
Put .at(n) before the two calls to apply them only to the drive to waypoint n, with the
rules of a leg. See Commands for this run only.
A leg the planner cannot solve
A leg can’t be planned when its target is inside an obstacle or an avoid zone, when no route
connects its ends, or when no speed profile within its limits can drive it (see
Zones & regions). Tempo skips the leg before driving it, starts its
runOnFailure command and moves on. If every leg of a route is skipped the route finishes right
away and the robot doesn’t move.
Each skipped leg prints a [Tempo] line that names it and logs a giveUps event with cause
noRoute (Log Tempo state).
In Java, route.handle().skippedSegments() counts the skipped legs (a segment is a leg) and
skippedSegmentIndices() lists them, counting legs from 0.
Missed arrivals
A leg ends once the robot is inside the arrival tolerance. That’s the leg’s arriveWithin, or
else the tolerance set with TempoConfig.withTolerance(...), 5 cm and 3 degrees unless changed.
The heading counts only at a waypoint that has one. A leg the robot drives through without
stopping also ends, as arrived, when its planned motion ends with the robot within the
replanning threshold of the waypoint.
A robot inside the tolerance still waits in these cases:
- It’s behind its planned pose. It arrives when the planned motion ends.
- The leg ends in a stop, and the planned motion is still slowing or the robot would coast to rest outside the tolerance.
- The leg has a required crossing that hasn’t been driven.
A robot that’s still outside the tolerance when the planned motion ends settles on the target, and the follower keeps correcting toward it. Settling starts once the robot is within the replanning threshold of the target and any required heading is within tolerance. It ends after 1.0 s without 1 cm of improvement, or after 4.0 s total.
If the robot is then within twice the translation tolerance and has driven its required
crossings, the leg counts as arrived. Farther than that is a missed arrival. If settling never
starts, the leg runs until it stalls or giveUpAfter ends it.
For a missed arrival at a stopping waypoint, the console prints a line such as [Tempo] leg 3 (target 2.20, 2.50) ended 0.23 m from its target, outside its 0.05 m arrival tolerance; the arrival is missed.
A missed arrival on its own isn’t a failure of the leg. The leg’s runAfter commands run and
its runOnFailure doesn’t.
A run in a Setlist starts the run’s
runOnFailure on one. A leg that the heading check or the custom-follower check under
Stalls ends is both missed and failed, so its runOnFailure runs.
In Java, route.handle().missedSegments() counts the missed legs. Those are the missed
arrivals above and legs that gave up or stalled short of the waypoint. arrivedEveryLeg() is
true only when no leg was skipped or missed. Read them after the command ends
(Inspect a running auto).
Python and C++ expose missed_segments() on TempoAuto. For scheduled routes, use
logging to inspect arrivals.
If it fails…
A runBefore or runAfter command or a waitUntil is blocking, and giveUpAfter doesn’t limit those. Give it a timeout, or limit the whole auto.
runAfter is skipped on a failed leg. Score in runOnFailure, or in a later Setlist when(...) step that reads route.handle().arrivedEveryLeg() in Java.
Every leg was skipped. Read the [Tempo] lines and check the targets.
A recovery is still running and holds the subsystem. Give the recovery an end condition and a cleanup.
The robot was commanded to move without enough progress along or toward the path. Check for an obstruction and check that the drivetrain responds to the commanded speeds.
The robot stopped and no new path was found. Check its reported pose and the obstacles around it. See When replanning fails.
The leg’s giveUpAfter time ran out before arrival. Check the time limit and whether the robot is following the path.
The leg’s giveUpAfter time includes the arriveWith command. Check that command’s end condition and the leg’s time limit.
The heading error stopped dropping for 2 s. Tune rotation kP on Tune path following.