Ultrasonic PID dilemma

Hey guys I need some halp. Trying to use a PID with an ultrasonic sensor to always go to the correct distance. I’m finding that my PID is giving enough power to the wheels to make tiny adjustments. Obviously when I increase the Kp to get more power i’m getting a lot more overshoot. When I add enough Kp until it can make small adjustments i’m getting huge amounts of over shoot. Should I some how get the ultrasonic sensor to communicate with shaft encoders to reach the desired value?

Ultrasonic isn’t fast enough to do that. Your sample rate will be way too slow.

But in general the D term does help mitigate overshoot (back down P, add D).

-Cody

I’ll try adding more Kd monday but I still need a way to add more power to the PID while reducing error. We have speed gearing on the drive so maybe switching to standard gearing would be better. It would suck to lose the speed though.

What are you setting the ultra sonic range sensors to read at? (inches, cm, or mm)?

Millimeter is going to be your best option, but I chooses not to use millimeter because of the bad readings from the sonars.

I personally would just slow down if your robot is rolling a lot. The PID function won’t predict the roll unless you create some function to do so. You don’t need to change the gears just put a cap on the maximum speed in the PID function.

I agree with these suggestions and have one more. For really small distances, don’t use PID at all.

For PID to kick in, you would have to wait a long time (relatively) for the integral to give you enough power to move and the kp would be overshooting at small movements.

kd is a localized change since the last reading, not an additive one like the ki

So for really small distances, turn the PID off and use some low enough power to get you where you want to be is what I tell people. Driving 6 inches or less from the initial target was the cut off point. Once you are where you want to be, you can re-initialize the PID to hold you there.