Class DifferentialDrivePoseEstimator

java.lang.Object
edu.wpi.first.math.estimator.DifferentialDrivePoseEstimator

public class DifferentialDrivePoseEstimator
extends Object
This class wraps an Unscented Kalman Filter to fuse latency-compensated vision measurements with differential drive encoder measurements. It will correct for noisy vision measurements and encoder drift. It is intended to be an easy drop-in for DifferentialDriveOdometry; in fact, if you never call addVisionMeasurement(edu.wpi.first.math.geometry.Pose2d, double) and only call update(edu.wpi.first.math.geometry.Rotation2d, edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds, double, double) then this will behave exactly the same as DifferentialDriveOdometry.

update(edu.wpi.first.math.geometry.Rotation2d, edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds, double, double) should be called every robot loop (if your robot loops are faster than the default then you should change the nominal delta time.) 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 exactly like regular encoder odometry.

The state-space system used internally has the following states (x), inputs (u), and outputs (y):

x = [x, y, theta, dist_l, dist_r]ᵀ in the field coordinate system containing x position, y position, heading, left encoder distance, and right encoder distance.

u = [v_l, v_r, dtheta]ᵀ containing left wheel velocity, right wheel velocity, and change in gyro heading.

NB: Using velocities make things considerably easier, because it means that teams don't have to worry about getting an accurate model. Basically, we suspect that it's easier for teams to get good encoder data than it is for them to perform system identification well enough to get a good model.

y = [x, y, theta]ᵀ from vision containing x position, y position, and heading; or y = [dist_l, dist_r, theta] containing left encoder position, right encoder position, and gyro heading.

  • Constructor Details

    • DifferentialDrivePoseEstimator

      public DifferentialDrivePoseEstimator​(Rotation2d gyroAngle, Pose2d initialPoseMeters, Matrix<N5,​N1> stateStdDevs, Matrix<N3,​N1> localMeasurementStdDevs, Matrix<N3,​N1> visionMeasurementStdDevs)
      Constructs a DifferentialDrivePoseEstimator.
      Parameters:
      gyroAngle - The current gyro angle.
      initialPoseMeters - The starting pose estimate.
      stateStdDevs - Standard deviations of model states. Increase these numbers to trust your model's state estimates less. This matrix is in the form [x, y, theta, dist_l, dist_r]ᵀ, with units in meters and radians.
      localMeasurementStdDevs - Standard deviations of the encoder and gyro measurements. Increase these numbers to trust sensor readings from encoders and gyros less. This matrix is in the form [dist_l, dist_r, theta]ᵀ, with units in meters and radians.
      visionMeasurementStdDevs - Standard deviations of the vision measurements. Increase these numbers to trust global measurements from vision less. This matrix is in the form [x, y, theta]ᵀ, with units in meters and radians.
    • DifferentialDrivePoseEstimator

      public DifferentialDrivePoseEstimator​(Rotation2d gyroAngle, Pose2d initialPoseMeters, Matrix<N5,​N1> stateStdDevs, Matrix<N3,​N1> localMeasurementStdDevs, Matrix<N3,​N1> visionMeasurementStdDevs, double nominalDtSeconds)
      Constructs a DifferentialDrivePoseEstimator.
      Parameters:
      gyroAngle - The current gyro angle.
      initialPoseMeters - The starting pose estimate.
      stateStdDevs - Standard deviations of model states. Increase these numbers to trust your model's state estimates less. This matrix is in the form [x, y, theta, dist_l, dist_r]ᵀ, with units in meters and radians.
      localMeasurementStdDevs - Standard deviations of the encoder and gyro measurements. Increase these numbers to trust sensor readings from encoders and gyros less. This matrix is in the form [dist_l, dist_r, theta]ᵀ, with units in meters and radians.
      visionMeasurementStdDevs - Standard deviations of the vision measurements. Increase these numbers to trust global measurements from vision less. This matrix is in the form [x, y, theta]ᵀ, with units in meters and radians.
      nominalDtSeconds - The time in seconds between each robot loop.
  • Method Details