EasyStack Docs

EasySimpleMotorFeedForward

Esta página aún no está traducida. Se muestra la versión en inglés.

Simple Motor Feedforward

A motor feedforward model estimates the output needed to produce a requested velocity and acceleration.

Instead of calculating a correction from measurement error, it uses a model of static friction and motion. This can provide an initial output estimate for mechanisms such as flywheels and drivetrain wheels.

EasyStack's EasySimpleMotorFeedforward calculates this estimate using three gains: kS, kV, and kA.

It does not include gravity compensation.

Creating a Simple Motor Feedforward

To create an EasySimpleMotorFeedforward, provide the gains in the following order:

Java
EasySimpleMotorFeedforward feedforward
        new EasySimpleMotorFeedforward(kS, kV, kA);

The parameters are:

ParameterDescription
kSStatic friction compensation, applied according to the sign of velocity.
kVVelocity gain.
kAAcceleration gain.

For example:

Java
EasySimpleMotorFeedforward feedforward =
        new EasySimpleMotorFeedforward(
                0.2,
                0.1,
                0.01
        );

These values are illustrative. Determine the gains for your mechanism, gearing, load, and measurement units.

Without Acceleration Compensation

A two-argument constructor is also available:

Java
EasySimpleMotorFeedforward feedforward
        new EasySimpleMotorFeedforward(kS, kV);

This sets kA to 0.0.

For example:

Java
EasySimpleMotorFeedforward feedforward =
        new EasySimpleMotorFeedforward(0.2, 0.1);

This is equivalent to:

Java
EasySimpleMotorFeedforward feedforward
        new EasySimpleMotorFeedforward(@.2, 0.1, 0.0);

Units and Output

The units of the gains must match the velocity, acceleration, and intended output.

For a voltage-based model using angular velocity in radians per second:

GainUnits
kSVolts
kVVolts per radian per second
kAVolts per radian per second squared

With these gains, calculate() returns volts.

You can also use other consistent measurement units:

VelocityAcceleration
Meters per secondMeters per second squared
Rotations per secondRotations per second squared
Encoder ticks per secondEncoder ticks per second squared

Changing measurement units requires corresponding changes to kV and kA.

The class does not convert units or apply the calculated output to a motor.

Calculating Feedforward

Use calculate() with the requested velocity and acceleration:

Java
double voltage = feedforward.calculate(
        targetVelocity,
        targetAcceleration
);

The parameters are:

ParameterDescription
velocityRequested velocity in your chosen units.
accelerationRequested acceleration in the corresponding units per second.

The calculation is:

Java
output * Math.signum(velocity)
             * velocity
             * acceleration;

For example:

Java
double voltage feedforward.calculate(50.0, 20.0);

Using the example gains:

Java
output 0.2 + (0.1 * 50.0) + (0.01 * 20.0);

The result is 5.4 volts.

For motion tracking, these inputs normally come from the desired motion reference. The method does not accept a measured velocity or calculate a tracking error separately.

Calculating Without Acceleration

Use the single-argument overload when acceleration compensation is not needed:

Java
double voltage feedforward.calculate(targetVelocity);

For example:

Java
double voltage feedforward.calculate(50.0);

This is equivalent to:

Java
double voltage = feedforward.calculate(50.0, 0.0);

The acceleration contribution is zero even if the object has a nonzero kA.

Using the example gains, the result is:

Java
0.2 + (0.1 * 50.0) 5.2

Static Friction Compensation

The static term follows the sign of the supplied velocity:

Java
staticCompensation = kS * Math.signum(velocity);

Its behavior is:

VelocityStatic contribution
Positive+kS
Negative-kS
Zero0.0

For example:

Java
feedforward.calculate(50.O);

includes +kS, while:

Java
feedforward.calculate(-50.0);

includes -kS.

Starting from Zero Velocity

At exactly zero velocity, the static contribution is zero even if acceleration is nonzero:

Java
double voltage = feedforward.calculate(0.0, 20.0);

