Let's Make Robots!

Homemade Laser Rangefinder

OddBot's picture

My laser range finder got a lot of interest so I thought I'd try to explain it in more detail.

Laser_rangefinder.jpg

It's not finished yet as it still needs to be mounted on it's stepper motor with a home position switch.

The sensor side has been tested on an oscilliscope. When I moved my hand in front of it, the pulse width varied to match.  Below is a diagram showing how the sensor works.

 On the underside of the cpu fan is a small piece of a blank cd glued to the centre of the fan.  This spinning mirror directs the laser (5mW red) around the room. The small black tube at the upper right is a phototransistor with a piece of heatshrink on it so it only detects light from in front of it.  This signal is amplified by a couple of transistors and mixed with the tacho output from the fan to give me a pulse with a width that represents the angle of the mirror when the phototransistor was hit by the beam.  The chip at the top is a "D" type flip flop that is used to mix the tacho signal and the pulse from the amplifier. 

 

Robot_Laser_Ranger_Explanation.jpgAs you can see, the closer the object, the sharper the angle of the laser. This isn't how the commercial units work, I couldn't find anything on how they worked. because of the way this works the output is logarithmic.

This means that close up, the resolution might be a couple of mm's but further away it will be in cm's.

 Resolution can be improved by increasing the distance between the spinning mirror and the phototransistor but may reduce the overall range.  I'm not certain why the range is so limited, I was expecting to pick up objects up to 4 or 5 meters away (about 15 feet).  I noticed that commercial units have a fairly big lens at the front so I suspect it needs glasses (it's short sighted like it's creator ha ha).

Despite it's range limitations (at the moment) it has the advantage of being able to detect chair / table legs more accurately.  These have always been the nemisis of robots using sonar and infra red.

For those using picaxe basic this is easy to use with the pulsin command doing all the hard work. Higher proccesor clock speeds will also increase resolution.

At the moment I'm using a BPV11 phototransistor from Dick Smith Electronics as the beam detector. It's very sensitive to red and infrared light. It just has a piece of black heatshrink on it at the moment so that it can only dectect light directly in front but later I will mount it in a seperate case if I can find a suitable lens to increase it's range.

 

 

 

 

 


LASER RANGE FINDER MADE EASY!

For anyone interested in making they're own laser rangefinder I've stripped down the original schematic to make it easier to understand and to adapt to your own robot. You can use any processor, laser and spinning mirror you want. See the attachment for a full sized schematic.

Easypeesy_Laser_Rangefinder_Schematic.jpg

The power supply with +3V for a laser is optional, you may already have a suitable supply and/or a laser that needs a different voltage.

The Amplifier with sensor is the really important bit, I've simplified it a bit from the original.  If you can't get the exact components, don't panic!  The transistors are just general purpose NPN and PNP transistors with a hfe of about 400. This amplifier just boost the pulse from the sensor into a sharp on/off pulse, nothing fancy. I did try a third stage originally but found I was getting too much noise. If you end up using a different phototransistor than the BPV11 you may have to change the 10K resistor in series with it.

The Mixer, I've shown two different variations of the mixer because the tacho on my fan gave out 2 pulses per revolution.  The flip-flop in option (a) divides this down to 1 pulse per revolution with the output of the amplifier cutting the pulse short in response to detection of the beam. Option (b) is for spinning mirrors of your own design that would probably only give one pulse, from positive to ground and back to positive again.

 The Output to the processor is a pulse of variable width, picaxe basic users can just use the pulsin command to do the hard work.

You'll notice that I have a 12V cpu fan running on 5V, this isn't just to make power supply issues easier, it's to slow the fan down.  The slower your mirror spins, the wider the pulse, the more resolution you get.  Between 20 and 60 revolutions a second (120-360rpm) is ideal as long as the mirror spins at a constant speed.  Some motors may get a bit jerky at slow speeds in which case you should use a gearbox for low rpm.

If you are making your own spinning mirror then make sure your mirror is a high grade, toy mirrors are crap, the easiest solution is to cut out a piece of a blank CD/DVD about 10mm square.  You can go bigger but the heavier it gets, the more it will vibrate if it's out of balance (and another reason that slow speed is good speed).

I used a stepper motor to rotate my whole assembly around for scanning because it was cheap and didn't require a constant signal from the processor to maintain position however a servo works just as well or you might just scan forward and rotate the robot on the spot (easy to do with skid steer).

