EasyCRServo
The EasyCRServo class is an incredibly powerful abstraction over the FTC CRServoImplEx (Continuous Rotation Servos).
Unlike standard Continuous Rotation servos which only accept raw power commands, EasyStack's EasyCRServo transforms them into smart actuators. It allows for closed-loop RPM velocity control, exact positional control (when paired with an EasyAbsoluteAnalogEncoder), and automatic motion profile execution with Feedforward and PID compensation.
#Creating an EasyCRServo
To create an EasyCRServo, provide the hardware map and the exact device name configured on your Driver Station.
EasyCRServo intakeServo = new EasyCRServo(hardwareMap, "intake");#Basic Open-Loop Control
If you just want to spin the servo continuously using direct power, you can use setPower():
intakeServo.setPower(1.0); Spins full speed forward
intakeServo.setPower(-0.5); Spins half speed backward
intakeServo.stop(); stop the servoLike EasyServo, this class also implements aggressive I2C caching. If you send the exact same power level in a loop, it won't spam the Control Hub, improving your loop times.
#Closed-Loop Velocity Control (RPM)
Standard CR servos don't hold a constant speed as the battery drains or as friction increases. By providing the servo's physical maxRpm and an external encoder, EasyCRServo can actively manage its own speed.
First, you must configure the velocity model:
// Sets the theoretical maximum speed of the physical servo (e.g. 150 RPM)
intakeServo.setMaxRpm(150.0);
// (Optional) Adjust the minimum power required to overcome static friction
intakeServo.setMinPower(0.05);#Pure Feedforward Velocity (No Encoder Required)
If you don't have an encoder attached to the servo mechanism, the class can still use its internal velocity model to estimate the correct power needed to reach a target RPM.
// Will automatically calculate and apply the correct fractional power to achieve 75 RPM
intakeServo.setTargetRpm(75.0);#Closed-Loop PID Velocity (Encoder Required)
If you have an EasyAbsoluteAnalogEncoder connected to the mechanism, you can inject it along with PID coefficients. The servo will now measure its own real-world RPM and actively correct any speed drops.
// Links the encoder and enables active RPM correction
intakeServo.setVelocityControl(myEncoder, velPid);
// Sets the target speed
intakeServo.setTargetRpm(100.0);Note: You must call intakeServo.update() once every loop for the internal PID controllers and velocity filters to process the encoder data and adjust the motor power!
#Velocity Smoothing (Low-Pass Filter)
Reading velocity from an absolute encoder by differentiating position over tiny loop times often results in very noisy RPM spikes. EasyCRServo includes a built-in LowPassFilter. You can adjust how strongly it smooths the data:
Java
// Smooths the velocity readings. Higher time constant = smoother but more delayed.
intakeServo.setVelocityFilter(0.1);#Closed-Loop Positional Control
By connecting an EasyAbsoluteAnalogEncoder, EasyCRServo essentially becomes a standard, powerful servo that can turn infinitely but still lock onto precise angular targets.
#Configuring Positional Control
You must provide the encoder, your position PID coefficients, and the acceptable tolerance (how close it needs to be to be considered "at target").
PIDCoefficients posPid = new PIDCoefficients(0.05, 0.0, 0.001);
// Configures the servo to use the encoder to seek positions, with a 5-degree tolerance
intakeServo.setPositionalControl(myEncoder, posPid, 5.0, AngleUnit.DEGREES);#Setting Target Angles
Once configured, you can command the servo to lock onto specific angles. The class handles the wraparound math automatically (e.g., if the servo is at 350° and you command it to 10°, it will take the shortest path by moving forward 20° rather than spinning backward 340°).
intakeServo.setTargetAngle(90.0); // 90 Degrees#Positional Feedforward
If your continuous rotation servo is lifting a heavy arm, you can add an FFController to help it fight gravity or friction while moving to a position.
FFCoefficients armFF = new FFCoefficients(0.05, 0.01 0.0) // kS,
intakeServo.setFeedforward(armFF);#Motion Profiling
Instead of just snapping to a position instantly, EasyCRServo supports full motion profiling references. You can feed it the current desired position, velocity, and acceleration from a trajectory or profile generator.
// Called inside your loop. The servo will use PID to track the positionRef,
// and the Feedforward controller to track the velocity and acceleration refs.
intakeServo.update();Última actualización 2026-11-16