Problem with PID controller

Hi, 

i'm making a line follower project and i was thinking to use PID controller, but i don't know how to calculate the kp,ki,kd ..!

and there's a little probleme, i don't know what's beter to use, digital or analog ir sensor in PIC16F877A ?

thanks .

PID Tuning

There are some good internet article on PID tuning. To get started I would get a mount that keeps the wheels off the ground and set kp to 1, kd to 0.01, and kd to 0.0. To use PID you need feedback. You also need to chose between speed or distance as the error term. On the PIC16 you will probably want to use integer math we means scaling the intermediate calculations to powers of 2 for speed purposes.

What specific IR sensors are you looking at? Some of the digital models only report near/far. The models that report distance (analog,spi) usually have a non-linear response that you will need to convert to usable units either by lookup or math or both. I have some pic18 code in assembler that might be useful

Thanks for your support

Thanks for your support @ggallant 
but could you please give me an example code using those constances ?

and how i could calculate or write the error ?

and the ir sensor , i’m gonna use this sensor http://ram-e-shop.com/oscmax/catalog/images/images_big/IR_3mm_Rx.JPG
a normal ir reciever and ir led … what’s better for use ?
i use an Op-Amp and use a digital signal or use the sensor with out Op-Amp using an analog signal ??
and if i used a digital signal that gonna be ok with PID ??

thanks alot 

PID

That appears to be a passive IR sensor. It is dependent on the target emitting a significant amount of energy such as a lamp or candle. You will probably need an IR emitter to illuminate the line.

I typically use quadrature encoders on motor shafts. Depending on the number of pulses per revolution I either measure the pulse with (slow) or count the pulses per unit time (fast). With an encoder that generates 100 pulses per revolution at 6000 RPM I use hardware decoders available in some of the PIC chips such as the dsPIC33F series. For slower pulse count such as found on the wheels the decoding can be done in software. The pulses can be converted to speed or conversely the speed can be converted tp pulses. The PID error is the difference between the target and current velocities.

BTW, PID may be unnecessary for just a line follower.

Please post some details of your implementation. I am in the process of writing a forum post on quad decoders which may be useful in your project

PID Controller

Thanks for you support dear @ggallant

acually i’m making this line follower robot for a compettition, and everything must be a self-made so i must make the sensor by an IR Led and the IR Receiver .
so, what’s better for accurate move using an analog sensor or digitat sensor by adding an Op-Amp to the sensor cercuit ??
and i stiil can’t know how to use PID …!

i’m using Microcontroller PIC16F877A .

thanks alot for your support.