The result contains only:

Java
kA * 20.0

The implementation does not use acceleration to choose the direction of static friction compensation.

Velocity and Acceleration Direction

Positive and negative inputs represent opposite directions.

For example:

Java
double voltage feedforward.calculate(-50 . 0, -20.0);

Using the example gains:

Java
output -0.2 5.0 0.2

The result is -5.4 volts.

Acceleration can also oppose velocity:

Java
double voltage feedforward.calculate(50.0, -20.0);

This represents positive motion with negative acceleration. The acceleration term reduces the requested output.

The model calculates the combined voltage; it does not decide when the mechanism should accelerate or decelerate.

Zero Velocity and Acceleration

When both inputs are zero:

Java
double voltage feedforward. .0,

the result is zero.

This model does not provide a holding output against gravity. For a mechanism that needs gravity compensation, use an appropriate arm or elevator feedforward model.

Combining Feedforward with PID

Feedforward estimates the output needed for the desired motion. PID can correct the difference between the target velocity and measured velocity.

Add their outputs when they use the same output units:

Java
double pidVoltage = controller.calculate(
        measuredVelocity,
        targetVelocity
);

double feedforwardVoltage = feedforward.calculate(
        targetVelocity,
        targetAcceleration
);

double requestedVoltage = pidVoltage + feedforwardVoltage;

For a constant-speed reference:

Java
double feedforwardVoltage
        feedforward.calculate(targetVelocity);

If feedforward returns volts, configure the PID gains to produce volts as well.

The feedforward class does not generate target velocity or acceleration. Your program must supply them.

Maximum Achievable Velocity

Use maxAchievableVelocity() to estimate the positive-velocity boundary for an available voltage and specified acceleration:

Java
double maxVelocity = feedforward.maxAchievableVelocity(
        maxVoltage,
        acceleration
);

The parameters are:

ParameterDescription
maxVoltagePositive available voltage magnitude.
accelerationSpecified acceleration in the model's units.

For example:

Java
double maxVelocity = feedforward.maxAchievableVelocity(
        12.0,
        0.0
);

The calculation is:

Java
maxVelocity =
        (maxVoltage - kS - acceleration * kA) / kV;

Using the example gains:

Java
maxVelocity (12.0 0.2) / 0.1;

The result is 118.0 velocity units.

This formula assumes positive velocity when applying static compensation. If it returns a negative value, that result is outside the assumed positive-velocity branch.

Minimum Achievable Velocity

Use minAchievableVelocity() for the negative-velocity branch:

Java
double minVelocity = feedforward.minAchievableVelocity(
        maxVoltage,
        acceleration
);

For example:

Java
double minVelocity = feedforward.minAchievableVelocity(
        12.0,
        0.0
);

The calculation is:

Java
minVelocity =
        (-maxVoltage + kS - acceleration * kA) / kV;

Using the example gains, the result is -118.0 velocity units.

This formula assumes negative velocity.

Both velocity methods require a nonzero kV. Use a positive kV for the usual interpretation of maximum and minimum boundaries.

These values are model estimates. They do not enforce speed limits or guarantee that the hardware can achieve the predicted motion.

Maximum Achievable Acceleration

Java
Use maxAchievableAcceleration():
Java
double maxAcceleration =
        feedforward.maxAchievableAcceleration(
                maxVoltage,
                velocity
        );

For example:

Java
double maxAcceleration =
        feedforward.maxAchievableAcceleration(
                12.0,
                50.0
        );

The calculation is:

Java
maxAcceleration =
        (maxVoltage
                - kS * Math.signum(velocity)
                - kV * velocity)
        / kA;

The result uses the acceleration units associated with your gains.

Static compensation follows the sign of the supplied velocity. At zero velocity, the static term is zero.

Minimum Achievable Acceleration

Java
Use minAchievableAcceleration():
Java
double minAcceleration =
        feedforward.minAchievableAcceleration(
                maxVoltage,
                velocity
        );

