DutyCycleEncoder

class wpilib.DutyCycleEncoder(*args, **kwargs)

Bases: wpilib.ErrorBase, wpilib.Sendable

Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with PWM Output, the CTRE Mag Encoder, the Rev Hex Encoder, and the AM Mag Encoder.

Overloaded function.

  1. __init__(self: wpilib._wpilib.DutyCycleEncoder, channel: int) -> None

Construct a new DutyCycleEncoder on a specific channel.

Parameters

channel – the channel to attach to

  1. __init__(self: wpilib._wpilib.DutyCycleEncoder, dutyCycle: wpilib._wpilib.DutyCycle) -> None

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters

dutyCycle – the duty cycle to attach to

  1. __init__(self: wpilib._wpilib.DutyCycleEncoder, digitalSource: wpilib._wpilib.DigitalSource) -> None

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters

source – the digital source to attach to

get(self: wpilib.DutyCycleEncoder) → turns

Get the encoder value since the last reset.

This is reported in rotations since the last reset.

Returns

the encoder value in rotations

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

Get the distance per rotation for this encoder.

Returns

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

getFPGAIndex(self: wpilib.DutyCycleEncoder) → int

Get the FPGA index for the DutyCycleEncoder.

Returns

the FPGA index

getFrequency(self: wpilib.DutyCycleEncoder) → int

Get the frequency in Hz of the duty cycle signal from the encoder.

Returns

duty cycle frequency in Hz

getSourceChannel(self: wpilib.DutyCycleEncoder) → int

Get the channel of the source.

Returns

the source channel

initSendable(self: wpilib.DutyCycleEncoder, builder: wpilib.SendableBuilder) → None
isConnected(self: wpilib.DutyCycleEncoder) → bool

Get if the sensor is connected

This uses the duty cycle frequency to determine if the sensor is connected. By default, a value of 100 Hz is used as the threshold, and this value can be changed with SetConnectedFrequencyThreshold.

Returns

true if the sensor is connected

reset(self: wpilib.DutyCycleEncoder) → None

Reset the Encoder distance to zero.

setConnectedFrequencyThreshold(self: wpilib.DutyCycleEncoder, frequency: int) → None

Change the frequency threshold for detecting connection used by IsConnected.

Parameters

frequency – the minimum frequency in Hz.

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