Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

P & PD control algorithms applied to PIC based line foll

Status
Not open for further replies.

metal

New Member
Hello

I need to build a line follower, based on PIC16F84A. I was asked to depend on designing the program with P & PD trasnfer functions.

I need to know the algorithms that interpret P & PD transfer functions into flowcharts at least.

I use PIC Basic Pro to write PIC programs, so any flowchart, but right one will be easily done.

Thanks in advance
 
Implementing a PID controller in code is fairly easy; you just need to translate the equasions into code.

Error signal e: e = setpoint - measured_location.

Proportional control: P is a constant that you detirmine through testing.

control_output = P*e.

Derivative control: You can aproximate the derivative by calculating the difference between the newest error sample and the previous error sample. derivative(e) = e - previous_e.
D is another constant that you detirmine through testing.

PD controller:
control_output = P*e + D*derivative(e)

Make sure you get the sign correct on P and D. The sign depends on the order you do the subtraction for e and derivative(e). P should cause a push towards the setpoint. D should oppose the direction of motion.
 
Hello

Thanks for this reply, I was going to abandon the whole idea, but you gave me a step forward to continue.

I am using PICBasic Pro compiler to write my program and PIC microcontroller, the two rear motors are those types found in toys.

If I want to use three infra-red transceivers as sensors for my robot
"Left - Middle - Right", considering the output of each sensor as logic 1 or logic 0, depending on whether the line exists beneath the sensor or not. Then, I will have eight possible states for these three sensors. Shall I consider these eight outputs the measured location, or not.

The setpoint, what is it practically in my robot, is it a predefined constant, a variable, or one of the measured locations that I will consider to be a reference for instance. I need more explaination please.


Now, when I get the error sample, how can I perform subtraction of the new and the previous value, to obtain derivative control part.

The control output is simply the direction of each rear motor, how can I sum P and D control parts to obtain PD control algorithm.

Thanks
 
Using a PID controller with your sensors really doesn't make sense. You need a better position sensor for PID to be useful.

I think you're overcomplicating your solution. With your 3 sensors a simple algoritm should do a decent job of line following.

If the middle sensor is on turn both motors on.
If the Left sensor is on turn the right motor on.
If the Right sensor is on turn the left motor on.
 
bmcculla, very good explanation about implementation of Proportional and derivative. Can you please let me know about integral as well? Cheers
 
Last edited:
The integral part is only needed if you require precise position. The integral term will cause a small error to be amplified over time and result in zero error position. It is only useful in systems that require accuracy rather than fast response.

Mike.
 
i mean how do we implement on microcontroller. Like as bmculla said

"Derivative control: You can aproximate the derivative by calculating the difference between the newest error sample and the previous error sample. derivative(e) = e - previous_e.
D is another constant that you detirmine through testing.

PD controller:
control_output = P*e + D*derivative(e)"


but whats about integral? i.e. if i want to implement PID? By the way i am working on inverted pendulum on cart so you think i can get away with PD only?
thanks
 
I'd have thought that a Proportinal and Integral functions would have been more suited...Derivative is usually employed to reduce time lags in slow changing processes...

Least that's what I was taught at college....
 
Last edited:
Hi,


Another idea is to start with the Laplace form of a PID controller, then do a
bilinear Z transform on the Laplace, then convert that to a difference equation.
You end up with another form suitable for a micro controller.


BTW, here is a flow graph of a typical PID controller...does it really help any?
 

Attachments

  • FlowGraph01b.gif
    FlowGraph01b.gif
    5.1 KB · Views: 551
Last edited:
**broken link removed**

"PID without a PHD," a very good online explanation of PID control and how to implement it.
 
Status
Not open for further replies.

Latest threads

Back
Top