Class RobotPoseSubsystem
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable,edu.wpi.first.wpilibj2.command.Subsystem
All pose sources (cameras, LIDAR, future sensors) funnel their measurements through this subsystem via addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d, double, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1>). Fusion math
is delegated to the drivebase's internal YAGSL SwerveDrivePoseEstimator, which provides Kalman-filter-based
fusion with latency compensation and uncertainty weighting. This subsystem reads the fused result each cycle and exposes it as the authoritative
pose for commands and other subsystems.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRobotPoseSubsystem(RobotPoseSubsystemConfig config, Supplier<edu.wpi.first.math.geometry.Pose2d> fusedPoseSupplier, Supplier<edu.wpi.first.math.geometry.Pose2d> odometryOnlyPoseSupplier, VisionMeasurementConsumer visionForwarder, Consumer<edu.wpi.first.math.geometry.Pose2d> odometryResetConsumer) Creates the Robot Pose subsystem with all cross-subsystem dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVisionMeasurement(edu.wpi.first.math.geometry.Pose2d robotPose, double timestampSeconds, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1> standardDeviations) Accepts a vision-based robot pose measurement and forwards it to the drivebase's pose estimator for fusion.doublegetDistanceToPointMeters(edu.wpi.first.math.geometry.Translation2d targetFieldPositionMeters) Computes the straight-line distance from the robot's current estimated position to a field-relative target point.edu.wpi.first.math.geometry.Pose2dReturns the current fused pose estimate.voidperiodic()Reads the latest fused pose from the drivebase estimator and logs telemetry each robot loop.voidresetPose(edu.wpi.first.math.geometry.Pose2d pose) Resets all pose tracking to the provided pose.voidResets the robot pose to the most recent vision measurement.Methods inherited from class frc.robot.shared.subsystems.AbstractSubsystem
getConfig, isFMSAttached, isSimulation, isSubsystemDisabled, isVerbose, isVerboseLoggingEnabled, logDisabled, reportWarningMethods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
Method Details
-
periodic
public void periodic()Reads the latest fused pose from the drivebase estimator and logs telemetry each robot loop. -
addVisionMeasurement
public void addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d robotPose, double timestampSeconds, edu.wpi.first.math.Matrix<edu.wpi.first.math.numbers.N3, edu.wpi.first.math.numbers.N1> standardDeviations) Accepts a vision-based robot pose measurement and forwards it to the drivebase's pose estimator for fusion.All pose sources (cameras, LIDAR, etc.) should call this single method. The measurement is forwarded to the drivebase's YAGSL
SwerveDrivePoseEstimatorwhich handles Kalman-filter-based fusion, latency compensation, and uncertainty weighting. When vision fusion is disabled in config, measurements are recorded for logging but not forwarded.- Parameters:
robotPose- pose measurement in meters and radianstimestampSeconds- FPGA timestamp of the measurement in secondsstandardDeviations- uncertainty in x (meters), y (meters), and rotation (radians)
-
resetPose
public void resetPose(edu.wpi.first.math.geometry.Pose2d pose) Resets all pose tracking to the provided pose.Use this at the start of autonomous or after localization resets so odometry and vision agree on the robot's position. The reset is forwarded to the drivebase so the internal YAGSL estimator is also reset.
- Parameters:
pose- pose to apply to odometry and the fused estimate in meters and radians
-
resetPoseFromVision
public void resetPoseFromVision()Resets the robot pose to the most recent vision measurement.Call this at the start of a match to seed the pose estimator with the camera-derived position before switching to fused odometry-plus-vision tracking. If no vision measurement has been received yet, the reset is skipped and a warning is logged so operators can diagnose camera issues.
-
getEstimatedPose
public edu.wpi.first.math.geometry.Pose2d getEstimatedPose()Returns the current fused pose estimate.Commands and subsystems should use this pose for field-relative decisions. This is the single authoritative source of robot pose for the entire codebase.
- Returns:
- latest fused pose in meters and radians
-
getDistanceToPointMeters
public double getDistanceToPointMeters(edu.wpi.first.math.geometry.Translation2d targetFieldPositionMeters) Computes the straight-line distance from the robot's current estimated position to a field-relative target point.Use this for distance-based calculations such as shooter RPM scaling or approach detection.
- Parameters:
targetFieldPositionMeters- target position on the field in meters- Returns:
- distance in meters from the robot to the target point
-