Class DifferentialDriveOdometry3d

java.lang.Object
org.wpilib.math.kinematics.Odometry3d<DifferentialDriveWheelPositions>
org.wpilib.math.kinematics.DifferentialDriveOdometry3d

public class DifferentialDriveOdometry3d extends Odometry3d<DifferentialDriveWheelPositions>
Class for differential drive odometry. Odometry allows you to track the robot's position on the field over the course of a match using readings from 2 encoders and a gyroscope.

This class is meant to be an easy replacement for DifferentialDriveOdometry, only requiring the addition of appropriate conversions between 2D and 3D versions of geometry classes. (See Pose3d(Pose2d), Rotation3d(Rotation2d), Translation3d(Translation2d), and Pose3d.toPose2d().)

Teams can use odometry during the autonomous period for complex tasks like path following. Furthermore, odometry can be used for latency compensation when using computer-vision systems.

It is important that you reset your encoders to zero before using this class. Any subsequent pose resets also require the encoders to be reset to zero.

  • Constructor Details

    • DifferentialDriveOdometry3d

      public DifferentialDriveOdometry3d(Rotation3d gyroAngle, double leftDistance, double rightDistance, Pose3d initialPose)
      Constructs a DifferentialDriveOdometry3d object.
      Parameters:
      gyroAngle - The angle reported by the gyroscope. This does not need to be offset to match the robot's orientation on the field.
      leftDistance - The distance traveled by the left encoder in meters.
      rightDistance - The distance traveled by the right encoder in meters.
      initialPose - The starting position of the robot on the field.
    • DifferentialDriveOdometry3d

      public DifferentialDriveOdometry3d(Rotation3d gyroAngle, Distance leftDistance, Distance rightDistance, Pose3d initialPose)
      Constructs a DifferentialDriveOdometry3d object.
      Parameters:
      gyroAngle - The angle reported by the gyroscope. This does not need to be offset to match the robot's orientation on the field.
      leftDistance - The distance traveled by the left encoder.
      rightDistance - The distance traveled by the right encoder.
      initialPose - The starting position of the robot on the field.
    • DifferentialDriveOdometry3d

      public DifferentialDriveOdometry3d(Rotation3d gyroAngle, double leftDistance, double rightDistance)
      Constructs a DifferentialDriveOdometry3d object.
      Parameters:
      gyroAngle - The angle reported by the gyroscope.
      leftDistance - The distance traveled by the left encoder in meters.
      rightDistance - The distance traveled by the right encoder in meters.
    • DifferentialDriveOdometry3d

      public DifferentialDriveOdometry3d(Rotation3d gyroAngle, Distance leftDistance, Distance rightDistance)
      Constructs a DifferentialDriveOdometry3d object.
      Parameters:
      gyroAngle - The angle reported by the gyroscope.
      leftDistance - The distance traveled by the left encoder.
      rightDistance - The distance traveled by the right encoder.
  • Method Details

    • resetPosition

      public void resetPosition(Rotation3d gyroAngle, double leftDistance, double rightDistance, Pose3d pose)
      Resets the robot's position on the field.

      The gyroscope angle does not need to be reset here in the user's robot code.

      Parameters:
      gyroAngle - The angle reported by the gyroscope.
      leftDistance - The distance traveled by the left encoder in meters.
      rightDistance - The distance traveled by the right encoder in meters.
      pose - The position on the field that your robot is at.
    • resetPosition

      public void resetPosition(Rotation3d gyroAngle, Distance leftDistance, Distance rightDistance, Pose3d pose)
      Resets the robot's position on the field.

      The gyroscope angle does not need to be reset here in the user's robot code.

      Parameters:
      gyroAngle - The angle reported by the gyroscope.
      leftDistance - The distance traveled by the left encoder.
      rightDistance - The distance traveled by the right encoder.
      pose - The position on the field that your robot is at.
    • update

      public Pose3d update(Rotation3d gyroAngle, double leftDistance, double rightDistance)
      Updates the robot position on the field using distance measurements from encoders.
      Parameters:
      gyroAngle - The angle reported by the gyroscope.
      leftDistance - The distance traveled by the left encoder in meters.
      rightDistance - The distance traveled by the right encoder in meters.
      Returns:
      The new pose of the robot.