Class TagEkf
java.lang.Object
frc.spectrumLib.localization.TagEkf
An extended Kalman filter over (x, y, heading) that takes every camera's tags one at a time, in
the style of 971's AOS localizer: each tag is a bearing and a distance from its camera, so a
single or far tag still corrects the pose at a low weight instead of being thrown away, and every
camera feeds the same estimate.
- Predict on every odometry sample: wheel translation, gyro heading change. Variance grows with distance driven, and more when the modules disagree with each other or with the gyro (slip). Heading gets very little.
- Correct per tag, at the frame's capture time. About
HISTORY_SECONDSof states are kept; a frame is inserted at its time and odometry and later frames are replayed over it, so the result does not depend on arrival order. - Reject a tag whose innovation fails a chi-squared test. If tags keep failing for
RELOCALIZE_SECONDS, the covariance is widened so the cameras can pull it back.
Noise values are starting points to tune against logs, not measured.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classPer-camera tag counts, and this loop's residuals of the tags that passed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFrame(List<TagSighting> frame) Applies one camera frame's tags.voidaddOdometry(double timestampSeconds, Rotation2d gyro, SwerveModulePosition[] positions) Predicts with one odometry sample.voidApplies a whole-pose measurement at its capture time (the seed every track shares).voidClears this loop's residuals; call after logging.longgetPose()longlongdouble[]Std-devs [x m, y m, heading rad].booleanisSeeded()voidHard-resets the pose (auto start, driver reorient).voidsetOdometryNoiseScale(double scale) Multiplies odometry translation variance, e.g.voidCounts a tag the caller chose not to apply.
-
Constructor Details
-
TagEkf
- Parameters:
moduleLocations- module positions from the robot centre, robot frame
-
-
Method Details
-
setOdometryNoiseScale
public void setOdometryNoiseScale(double scale) Multiplies odometry translation variance, e.g. while the robot is tilted on a bump.- Parameters:
scale- 1 for normal driving
-
addOdometry
Predicts with one odometry sample.- Parameters:
timestampSeconds- sample timegyro- gyro yawpositions- module positions, same order as the locations
-
reset
Hard-resets the pose (auto start, driver reorient). Frames captured before it are dropped.- Parameters:
pose- the new pose
-
addPose
Applies a whole-pose measurement at its capture time (the seed every track shares).- Parameters:
pose- measured posetimestampSeconds- capture timexyStd- translation std-dev, metresthetaStd- heading std-dev, radians
-
addFrame
Applies one camera frame's tags. They must share one capture time.- Parameters:
frame- the frame's tags
-
skip
-
clearLoopStats
public void clearLoopStats()Clears this loop's residuals; call after logging. -
getPose
-
getStdDevs
public double[] getStdDevs()Std-devs [x m, y m, heading rad]. -
isSeeded
public boolean isSeeded() -
getAcceptedCount
public long getAcceptedCount() -
getRejectedCount
public long getRejectedCount() -
getRelocalizations
public long getRelocalizations() -
getRejectionCounts
-
getCameraStats
-