2.1 Alliance flipping
originAlliance(BLUE) marks a Setlist or Composer
as written for blue, and blue is also the default. When the robot is on
red, Tempo mirrors the route’s poses and headings to the red side before
planning it.
Write the route for blue
import com.tempo.Alliance;
import com.tempo.Composer;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
Pose2d START_CENTER = new Pose2d(7.58, 4.03, Rotation2d.fromDegrees(180));
Pose2d REEF_G = new Pose2d(5.77, 4.03, Rotation2d.fromDegrees(180));
Composer approach = Composer.startAt(START_CENTER)
.originAlliance(Alliance.BLUE)
.to(REEF_G);from tempo import Alliance, Composer
from wpimath.geometry import Pose2d, Rotation2d
START_CENTER = Pose2d(7.58, 4.03, Rotation2d.fromDegrees(180))
REEF_G = Pose2d(5.77, 4.03, Rotation2d.fromDegrees(180))
approach = (Composer.start_at(START_CENTER)
.origin_alliance(Alliance.BLUE)
.to(REEF_G))#include <frc/geometry/Pose2d.h>
#include <tempo/Composer.h>
const frc::Pose2d START_CENTER{7.58_m, 4.03_m, 180_deg};
const frc::Pose2d REEF_G{5.77_m, 4.03_m, 180_deg};
auto approach = tempo::Composer::start_at(START_CENTER)
.origin_alliance(tempo::Alliance::Blue)
.to(REEF_G);Don’t mirror the poses in robot code when the robot is on red, or they get flipped twice.
When the route is flipped
Tempo reads the robot’s alliance when it plans a route ahead of time and again when the route starts. If that alliance is the opposite of the origin alliance, the route is mirrored. A route keeps the alliance it started with until it ends, so an alliance change takes effect on the next route.
For a pack with rotational symmetry:
x' = 2 * cx - x
y' = 2 * cy - y
theta' = wrap_pi(theta + pi)A pack with symmetry = "mirror" reflects X across the center line, keeps Y,
and maps a heading to pi - theta. A pack with symmetry = "none" still flips
routes with the rotational formula. none only stops the pack from
building red copies of its field elements. In a pack whose origin is
fieldCenter, the center is (0, 0).
Targets read from a supplier while the robot drives are in the field frame and
are never flipped. To mirror a single pose or point yourself, use
Field.mirror (Mirroring).
Where the alliance comes from
Tempo reads the alliance from the Driver Station. If your robot has its own
alliance logic, pass it to Tempo.configure(...) right after the config. It’s optional
and takes anything that returns true on red, like 6328’s AllianceFlipUtil.shouldFlip():
Tempo.configure(this::getPose, this::resetPose, this::getRobotRelativeSpeeds,
this::driveRobotRelative, CONFIG,
AllianceFlipUtil::shouldFlip, this);Tempo.configure(self.get_pose, self.reset_pose, self.get_robot_relative_speeds,
self.drive_robot_relative, CONFIG,
AllianceFlipUtil.should_flip, self)tempo::wpi::configure(
[this] { return GetPose(); },
[this](const frc::Pose2d& pose) { ResetPose(pose); },
[this] { return GetRobotRelativeSpeeds(); },
[this](const frc::ChassisSpeeds& speeds) { RunVelocity(speeds); },
kConfig,
AllianceFlipUtil::ShouldFlip,
{this});tempo::wpi::configure(...) reads the Driver Station. A robot that connects its
drivetrain some other way runs every route as blue unless it passes the check to
tempo::Tempo::configure(config, check) (Alliance, C++).
Every language uses blue when the Driver Station reports no alliance, for example before it connects or in a simulation without one. A route written for blue then runs as written and a route written for red is flipped to blue. Check the alliance the robot reports before a field run.
Neutral routes
A route with originAlliance(Alliance.NEUTRAL)
(origin_alliance(Alliance.NEUTRAL) in Python,
origin_alliance(tempo::Alliance::Neutral) in C++) is never flipped and runs
the same coordinates on both alliances. Use it for targets that are fixed on
the field and for tests.
Tests
To test the red side, pass a check that returns true after the test’s config.
Tempo.configure(CONFIG, () -> true);Tempo.configure(CONFIG, lambda: True)tempo::Tempo::configure(kConfig, [] { return true; });Test an auto covers setting up the Driver Station for a red run.
If it fails…
The poses were mirrored in robot code as well as by Tempo, so they were flipped twice. Write them for blue and leave the mirroring to originAlliance.
No alliance was reported, so Tempo used blue. Check the Driver Station connection, or the alliance check passed to Tempo.configure(...).
The robot wasn’t set up with tempo::wpi::configure(...), so nothing reads the Driver Station. Pass the alliance check to tempo::Tempo::configure(...).