Encoder

open class Encoder

Represents a motor or external encoder that takes in suppliers of position and velocity to calculate encoder ticks. The velocity methods of this class have been adjusted to include acceleration and corrected velocity receivers.

This class uses an internal accumulator to determine the current position of the encoder, allowing for the current position to be asserted by the end user.

Author

Lucas Bubner, 2024

Since

4.0.0

See also

RawEncoder

RawEncoder - used in drivebases and for RoadRunner

Constructors

Link copied to clipboard
constructor(@NonNull position: Supplier<Integer>, @NonNull velocity: Supplier<Double>)
The encoder object for some positional and velocity supplier.

Properties

Link copied to clipboard
@get:NonNull
open var direction: DcMotorSimple.Direction

Functions

Link copied to clipboard
Link copied to clipboard
Gets the current encoder velocity while also correcting for velocity overflow (REV hardware limitation workaround)
Link copied to clipboard
open fun getPosition(): Int
Link copied to clipboard
Link copied to clipboard
open fun getVelocity(): Double
Link copied to clipboard
open fun reset()
Resets the encoder without having to adjust output speed.
Link copied to clipboard
open fun setAccelLowPassGain(gain: Double)
Set a new Low Pass filter gain for use with acceleration estimation readings.
Link copied to clipboard
open fun setKnownPosition(position: Int)
Sets the current (known) position of the encoder to this value.
Link copied to clipboard
open fun trackDirection(@NonNull supplier: Supplier<DcMotorSimple.Direction>)
Set a supplier that will be used to auto-set encoder direction.
Link copied to clipboard
Call to use encoder overflow (exceeding 32767 ticks/sec) correction on getVelocity.