Line Following Sensor Arrangement Algorithm

Interested in Robotics? Here's the place to be.
Post Reply
richardv2
Posts: 8
Joined: Sat Jan 19, 2008 11:03 am
Contact:

Line Following Sensor Arrangement Algorithm

Post by richardv2 »

I'm building several line following sensor arrays. One is an 8-inline array with QRD1114 sensors spaced at 0.5 inches. The 'line' will be 0.75 inch electrical tape. I want a more precise reading, so closer spacing, allowing two sensors to react when both are over the line, will give me more readings per inch.

I also have a theory about an inverted V array, like this:

#.........# front
.#.......#
..#.....#
...#...#
....#.#
.....#
***********
***ROBOT***
***BODY****
***********
***********

(# = sensor. periods are just spacers so your screen won't delete or ignore the spacing.)

My theory is that putting the prongs of the V out front, that I will be able to get earlier detection of 90 degree intersections and greater than 90 degree turns. (And other complex turns that might 'fool' an inline array.) And I equate earlier detection with the ability to go faster and still make the turn, therefore traversing a course or maze faster.

I've completed the inline array, and once working, will make the inverted V array and test both pretty extensively.

Does anyone have any wisdom on this? I've seen one robot on the net with a V, but with the point of the V out front, but not an array like above.

I would like to hear your thoughts or ideas on this.
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

hello richard,

the most accurate line following setup will be one that is analog rather than digital. You will also need much less hardware To accomplish this. I had a robot that could hug a line very well

http://www.sambuchi.net/Projects/Roboti ... botics.htm

heres the pic.


Image
richardv2
Posts: 8
Joined: Sat Jan 19, 2008 11:03 am
Contact:

Post by richardv2 »

So how does an analog line follower work?
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

Well, I am not sure if you understood me when I say Digital vs Analog.

In "line following" same concept can be used in other applications...

A digital signal will provide you with two answers on the line or off the line. These inputs would generally go into a I/O port of a micro... This is pretty extreme...ON OR OFF :shock: Say you have a good hardware setup over a line. The result would be "at best" your bot doing some jig & jag over a line.

If you do a analog setup... inputs would need to go into the analog port of a micro. In my picture above I have the optic sensor in the middle of 4 bight LED's.. the sensor is shielded with ducktape so the sensor needs to see the light being bounced from the ground.

WHAT DOES THIS DO?
Well.... I now have setup that allows me to see if I am "partially" on the line. :D

WHAT DOES THAT DO?
This allows me to do LOTS!!!!!! This is a great linear controls problem! I would then write up a PID controller in my micro to follow the lines..
Now I might be getting a little over your head. Not sure how much experience you have with micos.. math.. or this concept.. but if you would like to know more about this... give this a read.

http://www.chibots.org/drupal/?q=node/339

Hope this helps.

Tony
richardv2
Posts: 8
Joined: Sat Jan 19, 2008 11:03 am
Contact:

Post by richardv2 »

Sambuchi wrote:If you do a analog setup... inputs would need to go into the analog port of a micro. In my picture above I have the optic sensor in the middle of 4 bight LED's.. the sensor is shielded with ducktape so the sensor needs to see the light being bounced from the ground.
When I was testing my sensors, I noticed as the sensor approached the line, the output went from 0.20V (over white) and up to 4.2V (over black) so I think you are saying instead of running this signal lead to a gate or digital input and only getting 1 or 0, that I can run it to an analog input on the chip and get finer control, because you have many readings between 0.2V and 4.2V that you can catch or react to. If that's what you mean, then I understand.

Also, I've read several articles about PID, but I'm stumped as to *exactly* apply them to the code. See if I have the right idea below.

For example, let's say I have 7 sensors and 1 = over black and I get this reading:

0100000

so I know the line is under the left side of the robot and I need to turn left.
From the article you linked to:
Proportional = Target - measured position
This one seems easy. Target is 0001000 and I'm at 0100000 so I am off two positions to the left, which I might call -2. ...and 0000001 would be +3, and so on.
so...
0 = right on - keep going straight.
-1 = turn a little left
+1 = turn a little right

Integral
"Stores accumulated value" What does this mean? Suppose I'm coming back towards "center", and I get these readings..

0100000 = -2 total = -2
0100000 = -2 total = -4
0010000 = -1 total = -5
0001000 = 0 total = -5 (overshoot a little)
0000100 = +1 total = -4
Is the right hand column the "I" term??

And for Derivative, How do I get "Rate of Change"??
Bigglez
Posts: 1282
Joined: Mon Oct 15, 2007 7:39 pm
Contact:

Post by Bigglez »

Greetings (No First Name Supplied),
richardv2 wrote: Also, I've read several articles about PID, but I'm stumped as to *exactly* apply them to the code. See if I have the right idea below.
Here's a completed line-follower robot project
with a good explaination of PID signal processing.

Comments Welcome!
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi »

Richard

I am impressed on how well you grasped this new concept!

PID Controller
Proportional : You are correct! This is the simplest part of the controller.
Proportional is simply the difference where you are at from where you want to be. [Diff]

Now here comes some calculus…
calculus deals with the rate of change over a period of time.

Integral
To answer your question... Not really. You still to introduce time... so use the previous value with the current. Look at the code below.
Will calculate the acceleration of the bot.

Derivative
Will calculate the velocity of the bot.

Here is how the code will look…

Code: Select all


Diff = Tpos - Mpos
   Prop = Diff * Kp                                         'Calculate Proportional

   Integral = Integral + Diff                               'Calculate Integral
   Integral = Integral * Ki

   Rate = Diff - Difflast                                   'Calculate Differential
   Deriv = Rate * Kd

   Difflast = Diff

   Control = Prop + Deriv                                   'New control value
   Control = Control + Integral


   If Control > Upperlimit Then Control = Upperlimit        'Keep within safe range
   If Control < Lowerlimit Then Control = Lowerlimit

   Temp = Scenterf - Control
   Myint = Temp                                             'Convert Single to Integer
   Steeringfront = Myint
   Temp = Scenterr + Control
   Myint = Temp
   Steeringrear = Myint                                     'Convert Single to Integer

   Waitms 5                                                 'wait 5ms between loops (200 times a second)
Each term (P, I, D) Kp Ki Kd will need to be tweaked in your code.
There are many things about a robot that is very difficult to another
mathematically (ground friction, motor inductance, center of mass.
You will need to build the robot, implement a control equation, then
tweak the equation until it works properly.

Hope this helps.. Have you built your bot yet?
Engineer1138
Posts: 458
Joined: Thu Feb 05, 2004 1:01 am
Location: Minneapolis, MN
Contact:

Post by Engineer1138 »

I don't see why you need a V. A straight line of sensors at right angles to the travel of the robot will do just fine assuming you have processing power. The straight line, sampled at a high enough rate will give you a moving 2-D representation of the line (basically a low resolution camera) and you'll immediately be able to see that a 90 degree corner (or other shape) is coming.
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests