Class DifferentialDriveOdometry

java.lang.Object
org.wpilib.math.kinematics.Odometry<DifferentialDriveWheelPositions>
org.wpilib.math.kinematics.DifferentialDriveOdometry

public class DifferentialDriveOdometry extends Odometry<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.

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

    • DifferentialDriveOdometry

      public DifferentialDriveOdometry(Rotation2d gyroAngle, double leftDistance, double rightDistance, Pose2d initialPose)
      Constructs a DifferentialDriveOdometry 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.
    • DifferentialDriveOdometry

      public DifferentialDriveOdometry(Rotation2d gyroAngle, Distance leftDistance, Distance rightDistance, Pose2d initialPose)
      Constructs a DifferentialDriveOdometry 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.
    • DifferentialDriveOdometry

      public DifferentialDriveOdometry(Rotation2d gyroAngle, double leftDistance, double rightDistance)
      Constructs a DifferentialDriveOdometry 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.
    • DifferentialDriveOdometry

      public DifferentialDriveOdometry(Rotation2d gyroAngle, Distance leftDistance, Distance rightDistance)
      Constructs a DifferentialDriveOdometry 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.
  • Method Details

    • resetPosition

      public void resetPosition(Rotation2d gyroAngle, double leftDistance, double rightDistance, Pose2d 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. 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.
      pose - The position on the field that your robot is at.
    • resetPosition

      public void resetPosition(Rotation2d gyroAngle, Distance leftDistance, Distance rightDistance, Pose2d 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. 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.
      pose - The position on the field that your robot is at.
    • update

      public Pose2d update(Rotation2d 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. 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.
      Returns:
      The new pose of the robot.