PID with Bang-bang?

Is there such thing as PID with Bang-bang velocity controller? Has anyone successfully integrated these two velocity controller concept. I think I have an idea but not sure if it will work. The problem with the proportional part of PID is it depends on the error of the measurement. So as the error gets smaller and so the amount of motor output and thus the Proportional part is always just close to the setpoint.

I was thinking of forcing a bang-bang controller so we can get to the setpoint faster. Then once we cross the setpoint we let the PID work on the steady state.

The equation goes something like this. The CObias will be the Bang-bang part of the code.
pasted_image.png

If you’re simply forcing bang-bang until it passes the setpoint, isn’t that just having the motors at full power until you overshoot your setpoint? It may work to reduce integral windup, but other than that I think a properly tuned PID would be almost as quick, with less overshooting.

Its the same as having p be absurdly high.

And then lowering it after one zero crossing (I think).

The problem with PID is that the, Proportional and Derivative are counteracting each other. I have attached our waveform to clarify my point. As you could see the flywheels speeds go from zero to about 9800 ticks per second (shaft encoder number). I could not totally eliminate the derivative part because it is important if we disturb the system (say shooting a ball). The derivative takes action by resisting that change in speed. So here is my dilemma, during autonomous part, I have to wait 3-4 seconds before I could fire my balls because that’s what it takes to stabilize the system.

So I’m thinking is it possible to do the Bang-bang only at the beginning to improve the rise time and to get rid of the problem of the derivative action.

So, some might ask why not just do the Bang-bang all throughout. Personally, I broke more than 6 motors already from the oscillation, so I don’t want to gamble anymore especially there is only a few days left for Worlds.

But anyways, if some have done it safely then please let me know.
chart.pdf (102 KB)

We use PI or just P to control the flywheel because D slows down recovery rate. You don’t have to use the derivative term. If tuned correctly you shouldn’t break motors or anything either; the flywheel shouldn’t oscillate that much.

Thanks for the reply. I thought we need derivative especially for highly dynamic system (high velocity control). I know that the D (derivative) slows down at the beginning but the derivative plays an important role in resisting change once we have achieve the setpoint. May I know what is your recovery time during shooting of the balls? Are you using double flywheel for your shooter? Thanks again.

Single flywheel at disco speed.

What you’re talking about sounds just like take back half. It runs at 127 until the first set point, then sets to the correct speed and scales from there.

Could someone please tell me how to create a Bang Bang loop?

Search the forum, there have been a handful of threads with that question exactly.

if (currentSpeed < target) flywheel(127);
else flywheel(60);

That’s a bit dangerous since the noise may make the motors rapidly switch between full and base speed.
It may be good to use a tolerance of like +/- 5 or so RPM. It may be a good idea to cut off the full speed at a bit before your target too, since it overshoots if you cut off right at the target.

I haven’t broken any motors yet with bang-bang, but I’m thinking of switching driver loads to PI since it’s inaccurate right now. (Currently, I have a small P incorporated to adjust for battery)

Yeah, don’t actually use that code, it was just some basic pseudocode anyways. I have found that there isn’t much point in bang bang since a PI controller with a really high P is effectively the same thing.

We didn’t have time to tune a full PI loop, so I threw together a bang bang in about 15 minutes. Other than that though, PI/D loops are better.

Thanks Michael, good job on that high robot and programming skills. I think I get it now. The problem is inherent with our shooter. We require more power to speed up TWO flywheels. Unlike yours, with a single flywheel you should have enough power for quick rise time. Plus our angle is a little flatter to make up with the variance in shooting. Flatter angle requires higher RPM to counteract the gravity.

I agree with Michael. Also, someone told me to do some kind of Fuzzy logic with four states. Meaning, you don’t have to keep swinging between power of 127 to 60. You could also make a scale of 100 to 80. Then closer to power needed to maintain your setpoint. Say if you require a power of 90, then keep swinging between 95 to 85.

974X Cyberbrains used the four state bang bang to great success (won every Colorado tournament) with their double flywheel. Read more in their reveal thread.

I agree that PID loops are more stable but requires a lot of experience tuning. The first time I had to tune a PID took me half a day. I also broke more than 6 motors from the oscillation. Piece of advice, stay away from Zeigler-Nichols method of tuning PID. It’s not worth it.

Ditto. I tried ziegler nichols and it was terrible. If you have ratchets on your flywheel, bangbang should be safe.