0 Members and 1 Guest are viewing this topic.

#### aruna1

• Supreme Robot
• Posts: 381
• I'm an Ordinary guy
« on: February 18, 2010, 05:24:44 PM »
hi,i'm working on a fast line following robot which uses analog sensor readings to follow line.can some one tell me how to programme the robot to remove ambient light interference from sensor readings and then use those ambient interference free sensor values to follow the line?.im more interested in some kind of adaptive algorithm that allows robot to work under both bright sunlight and in a dark room without physicalli adjusting or manually recallibrating sensors.hope you got what i trying to say,thanks.
I'm Me

• Robot Overlord
• Posts: 202
« Reply #1 on: February 18, 2010, 05:36:04 PM »
See This tiny line follower. It nicely implements what you are asking (and is tiny ).

#### aruna1

• Supreme Robot
• Posts: 381
• I'm an Ordinary guy
« Reply #2 on: February 18, 2010, 10:42:48 PM »
hi, i have already read that article.bt i didnt understand how algorithm is made. he samples two values and substract them to get ambient light free sensor value.that part was ok.problem is how to use that obtained ambient free values to find which part of sensor is on the line and which part is outside? dont we need some kind of threshold value?  thanks
I'm Me

• Robot Overlord
• Posts: 202
« Reply #3 on: February 19, 2010, 02:21:49 AM »
After taking those readings compare values between different sensors.

At a trivial level working out the mean of the sensor readings each 'sweep' should give you a threshold value, with the 'Line=FALSE' sensors on one side and 'Line=TRUE' on the other (providing sensor response is fairly even across all sensors). Really you are just applying largest value=closest to line centre.
« Last Edit: February 19, 2010, 02:26:13 AM by hopslink »

#### aruna1

• Supreme Robot
• Posts: 381
• I'm an Ordinary guy
« Reply #4 on: February 19, 2010, 03:27:06 AM »
so if i use this algo,i dont need to calibrate my sensors right? is there any exceptions where this algo will fail?
I'm Me

• Robot Overlord
• Posts: 202
« Reply #5 on: February 19, 2010, 03:52:35 AM »
You will want to calibrate each sensor so they all give the same reading under the same conditions as you build the 'bot. Once that is done there should be no need to recalibrate providing nothing changes.

As for failure, the algorithm should be sound ...but there are no guarantees. Build it and test it.

#### Pratheek

• Contest Winner
• Robot Overlord
• Posts: 125
« Reply #6 on: February 19, 2010, 08:43:57 AM »
I have not tried this but it just flashed to my mind - use another sensor to sense the light conditions of the robot's surroundings, based on this calculate the line sensors' value.

#### Webbot

• Expert Roboticist
• Supreme Robot
• Posts: 2,136
« Reply #7 on: February 19, 2010, 01:21:07 PM »
If you store the first reading of each sensor and then subtract it from future readings then you will be getting a 'difference' - so it should adapt to the initial light level.

Things to be wary of: when powering on the robot then make sure that all sensors are either on or off the line and that you aren't casting a shadow over some but not others.

The other alternative is to store the minimum and maximum ADC readings for each sensor on an on-going basis. This may cope better given that each resistor/device may not be identically matched. So one sensor may give: 1v-4v and the other may give 0.8v-4.2v; say; for the same light conditions. So what you could do is:
2. SensorMin = MIN(SensorMin, newReading); // keep smallest so far
3. SensorMax = MAX(SensorMax, newReading); // keep largest so far
4. Range = SensorMax - SensorMin;  // The range of values it has seen
5. X = newReading - SensorMin;       // The new value - between 0 and Range
6. Percent = (100 * X) / Range         // A value from 0 to 100%

Now you have a percentage value for each sensor ie what the current value is, expressed as a percentage of the light values it has seen.

So if all sensors have seen the same range of light values then they will all return 50%, for example, for the same light level.
You need to guard against a divide by 0 at step 6. This can be done in your startup code by taking an initial reading and setting SensorMin = that value - 'fudge' and SensorMax = that value + 'fudge' where the 'fudge' value represents a major shift in light level ie Black vs White rather than a small shadow.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

#### aruna1

