A simple distance measurement system that uses a laser and a webcam

Or would you rather view Home!, Projects! , Tux the penguin!, My resume.


Of course the system uses Linux. Information for building your own (currently incomplete) follows.

The system

Schematic Diagram

The laser emits a beam at angle beta with respect to the line formed by the laser and the video camera. That beam then bounces off some object distance c away and enters the camera at angle alpha. Since we know the d, alpha, and beta, we can easily calculate h. Alpha is easy to calculate when once the position of the dot in the image from the camera is known.

Electronics

[Diagram not available]

The electronics is simply a simple 3 volt power supply that can be disabled by an external TTLish signal. This allows the computer to compare images with and without the laser on in order to find the dot easily. The TTLish input signal is connected to one of the pins of a spare serial port.

Mathematics


From the triangle above, we know:

,


and,


.

Therefore:

,


and,


.


All we must do now is calculate alpha as a function of the position of the dot within the image. From geometrical optics, we find that: Alpha=Arctan(f/(X*s/n))

Where X is the position of the dot relative to the center of the image, s is the size of the detector, f is the focal length of the lens , and n is the number of pixels of the detector.

Downloading and compiling

If you like, you can Download the source code to a program I wrote for Linux that does all this. You simply need a video camera for Linux and a similar electrical setup. It's badly written and not intended as an example of good programming. It is also a part of a larger project so their are some weird interface artifacts.

To compile the program, compile video.c and Xgraphics.c separately into .o files. You will need the -O2 flag for the IO assembly inlines to work correctly. Then link the two object files together and against the X11 and math libraries. The program works with glibc2.1 but some include file names need to be changed to work with libc5.

If you have any questions, problems, or suggestions, please email me at dstaff(at)ugcs.caltech.edu


dstaff(at)ugcs.caltech.edu