Skip to main content

Feedforward Systems

MotorMotor

A MotorFeedforward is the baseline feedforward and can be used when there are no external forces acting on the mechanism. An example of this would be a the robot drivetrain, where the motors only have to fight against friction and inertia. If your motors are constantly fighting against gravity, an ElevatorFeedforward might be a better option.

// Create the feedforward controller
MotorFeedforward feedforward = MotorFeedforward(MotorFeedforward::Options {
// All these values will need to be tuned to your robot
staticFriction = 1.0f, // <-- Power required to overcome static friction
velocityGain = 1.0f, // <-- Power required to maintain a constant velocity
accelerationGain = 1.0f // <-- Power required to accelerate
});

void opcontrol() override
{
while (true) {
// This is how fast the motor should be moving currently (in/s)
float targetVelocity = 100.0f;

// This is how fast the motor should be accelerating (in/s^2)
float targetAcceleration = 0.0f;

// Calculate the amount of voltage to apply to the motor
float feedforwardOutput = feedforward.update(targetVelocity, targetAcceleration);
sampleMotor.move(feedforwardOutput);

// ...
}
}