Class AnalogPotentiometer

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

public class AnalogPotentiometer extends Object implements TelemetryLoggable, AutoCloseable
Class for reading analog potentiometers. Analog potentiometers read in an analog voltage that corresponds to a position. The position is in whichever units you choose, by way of the scaling and offset constants passed to the constructor.
  • Constructor Details

    • AnalogPotentiometer

      public AnalogPotentiometer(int channel, double fullRange, double offset)
      AnalogPotentiometer constructor.

      Use the fullRange and offset values so that the output produces meaningful values. I.E: you have a 270 degree potentiometer, and you want the output to be degrees with the halfway point as 0 degrees. The fullRange value is 270.0(degrees) and the offset is -135.0 since the halfway point after scaling is 135 degrees. This will calculate the result from the fullRange times the fraction of the supply voltage, plus the offset.

      Parameters:
      channel - The SmartIO channel this potentiometer is plugged into.
      fullRange - The scaling to multiply the fraction by to get a meaningful unit.
      offset - The offset to add to the scaled value for controlling the zero value
    • AnalogPotentiometer

      public AnalogPotentiometer(AnalogInput input, double fullRange, double offset)
      AnalogPotentiometer constructor.

      Use the fullRange and offset values so that the output produces meaningful values. I.E: you have a 270 degree potentiometer, and you want the output to be degrees with the halfway point as 0 degrees. The fullRange value is 270.0(degrees) and the offset is -135.0 since the halfway point after scaling is 135 degrees. This will calculate the result from the fullRange times the fraction of the supply voltage, plus the offset.

      Parameters:
      input - The AnalogInput this potentiometer is plugged into.
      fullRange - The angular value (in desired units) representing the full 0-3.3V range of the input.
      offset - The angular value (in desired units) representing the angular output at 0V.
    • AnalogPotentiometer

      public AnalogPotentiometer(int channel, double scale)
      AnalogPotentiometer constructor.

      Use the scale value so that the output produces meaningful values. I.E: you have a 270 degree potentiometer, and you want the output to be degrees with the starting point as 0 degrees. The scale value is 270.0(degrees).

      Parameters:
      channel - The analog input channel this potentiometer is plugged into.
      scale - The scaling to multiply the voltage by to get a meaningful unit.
    • AnalogPotentiometer

      public AnalogPotentiometer(AnalogInput input, double scale)
      AnalogPotentiometer constructor.

      Use the fullRange and offset values so that the output produces meaningful values. I.E: you have a 270 degree potentiometer, and you want the output to be degrees with the starting point as 0 degrees. The scale value is 270.0(degrees).

      Parameters:
      input - The AnalogInput this potentiometer is plugged into.
      scale - The scaling to multiply the voltage by to get a meaningful unit.
    • AnalogPotentiometer

      public AnalogPotentiometer(int channel)
      AnalogPotentiometer constructor.

      The potentiometer will return a value between 0 and 1.0.

      Parameters:
      channel - The analog input channel this potentiometer is plugged into.
    • AnalogPotentiometer

      public AnalogPotentiometer(AnalogInput input)
      AnalogPotentiometer constructor.

      The potentiometer will return a value between 0 and 1.0.

      Parameters:
      input - The AnalogInput this potentiometer is plugged into.
  • Method Details

    • get

      public double get()
      Get the current reading of the potentiometer.
      Returns:
      The current position of the potentiometer.
    • 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
    • close

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