I have a flywheel with a somewhat simple PID loop and I’m wondering if I could get some advice in tuning it. I’m able to graph data from it, and it gets to the correct speed over time more easily, but on short notices, like during firing, it won’t get to the correct speed. I’ve attached the graphs of the first few tests and the final two which i got to get. The accuracy of my flywheel is still only 50% or less even with this code. The PID loop works like this:

```
Tgain = .033;
Igain = .025;
while(true)
{
Error = setRPM - actual(Quad encoder RPM);//calculate error
Tunedpower = Tgain * setRPM;// power to get in the general range of the RPM
Ipower += Igain* error;// Integrator to change speeds over time.
constrain (Ipower,-15,15);
motor_power = Tpower + Ipower;
Constrain( motor_power,0,120);
if (abs(motor_power - Tunedpower) >15)//if not within the safe range to set speed quickly, slew to that range.
{
slewmotors(motor_power);//slew rate on spin up and spin down to keep from stalling
}
else
{
motor flywheel1] = speed;
}
delay(30);
}
```

I came up with this Idea for speed control after listening to how some flywheels run at a competition, and it seems to be working, but I can’t get it tuned right. Should I just have an P(not cumulative adding) instead of I gain(cumulative error over time) with the adjustment power? Any Advice?

Also, should I be using the Integrated Encoder RPM or the Quadrature Encoder RPM? The Integrated is at the bottom of a 1:35 single flywheel, while the quad encoder is geared down directly from the flywheel 4:1. The Quad encoder seems to read higher than the integrated, but the integrated is more erratic. They are both averaged with 2 previous values every 50msec.

All the graphs with these phenomena are included in the data, which are firing tests of 24-32 balls automatically whenever error is between -10 or +85 of the set value.