Class LightningOdometer


  • public class LightningOdometer
    extends java.lang.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.

    • Constructor Summary

      Constructors 
      Constructor Description
      LightningOdometer​(edu.wpi.first.math.geometry.Rotation2d gyroAngle)
      Constructs a DifferentialDriveOdometry object with the default pose at the origin.
      LightningOdometer​(edu.wpi.first.math.geometry.Rotation2d gyroAngle, edu.wpi.first.math.geometry.Pose2d initialPoseMeters)
      Constructs a DifferentialDriveOdometry object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      edu.wpi.first.math.geometry.Pose2d getPoseMeters()
      Returns the position of the robot on the field.
      void resetPosition​(edu.wpi.first.math.geometry.Pose2d poseMeters, edu.wpi.first.math.geometry.Rotation2d gyroAngle)
      Resets the robot's position on the field.
      void setPose​(edu.wpi.first.math.geometry.Pose2d pose)  
      edu.wpi.first.math.geometry.Pose2d update​(edu.wpi.first.math.geometry.Rotation2d gyroAngle, double leftDistanceMeters, double rightDistanceMeters)
      Updates the robot position on the field using distance measurements from encoders.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LightningOdometer

        public LightningOdometer​(edu.wpi.first.math.geometry.Rotation2d gyroAngle,
                                 edu.wpi.first.math.geometry.Pose2d initialPoseMeters)
        Constructs a DifferentialDriveOdometry object.
        Parameters:
        gyroAngle - The angle reported by the gyroscope.
        initialPoseMeters - The starting position of the robot on the field.
      • LightningOdometer

        public LightningOdometer​(edu.wpi.first.math.geometry.Rotation2d gyroAngle)
        Constructs a DifferentialDriveOdometry object with the default pose at the origin.
        Parameters:
        gyroAngle - The angle reported by the gyroscope.
    • Method Detail

      • resetPosition

        public void resetPosition​(edu.wpi.first.math.geometry.Pose2d poseMeters,
                                  edu.wpi.first.math.geometry.Rotation2d gyroAngle)
        Resets the robot's position on the field.

        You NEED to reset your encoders (to zero) when calling this method.

        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:
        poseMeters - The position on the field that your robot is at.
        gyroAngle - The angle reported by the gyroscope.
      • setPose

        public void setPose​(edu.wpi.first.math.geometry.Pose2d pose)
      • getPoseMeters

        public edu.wpi.first.math.geometry.Pose2d getPoseMeters()
        Returns the position of the robot on the field.
        Returns:
        The pose of the robot (x and y are in meters).
      • update

        public edu.wpi.first.math.geometry.Pose2d update​(edu.wpi.first.math.geometry.Rotation2d gyroAngle,
                                                         double leftDistanceMeters,
                                                         double rightDistanceMeters)
        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.
        leftDistanceMeters - The distance traveled by the left encoder.
        rightDistanceMeters - The distance traveled by the right encoder.
        Returns:
        The new pose of the robot.