Questions On PID

Hi my team is new this year and i just wanted to ask what exactly is PID and TBH and how would i go about using them. I heard it can help with fire rate and accuracy right? Also if there is an easier way to do it in robotC. Thanks.

Hello and welcome to the forum!

Yep. PID and TBH are both forms of velocity control. PID is a more general program that can be used for other tasks and TBH is (as far as I know) specifically for velocity control. Both of them, when tuned correctly, will help with fire rate and accuracy.

There isn’t really an easy way out of writing flywheel velocity control. But don’t worry, there are plenty of people on this forum who will be happy to lend you guidance. I’ll give a quick overview over both PID and TBH.

PID is an acronym for the three different parts of control loop: Proportional-Integral-Derivative. The three parts of the loop can be mixed and matched to achieve different results or to meet different situations.

The proportional loop is the most basic part of the loop and the foundation for the control. It finds the difference between a target value(in this case target velocity) and the current value of your encoder. It then outputs a value to the motors to decrease the “error” between the current and target values. The motors will automatically slow down as they approach the target value.

The integral loop is the running sum of past “errors.” The proportional loop, while effective, won’t completely eliminate the error between the target and current values. The Integral loop helps to further decrease the “error” but needs to be limited so that it doesn’t keep the motors running infinitely.

The derivative loop calculates the difference between the current error and the past error. It then predicts the next error. It not only helps to bring down error even further, but it also helps to decelerate the motors gently into the target value.

PID is pretty complicated but worth your time to learn IMO. I don’t know much about TBH, but a lot of teams have found success using it. There’s only one constant to tune as opposed to the three constants that come with PID. More info can be found in this thread: Flywheel velocity control - Technical Discussion - VEX Forum

Happy day.

Ok thanks, I really appreciate it when people like you take the time and help! So i’m thinking about using TBH since there is only one constant so thanks for that thread. Also we currently have set buttons for full field and mid-field and a couple more for adding 1,5, or 10 to motor speed with about 70-85% accuracy at a fairly slow rate (about 1 shot every 2 seconds) so could we have those in affect with PID or TBH because i heard there is some sort of thing that counts the ticks of your motor and adjusts based on that so i think it could be affected by the buttons. And do you have to put anything in the motors for PID of TBH? Well anyway thanks again!

I actually just had the idea could you have sort of like multiple PID’s for example one for when you are shooting from the back and it sets a speed and adjusts from there and one for mid field. Is something like that possible or am i just being silly.

Yes, something like that is definitely possible. You can just toggle the target RPM.

It’s a bit simpler than that actually. You can keep your presets as they are but instead have different target rpms for each button. So you could have a target of 1000 rpm for mid field, 700 for bar shots, etc. You won’t have to change anything in your motor sensor setup but remember that the velocity control will output a value to your flywheel motors in the loop.

So you will need an encoder. Either a red one or integrated one.

Ok thanks for all the help I understand it a lot more now!

Edit: And on that link that Nehalem sent i noticed instead of an encoder he used a light sensor and sheet of paper to calculate velocity could that work out to still be as accurate as the encoder?

Both of them are valid methods of calculating the velocity. I don’t think the paper method is technically legal for competition since VEX doesn’t sell paper, but don’t quote me on that. My team uses an encoder to calculate velocity.

The only thing is that i’m not sure if we have one and i don’t think our coach really wants to tamper with the inner workings of a motor. But thanks i’ll have to look more into it.

My mistake. The color filter method is legal.
You won’t have to tamper with encoders or anything like that.

ok great thanks!

Any suggestions for fine tuning PID? For example, what should we be changing to make it shoot faster? Do we adjust the error divider? P? I? etc. What should we change to make it more accurate. We have had mixed results and regardless of the changes we have made, we are not seeing big differences in our shot.

“Originally Posted by Wikipedia
If the system must remain online, one tuning method is to first set Ki and Kd values to zero. Increase the Kp until the output of the loop oscillates, then the Kp should be set to approximately half of that value for a “quarter amplitude decay” type response. Then increase Ki until any offset is corrected in sufficient time for the process. However, too much Ki will cause instability. Finally, increase Kd, if required, until the loop is acceptably quick to reach its reference after a load disturbance. However, too much Kd will cause excessive response and overshoot. A fast PID loop tuning usually overshoots slightly to reach the setpoint more quickly; however, some systems cannot accept overshoot, in which case an over-damped closed-loop system is required, which will require a Kp setting significantly less than half that of the Kp setting causing oscillation.”

Basically you increase Kp until it over shoots than undershoots consistently. Then you increase KI until it is accurate consistently. Then people say to do that over again until you can’t get KI to oscillate anymore and then go back to last time you had it accurate.

After that you can increase Kd just a little bit to make it faster. It should be super small though like .0005 and stuff.