Package edu.wpi.first.math.estimator
Class SwerveDrivePoseEstimator3d
java.lang.Object
edu.wpi.first.math.estimator.PoseEstimator3d<SwerveModulePosition[]>
edu.wpi.first.math.estimator.SwerveDrivePoseEstimator3d
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 SwerveDriveOdometry3d
. It is also intended to be an easy
replacement for SwerveDrivePoseEstimator
, only requiring the addition of a standard
deviation for Z and appropriate conversions between 2D and 3D versions of geometry classes. (See
Pose3d(Pose2d)
, Rotation3d(Rotation2d)
, Translation3d(Translation2d)
, and Pose3d.toPose2d()
.)
PoseEstimator3d.update(edu.wpi.first.math.geometry.Rotation3d, T)
should be called every robot loop.
PoseEstimator3d.addVisionMeasurement(edu.wpi.first.math.geometry.Pose3d, double)
can be called as infrequently as you
want; if you never call it, then this class will behave as regular encoder odometry.
-
Constructor Summary
ConstructorDescriptionSwerveDrivePoseEstimator3d
(SwerveDriveKinematics kinematics, Rotation3d gyroAngle, SwerveModulePosition[] modulePositions, Pose3d initialPoseMeters) Constructs a SwerveDrivePoseEstimator3d with default standard deviations for the model and vision measurements.SwerveDrivePoseEstimator3d
(SwerveDriveKinematics kinematics, Rotation3d gyroAngle, SwerveModulePosition[] modulePositions, Pose3d initialPoseMeters, Matrix<N4, N1> stateStdDevs, Matrix<N4, N1> visionMeasurementStdDevs) Constructs a SwerveDrivePoseEstimator3d. -
Method Summary
Modifier and TypeMethodDescriptionupdateWithTime
(double currentTimeSeconds, Rotation3d gyroAngle, SwerveModulePosition[] wheelPositions) Updates the pose estimator with wheel encoder and gyro information.Methods inherited from class edu.wpi.first.math.estimator.PoseEstimator3d
addVisionMeasurement, addVisionMeasurement, getEstimatedPosition, resetPose, resetPosition, resetRotation, resetTranslation, sampleAt, setVisionMeasurementStdDevs, update
-
Constructor Details
-
SwerveDrivePoseEstimator3d
public SwerveDrivePoseEstimator3d(SwerveDriveKinematics kinematics, Rotation3d gyroAngle, SwerveModulePosition[] modulePositions, Pose3d initialPoseMeters) Constructs a SwerveDrivePoseEstimator3d 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, 0.1 meters for z, and 0.1 radians for angle. The default standard deviations of the vision measurements are 0.9 meters for x, 0.9 meters for y, 0.9 meters for z, and 0.9 radians for angle.
- 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.
-
SwerveDrivePoseEstimator3d
public SwerveDrivePoseEstimator3d(SwerveDriveKinematics kinematics, Rotation3d gyroAngle, SwerveModulePosition[] modulePositions, Pose3d initialPoseMeters, Matrix<N4, N1> stateStdDevs, Matrix<N4, N1> visionMeasurementStdDevs) Constructs a SwerveDrivePoseEstimator3d.- 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 Pose3d updateWithTime(double currentTimeSeconds, Rotation3d gyroAngle, SwerveModulePosition[] wheelPositions) Description copied from class:PoseEstimator3d
Updates the pose estimator with wheel encoder and gyro information. This should be called every loop.- Overrides:
updateWithTime
in classPoseEstimator3d<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.
-