EasyAbsoluteAnalogEncoder
The EasyAbsoluteAnalogEncoder class abstracts reading a standard FTC AnalogInput). This tool handles all the complex math required to convert raw voltage values into precise angles, supporting logical inversion, variable measurement units, and zero-point calibration.
It is frequently used in conjunction with the EasyCRServo class to create closed-loop positional control for continuous rotation mechanisms.
#Creation and Initialization
To create an EasyAbsoluteAnalogEncoder, provide the hardware map and the device name configured on the Driver Station.
By default, the basic constructor assumes the encoder operates on a 3.3V range and uses Radians (AngleUnit.RADIANS) as the standard unit:
// Initializes the encoder with default settings (3.3V, Radians)
= new EasyAbsoluteAnalogEncoder(hardwareMap, "ar encoder");If your encoder uses a different voltage (e.g., 5.0V) or you prefer to work natively with Degrees, you can use the detailed constructor:
// Initializes the encoder for 5.0 Volts and uses Degrees as the base unit
EasyAbsoluteAnalogEncoder clawEncoder = new EasyAbsoluteAnalogEncoder(
hardwareMap,
"clawEncoder",
5.0,
AngleUnit.DEGREES
);#Reading Angles
The class automatically converts voltage to an angle and ensures the value remains continuous within a full rotation (0 to 360 degrees, or 0 to 2π radians).
You can read the angle in the configured base unit or request a direct conversion to another unit:
Java
// Returns the angle in the base unit defined during initialization
double currentAngle = armEncoder.getAngle();
// Specifically returns the angle in Degrees
double degrees = armEncoder.getAngleDegrees();
// Specifically returns the angle in Radians
double radians = armEncoder.getAngleRadians();
// Returns the angle converted to an arbitrary unit of your choice
double convertedAngle = armEncoder.getAngle(AngleUnit.DEGREES);#Calibration and Zero Point (Offset)
When physically mounting an absolute encoder on a robot, its mechanical "zero" point rarely aligns perfectly with the desired logical zero for your mechanism. The class allows you to easily adjust this offset.
You can set a manual offset value:
// Subtracts 45 degrees (or radians, depending on the base unit) from all readings
armEncoder.setOffset(45.0);Alternatively, you can calibrate the mechanism dynamically. The zero() method reads the current physical position and immediately sets it as the new logical 0.0:
// Wherever the mechanism is right now becomes position
armEncoder.zero();#Inverting Direction
If the mechanical assembly causes the encoder values to increase in the opposite direction of what you want (e.g., values increase as the arm goes down), you can invert the logical reading.
// Inverts the reading direction of the encoder
armEncoder.setlnverted(true)Inversion subtracts the raw value from the full rotation (e.g., 360.0 - rawValue) before applying the offset, ensuring consistent behavior.
#Accessing Class Properties
If you need to access the encoder's internal configuration during your code, the class provides direct reading methods:
// Returns the value representing a full rotation (360.0 or 21)
double maxRotation = armEncoder.getFullRotation();
// Returns the angular unit configured in the constructor
AngleUnit currentUnit = armEncoder.getUnit();Última actualización 2026-11-16