Hope this helps :)

 


I did a few experiments which I briefly covered in boozebot's update.  This was the first time I was using a picaxe and not just the oscilloscope to measure the mixers output. I've been trying to improve the range of the laser rangefinder.

 

Rangefinder_test_1.jpg

The oscilloscope is measuring the output of the amplifier. I was using debug in the picaxe basic editor to monitor the distance of my hand but the white sceen in the background was messing with the camera.

As you can see, I'm extreemly jealous of Rik's new setup. The rangefinder with it's new monacle is balanced precariously on the front of the keyboard tray while the keyboard is hanging on for dear life at the back!

The picture that you can't make out is Leela from futurama drawn Tomb Raider style!

 

 

 

 

 

 

 

Anyway, enough of my jealousy and perverted taste, back to the laser rangefinder!

test_1_closeup.jpg

As you can see, I've got a 60mm magnifying glass taped to the front of a cardboard tube and mounted the phototransistor at the focal point. This does work better but I have to work on aligning all the optical components. I need to get the phototransistor / lens in line with the laser. At the moment moving the PCB up and down or tweaking the laser up and down affects the distance it can detect. I did get it to pick up a white object at about 2 meters but with some adjustments to both the optical alignment and the amplifier I think I can increase the range to a useful 3 or 4 meters.

The optical setup I've got here is probably bigger than I need but it was what I had laying about.

During this test (aside from things falling off) I noticed that turning off the lights reduced the range.  With the oscilloscope on the first stage of the amplifier the signal from the phototransistor dropped off dramatically.  I realised this was because with the base pin cut off of the phototransistor the only energy turning on the transistor was the photons hitting it. I tried biasing another phototransistor that didn't have thebase lead cut off but rather than boosting the signal it swamped it. Even with resistors in the megaohm range it did more harm than good plus all this high impedance circuitry connected to the base was picking up electrical interferance.

The upshot of all this sofar is that I'm going to mount some high intensity red leds inside the cardboard tube where they won't block the light coming in but will ensure a minimum amount of light hits the phototransistor.  The reason for the red LED's is that the phototransistor is only sensitive to red and infrared light. By adjusting the intensity of these LED's I should be able to achieve optimum sensitivity in any light condition and my robot will have a glowing red eye just like the terminator. I suppose the scanning laser is the other eye (like the borg). Hmmm will Boozebot (a) get me a beer, (b) steal my clothes and bike or (c) assimilate me.  Only time will tell.

 

 

 

AttachmentSize
Easypeesy_Laser_Rangefinder_Schematic.jpg220.48 KB
Mr Clean's picture

Hey!  This actually makes

Hey!  This actually makes sense to me!  Well, mostly.  :)  Those guys at "idiot's guide to ..." should hire you.

One question, though.  In order to know the calculate the distance, your microcontroller has to know the position of the mirror on the fan, right?  I would understand if the mirror were mounted on a stepper motor, but I don't get how you can know the angle of the mirror at the exact time that the reflection of the beam is detected by the phototransistor.

OddBot's picture

Wait a sec and I'll update

Wait a sec and I'll update the blog so it explains that better but basically thats where the fan's tacho output comes into play.
robologist's picture

Great schematic and description!

Looks pretty cool, need more analog designs showing amps, and how to derive good usable outputs. This is really cool, a sort of big Sharp GP2D12, but using a laser and scans. You've got a good triangulation set-up. Others using this range technique have scanned the laser and used a camera to pick up the differing angles.

I've heard of some folks using something called a PIN diode as a detector, for getting either the time of flight measurements or maybe the phase shift measurement methods of laser rangefinding. That might get you more sensitivity and range, but they might be somewhat expensive if I remember correctly. 

OddBot's picture

PIN diode

The phototransistor contains a PIN diode or an equivelant. The only advantage to using a photodiode (a type of PIN diode) is it has a faster response time (nano seconds rather than milliseconds) but in my design that isn't necessary.  Originally I used a RED led with the same wavelength as the laser.  LED's can be used as photodiodes but they're not very sensitive.

Check out this amazing video of using LEDS as a touch sensor!

http://cs.nyu.edu/~jhan/ledtouch/index.html

Mr Clean's picture

Woah!  That video is crazy!

Woah!  That video is crazy!
BaseOverApex's picture

How it works!

...and HERE's how it works. With ... (wait for it) ... some PIC RISC assembler code to show you how to do it!!!!
BaseOverApex's picture

