SwerveDrive4PoseEstimator

class wpimath.SwerveDrive4PoseEstimator(*args, **kwargs)

Bases: SwerveDrive4PoseEstimatorBase

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 for SwerveDriveOdometry.

update() should be called every robot loop.

addVisionMeasurement() can be called as infrequently as you want; if you never call it, then this class will behave as regular encoder odometry.

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

\(x = [x, y, \theta]^T\) in the field-coordinate system containing x position, y position, and heading.

\(y = [x, y, \theta]^T\) from vision containing x position, y position, and heading; or \(y = [theta]^T\) containing gyro heading.

Overloaded function.

  1. __init__(self: wpimath._wpimath.SwerveDrive4PoseEstimator, kinematics: wpimath._wpimath.SwerveDrive4Kinematics, gyroAngle: wpimath._wpimath.Rotation2d, modulePositions: Tuple[wpimath._wpimath.SwerveModulePosition, wpimath._wpimath.SwerveModulePosition, wpimath._wpimath.SwerveModulePosition, wpimath._wpimath.SwerveModulePosition], initialPose: wpimath._wpimath.Pose2d) -> None

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 and rotation measurements of the swerve modules.

  • initialPose – The starting pose estimate.

  1. __init__(self: wpimath._wpimath.SwerveDrive4PoseEstimator, kinematics: wpimath._wpimath.SwerveDrive4Kinematics, gyroAngle: wpimath._wpimath.Rotation2d, modulePositions: Tuple[wpimath._wpimath.SwerveModulePosition, wpimath._wpimath.SwerveModulePosition, wpimath._wpimath.SwerveModulePosition, wpimath._wpimath.SwerveModulePosition], initialPose: wpimath._wpimath.Pose2d, stateStdDevs: Tuple[typing.SupportsFloat | typing.SupportsIndex, typing.SupportsFloat | typing.SupportsIndex, typing.SupportsFloat | typing.SupportsIndex], visionMeasurementStdDevs: Tuple[typing.SupportsFloat | typing.SupportsIndex, typing.SupportsFloat | typing.SupportsIndex, typing.SupportsFloat | typing.SupportsIndex]) -> None

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.

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