Main Site Documentation

Need help with a PID (PD?) controller


I’m having a problem trying to wrap my mind around how a PID controller works.

I need one for RWAR that will correct the steering servo (0-180) to allow it to follow a heading.

I looked at the formula, and it looks like I have the following variables in the following formula:

Note there is no integral term. I don’t think I really need it, so I am more talking about a PD controller.

I have a few question:
[li]For the accumulative_error, do I literally just add up the error (desired_heading - current_heading) since the control loop started? [/li]
[li]I need the output to be 0-180. How does the output of the above equation correspond to that? I guess I need to manually map it’s output to that 0-180 range? What’s the best way to do that?




I think you might want to start out with just a proportional controller. The other factors in a PID controller are for situations you might not see.

Basically, a proportional controller measures where you are and based upon where you want to be, develops an error value.

In this case, the error would deternine if you needed to go to the left or right. You would then adjust the servo to the correct direction, wait a little and see what direction you were going, and repeat correction process.

The number of degrees you are off course determines what direction you need to steer, but I think other factors will determine how fast you turn. I don’t know if there is a direct fudge factor to take you from error degrees to how many degrees you need to change steering.

Of course, speed determines how much of a correction you could do each time. If you were going very slow you could make a bigger correction than if you were going fast. Too much of a correction at high speed will cause a roll over.

As you get closer to the correct direction you would be making smaller and smaller corrections until you were on course.

The corrections you make are proportional to how far you are from the desired course, If your corrections are too big, then you will overshoot your course and begin to oscillate.

Rather then understanding the math, I would focus on the principle and heuristically solve the problem.

I don’t know if I have been clear and this helps?


Hi Mike,

That was very clear, thank you!

I talked to a few people, and their advice was right on par with what you are suggesting. As soon as I get my GPS and new brushless motor system I’ll be posting more about this.