DifferentialDriveOdometry

class wpimath.kinematics.DifferentialDriveOdometry(gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: meters, rightDistance: meters, initialPose: wpimath.geometry._geometry.Pose2d = Pose2d(Translation2d(x=0.000000, y=0.000000), Rotation2d(0.000000)))

Bases: pybind11_object

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.

Constructs a DifferentialDriveOdometry object.

IF leftDistance and rightDistance are unspecified, You NEED to reset your encoders (to zero).

Parameters:
  • gyroAngle – The angle reported by the gyroscope.

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

getPose() wpimath.geometry._geometry.Pose2d

Returns the position of the robot on the field.

Returns:

The pose of the robot.

resetPosition(gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: meters, rightDistance: meters, pose: wpimath.geometry._geometry.Pose2d) None

Resets the robot’s position on the field.

IF leftDistance and rightDistance are unspecified, You NEED to reset your encoders (to zero).

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

Parameters:
  • pose – The position on the field that your robot is at.

  • gyroAngle – The angle reported by the gyroscope.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

update(gyroAngle: wpimath.geometry._geometry.Rotation2d, leftDistance: meters, rightDistance: meters) wpimath.geometry._geometry.Pose2d

Updates the robot position on the field using distance measurements from encoders. This method is more numerically accurate than using velocities to integrate the pose and is also advantageous for teams that are using lower CPR encoders.

Parameters:
  • gyroAngle – The angle reported by the gyroscope.

  • leftDistance – The distance traveled by the left encoder.

  • rightDistance – The distance traveled by the right encoder.

Returns:

The new pose of the robot.