AnalogEncoder

class wpilib.AnalogEncoder(self: wpilib.AnalogEncoder, analogInput: wpilib.AnalogInput) → None

Bases: wpilib.ErrorBase, wpilib.Sendable

Class for supporting continuous analog encoders, such as the US Digital MA3.

Construct a new AnalogEncoder attached to a specific AnalogInput.

Parameters

analogInput – the analog input to attach to

get(self: wpilib.AnalogEncoder) → turns

Get the encoder value since the last reset.

This is reported in rotations since the last reset.

Returns

the encoder value in rotations

getChannel(self: wpilib.AnalogEncoder) → int

Get the channel number.

Returns

The channel number.

getDistance(self: wpilib.AnalogEncoder) → 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(self: wpilib.AnalogEncoder) → float

Get the distance per rotation for this encoder.

Returns

The scale factor that will be used to convert rotation to useful units.

getPositionOffset(self: wpilib.AnalogEncoder) → float

Get the offset of position relative to the last reset.

GetPositionInRotation() - 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(self: wpilib.AnalogEncoder, builder: wpilib.SendableBuilder) → None
reset(self: wpilib.AnalogEncoder) → None

Reset the Encoder distance to zero.

setDistancePerRotation(self: wpilib.AnalogEncoder, 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