Class SwerveDrivePoseEstimator

java.lang.Object
edu.wpi.first.math.estimator.PoseEstimator<SwerveModulePosition[]>
edu.wpi.first.math.estimator.SwerveDrivePoseEstimator

This class wraps Swerve Drive Odometry to fuse latency-compensated vision measurements with swerve drive encoder distance measurements. It is intended to be a drop-in replacement for SwerveDriveOdometry.

PoseEstimator.update(edu.wpi.first.math.geometry.Rotation2d, T) should be called every robot loop.

PoseEstimator.addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d, double) can be called as infrequently as you want; if you never call it, then this class will behave as regular encoder odometry.

  • Constructor Details

    • SwerveDrivePoseEstimator

      public SwerveDrivePoseEstimator(SwerveDriveKinematics kinematics, Rotation2d gyroAngle, SwerveModulePosition[] modulePositions, Pose2d initialPoseMeters)
      Constructs a SwerveDrivePoseEstimator with default standard deviations for the model and vision measurements.

      The default standard deviations of the model states are 0.1 meters for x, 0.1 meters for y, and 0.1 radians for heading. The default standard deviations of the vision measurements are 0.9 meters for x, 0.9 meters for y, and 0.9 radians for heading.

      Parameters:
      kinematics - A correctly-configured kinematics object for your drivetrain.
      gyroAngle - The current gyro angle.
      modulePositions - The current distance measurements and rotations of the swerve modules.
      initialPoseMeters - The starting pose estimate.
    • SwerveDrivePoseEstimator

      public SwerveDrivePoseEstimator(SwerveDriveKinematics kinematics, Rotation2d gyroAngle, SwerveModulePosition[] modulePositions, Pose2d initialPoseMeters, Matrix<N3,N1> stateStdDevs, Matrix<N3,N1> visionMeasurementStdDevs)
      Constructs a SwerveDrivePoseEstimator.
      Parameters:
      kinematics - A correctly-configured kinematics object for your drivetrain.
      gyroAngle - The current gyro angle.
      modulePositions - The current distance and rotation measurements of the swerve modules.
      initialPoseMeters - The starting pose estimate.
      stateStdDevs - Standard deviations of the pose estimate (x position in meters, y position in meters, and heading in radians). Increase these numbers to trust your state estimate less.
      visionMeasurementStdDevs - Standard deviations of the vision pose measurement (x position in meters, y position in meters, and heading in radians). Increase these numbers to trust the vision pose measurement less.
  • Method Details

    • updateWithTime

      public Pose2d updateWithTime(double currentTimeSeconds, Rotation2d gyroAngle, SwerveModulePosition[] wheelPositions)
      Description copied from class: PoseEstimator
      Updates the pose estimator with wheel encoder and gyro information. This should be called every loop.
      Overrides:
      updateWithTime in class PoseEstimator<SwerveModulePosition[]>
      Parameters:
      currentTimeSeconds - Time at which this method was called, in seconds.
      gyroAngle - The current gyro angle.
      wheelPositions - The current encoder readings.
      Returns:
      The estimated pose of the robot in meters.