4.19 Regions, zones and terrain
Use a Region for a shape you place on the field, a Zone for a game pack element
by its id, and a Terrain for pack terrain the robot should cross. This route uses
ids from the bundled REBUILT 2026 pack.
import com.tempo.Composer;
import com.tempo.Region;
import com.tempo.Terrain;
import com.tempo.Zone;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
var route = Composer.startAt(start)
.avoid(Region.circle(8.27, 4.03, 0.6)) // whole route
.to(7.50, 2.00)
.stayWithin(Zone.named("neutralZone")) // this leg
.to(3.00, 5.50)
.cross(Terrain.named("bumpLeft").target(new Pose2d(4.63, 5.56, Rotation2d.kZero)));from tempo import Composer, Region, Terrain, Zone
from wpimath.geometry import Pose2d
route = (Composer.start_at(start)
.avoid(Region.circle(8.27, 4.03, 0.6)) # whole route
.to(7.50, 2.00)
.stay_within(Zone.named("neutralZone")) # this leg
.to(3.00, 5.50)
.cross(Terrain.named("bumpLeft").target(Pose2d(4.63, 5.56, 0.0))))#include <tempo/Composer.h>
#include <tempo/Region.h>
#include <tempo/Terrain.h>
auto route = tempo::Composer::start_at(start)
.avoid(tempo::Region::circle(8.27, 4.03, 0.6)) // whole route
.to(7.50, 2.00)
.stay_within(tempo::Zone::named("neutralZone")) // this leg
.to(3.00, 5.50)
.cross(tempo::Terrain::named("bumpLeft").target(4.63, 5.56, 0.0));| Composer method | Scope | Takes |
|---|---|---|
avoid(region) | Whole route | Region |
ignore(zone), allow(zone) | Whole route | Zone naming a pack avoid zone |
stayWithin(region) (stay_within) | The leg of the to(...) before it | Region or Zone |
cross(terrain) | The leg of the to(...) before it. Several cross in call order | Terrain |
ignore(zone) lets the path go through a pack avoid zone. allow(zone) makes the
route obey a zone again, so the path stays out of it. It’s for a zone an earlier
ignore(zone) turned off or one the pack starts switched off.
Coordinates are in meters and mirror with the route. A stayWithin region keeps the
whole footprint inside it along the leg. A rectangular region has to be wider than the
footprint at the heading the robot holds, and a region wider than twice the footprint’s
circumradius fits at any heading. The centers of the start and the target can sit on
the boundary, with the footprint hanging over it.
The guides are Zones & regions and Terrain crossings.
Region
| Factory | Java | Python | C++ |
|---|---|---|---|
| Rectangle | rectangle(minX, minY, maxX, maxY), rectangle(bottomLeft, topRight) | rectangle(min_x, min_y, max_x, max_y) | rectangle(min_x, min_y, max_x, max_y), rectangle(bottom_left, top_right) |
| Circle | circle(x, y, radius), circle(center, Distance) | circle(x, y, radius), circle(center, radius) | circle(x, y, radius), circle(center, radius) |
| Square, by center and side | square(x, y, side), square(center, Distance) | square(x, y, side), square(center, side) | square(x, y, side), square(center, side) |
| A pack element’s bounding box | zone(Zone) | zone(zone) | zone(Zone) |
| That box grown outward | near(Zone, Distance) | near(zone, margin_m) | zone(z).grown_by(margin) |
center, bottomLeft and topRight are Translation2d. Rectangles and squares are
axis-aligned. zone and near read the loaded pack, so Tempo.configure(...) must
run first.
Python takes plain meters for every size and margin.
| Member | Java | Python | C++ | Result |
|---|---|---|---|---|
| Grow | grownBy(margin) | None, use Region.near(zone, margin_m) | grown_by(margin) | A copy grown outward by margin meters |
| Keep-in form | asKeepIn() | as_keep_in() | as_keep_in() | A KeepIn. A square becomes its rectangle |
| Avoid form | asAvoidZone() | as_avoid_zone() | as_avoid_region() | An AvoidZone (AvoidRegion in C++) |
stayWithin and avoid convert the Region they’re given, so route code doesn’t
need asKeepIn() or asAvoidZone().
Zone
Zone.named(id) (Zone::named in C++) refers to a pack element by its TOML
id, and the element can be an obstacle, region, terrain or avoid zone. The id
is looked up when the method that takes the Zone runs.
Terrain
Terrain.named(id) refers to a [[terrain]] entry, and each modifier returns a
new Terrain.
| Modifier | Effect |
|---|---|
crossingDepth(depth) (crossing_depth) | When the straight leg misses the terrain, cross this far in from its nearest edge toward its center, capped at the center. Zero, the default, uses the near edge. |
target(pose) | Cross through the pose’s position, holding its heading |
target(pose, heading) | The pose’s position with this heading |
target(point), target(x, y) | Cross through the point, keeping the incoming heading |
target(point, heading), target(x, y, heading) | The point with this heading |
Java takes depth as Distance or meters, and headings as radians, Rotation2d
or Angle.
Python and C++ take meters and radians.
Python also takes a Rotation2d heading. In Python the coordinate form with a
heading is target(x, y, heading_rad=h), because the second positional argument
is y.
- A required heading is reached before the footprint enters the terrain and held until the robot’s center is past the terrain’s far edge, and travel follows a straight line through the target.
- The target must lie on the terrain, and a target that can’t be reached fails planning.
- The crossing completes when the robot passes within 0.05 m of the target and
its center passes the terrain’s far edge along that line, with 0.05 rad of
heading error allowed. A missed crossing fails the leg, and the leg then runs
its
runOnFailurerecovery. - A targeted leg with a required heading, rotation targets or
facingTravel()stops at the waypoints on either side. A differential drive can require only the heading of straight travel.
Crossing console lines
A crossing that can’t be planned or driven prints one line for its leg. Each line starts
[Tempo] leg {n} (target {x}, {y}): crossing '{id}'. n counts the route’s legs from 1,
and the target is the leg’s waypoint in the coordinates the robot drives. On a leg with
several crossings where the one that failed isn’t known, the line names them all as
one of crossings 'a', 'b'.
| Line continues | When |
|---|---|
cannot be reached: {reason}; the leg drives to its target without crossing it | A crossing without a target that no plan reaches, so the leg routes around the terrain. Without a reason when none of the checks below finds one |
cannot be reached: {reason}; a crossing with a target has no fallback, so the leg has no route | A targeted crossing that no plan reaches, so the leg is skipped. When the leg has no route even without its crossings, or none of the reasons in the next table applies, only the leg’s has no plannable route; skipped line prints |
failed: {reason}; the leg fails | A targeted crossing’s heading check failed while the robot drove it |
was not completed when {end}: {reason}; the leg fails | The leg reached its target, timed out or ended on endWhen before the crossing was driven |
The reasons for a crossing no plan reaches:
| Reason | Cause |
|---|---|
the robot does not fit at the crossing's entry ({x}, {y}): {why}, with target or exit in place of entry | A point of a targeted crossing’s line is within the robot’s reach of an obstacle (named by id) or the field wall, outside a stayWithin region, or inside an avoid zone |
its target is not on the terrain | The crossing’s target point is outside the terrain’s shape |
the robot needs {r} m clear around its center to sit at any heading, and no spot on the terrain has that much room from the obstacles beside it | No point of the terrain is r clear of the obstacles around it, where r is the footprint’s circumradius |
no route reaches the crossing's entry at ({x}, {y}) | The leg’s start, or the crossing before, has no route to the crossing |
no route leads from the crossing's exit at ({x}, {y}) to the leg's target | The far side of the crossing has no route to the waypoint |
The reasons for a crossing that fails or isn’t completed:
| Reason | Cause |
|---|---|
the robot stopped turning toward the crossing's heading before it reached the terrain | The heading stopped closing on the required heading before the terrain |
the robot moved off before it had turned to the crossing's heading | The robot drove away from where it turns to the required heading |
the robot's heading was more than 2.9 deg off the crossing's heading while it was on the terrain | The heading was more than 0.05 rad from the required heading on the terrain |
the robot reached the terrain {d} m beside the crossing's line, more than the 0.10 m the line allows, so it never entered the crossing | The robot’s center was d m to the side of the straight line through the target when its body reached the terrain |
the robot reached the terrain without passing through the crossing's entry | The robot reached the terrain on the line and at the heading, but never passed the start of the line, as after a pose reset onto the terrain |
the robot never drove onto the terrain | The robot’s center never came within 0.05 m of the terrain of a crossing without a target |
the robot never reached the crossing's entry | The leg ended before the straight line through the target began |
the robot reached the crossing's entry but did not pass through its target | The robot left the line before passing within 0.05 m of the target |
the terrain's far edge lies {d} m past the leg's target, and the robot's center did not pass it before the leg ended | Measured along the crossing’s line, the terrain’s far edge is d m beyond the leg’s waypoint, and d includes a 2 cm allowance. The waypoint can be beside the terrain and not on it. Move the waypoint at least d m farther along the line |
the robot passed the target but its center did not pass the terrain's far edge | The robot left the line before its center was past the terrain |
Errors
| Cause | Result |
|---|---|
| Rectangle min not below max | region rectangle: minX/minY must be strictly less than maxX/maxY (min_x/min_y and max_x/max_y in Python and C++) |
| Circle radius not positive | region circle: radius must be positive; got {value} |
| Square side not positive | region square: side length must be positive; got {value} |
Zone.named blank (Java) | zone id must not be blank |
Terrain.named blank | terrain id must not be blank |
| Negative or non-finite depth | [Tempo] crossing depth must be finite and >= 0 |
| Depth and a target together | [Tempo] positive crossing depth cannot be combined with a target |
Region.zone, near or stayWithin(Zone) with an unknown id | no field element named '{id}' in the game pack |
cross with an unknown id | cross(Terrain.named("{id}")): no terrain in the game pack has that id. ... |
cross with an obstacle, region or avoid zone id | cross(Terrain.named("{id}")): the pack has an obstacle or region with that id, not a crossable terrain feature. ... (an avoid zone for an avoid zone id) |
ignore or allow with an unknown id | Nothing is thrown and the route still runs. The console prints a line that starts [Tempo] ignore(Zone.named("{id}")) does nothing: ... (allow(...) for allow) and lists the pack’s avoid zones |
| Error | Java | Python | C++ |
|---|---|---|---|
| Shape and depth errors | IllegalArgumentException | ValueError | std::invalid_argument |
Blank Terrain id, and in Java a blank Zone id | TempoException | ValueError | std::invalid_argument |
Unknown id in Region.zone, near or stayWithin(Zone) | TempoException | TempoException | std::runtime_error, with tempo: before the message |
cross id errors | TempoException | TempoException | std::invalid_argument |
C++ drops the ; got value from shape errors.
Java and Python also send the ignore/allow line to the Driver Station.
In the cross messages, Python quotes the id as '{id}' and C++ writes Terrain::named.