Package edu.wpi.first.wpilibj
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 Summary
Fields Modifier and Type Field Description protected SimDouble
m_simAbsolutePosition
protected SimDevice
m_simDevice
protected SimDouble
m_simPosition
-
Constructor Summary
Constructors Constructor Description AnalogEncoder(int channel)
Construct a new AnalogEncoder attached to a specific AnalogIn channel.AnalogEncoder(AnalogInput analogInput)
Construct a new AnalogEncoder attached to a specific AnalogInput. -
Method Summary
Modifier and Type Method Description void
close()
double
get()
Get the encoder value since the last reset.double
getAbsolutePosition()
Get the absolute position of the analog encoder.int
getChannel()
Get the channel number.double
getDistance()
Get the distance the sensor has driven since the last reset as scaled by the value fromsetDistancePerRotation(double)
.double
getDistancePerRotation()
Get the distance per rotation for this encoder.double
getPositionOffset()
Get the offset of position relative to the last reset.void
initSendable(SendableBuilder builder)
Initializes thisSendable
object.void
reset()
Reset the Encoder distance to zero.void
setDistancePerRotation(double distancePerRotation)
Set the distance per rotation of the encoder.void
setPositionOffset(double offset)
Set the position offset.
-
Field Details
-
Constructor Details
-
AnalogEncoder
Construct a new AnalogEncoder attached to a specific AnalogIn channel.- Parameters:
channel
- the analog input channel to attach to
-
AnalogEncoder
Construct a new AnalogEncoder attached to a specific AnalogInput.- Parameters:
analogInput
- the analog input to attach to
-
-
Method Details
-
get
Get the encoder value since the last reset.This is reported in rotations since the last reset.
- Returns:
- the encoder value in rotations
-
getAbsolutePosition
Get the absolute position of the analog encoder.getAbsolutePosition() - getPositionOffset() will give an encoder absolute position relative to the last reset. This could potentially be negative, which needs to be accounted for.
This will not account for rollovers, and will always be just the raw absolute position.
- Returns:
- the absolute position
-
getPositionOffset
Get the offset of position relative to the last reset.getAbsolutePosition() - 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
-
setPositionOffset
Set the position offset.This must be in the range of 0-1.
- Parameters:
offset
- the offset
-
setDistancePerRotation
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 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
Get the distance per rotation for this encoder.- Returns:
- The scale factor that will be used to convert rotation to useful units.
-
getDistance
Get the distance the sensor has driven since the last reset as scaled by the value fromsetDistancePerRotation(double)
.- Returns:
- The distance driven since the last reset
-
getChannel
Get the channel number.- Returns:
- The channel number.
-
reset
Reset the Encoder distance to zero. -
close
- Specified by:
close
in interfaceAutoCloseable
-
initSendable
Description copied from interface:Sendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceSendable
- Parameters:
builder
- sendable builder
-