EasyStack Docs

EasyServo

Esta página ainda não foi traduzida. Mostrando a versão em inglês.

The EasyServo class is a highly advanced abstraction over the standard FTC ServoImplEx. It removes boilerplate code, prevents hardware damage through logical limits, implements aggressive I2C caching to improve loop times, and provides a built-in physics estimator to track the servo's physical location over time.

It natively supports exact angle commands (degrees or radians), pre-defined named "states", and expanded PWM ranges for third-party hardware.

#Creating an EasyServo

To create an EasyServo, provide the hardware map and the device name exactly as configured on your Driver Station.

Java
EasyServo claw = new EasyServo(hardwareMap, "claw");

If you plan to use angle-based control, you can optionally define the physical sweep range of your servo (in degrees) directly in the constructor:

Java
// Initializes a servo with a known 270-degree physical sweep
EasyServo armServo = new EasyServo(hardwareMap, "arm", 270.0)

#Basic Positioning and Incremental Movement

Like a standard servo, you can command the position using a normalized value between 0.0 and 1.0.

Java
claw.setPosition(0.5); // Moves to the exact middle

You can also bump the servo's position by a relative amount using rotateBy(). This is incredibly useful for tele-operated manual adjustments without needing to read and calculate the current position manually:

Java
claw.rotateBy(0.1);  // Moves the servo 10% further forward
claw.rotateBy(-0.05); // Retracts the servo by 5%

#Safety and Logical Limits

Sending a servo to absolute 0.0 or 1.0 can often cause it to crash into your physical mechanism, burning out the motor. You can define a safe travel window using setLimits().

Java
// Restricts the physical travel between 20% and 80% of the servo's true range
claw.setLimits(0.2, 0.8);

Once limits are set, EasyServo dynamically scales all your inputs. If you call setPosition(0.0), the hardware will safely stop at 0.2. If you call setPosition(1.0), it stops at 0.8. The math is handled internally so your logic remains clean.

(Note: Calling setLimits(min, max) automatically clears the internal command cache to ensure the hardware updates immediately).

#Hardware Caching and Loop Performance

The FTC SDK wastes valuable loop time if you repeatedly send the exact same command to a servo over I2C. EasyServo fixes this with aggressive caching.

If you send a command that is identical (or extremely close) to the previous one, EasyServo intercepts it and ignores the redundant hardware call.

Java
// Customizes the caching tolerance (Default is a very precise 0.0001)
claw.setCachingTolerance(0.005);

#State Management

Instead of littering your TeleOp or Autonomous code with "magic numbers" (like 0.34 or 0.87), you can define named states during initialization. This makes your logic self-documenting.

Java
claw.addState(, 0.3)
         .addState("CLOSE", 0.75)
         .addState("GRIP LIGHT", 0.6);

Later, in your main control loop, simply call the state by name:

Java
if (gamepad1.a) {
    claw.setState("CLOSED");
} else if (gamepad1.b) {
    claw.setState("OPEN");
}

#Angle-Based Kinematics

If you set the physical angle range of the servo (e.g., 180, 270, or 300 degrees), you can command it using real-world angles instead of arbitrary percentages.

Java
// Sets the range if you didn't do it in the constructor
claw.setAngleRange(300.0);
Java
// Moves the servo to exactly 90 degrees
claw.setAngle(90.0);
Java
// Moves the servo to PI/2 radians
claw.setAngle(Math.P1 / 2, AngieUnit.radians);

Just like raw positions, you can also rotate by relative angles:

Java
claw.turnByAngle(15.0); // Rotates exactly 15 degrees further

#Motion Profiling and Position Estimation

Standard servos are "dumb" — they only know where they were told to go, not where they actually are. EasyServo features a time-based position estimator to simulate the physical motion of the servo horn.

First, you must configure the physical speed of your specific servo model (in normalized position units per second):

Java
// Tells the class the servo takes exactly 2 seconds to travel from 0.0 to 1.0 (speed of 0.5 sec)
claw.setspeed(0.5);

Once a speed is set, you can query where the servo theoretically is in the real world at that exact microsecond:

Java
claw.setPosition(1.0);

// As the loop runs, this will smoothly rise from 0.0 up to 1.0 based on elapsed time
double estimatedPos = claw.getEstimatedPosition();

#Checking if "At Target"

The estimation engine allows you to write intelligent Autonomous sequences that wait for a servo to finish its physical movement before proceeding:

Java
if (claw.isAtTarget()) {
    // The servo has theoretically arrived at its destination!
    liftArm();
}

(Note: If you do not configure a speed using setSpeed(), isAtTarget() will instantly return true because it assumes infinite speed).

#Extended PWM Ranges (goBILDA / Custom Servos)

Servos from brands like goBILDA require expanded PWM limits to reach their full mechanical sweep. The standard REV Hub limits will artificially restrict how far they can turn.

You can safely expand this using the PwmPresets class:

Java
// Expands the PWM to 500-2500 microseconds (Full goBILDA sweep)
claw.setPwmRange(PwmPresets.FULL_RANGE);
// Resets back to the SDK default (600-2400)
claw.setPwmRange(PwmPresets.SDK_DEFAULT);

Disclaimer: We do NOT take responsibility for broken servos caused by pushing mechanisms past their mechanical capabilities!

#Power and Direction Management

If your servo is mounted backward, you can invert its logic. A command to move to 0.0 will physically move the inverted servo to 1.0.

Java
claw.setInverted(true)
claw.reverse();

You can also cut power to the servo entirely, allowing it to go "limp" (useful for gravity-assisted drops or end-of-game safety):

Java
claw.disable(); // Cuts the PWM signal
claw.enable();  // Restores the PWM signal

if (claw.isEnabled()) {
    // Servo is actively holding its position
}

#Reading Data

EasyServo provides multiple ways to read its current target and configuration:

Java
// Returns the logical position (0.0 to 1.0) factoring in your custom limits
double pos = claw.getPosition();

// Returns the raw, unscaled hardware target position
double rawPos = claw.getRawPosition();

// Returns the target angle in degrees or radians
double degrees = claw.getAngle();
double radians = claw.getAngle(AngleUnit.RADIANS);

Última atualização 2026-11-16

EasyStack - FTC Java library

This site records page views of visitors to understand how the documentation is used. Nothing is sold or shared with third parties.