Class AnalogEncoder
java.lang.Object
org.wpilib.hardware.rotation.AnalogEncoder
- All Implemented Interfaces:
AutoCloseable, TelemetryLoggable
Class for supporting continuous analog encoders, such as the US Digital MA3.
-
Constructor Summary
ConstructorsConstructorDescriptionAnalogEncoder(int channel) Construct a new AnalogEncoder attached to a specific AnalogIn channel.AnalogEncoder(int channel, double fullRange, double expectedZero) Construct a new AnalogEncoder attached to a specific AnalogIn channel.AnalogEncoder(AnalogInput analogInput) Construct a new AnalogEncoder attached to a specific AnalogInput.AnalogEncoder(AnalogInput analogInput, double fullRange, double expectedZero) Construct a new AnalogEncoder attached to a specific AnalogInput. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()doubleget()Get the encoder value.intGet the channel number.Gets the telemetry table type.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.voidsetInverted(boolean inverted) Set if this encoder is inverted.voidsetVoltagePercentageRange(double min, double max) Set the encoder voltage percentage range.
-
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 tofullRange- the value to report at maximum travelexpectedZero- the reading where you would expect a 0 from get()
-
AnalogEncoder
Construct a new AnalogEncoder attached to a specific AnalogInput.- Parameters:
analogInput- the analog input to attach tofullRange- the value to report at maximum travelexpectedZero- 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
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:
closein interfaceAutoCloseable
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets 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:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-