Help on PID control Resources

Hi all,

I’ve updated my 3pi with a small gyro and wheel click sensors, from with I work out an (x,y) coordinate for the robots position.

I want to be able to give it a start and end point and drive to it. I was looking into using PID to workout how to update the motor power to ensure it keeps to it’s heading.

I realise I can use the shift off the X axis to determine if the bot it drifting off the desired line so P= XDesired - XActual.

So the +/- error of the desired becomes the P?
Then the I is the sum of those error calculations
D = difference between this P and last P

The area’s I’m unsure about are:

  1. How to work out the constants (I’m using the 3Pi as a testbed for a larger robot so I’l like to know how to change them)

I’ve found most useful for basic tuning. Any other ideas?

Does this look like it’ll work?



Hello Mark,

It sounds like you are roughly on the right track with what you are doing. Before you make your PID control and figure out the constants involved, you should probably figure out how to interpret the information you are reading from your sensors. You say that your error is calculated by XDesired - XActual, but you need to calculate what XActual is from your sensor readings. Without XActual, you are not going to be able to tune your PID control loop.

What kind of gyro and wheel click sensors are you using? Can you post a picture of your setup? What kind of readings are you getting from your gyro and click sensors? If you just push your 3pi around with your hand (not driving the motors), do the readings from the sensors make sense?

- Ryan

Google “PID tuning”

This will bring up a number of web pages that discuss what the P, I and D terms are, how to apply them to correct course errors and also how to adjust them for your particular application.

The latter step involves the determination of three multiplicative constants (usually called Kp, Ki and Kd, which can be zero) that are unique to every control situation. The proper values will lead to smooth corrections if the robot drifts off the intended course.


Cheers for the replies,

The gyro just returns a values from 0-359 degrees. There are about 88 clicks per rev on the wheel. The motors are driven via PWM setup.

XActual is calculated with basic sin/cos trig using the current gyro value and the distance travelled is a given internal.

How often should the PID control be called? Every 10ms seems to be a reasonable number.



Trial and error!

Some PID algorithms are called on every wheel click (by interrupt) which allows the velocity to be determined from the interval between clicks. In any case, you have to know whether the current wheel position/velocity has been updated recently or the correction will be wrong.

You may also have to smooth the measured intervals between wheel clicks with a digital low pass filter, typically of the form
smoothed_interval = smoothed_intervalbeta + most_recent_interval(1-beta)
with beta some adjustable fraction (like 0.25).

Since you have a gyro, you should check out Borenstein’s papers on "gyrodometry"
which corrects for tracking errors due to uneven surfaces and wheel bumps.

Umm remember seeing that paper once before (Pre Gyro)- shall give it a try, looks promising - have you had any luck with it. I seem they don’t have results for when the robot is cornering