AnalogEncoder¶
- class wpilib.AnalogEncoder(*args, **kwargs)¶
Bases:
Sendable
Class for supporting continuous analog encoders, such as the US Digital MA3.
Overloaded function.
__init__(self: wpilib._wpilib.AnalogEncoder, channel: int) -> None
Construct a new AnalogEncoder attached to a specific AnalogIn channel.
- Parameters:
channel – the analog input channel to attach to
__init__(self: wpilib._wpilib.AnalogEncoder, analogInput: wpilib._wpilib.AnalogInput) -> None
Construct a new AnalogEncoder attached to a specific AnalogInput.
- Parameters:
analogInput – the analog input to attach to
- get() turns ¶
Get the encoder value since the last reset.
This is reported in rotations since the last reset.
- Returns:
the encoder value in rotations
- getAbsolutePosition() float ¶
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
- getChannel() int ¶
Get the channel number.
- Returns:
The channel number.
- getDistance() float ¶
Get the distance the sensor has driven since the last reset as scaled by the value from SetDistancePerRotation.
- Returns:
The distance driven since the last reset
- getDistancePerRotation() float ¶
Get the distance per rotation for this encoder.
- Returns:
The scale factor that will be used to convert rotation to useful units.
- getPositionOffset() float ¶
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
- initSendable(builder: wpiutil._wpiutil.SendableBuilder) None ¶
- reset() None ¶
Reset the Encoder distance to zero.
- setDistancePerRotation(distancePerRotation: float) None ¶
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
- setPositionOffset(offset: float) None ¶
Set the position offset.
This must be in the range of 0-1.
- Parameters:
offset – the offset