@@ -80,9 +80,10 @@ The returned setpoint might then be used as in the following example:
80
80
// Controls a simple motor's position using a SimpleMotorFeedforward
81
81
// and a ProfiledPIDController
82
82
public void goToPosition(double goalPosition) {
83
- double acceleration = (controller.getSetpoint().velocity - lastSpeed) / (Timer.getFPGATimestamp() - lastTime)
83
+ double pidVal = controller.calculate(encoder.getDistance(), goalPosition);
84
+ double acceleration = (controller.getSetpoint().velocity - lastSpeed) / (Timer.getFPGATimestamp() - lastTime);
84
85
motor.setVoltage(
85
- controller.calculate(encoder.getDistance(), goalPosition)
86
+ pidVal
86
87
+ feedforward.calculate(controller.getSetpoint().velocity, acceleration));
87
88
lastSpeed = controller.getSetpoint().velocity;
88
89
lastTime = Timer.getFPGATimestamp();
@@ -96,10 +97,11 @@ The returned setpoint might then be used as in the following example:
96
97
// Controls a simple motor's position using a SimpleMotorFeedforward
97
98
// and a ProfiledPIDController
98
99
void GoToPosition(units::meter_t goalPosition) {
100
+ auto pidVal = controller.Calculate(units::meter_t{encoder.GetDistance()}, goalPosition);
99
101
auto acceleration = (controller.GetSetpoint().velocity - lastSpeed) /
100
102
(frc2::Timer: :GetFPGATimestamp() - lastTime);
101
103
motor.SetVoltage(
102
- controller.Calculate(units::meter_t{encoder.GetDistance()}, goalPosition) +
104
+ pidVal +
103
105
feedforward.Calculate(controller.GetSetpoint().velocity, acceleration));
104
106
lastSpeed = controller.GetSetpoint().velocity;
105
107
lastTime = frc2::Timer: :GetFPGATimestamp();
0 commit comments