Time of flight

You won't measure time of flight with a PIC...

Phase shift. Hmmm... If two convergent beams were shone onto a phototransistor mounted on a servo head, the phase shift might be measurable. I seem to remember that the "peaks and troughs" can be several millimetres apart... What do you think?

OddBot's picture

I had considered phase shift

I had considered phase shift but how would you measure it?  This is why I ended up with the design I have, it was easy to implement.  The most expensive part was the cpu fan.
OddBot's picture

Sharp GP2D12

Hmmm, maybe I should cheat and just buy those.   I didn't know you could get anything like that so cheap and small.  But at this stage I'll continue with my home made version for the education and because it doesn't suddenly tell you the wall is a long way away when you get to close. That can be dangerous with a big heavy robot that can exceed 10km/hour.  Imagine all the big holes in the plasterboard during fine tuning of the software:(
rik's picture

optics

The range would indeed profit from a lens. Not because of the improved focus (a sharper image on the "retina"), but because of the improved aperture (more light reaching the retina aka photo transistor). The bigger the surface area of the lens, the more reflected light it will receive (and subsequently focus on the transistor).

8ik

(wears the wrong kind of lenses)

Mr Clean's picture

Yes but you'd need a very

Yes but you'd need a very deep depth of field, right?  If the laser's reflection is out of focus, the phototransistor may not register.  Unfortunately the larger the lens, the shallower the depth of field, so it might just complicate things rather than improve the design in this case.

However, it could be done.  I'm sure that if you know anything about optics you'd be able to figure it out.  :) 

OddBot's picture

The best I have at the

The best I have at the moment is the lens system used by disposable camera's. A combination of a Concave and a convex lens provide a form of autofocus but the disposable camera's have a wide view lens system.  My range finder needs a narrow view.  Might get a cheap telescope and pull it apart.
Mr Clean's picture

I'm honestly not sure that

I'm honestly not sure that this would cause a problem, but it's worth bringing up.  A telescope will still present difficulties with focus.  Telescopes are usually default "infinite" focus, meaning that an image is in focus only if light is coming into the lens completely straight.  This is fine for astronomy since everything in the night sky is far enough away to basically be coming in with parallel beams of light (as opposed to light that is spreading out ... think about how a shadow is bigger if the light source is closer to an object).  So, anything close enough to be within effective range of your laser will be our of focus.

What I'm not sure about is how the phototransistor will react to an out-of-focus image.  Even if diffused, most of the reflected light is still there, so it might not matter at all.  Worth experimenting with.  If I were you, I'd head to a toy store and buy the cheapest telescope or binocular type thingy they have. 

OddBot's picture

Focus doesn't matter as it's

Focus doesn't matter as it's only detecting the presence of the laser light.  The important bit is that as much light as possible hits the photo transistor. I agree with rik, considering that the diameter of the phototransistors lens is 5mm, even a 20mm lens would increase it's sensitivity 16 times.  Think I'll keep an eye out for a cheap telescope.
rik's picture

plenty choice

more than plenty

if REALLY cheap is your taste

OddBot's picture

Thanx

Thanx for the help but I've already tried a $2 set of binoculars without any luck, I'm going to experiment with a small magnifying glass (made with real glass) next. It's bigger than I was originally looking for at 65mm but that should boost the light input by a factor of 169 (65mm/5mm=13, 13^2=169). If that doesn't work then nothing will!

