DifferentialDrivePoseEstimator

class wpimath.estimator.DifferentialDrivePoseEstimator(*args, **kwargs)

Bases: DifferentialDrivePoseEstimatorBase

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(), and only call update(), this will behave exactly the same as DifferentialDriveOdometry.

update() should be called every robot loop (if your robot loops are faster or slower than the default, then you should change the nominal delta time via the constructor).

addVisionMeasurement() can be called as infrequently as you want; if you never call it, then this class will behave 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]^T\) in the field coordinate system containing x position, y position, heading, left encoder distance, and right encoder distance.

\(u = [v_l, v_r, d\theta]^T\) 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]^T\) from vision containing x position, y position, and heading; or \(y = [dist_l, dist_r, \theta]^T\) containing left encoder position, right encoder position, and gyro heading.

Overloaded function.

  1. __init__(self: wpimath._controls._controls.estimator.DifferentialDrivePoseEstimator, kinematics: wpimath.kinematics._kinematics.DifferentialDriveKinematics, gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: wpimath.units.meters, rightDistance: wpimath.units.meters, initialPose: wpimath.geometry._geometry.Pose2d) -> None

Constructs a DifferentialDrivePoseEstimator with default standard deviations for the model and vision measurements.

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

Parameters:
  • kinematics – A correctly-configured kinematics object for your drivetrain.

  • gyroAngle – The gyro angle of the robot.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

  • initialPose – The estimated initial pose.

  1. __init__(self: wpimath._controls._controls.estimator.DifferentialDrivePoseEstimator, kinematics: wpimath.kinematics._kinematics.DifferentialDriveKinematics, gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: wpimath.units.meters, rightDistance: wpimath.units.meters, initialPose: wpimath.geometry._geometry.Pose2d, stateStdDevs: Tuple[float, float, float], visionMeasurementStdDevs: Tuple[float, float, float]) -> None

Constructs a DifferentialDrivePoseEstimator.

Parameters:
  • kinematics – A correctly-configured kinematics object for your drivetrain.

  • gyroAngle – The gyro angle of the robot.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

  • initialPose – The estimated initial pose.

  • 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.

resetPosition(gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: wpimath.units.meters, rightDistance: wpimath.units.meters, pose: wpimath.geometry._geometry.Pose2d) None

Resets the robot’s position on the field.

Parameters:
  • gyroAngle – The current gyro angle.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

  • pose – The estimated pose of the robot on the field.

update(gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: wpimath.units.meters, rightDistance: wpimath.units.meters) wpimath.geometry._geometry.Pose2d

Updates the pose estimator with wheel encoder and gyro information. This should be called every loop.

Parameters:
  • gyroAngle – The current gyro angle.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

Returns:

The estimated pose of the robot.

updateWithTime(currentTime: wpimath.units.seconds, gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: wpimath.units.meters, rightDistance: wpimath.units.meters) wpimath.geometry._geometry.Pose2d

Updates the pose estimator with wheel encoder and gyro information. This should be called every loop.

Parameters:
  • currentTime – The time at which this method was called.

  • gyroAngle – The current gyro angle.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

Returns:

The estimated pose of the robot.