Class AnalogEncoder

java.lang.Object
org.wpilib.hardware.rotation.AnalogEncoder
All Implemented Interfaces:
AutoCloseable, TelemetryLoggable

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

    • AnalogEncoder

      public AnalogEncoder(int channel, double fullRange, double expectedZero)
      Construct a new AnalogEncoder attached to a specific AnalogIn channel.
      Parameters:
      channel - the analog input channel to attach to
      fullRange - the value to report at maximum travel
      expectedZero - the reading where you would expect a 0 from get()
    • AnalogEncoder

      public AnalogEncoder(AnalogInput analogInput, double fullRange, double expectedZero)
      Construct a new AnalogEncoder attached to a specific AnalogInput.
      Parameters:
      analogInput - the analog input to attach to
      fullRange - the value to report at maximum travel
      expectedZero - the reading where you would expect a 0 from get()
    • AnalogEncoder

      public AnalogEncoder(int channel)
      Construct a new AnalogEncoder attached to a specific AnalogIn channel.

      This has a fullRange of 1 and an expectedZero of 0.

      Parameters:
      channel - the analog input channel to attach to
    • AnalogEncoder

      public AnalogEncoder(AnalogInput analogInput)
      Construct a new AnalogEncoder attached to a specific AnalogInput.

      This has a fullRange of 1 and an expectedZero of 0.

      Parameters:
      analogInput - the analog input to attach to
  • Method Details

    • get

      public double get()
      Get the encoder value.
      Returns:
      the encoder value scaled by the full range input
    • setVoltagePercentageRange

      public void setVoltagePercentageRange(double min, double max)
      Set the encoder voltage percentage range. Analog sensors are not always fully stable at the end of their travel ranges. Shrinking this range down can help mitigate issues with that.
      Parameters:
      min - minimum voltage percentage (0-1 range)
      max - maximum voltage percentage (0-1 range)
    • setInverted

      public void setInverted(boolean inverted)
      Set if this encoder is inverted.
      Parameters:
      inverted - true to invert the encoder, false otherwise
    • getChannel

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

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

      public void logTo(TelemetryTable table)
      Description copied from interface: TelemetryLoggable
      Logs the object to a TelemetryTable.
      Specified by:
      logTo in interface TelemetryLoggable
      Parameters:
      table - telemetry table
    • getTelemetryType

      public String getTelemetryType()
      Description copied from interface: TelemetryLoggable
      Gets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.
      Specified by:
      getTelemetryType in interface TelemetryLoggable
      Returns:
      Table type