I have been trying to optomize the PID to control my 3pi, however I am still getting a lot of gitter.

Any help would be appreciated. See Attachment

# 3pi Line Follower PID

**sheltoj**#1

**paul**#2

I don’t see any attachment. Can you describe the jitter you are seeing a little more? What happens if you set I and D terms to zero? It might help you to look at Section 5 of the jrk motor controller User’s Guide, where we talk about how to tune PID constants in a lot of detail. Scroll down to the part with the graphs and you might get some good ideas.

-Paul

**paul**#4

I don’t know if you expect me to read through the whole program or what, but it looks pretty similar to our demo line following code. You have increased the max speed a lot without changing the constants much, except that you decreased the proportional constant by a lot. Here is the most critical line:

I notice that you are casually using a floating point value of 1.3 in the expression. That is asking a lot for a tiny processor when you are expecting this computation to take a small fraction of a millisecond! I am not sure about the exact timing, but I suspect that doing derivative*4/3 is going to be much more efficient. That is why we wrote it that way in the first place.

Anyway, I suggest you go through the PID tuning strategy described in the link from my previous post. Basically, start with only a proportional term, increase it until you reach the limit of stability, set it to about half of that value, and add in just enough of a derivative term to prevent overshooting. After that you can experiment with the effect of the integral term.

Good luck!

-Paul

**Lucky13**#5

i dont want to start a new topic so i ask here. Im trying for 2 days now to tune the PID and i havent done it right yet. Ive already read the link that you have above but still no luck. Can anyone give some basic rules to start tuning the PID? I tune it a little bit in a slow speed but only with the trial and error method without knowing what im doing… =\

**paul**#6

Hello,

That link does give some basic rules. Basically, start with just a small proportional term, increase the coefficient until line following becomes unstable, then decrease it somewhat and add a derivative term.

For the 3pi, you should also start with a low *speed*, and increase the speed only after you have made progress.

I recommend leaving out the integral term until you have it following well at full speed - and even then you might not want it at all.

-Paul

**sa5mmm7**#7

Hello, I am also trying to perfect PID. My equation is:

`int power_difference = proportional*1/8 + derivative*25/10;`

I think I have been doing pretty well, except for the fact that I am unsure on when I should bump up the speed. This equation so far works for a rectangle-ish track with 2 inch rounded corners. The max speed that this works at is 200, but when turning the corners it is too wobbly. Should I continue to change the values at speed 200 or add in the integral value? Or should I go back to a lower speed to test out values?

When I bumped the speed up to 255 my 3pi stayed somewhat on the track. It would overshoot and escape the line a tad but get back on the line and be fine, so I know that something needs to change.

**JonathanKosh**#8

Hello.

Like Paul said, I think you can leave out the integral value until you achieve reasonable performance at max speed. I think you could keep focusing on tuning P and D at a speed of 200 to see if you can get the wobbly cornering to disappear. If you can’t make any progress, try lowering the speed and then seeing if you can tune P and D to reduce the wobbling around corners. Then, you can try increasing the speed a little and fine tune P and D some more.

Also, a 2-inch corner radius is quite tight; you might also try experimenting with rotating your wheels in opposite directions during the robot’s cornering for a tighter turning radius.

-Jon