EasyElevatorFeedForward
Elevator Feedforward
An elevator feedforward model estimates the output needed to hold or move a vertical mechanism, such as an elevator or linear slide.
It accounts for static friction, gravity, velocity, and acceleration without calculating position error.
EasyStack's EasyElevatorFeedforward provides this model using four configurable gains. It can be combined with a feedback controller to help the mechanism follow a target position.
Creating an Elevator Feedforward
To create an EasyElevatorFeedforward, provide the gains in the following order:
EasyElevatorFeedforward feedforward
new EasyElevatorFeedforward(kS, kG, kV, kA);The parameters are:
| Parameter | Description |
|---|---|
kS | Static friction compensation, applied according to the sign of velocity. |
kG | Constant gravity compensation. |
kV | Velocity gain. |
kA | Acceleration gain. |
For example:
EasyElevatorFeedforward feedforward =
new EasyElevatorFeedforward(
0.2,
0.7,
3.0,
0.4
);These values are illustrative. Determine the gains for your mechanism, gearing, and load.
Without Acceleration Compensation
A three-argument constructor is also available:
EasyElevatorFeedforward feedforward =
new EasyElevatorFeedforward(kS, kG, kV);This sets kA to 0.0.
For example:
EasyElevatorFeedforward feedforward
new EasyElevatorFeedforward(@.2, 0.7, 3.0);This is equivalent to:
EasyElevatorFeedforward feedforward
new EasyElevatorFeedforward(@.2, 0.7, 3.0, 0.0);Units and Direction
For a voltage-based model using meters, configure the gains with these units:
| Gain | Units |
|---|---|
kS | Volts |
kG | Volts |
kV | Volts per meter per second |
kA | Volts per meter per second squared |
With these gains, calculate() returns volts.
Other distance units, such as encoder ticks, can be used if the velocity, acceleration, and gains are consistent.
The class does not convert units or apply its output to a motor.
Positive Direction
A common convention is:
| Quantity | Positive direction |
|---|---|
| Position | Upward |
| Velocity | Moving upward |
| Acceleration | Acceleration upward |
| Motor output | Produces upward force |
Under this convention, kG is normally positive because holding the elevator requires an upward output.
Gravity compensation is added in the same direction whether the elevator is moving upward, moving downward, or stationary.
Calculating Feedforward
Use calculate() with the requested velocity and acceleration:
double voltage = feedforward.calculate(
velocity,
acceleration
);The parameters are:
| Parameter | Description |
|---|---|
velocity | Linear velocity, such as meters per second. |
acceleration | Linear acceleration, such as meters per second squared. |
The calculation is:
output * Math.signum(velocity)
* velocity
* acceleration;For example:
double voltage = feedforward.calculate(0.5, 1.0);Using the example gains:
output 0.2 + 0.7 + (3.0 * 0.5) + (0.4 * 1.0);The result is 2.8 volts.
For motion tracking, velocity and acceleration normally come from the desired motion reference.
Calculating Without Acceleration
Use the single-argument overload when acceleration compensation is not needed:
double voltage feedforward.calculate(velocity);For example:
double voltage = feedforward.calculate(0.5);This is equivalent to:
double voltage feedforward. .5,The acceleration contribution is zero even if the object has a nonzero kA.
Holding the Elevator Still
For a stationary reference, provide zero velocity and acceleration:
double holdingVoltage = feedforward.calculate(0.0, 0.0);This simplifies to:
holdingVoltageThe single-argument form produces the same result:
double holdingVoltage feedforward.calculate(0.0);With kG = 0.7, the estimated holding output is 0.7 volts.
This compensates for the modeled gravity load. It does not detect or correct a position error by itself.
Unlike an arm feedforward model, this implementation does not require an angle. It assumes a constant gravity compensation term.
Static Friction Compensation
The static term follows the sign of the supplied velocity:
staticCompensation = kS * Math.signum(velocity);Its behavior is:
| Velocity | Static contribution |
|---|---|
| Positive | +kS |
| Negative | -kS |
| Zero | 0.0 |
At exactly zero velocity, static compensation is zero even if the requested acceleration is nonzero.
The implementation does not use acceleration or position error to select a starting direction.
Moving Downward
For downward motion, use a negative velocity:
double voltage = feedforward.calculate(-0.5, 0.0);Using the example gains:
output -0.2 + 0.7 + (3.0 * -0.5);The result is -1.0 volts.
The gravity term remains positive while the static and velocity terms become negative.
A downward velocity does not always require negative output. Depending on the gains and requested speed, the model may return a positive output to oppose gravity while the mechanism descends.
Combining Feedforward with PID
Feedforward estimates the output needed for the requested motion. A feedback controller corrects position error.
Add the outputs when both use the same output units:
double pidVoltage = controller.calculate(
measuredPosition,
targetPosition
);
double feedforwardVoltage = feedforward.calculate(
targetVelocity,
targetAcceleration
);
double requestedVoltage = pidVoltage + feedforwardVoltage;For a stationary position target:
double feedforwardVoltage feedforward.calculate(0.0);This adds the constant gravity compensation to the PID correction.
If feedforward returns volts, configure the PID gains to produce volts as well. Do not directly add a normalized motor-power output to a voltage output.
EasyElevatorFeedforward does not generate a motion profile. Your program must supply any changing position, velocity, and acceleration references.
Maximum Achievable Velocity
Use maxAchievableVelocity() to estimate the positive-velocity boundary for an available voltage and specified acceleration:
double maxVelocity = feedforward.maxAchievableVelocity(
maxVoltage,
acceleration
);The parameters are:
| Parameter | Description |
|---|---|
maxVoltage | Positive available voltage magnitude. |
acceleration | Specified acceleration in the model's units. |
For example:
double maxVelocity = feedforward.maxAchievableVelocity(
12.0,
0.0
);The calculation is:
maxVelocity =
(maxVoltage - kS - kG - acceleration * kA)
/ kV;The result is in meters per second if the gains use the meter-based units described above.
This formula assumes positive velocity when applying static compensation. A negative result should not be treated as a validated reverse-motion boundary.
Minimum Achievable Velocity
Use minAchievableVelocity() for the negative-velocity branch:
double minVelocity = feedforward.minAchievableVelocity(
maxVoltage,
acceleration
);For example:
double minVelocity = feedforward.minAchievableVelocity(
12.0,
0.0
);The calculation is:
minVelocity =
(-maxVoltage + kS - kG - acceleration * kA)
/ kV;This formula assumes negative velocity.
Gravity makes the modeled upward and downward velocity boundaries asymmetric.
Both velocity methods require a nonzero kV. For the usual interpretation of maximum and minimum boundaries, use a positive kV.
These methods return model estimates. They do not enforce limits on the mechanism.
Maximum Achievable Acceleration
Use maxAchievableAcceleration():double maxAcceleration =
feedforward.maxAchievableAcceleration(
maxVoltage,
velocity
);For example:
double maxAcceleration =
feedforward.maxAchievableAcceleration(
12.0,
0.5
);The calculation is:
maxAcceleration =
(maxVoltage
- kS * Math.signum(velocity)
- kG
- kV * velocity)
/ kA;This returns acceleration in the units used by the model.
The static term follows the sign of the supplied velocity. At zero velocity, that term is zero.
Minimum Achievable Acceleration
Use minAchievableAcceleration():double minAcceleration =
feedforward.minAchievableAcceleration(
maxVoltage,
velocity
);Internally, it evaluates the acceleration formula at negative maximum voltage:
return maxAchievableAcceleration(
-maxVoltage,
velocity
);Both acceleration methods require a nonzero kA. For the usual maximum and minimum interpretation, use a positive kA.
The three-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:
= feedforward.kS;
= feedforward.kG;
= feedforward.kV;
= feedforward.kA;They can be read directly but cannot be reassigned after construction.
To change the gains, create another instance:
feedforward =
new EasyElevatorFeedforward(
0.25,
0.8,
3.2,
0.45
);The class does not validate the supplied values.
Limiting the Output
calculate() does not clamp its result to the available voltage.
Apply a limit before commanding the motor:
double requestedVoltage = feedforward.calculate(
targetVelocity,
targetAcceleration
);
double maxVoltage = 12.0;
double appliedVoltage = Math.max(
-maxVoltage,
Math.min(maxVoltage, requestedVoltage)
);For an FTC motor controlled through setPower(), convert the voltage request to normalized power using a valid measured supply voltage:
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 example combines the previously shown EasyPIDController with elevator feedforward to hold a target height.
It assumes that your encoder conversion provides height in meters, with upward motion positive and a known position reference.
Create the controllers before entering the loop:
import dev.easyfamily.easystack.control.EasyPIDController;
import dev.easyfamily.easystack.control.wpiLibControllers.EasyElevatorFeedforward;
// Illustrative gains: tune for your mechanism.
// PID input: meters. PID output: volts.
EasyPIDController controller =
new EasyPIDController(8.0, 0.0, 0.5);
EasyElevatorFeedforward feedforward =
new EasyElevatorFeedforward(
0.2,
0.7,
3.0,
0.4
);
controller.setTolerance(0.01);
controller.setTargetPosition(0.5);Inside the active control loop, obtain fresh values for measuredHeightMeters and batteryVoltage, then calculate:
double pidVoltage = controller.calculate(
measuredHeightMeters
);
// The target is stationary, so only gravity compensation remains.
double feedforwardVoltage = feedforward.calculate(0.0);
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)
);
power = appliedVoltage / batteryVoltage;motor.setPower(power);
telemetry.addData("Height (m) ", measuredHeightMeters);
telemetry.addData("Target (m) ", controller.getTargetPosition());
addData("PID, pidVoltage);
telemetry.addData("Feedforward Voltage", feedforwardVoltage);
addData("At Target", controller.atTarget());
telemetry.addData("power", power);
update();Configure the FTC motor for direct power control when this loop controls the mechanism.
To follow a moving reference, update the PID target and supply the reference velocity and acceleration:
controller.setTargetPosition(referencePosition);
double pidVoltage = controller.calculate(measuredHeightMeters);
double feedforwardVoltage = feedforward.calculate(
referenceVelocity,
referenceAcceleration
);When disabling the output:
motor.setPower(0.0);
controller.reset();Removing power also removes active gravity compensation; the elevator's behavior then depends on its mechanical support and motor configuration.
EasyElevatorFeedforward does not accumulate state and requires no reset.
Última atualização 2026-11-16