Internally, it evaluates the acceleration formula at negative maximum voltage:

Java
return maxAchievableAcceleration(-maxVoltage, velocity);

Both acceleration methods require a nonzero kA. Use a positive kA for the usual maximum and minimum interpretation.

The two-argument constructor sets kA to zero, so its acceleration-boundary calculations are not usable. Division by zero can produce infinity or NaN.

Reading and Changing the Gains

The gains are public and final:

Java
double staticGain = feedforward.kS;
double velocityGain feedforward.kV;
double accelerationGain = feedfo rd.kA;

They can be read directly but cannot be reassigned after construction.

To change the gains, create another instance:

Java
feedforward =
        new EasySimpleMotorFeedforward(
                0.25,
                0.12,
                0.015
        );

The class does not validate the supplied values.

Limiting the Output

calculate() does not clamp its output to the available voltage.

Apply a limit before commanding the motor:

Java
double requestedVoltage = feedforward.calculate(
        targetVelocity,
        targetAcceleration
);

double voltageLimit = 12.0;

double appliedVoltage = Math.max(
        -voltageLimit,
        Math.min(voltageLimit, requestedVoltage)
);

For an FTC motor controlled through setPower(), convert the voltage request to normalized power using a valid measured supply voltage:

Java
double power = appliedVoltage / batteryVoltage;

power = Math.max(-1.0, Math.min(1.0, power));

motor.setPower(power);

This approximates a voltage command through motor power.

Complete Example

The following control-loop example combines the previously shown EasyPIDController with motor feedforward for velocity control.

It uses radians per second for velocity and volts for both controller outputs.

Create the controllers before entering the loop:

Java
import dev.easyfamily.easystack.control.EasyPIDController;
import dev.easyfamily.easystack.control.wpiLibControllers.EasySimpleMotorFeedforward;

// Illustrative gains: tune for your mechanism.
// PID input: rad/s. PID output: volts.
EasyPIDController controller =
        new EasyPIDController(0.1, 0.0, 0.0);

EasySimpleMotorFeedforward feedforward =
        new EasySimpleMotorFeedforward(
                0.2,
                0.1,
                0.01
        );

controller.setTolerance(1.0);

double targetVelocity = 50.0;

Inside the active control loop, obtain fresh values for measuredVelocityRadPerSec and batteryVoltage, then calculate:

Java
double pidVoltage = controller.calculate(
        measuredVelocityRadPerSec,
        targetVelocity
);

// Constant-speed feedforward; acceleration is assumed zero.
double feedforwardVoltage =
        feedforward.calculate(targetVelocity);

double requestedVoltage = pidVoltage + feedforwardVoltage;

double power = 0.0;

if (Double.isFinite(batteryVoltage) && batteryVoltage > 0.0) {
    double voltageLimit = Math.min(12.0, batteryVoltage);

    double appliedVoltage = Math.max(
            -voltageLimit,
            Math.min(voltageLimit, requestedVoltage)
    );
Java
    power = appliedVoltage / batteryVoltage;

motor.setPower(power);

          addData("Target (rad/s) ", targetVelocity);
telemetry.addData("Velocity (rad/s) ", measuredVelocityRadPerSec);
          addData("PID, pidVoltage);
telemetry.addData("Feedforward Voltage", feedforwardVoltage);
          addData(controller.atTarget());
telemetry.addData("power", power);
           update();

Configure the FTC motor for direct power control when this loop supplies the velocity feedback control.

Convert encoder readings into the units used by your gains. FTC's no-argument DcMotorEx.getVelocity() returns ticks per second, so it cannot be substituted directly for a radian-per-second measurement without conversion.

For a moving velocity reference, include its requested acceleration:

Java
double feedforwardVoltage = feedforward.calculate(
        referenceVelocity,
        referenceAcceleration
);

When disabling control, stop applying the calculated output and command:

Java
motor.setPower(0.0);
controller.reset();

EasySimpleMotorFeedforward does not accumulate state and requires no reset.

Última actualización 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.