Skip to content

Commit c098a6a

Browse files
Finished the implementation section
1 parent 85d23ed commit c098a6a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/section-7/feedforward-control.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,22 @@ Once you have gotten good data and analysis, you should obtain kS, kV, kA and PI
176176

177177
## Implementation
178178

179+
WPILIB provides a [SimpleMotorFeedforward](https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.html) class that runs feedforward for a motor. After you obtain your feedforward constants (kS, kV, kA) from SysID, you throw them into the constructor of the `SimpleMotorFeedforward` and use the listed methods.
180+
```java
181+
// Create a new SimpleMotorFeedforward with gains kS, kV, and kA
182+
SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(kS, kV, kA);
183+
184+
// Calculates the feedforward for a velocity of 10 units/second and an
185+
// acceleration of 20 units/second^2
186+
// Units are determined by the units of the gains passed in at construction.
187+
double volts = feedforward.calculate(10, 20);
188+
189+
// drives the motor to the desired velocity and acceleration calculated
190+
// from the feedforward controller
191+
motor.setVoltage(volts);
192+
```
193+
194+
That's it!
195+
Similarly WPILIB provides a `ArmFeedforward` and an `ElevatorFeedforward` class whose only difference from `SimpleFeedforward` is that it accepts a \\(k_{g}\\) value.
196+
179197
## Conclusion

0 commit comments

Comments
 (0)