pid control using arduino for line follower robot......

i was trying to make a line follower robot...... with 2 sensors
initially i started with digital pins of sensors (0,1) and made the robot..... which was fishtailing....

then i did some research on google and find out that there is something like pid which could control the wobbling...... so i studied it, there were hundereds of arduino code which were for 5 or 7 ir sensor array and also for digital.... the thing i want was to control a robot using pid from analog output of 2 sensors and the tune it..... all the internet has robot code that is pid controlled for array of ir sensor......

so any idea would be appreciated for 2 sensors to control robot using pid....

You have to understand what PID is meant to do, and what it is not meant to do.

An example of an area where PID IS useful is controlling the temperature of the liquid in a slow cooker, where it can measure the temperature of the liquid, compare it to some set point, and turn the heater off or on, as needed to keep the temperature at the setpoint, or to get it there.

What are your input(s) and setpoint? How will you use the output to drive the input towards the setpoint?

The number of sensors is irrelevant, as long as you can use all of the data to arrive at a single value that is input to the PID algorithm.

What ARE your sensors measuring? What is your setpoint? What are you controlling?

i am using 2 ir analog sensors appox 3.2cm apart to follow a 3cm black strip…

i am not understanding how to could get 1 input for pid algorithm… as i have to drive 2 motors separately… this is the main problem i am facing…

thats why i am using 2 pid algorithms for both motors… but only one sensor is behaving like pid implemented…

the robot will follow the white line so its set point is that both sensors should adjust themselves in such a way that they should be always on white line… i am attaching pic of track so that you could have better idea of error i am facing…

sketch_feb26a.ino (2.41 KB)

Would the set point be equal readings from both sensors?

yes… while following white lines …if black comes below any sensor the opposite motor turns to original postion. and vice versa

as i have to drive 2 motors separately.... this is the main problem i am facing.....

So one makes the robot go forwards and backwards, and the other washes the windows?

The motors have ONE goal, don't they? That goal is to make the robot move forward. You vary the speed of one or both motors to steer, right?

So, the setpoint is 0 (no difference between the two sensor readings). The input is the difference between the readings (can be positive or negative) and the output will be used to determine how much faster one motor turns than the other motor.

Notice that the output says nothing about how fast the robot is moving. It can crawl along slowly, with one side still moving faster than the other to steer. Or, it can run like a bat out of hell, with one side still moving faster than the other to steer. If the motor that needs to turn faster is going all out, your only choice is to slow the other one down, instead.

PaulS:
The motors have ONE goal, don’t they? That goal is to make the robot move forward. You vary the speed of one or both motors to steer, right?

**************yes…

So, the setpoint is 0 (no difference between the two sensor readings). The input is the difference between the readings (can be positive or negative) and the output will be used to determine how much faster one motor turns than the other motor.

**********yes the set point is zero…

Notice that the output says nothing about how fast the robot is moving. It can crawl along slowly, with one side still moving faster than the other to steer. Or, it can run like a bat out of hell, with one side still moving faster than the other to steer. If the motor that needs to turn faster is going all out, your only choice is to slow the other one down, instead.

***********it very small speed… say 40 out of 256 duty cycle it follows line and and pid seems to be working. but at higher speeds, robot continues to wobble… and fish tailing increases and finally it comes out of line… another thing to mention that , in a straight track it wobbles at lower speed also.

it very small speed..... say 40 out of 256 duty cycle it follows line and and pid seems to be working. but at higher speeds, robot continues to wobble..... and fish tailing increases and finally it comes out of line..... another thing to mention that , in a straight track it wobbles at lower speed also.

This is where you need to tune the PID parameters.
I have never done it myself, but almost every discussion of a project using PID involved tuning the PID to reduce oscillation.

PID controller - Wikipedia