Bang Bang vs PID

I have a 2mtr turbo 1-7 flywheel for short range and am unable to decide which method to use, What are the pros and cons of each?

Bang-bang is simpler to code and tune, and results in faster spin up times, while PID is far more accurate. PID has 3 constants to tune, in addition to the target velocity, while bang-bang only has the target velocity to tune. For a short-range flywheel, I would probably suggest bang-bang. It will get you a faster fire rate at the cost of accuracy, but short range shots can afford to be less accurate (greater spread of shots). That’s just me, though. Does anyone else have any suggestions?

I agree with this. If you want only short shots then go with bang bang. Honestly, bang bang works for me even for long range shots. Bang bang is so simple, you should just try it out first and see if it gives you the desires results. If it doesn’t, go with pid

Thanks I’ll Try both

bang-bang also will break the crap out of motor gears. sudden acceleration like that is bad. also it is really inaccurate at range

1 Like

Bang-bang is less destructive when you use another low value other than 0. The difference between 60 and 127 is easier for gears to deal with.

What would you suggest as the greatest safe acceleration in pwm/millisecond (pwm is the power sent to the motor from -127 to 127)

I have to contest this because of 323Z. They are using Bang-Bang for almost full court shots on their flywheel. Bang-Bang must use a ratchet in order to not break gears, and You have to no run 0, but something about 20-30 below the needed speed to get Bang-bang to work with VEX.

I don’t think a bang-bang controller will break any gears, except maybe the skinny ones. As long as you don’t go from 127 to -127, it should be fine. Basically, just make sure you clamp your motor power to 0-127 (that goes for any velocity control), or you will break something.
However, I think the accuracy of a PID or TBH loop outweighs the fire rate of a bang-bang controller. That’s just based on my experience with both. A well-tuned PID loop can come really, really close to matching the fire rate of a bang-bang controller, but you don’t need to worry about oscillation nearly as much, so it can handle inconsistent loading times.

Our team has never tried a bang-bang controller, but we have been using PID for a couple months on our flywheel. PID works great, however, one thing to stress is to TUNE, TUNE, TUNE! I probably spent a couple days tuning and trying to fiddle with the P, I, and D constants to find a near perfect result. But once you have the tuning down, it will improve your performance by quite a bit.

Haven’t had any trouble with this since July. We don’t use a ratchet.

You might be able to get away without using a ratchet, but this season it hasn’t been uncommon for some teams to tear teeth off of the internal motor gears. Our sister team, not using bang-bang, managed to do this twice.

Can I just ask how you got the steady state error to disappear? I tried normal PID with error based on the flywheel RPM and it never got to the power needed to spin the flywheel fast enough. even with constants at almost 5 for both P and I (no D) it would not even come close (error of about 5-10 rpm each time). Would traditional tuning (P then D, later I) work?

What was the goal rpm? I’m trying to get a sense for the order of magnitude. It does sound like PI was not programmed correctly though.

We have lost a couple motors that way with 2 teams this year, but we also lost drive motors that way.

Are your motors using maximum power to reach your target speed?
If this is the case then the PID loop won’t be able to adjust to your target RPM becuase the motors won’t be able to increase their speed (as they are already being maxed out).
If your not sure, just construct a simple little RPM reading program and just run all your flywheel motors at several speeds to find your desired RPM. If you are reaching your desired RPM at full motor speed then the PID algorithm can’t adjust if your error is greater than 0.
Ideally, you would want your flywheel motors to be using about 60%ish power to reach your target RPM so the PID has room to increase/decrease the motor speed depending on the error.
About your P, I, D constants, it looks strange at why they are so high, try starting ridiculously low and work from there. Also regarding tuning, try some different procedures as a base point.

** The Ku term is the proportional term at which your flywheel starts to constantly oscillate around the target RPM.

I would say @lpieroni answer above it right to the point.

However I would disagree with the second statement. We did use bang-bang style control earlier in the season and ended up ruining our gears.

Also, I believe 323Z used to have six motors, so the shock is spread to six gear sets. If you have less motors then each is subjected to more shock.

I would agree with @TriDragon that ratchet is not as important. What is more important, in my opinion, is limiting a slew rate of the power to the motor.

If you take a look at our hybrid speed control code it tries to accelerate flywheel with bang-bang style, then maintain constant speed with PI, and limit slew rate to 1 power unit per 1 msec at all times. Seems to work nice and accurate.

Another observation that I have is that when we were tuning our algorithm it entered a weird oscillation mode (with ~0.5 sec period) and managed to ruin both IME encoder gear and the next one in line just in a few seconds before we stopped it. Try to avoid discontinuous power level jumps caused by if() statements believing noisy speed readings

Same as @mattiasZ I would say constants shouldn’t be that large for a steady speed maintenance segment, we have Kp=0.566, ki1=0.0008 and ki2=0.002 (with ki2 corresponding to overshooting), but those are dependent on specific launcher gear ratio and amount of friction in the system.

The slew rate you have seems very fast. 1 motor power level per millisecond would allow the motor to go from stopped to nearly full power in a tenth of a second. Is this enough to be effective?

Also, thanks for posting your code, somehow I hadn’t seen it before, and it’s very interesting.

I don’t know, I thought we should have 2 power units per 5 msec for two motors, but kids added a third motor and said it is going to be totally fine with 5 power units per 5 msec.

I guess we will open motors after the next competition and find out if it was a good choice or not. :slight_smile: