Please select To the mobile version | Continue to access the desktop computer version
| |

Robot Forum

 Forgot password?
View: 229712|Reply: 0

Understanding the IR compound eye

[Copy link]








Rank: 9Rank: 9Rank: 9

Post time: 2016-03-01 14:05:03
| Show all posts |Read mode
The IR compound eye consist of 4 simple analog sensors (up, down, left and right) that can be used to track movement of nearby objects (usually within 15cm indoors). Each sensor consist of two IR photo transistors wired in parallel to improve range. At the center of the eye is an IR lamp consisting of four IR LEDs. This IR lamp is controlled by software.


To use the eye with your robot you first need to read the sensors and eliminate any ambient light from the readings. If you don't eliminate the ambient light then the robot will track bright sources of ambient IR such as an open window on a hot sunny day.
Below we will look at some sample code and look at how it works.


This code starts by turning on the IR lamp and waiting 800uS to give all sensors plenty of time to respond to the change in light levels. The sensor values are then read and stored. These readings are a combination of both ambient light and light from the IR lamp that is reflecting from nearby objects.

The IR lamp is then turned off and we wait again for 800uS to ensure the sensors have had time to respond to the change in light levels. The new readings are ambient IR only so these values are subtracted from the previous readings. The resulting values are the change in IR due to light from the IR lamp reflecting from a nearby object.

If the object is directly in the center of view then it will reflect the IR evenly to all four sensors and all readings will be the same. If however the object then moved up and to the right, it would be closer to the up and right sensors and the reflected light would be brighter to these sensors because the intensity of light is inversly proportional to the distance squared.

The last line in the code takes all the sensor readings (up, down, left and right) and averages them together. This average value can be used as a rough distance measurement if the robot is solving a maze and all walls are the same colour. This value is also used to determine if there are any object within range to be tracked. When nothing is within range the value will be very small (usually less than 100). When something is very close this value can get above 900 (maximum is 1023).

If you want to track an objects movement then the compound eye needs to be fitted to a pan / tilt assembly. For fast smooth tracking the functions described here should be called every 15-20ms as that is the rate that servos are updated. The tracking function below is used to control the pan and tilt servos.


The first part of this code uses the distance value to determine if there is an object close enough to track. If not, the pan and tilt servos will slowly return to their center positions.

When there is an object to track the first thing we need to calculate are the pan and tilt scales. The reason for this is that the response from the sensors are non linear due to the fact that intensity of light is inversly proportional to the distance squared.

For example, an object is 10cm away from the sensor and when it moves left 2cm the left sensor value increases by 25 and the right sensor value decreases by 25. If the object had been only 5cm from the sensor when it moved left 2cm then the left sensor value would have increased by 100 and the right sensor value would decrease by 100 because half the distance will increase the intensity by a factor of 4.

Within the panscale and tiltscale calculations are the constants LRscalefactor and UDscalefactor. Typically these values are set to 2 so that the panscale is the average of the left and right sensor values and tiltscale is the average of the up and down sensor values. Depending on the speed of your servos and the rate that the code updates these constants can be tweaked. Bigger values with cause the servos to move faster but can cause over correction and servo jitter.

Once we have calculated our pan and tilt scale we can calculate how much and in which direction the servos need to move. The "leftright" value is the difference between left and right sensor readings multiplied by 5 and divided by the panscale. The "updown" value is calculated the same way but using the up and down sensor values.

Once the new pan and tilt positions have been calculated they are restrained to be within the minimum and maximum servo positions. The servo positions are then updated using the writeMicroseconds() command.

I have attached a text file with the functions shown here and their defined values. Just cut and paste directly into the Arduino IDE. You will need to change some definitions such as the IO pins and minimum / maximum servo positions to suit your project.

You can see the function of each pin in the picture below.


Compound Eye Code.txt

3.47 KB, Downloads: 672


Use magic Report

You have to log in before you can reply Login | Register

Points Rules


2010-04-30 15:41 GMT+8 , Processed in 0.254387 sec., 17 queries .

Powered by Discuz! X3.2

Release 20140618, © 2004-2010 Dagurobot

Quick Reply To Top Return to the list