EasyMotor
The EasyMotor class is an advanced wrapper over the standard FTC DcMotorEx. It abstracts away boilerplate code, automatically manages control loop states, and provides built-in tools for velocity control, position control, motion profiling, safety limits, and hardware integration.
By utilizing EasyMotor, you no longer need to manually manage DcMotor.RunMode states. The class dynamically switches between open-loop power, closed-loop velocity, and closed-loop position modes based on the commands you issue.
#Creating an EasyMotor
To create an EasyMotor, you must provide the hardware map and the device name configured on the Driver Station.
EasyMotor motor = new EasyMotor(hardwareMap, "motorName");#Motor Types and Configurations
For the class to accurately calculate speeds and rotations, it needs to know the physical specifications of your motor (Counts Per Revolution and Max RPM). You can provide this during initialization using the EasyMotorType enum.
EasyMotor armMotor = new EasyMotor(hardwareMap, "armMotor", EasyMotorType.GOBILDA_60);The EasyMotorType enum includes predefined specifications for popular commercial motors:
- GoBILDA 5203 Series:
GOBILDA_6000,GOBILDA_1620,GOBILDA_435,GOBILDA_312,GOBILDA_117,GOBILDA_60,GOBILDA_43,GOBILDA_30, etc. - REV Robotics:
REV_CORE_HEX,REV_HD_HEX_20,REV_HD_HEX_40,REV_HD_NAKED.
If your motor is not listed, you can manually configure its specifications or/and send to us and we can implement it:
EasyMotor customMotor = new EasyMotor(hardwareMap, "customMotor")
.setType(EasyMotorType.CONFIG) // Sets as a custom configuration
.setCPR(537.7) // Sets Counts Per Revolution
.setMaxRPM(312.0); // Sets Maximum RPM#Basic Open-Loop Control (Power Mode)
To apply direct power to the motor, use the setPower() method. The input range is -1.0 to 1.0. When this method is called, the motor automatically transitions to Mode.POWER.
motor.setPower(0.75); // Applies 75% power forward#Deadbands
Sometimes, applying a very small amount of power (e.g., 0.05) is not enough to overcome the internal friction of a mechanism, which can cause the motor to whine and overheat without moving. You can configure a deadband to ignore any power commands below a certain threshold:
motor.setDeadband(0.1);If you command motor.**setPower(0.05**), the motor will remain at 0 power.
#Power Ramping (Slew Rate Limiting)
Sudden changes in power (e.g., from 0.0 to 1.0 instantly) can shear gear teeth, snap belts, or cause wheel slip. You can limit how quickly the power output is allowed to increase using setPowerRamp().
motor.setPowerRamp(0.5); //The motor power will increase at a maximum rate of 0.5 (50%)If you apply setPower(1.0), the motor will take exactly 2 seconds to accelerate from 0 to full speed.
#Closed-Loop Velocity Control
EasyMotor can automatically maintain a specific target speed using internal PIDF controllers (Proportional, Integral, Derivative, Feedforward). Calling any velocity command switches the motor to Mode.VELOCITY.
#Setting Target Velocity
You can command the motor to maintain a specific speed using several methods:
// Sets the target speed to exactly 150 Rotations Per Minute
motor.setRPM(150.0);
// Sets the target speed based on a percentage of the configured Max RPM (e.g., 50% speed)
motor.setSpeedPercent(0.5);
// Sets the target speed in degrees per second
motor.setDegreesPerSecond(180.0);
// Sets the target speed in raw encoder ticks per second
motor.setVelocityTicks(500.0);#Customizing Velocity PIDF and Feedforward
If the default velocity controller struggles to maintain the target speed or oscillates, you can inject your own PIDF coefficients or a custom feedforward model.
PIDFCoefficients customVelocityGains = new PIDFCoefficients(
0.05, // kP
0.0, // kI
0.0, // kD
0.1 // kF
);
motor.setVelocityPIDF(customVelocityGains);
// Or add a custom Feedforward Controller (kS: static friction, kV: velocity constant)
motor.setVelocityFF(new FFController(0.01, 0.02));#Checking Velocity State
You can define a tolerance window and check if the motor has reached its target speed:
motor.setRPMTolerance(10.0); // Mechanism is considered "at target" if within +/- 10 RPM of the goal
if (motor.isAtRPM()) {
// The motor speed is stabilized
}#Closed-Loop Position Control
The EasyMotor can accurately move a mechanism to a specific location and hold it there using a built-in position PIDF controller. Calling any position command switches the motor to Mode.POSITION.
#Setting Target Position
You can set the target position in raw encoder ticks, full rotations, or degrees.
// Moves the mechanism to the absolute position of 1500 encoder ticks
motor.moveToPosition(1500.0);
// Moves the mechanism to 2.5 full rotations from its zero point
motor.moveToRotations(2.5);
// Moves the mechanism to a 90-degree angle
motor.moveToDegrees(90.0);#Customizing Position Controllers and Feedforward
Linear slides or arms often need to fight gravity. You can add a static feedforward to hold the mechanism up, and custom PID gains for the movement.
// Sets custom PID gains for position control
motor.setPositionPID(0.01, 0.0, 0.0005);
// Adds a constant 15% power to the output to counteract gravity (e.g., for an elevator)
motor.setStaticFeedforward(0.15);#Tolerances and State Checking
Just like velocity, you can define how close the mechanism needs to be to the target position to be considered "at target".
motor.setPositionTolerance(15.0); // +/- 15 ticks of tolerance
// OR motor.setDegreesTolerance(2.0); // +/- 2 degrees of tolerance
if (motor.isAtPosition()) {
// Mechanism has arrived at the destination
}#Encoder Management
You do not need to reset the physical motor encoder mode to zero its position. EasyMotor manages position offsets internally.
// Reads the current adjusted position
double pos = motor.getPosition();
// Sets the current physical position as the new 0.0, without resetting the hardware encoder
motor.setCurrentPositionAsZero();
// Defines the current physical position as a specific offset
motor.setPositionOffset(500.0);#Safety Features and Limits
To prevent mechanical damage, EasyMotor provides built-in safety boundaries.
#Soft Position Limits
You can define minimum and maximum travel limits. If the motor attempts to drive past these limits, EasyMotor will automatically clamp the power, only allowing the motor to move back towards the safe zone.
// Restricts movement between 0 and 3000 ticks
motor.setPositionLimits(0.0, 3000.0);
// Or using degrees
motor.setDegreePositionLimits(-45.0, 45.0);
// You can check if a limit has been reached
if (motor.isAtUpperLimit() || motor.isAtLowerLimit()) {
// Warning: Mechanism maxed out!
}#Automatic Homing (Hard Limits)
For mechanisms without limit switches, you can use physical stops and current sensing to home the mechanism. The homeToPhysicalLimit method drives the motor at a specified power until it detects a current spike (stall), then automatically zeros the encoder.
// Drives at -20% power until it hits a hard stop and draws more than 3.5 Amps
boolean homingComplete = motor.homeToPhysicalLimit(-0.2, 3.5);
if (homingComplete) {
// The motor stopped and set its current position to 0
}#Voltage Compensation
Battery voltage drops during a match, which causes motors to run slower at the same power level. You can enable voltage compensation to automatically scale motor output based on the current battery voltage, ensuring consistent behavior.
// Scales the output so it behaves as if the robot always has exactly 12.0 Volts
motor.setVoltageCompensation(12 .0);Last updated 2026-11-16