Skip to content

Commit 274a0b4

Browse files
added note about why motor controller pid > roborio pid
1 parent 57bdd65 commit 274a0b4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

docs/section-7/feedback-control.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ motor.set(ControlMode.Position, 0);
131131

132132
And for SparkMax, SparkFlex, or other Rev motor controllers, we use the [`SparkPIDController`](https://codedocs.revrobotics.com/java/com/revrobotics/sparkpidcontroller) (Take a look at the javadocs). Notice how there are other methods that let you control the velocity, acceleration, setting target, and more:
133133
``` Java
134-
CANPIDController pidController = motor.getPIDController();
134+
// Make CANSparkMaxes run at 1 ms instead of 20 ms by default
135+
motor.setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame.kStatus0, 1);
136+
motor.setPeriodicFramePeriod(CANSparkLowLevel.PeriodicFrame.kStatus1, 1);
137+
138+
SparkPIDController pidController = motor.getPIDController();
135139
// Config
136140
pidController.setOutputRange(-1.0, 1.0);
137141
pidController.setP(kP, 0);
@@ -164,6 +168,9 @@ if (!pidController.atSetpoint()) {
164168
pidController.reset();
165169
```
166170

171+
!!! note
172+
`SparkPIDController` which runs on a CANSparkMax can [obtain inputs and outputs at 1ms](https://docs.revrobotics.com/brushless/spark-max/control-interfaces), while the `PIDController` which runs on the RoboRIO runs every 20ms. For this reason, it is preferred to use the `SparkPIDController` for more precise control. Note that you need to write additional code to make the CANSparkMax run faster since by default it runs every 20ms.
173+
167174
You need to check out the documentation for each of these classes and familiarize youself with them. [Definitely read WPILIB's documentation on their PID Controllers](https://docs.wpilib.org/en/stable/docs/software/advanced-controls/controllers/pidcontroller.html).
168175

169176
# Conclusion

0 commit comments

Comments
 (0)