I'll post a video of this experiment in this blog so that everyone can see what I'm doing and then if it doesn't work you'll be able to tell me what to try next.  Ultimately (when/if it's all working properly) I'll design a pcb for the laser rangefinder with on board power supply to make it easy for anyone else to add it to their project.

Mr Clean's picture

I'd imagine a magnifying

I'd imagine a magnifying glass should do the trick.  Let us know how it goes.
BaseOverApex's picture

Loga-whatsit?

I don't have a full grasp of logarithmic things, but I think the angle / distance relationship is Tangential as discussed here. Your diagram is superb, by the way and explains everything perfectly.

After a quick glance at your schematic, I see you have given your MCU some control over the fan. Can't see why you'd want speed control, since you're measuring the fan RPM. My worry would be that if the MCU decided to stop the fan and leave the laser on, it would be left pointing in the one direction. Possibly into the eye of your dog(!)

OddBot's picture

Fan/Laser control

The MCU only turns the laser and fan on or off, That way it can turn the laser off when it's not required e.g. charging at a docking station

 

BaseOverApex's picture

Clearly

Yes. The concern is a glitch which might cause teh fan to stop but not the laser...
OddBot's picture

That's why I didn't use an

That's why I didn't use an infrared laser, at least you can tell if that happens.
OddBot's picture

Non linear

that's it! logawhowhatsy was just the way I was taught but all doughnuts are round (the good ones anyway)!

This is a really cool

This is a really cool project!  There was a team at the Trinity Home Fire Fighting contest 2003 I think, that used a green laser and a linear array.  The result was very small, and rotated around on the top of the bot fairly quickly, taking measurements as it spun.  I believe it works just like the GP2D12 do: http://www.acroname.com/robotics/info/articles/sharp/sharp.html   It was incredibly impressive, especially for its size.  I had planned on trying to build one,  but had forgot about it until now. 

I found the teams website which has some info on it: http://www.eng.buffalo.edu/ubr/ff03laser.php

OddBot's picture

Had a look at that site and

Had a look at that site and the schematic, it looked complicated though.  At this point I'm trying to make mine smaller. I might even be able to get rid of the big magnifying lens with a change to the amplifier design.
Mr Clean's picture

Green lasers are probably a

Green lasers are probably a bad idea for use in hobbies, though.  They're frickin powerful ... probably not a good thing to put in the hands of a homemade robot.  I borrowed one from my prof when I was taking astronomy.  They're awesome because you can point them into the sky at night and the visible beam seems to reach all the way to space, making it easy to point out astronomical objects.  They're so powerful, though, that the beam actually produces heat, and is powerful enough to pop a balloon.  It's generally not a good idea to shine red laser pointers into people's eyes, but green lasers can freaking blind you.
 
Not trying to discount the fact that the link to the university's design is a great reference ... it is.  Just wanted to point out that green lasers probably aren't the safest option for household use. 

I agree with you about the

I agree with you about the lasers, as cool as a robot with lasers is, I think that for more permanent applications, it would be better that sensors dont interfere with anyones health.  The commercial laser rangefinders seem to use class 1 IR lasers.  I like the idea of the sensor not outputing any visual clues of what it is scanning, although it probably makes debug harder.  DVD burner lasers are powerful (and fun to play with) too, I was burning holes in plastic before mine burned out, and that was before I got a lense for it.  I think Blue ray lasers are probably the sweetest out there right now. 
Mr Clean's picture

Hmm ... I was just wondering

Hmm ... I was just wondering about IR lasers, actually.  Those wouldn't harm peoples eyes, right?  If they were sub - green laser in their power so as not to create heat, they could be a really good option.  This is assuming of course that the phototransistor can pick up IR light.  It probably can.

And as far as DVD / BluRay laser go, do you have any idea where they are in the light spectrum?

I just saw a youtube video

I just saw a youtube video of the Sick laser in action, producing a 3d image of the crowd at a convention, so I am assuming it is very safe.  Class 1 is safe under all conditions of normal use, according to wikipedia: http://en.wikipedia.org/wiki/Laser_safety

I think most phototransistors are sensitive to IR light anyway, but you cen get specific IR ones as well (think IR remote recievers)

The Dvd burner laser I has was red, just much more powerful than your standard laser pointer, I was inspired by this page:  http://felesmagus.com/pages/lasers-howto.html

Blue Ray is in the low 400 nm range, but it is actually more of a violet color, true blue is higher.

heat and power is dependent on the mW rating of the diode.  Mine burnt out because I left it on for too long without a large enough heat sink.  You could get a green laser with much less power, it would not be as bright or go as far, but it would be safer.  

OddBot's picture

IR lasers are extremly

IR lasers are extremly dangerous because if one shines in your eye, you don't blink or turn away. You just go blind. In the case of my rangefinder I purposely used a visible laser so you'd know if it pointed at you. In this case it helps that it's spinning because even if it does get into your eye it's only for an instant.

Same as if you run your hand quickly through a candle flame it won't burn you but if you hold your hand still it will.

Mr Clean's picture

I wasn't aware that IR could

I wasn't aware that IR could harm your eyes.  I suppose that makes sense, though.  Just like invisible UV rays can give you skin cancer, scentless carbon monoxide can make you suffocate, and inaudible ninjas can sneak up on you and flip out and kill you. 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.