Class AnalogEncoder

java.lang.Object
edu.wpi.first.wpilibj.AnalogEncoder
All Implemented Interfaces:
Sendable, AutoCloseable

public class AnalogEncoder
extends Object
implements Sendable, AutoCloseable
Class for supporting continuous analog encoders, such as the US Digital MA3.
  • Field Details

  • Constructor Details

    • AnalogEncoder

      public AnalogEncoder​(int channel)
      Construct a new AnalogEncoder attached to a specific AnalogIn channel.
      Parameters:
      channel - the analog input channel to attach to
    • AnalogEncoder

      public AnalogEncoder​(AnalogInput analogInput)
      Construct a new AnalogEncoder attached to a specific AnalogInput.
      Parameters:
      analogInput - the analog input to attach to
  • Method Details

    • get

      public double get()
      Get the encoder value since the last reset.

      This is reported in rotations since the last reset.

      Returns:
      the encoder value in rotations
    • getPositionOffset

      public double getPositionOffset()
      Get the offset of position relative to the last reset.

      getPositionInRotation() - getPositionOffset() will give an encoder absolute position relative to the last reset. This could potentially be negative, which needs to be accounted for.

      Returns:
      the position offset
    • setDistancePerRotation

      public void setDistancePerRotation​(double distancePerRotation)
      Set the distance per rotation of the encoder. This sets the multiplier used to determine the distance driven based on the rotation value from the encoder. Set this value based on the how far the mechanism travels in 1 rotation of the encoder, and factor in gearing reductions following the encoder shaft. This distance can be in any units you like, linear or angular.
      Parameters:
      distancePerRotation - the distance per rotation of the encoder
    • getDistancePerRotation

      public double getDistancePerRotation()
      Get the distance per rotation for this encoder.
      Returns:
      The scale factor that will be used to convert rotation to useful units.
    • getDistance

      public double getDistance()
      Get the distance the sensor has driven since the last reset as scaled by the value from setDistancePerRotation(double).
      Returns:
      The distance driven since the last reset
    • getChannel

      public int getChannel()
      Get the channel number.
      Returns:
      The channel number.
    • reset

      public void reset()
      Reset the Encoder distance to zero.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • initSendable

      public void initSendable​(SendableBuilder builder)
      Description copied from interface: Sendable
      Initializes this Sendable object.
      Specified by:
      initSendable in interface Sendable
      Parameters:
      builder - sendable builder