SwerveDrive6PoseEstimatorBase

class wpimath.estimator.SwerveDrive6PoseEstimatorBase(kinematics: wpimath.kinematics._kinematics.SwerveDrive6KinematicsBase, odometry: wpimath.kinematics._kinematics.SwerveDrive6OdometryBase, stateStdDevs: Tuple[float, float, float], visionMeasurementStdDevs: Tuple[float, float, float])

Bases: pybind11_object

This class wraps odometry to fuse latency-compensated vision measurements with encoder measurements. Robot code should not use this directly- Instead, use the particular type for your drivetrain (e.g., DifferentialDrivePoseEstimator). It will correct for noisy vision measurements and encoder drift. It is intended to be an easy drop-in for Odometry.

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 like regular encoder odometry.

@tparam WheelSpeeds Wheel speeds type. @tparam WheelPositions Wheel positions type.

Constructs a PoseEstimator.

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

  • odometry – A correctly-configured odometry object for your drivetrain.

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

addVisionMeasurement(*args, **kwargs)

Overloaded function.

  1. addVisionMeasurement(self: wpimath._controls._controls.estimator.SwerveDrive6PoseEstimatorBase, visionRobotPose: wpimath.geometry._geometry.Pose2d, timestamp: wpimath.units.seconds) -> None

Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.

This method can be called as infrequently as you want, as long as you are calling Update() every loop.

To promote stability of the pose estimate and make it robust to bad vision data, we recommend only adding vision measurements that are already within one meter or so of the current pose estimate.

Parameters:
  • visionRobotPose – The pose of the robot as measured by the vision camera.

  • timestamp – The timestamp of the vision measurement in seconds. Note that if you don’t use your own time source by calling UpdateWithTime(), then you must use a timestamp with an epoch since FPGA startup (i.e., the epoch of this timestamp is the same epoch as frc::Timer::GetFPGATimestamp(). This means that you should use frc::Timer::GetFPGATimestamp() as your time source in this case.

  1. addVisionMeasurement(self: wpimath._controls._controls.estimator.SwerveDrive6PoseEstimatorBase, visionRobotPose: wpimath.geometry._geometry.Pose2d, timestamp: wpimath.units.seconds, visionMeasurementStdDevs: Tuple[float, float, float]) -> None

Adds a vision measurement to the Kalman Filter. This will correct the odometry pose estimate while still accounting for measurement noise.

This method can be called as infrequently as you want, as long as you are calling Update() every loop.

To promote stability of the pose estimate and make it robust to bad vision data, we recommend only adding vision measurements that are already within one meter or so of the current pose estimate.

Note that the vision measurement standard deviations passed into this method will continue to apply to future measurements until a subsequent call to SetVisionMeasurementStdDevs() or this method.

Parameters:
  • visionRobotPose – The pose of the robot as measured by the vision camera.

  • timestamp – The timestamp of the vision measurement in seconds. Note that if you don’t use your own time source by calling UpdateWithTime(), then you must use a timestamp with an epoch since FPGA startup (i.e., the epoch of this timestamp is the same epoch as frc::Timer::GetFPGATimestamp(). This means that you should use frc::Timer::GetFPGATimestamp() as your time source in this case.

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

getEstimatedPosition() wpimath.geometry._geometry.Pose2d

Gets the estimated robot pose.

Returns:

The estimated robot pose in meters.

resetPosition(gyroAngle: wpimath.geometry._geometry.Rotation2d, wheelPositions: wpimath.kinematics._kinematics.SwerveDrive6WheelPositions, pose: wpimath.geometry._geometry.Pose2d) None

Resets the robot’s position on the field.

The gyroscope angle does not need to be reset in the user’s robot code. The library automatically takes care of offsetting the gyro angle.

Parameters:
  • gyroAngle – The current gyro angle.

  • wheelPositions – The distances traveled by the encoders.

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

setVisionMeasurementStdDevs(visionMeasurementStdDevs: Tuple[float, float, float]) None

Sets the pose estimator’s trust in vision measurements. This might be used to change trust in vision measurements after the autonomous period, or to change trust as distance to a vision target increases.

Parameters:

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.

update(gyroAngle: wpimath.geometry._geometry.Rotation2d, wheelPositions: wpimath.kinematics._kinematics.SwerveDrive6WheelPositions) 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.

  • wheelPositions – The distances traveled by the encoders.

Returns:

The estimated pose of the robot in meters.

updateWithTime(currentTime: wpimath.units.seconds, gyroAngle: wpimath.geometry._geometry.Rotation2d, wheelPositions: wpimath.kinematics._kinematics.SwerveDrive6WheelPositions) 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.

  • wheelPositions – The distances traveled by the encoders.

Returns:

The estimated pose of the robot in meters.