• Supreme Robot
• Posts: 381
• I'm an Ordinary guy
« Reply #8 on: February 19, 2010, 05:45:09 PM »
You will want to calibrate each sensor so they all give the same reading under the same conditions as you build the 'bot. Once that is done there should be no need to recalibrate providing nothing changes.

As for failure, the algorithm should be sound ...but there are no guarantees. Build it and test it.

hi now I,m kind a confused.
• we read all 8 sensrs with light on and off
substract each values to get ambient fre reading for each sensor
calcuate thresh hold
decide which sensors are on the line and which are not,based on thresh hold

but what if robot goes off the line?,he want be able to identify it because it reads some values.

http://www.societyofrobots.com/programming_mobot.shtml
which one is better

PS. i'm currently buildng the robot,wanted to keep track of algorithm while its finished

I have not tried this but it just flashed to my mind - use another sensor to sense the light conditions of the robot's surroundings, based on this calculate the line sensors' value.

thought that too,you mean use differential amplifier to substract sensor readings from ambient light?
well i tried that before on my fire fighting robot,but didnt give much success

If you store the first reading of each sensor and then subtract it from future readings then you will be getting a 'difference' - so it should adapt to the initial light level.

Things to be wary of: when powering on the robot then make sure that all sensors are either on or off the line and that you aren't casting a shadow over some but not others.

The other alternative is to store the minimum and maximum ADC readings for each sensor on an on-going basis. This may cope better given that each resistor/device may not be identically matched. So one sensor may give: 1v-4v and the other may give 0.8v-4.2v; say; for the same light conditions. So what you could do is:
2. SensorMin = MIN(SensorMin, newReading); // keep smallest so far
3. SensorMax = MAX(SensorMax, newReading); // keep largest so far
4. Range = SensorMax - SensorMin;  // The range of values it has seen
5. X = newReading - SensorMin;       // The new value - between 0 and Range
6. Percent = (100 * X) / Range         // A value from 0 to 100%

Now you have a percentage value for each sensor ie what the current value is, expressed as a percentage of the light values it has seen.

So if all sensors have seen the same range of light values then they will all return 50%, for example, for the same light level.
You need to guard against a divide by 0 at step 6. This can be done in your startup code by taking an initial reading and setting SensorMin = that value - 'fudge' and SensorMax = that value + 'fudge' where the 'fudge' value represents a major shift in light level ie Black vs White rather than a small shadow.

is all this steps are for single sensor? (min max values)

thanks
I'm Me

#### Pratheek

• Contest Winner
• Robot Overlord
• Posts: 125
« Reply #9 on: February 19, 2010, 10:26:28 PM »
thought that too,you mean use differential amplifier to substract sensor readings from ambient light?
well i tried that before on my fire fighting robot,but didnt give much success

You don't need any external amplifier for that, you can always use the ADC of the microcontroller you are using, you will get better results for sure.

• Robot Overlord
• Posts: 202
« Reply #10 on: February 20, 2010, 12:15:55 PM »
hi now I,m kind a confused.
• we read all 8 sensrs with light on and off
substract each values to get ambient fre reading for each sensor
calcuate thresh hold
decide which sensors are on the line and which are not,based on thresh hold

Correct.

Quote
but what if robot goes off the line?,he want be able to identify it because it reads some values.

Ideally the robot will not go off the line because your control algorithm is good... , But here things start to get a little more involved. If there is no line all the sensors should read approximately the same value if you calibrated them when you built the 'bot. So you look at the values and if there is only minimal variation between all sensors you have no line.

Quote
http://www.societyofrobots.com/programming_mobot.shtml
which one is better

The best is which ever is more robust on the day... but you said you were looking for an adaptive system which doesn't require recalibration for each course. The difference here is that this algorithm adapts for every sensor sweep instead of having fixed thresholds like the one you link to, so if conditions change part way round a course it should prove more robust. But that is just conjecture without testing...

Quote
...is all this steps are for single sensor? (min max values)
thanks

Yes, for every sensor. Webbot suggests a refinement that provides a way of automatically overcoming mismatch between sensors. It will still be worth your while roughly calibrating your sensors to match each other initially and having measured figures for maximum variation between sensors under the same conditions as this value can be used for useful things like error checking.

#### aruna1

• Supreme Robot
• Posts: 381