Flywheel Speed Fluctuating, PID Help

Whenever I set my flywheel speed to below 100 percent, the flywheel fluctuates above and below the target RPM. I’ve heard that PID control can help, but I have never coded something like this. Could someone direct me to some resources that could help me learn how to code PID?

Here is my code:

1 Like

Here’s a good video to learn PID.

I’ll also add on that your target value in the algorithm should be your speed (RPM) that should be tracked by a rotation sensor.

There are also other resources that you can find with the searchbar.


PID is not the only “control algorithm” and is probably not even the best one for a velocity controller such as your FlyWheel. Purdue has documentation on a couple that may be both easier and more appropriate for your application:


Does it happen at low speeds like 20-40% throttle?

Hey @Dave-TBR! So you actually can’t run the PID in the background during driver control like this. There’s something called “Task” in PROS that you use so you can run it in the background. It essentially introduces the topic of threading, which allows you to run several things simultaneously. It is very useful and can be implemented very easily.

Here’s the link to the API:

Good luck!

1 Like

Sorry, didn’t see you’re using vexcode.


An issue you may run into is that if one of the motors on your flywheel is slightly worse than the other it requires more voltage to run. When you speed the weaker motor up it will increase the speed of the stronger motor since they are on the same gear train. Now the stronger motor will attempt to slow down which will bring the weaker motor down to. This will go back and forth causing oscillation.

I think this is one of those answers that sounds correct, but isn’t. If this were the case… practically everyone’s chassis would oscillate/surge/etc as you have to get 4 motors to work in parallel.

Typically, dissimilar motors share a proportion of the torque needed and run fine, provided they are reasonably matched.

1 Like

I think it’s the case sometimes. For example, last year my team ran into the same problem when we tried to control our 6m drivetrain (all geared together) with percent. We didn’t notice any oscillation but observed the issue by printing the motor speeds to the brain. There was a improvement when we switched to a voltage controller.

Ya your probably right. My team experienced this, but we had a bad motor that was barely working.