Search This Blog

Showing posts with label Open Source Laser Rangefinder. Show all posts
Showing posts with label Open Source Laser Rangefinder. Show all posts

Monday, 10 March 2014

Success! OSLRF01 (LIDAR) successfully Scanning and providing accurate results.


I've been working on getting the OSLRF01 (Open Source Laser Range Finder)  to provide Distance Readings, using an Arduino Fio, running at 8Mhz.  My objective was to create a library to communicate with the OSLRF and make the interface easier for the end user.

After several iterations of my own, I exchanged emails with Tim Eckel, who wrote the NewPing Library for Ultrasonic Rangefinders , and have successfully created a version that will manage the signals from the OSLRF01.

Below are some images of multiple "pings" of the OSLRF sampled through the ADC of the Arduino.


At first, I had a problem with Ghost images.  This turned out to be a problem with the way I was managing my timers during interrupts.

Similarly, once I got a handle on the overall timing structure, I found I was still getting some sporadic samples...  Time to move away from "Arduino Code".  The "price" for digitalRead(PIN) and analogRead(PIN)  is many cycles...  Tim's NewPing code  cured this with converting to bitmasks, and doing bit manipulation of the ports.    Significantly faster....



So now, we have a 100 ADC samples of  41 iterations, all neatly stacked on top of one another.

And here is an image of the "Zero" pulse (The outgoing Laser Pulse) superimposed on the Return Echo "Signal".
This represents 64 "pings" of 59 ADC samples.   In here you can see I only had two bad samples, which are easy to remove with a median filter.


Now, using a slightly modified version of the NewPingExample Sketch 

// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define SYNC_PIN  2  // Arduino pin tied to SYNC pin on the OSLRF01 RangeFinder.
#define ZERO_PIN     A1  // Arduino pin tied to Zero pin on the  OSLRF01 RangeFinder.
#define SIGNAL_PIN     A3  // Arduino pin tied to Signal pin on the  OSLRF01 RangeFinder.
#define MAX_DISTANCE 1000 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 900-1000cm.

NewPing oslrf(SYNC_PIN, ZERO_PIN,  SIGNAL_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
unsigned long int syncWidth;                  // Retrieve Sync PulseWidth - used for calculating Timebase
unsigned long int zeroRise;                      //  Retrieve Strating edge of outgoing Laser Pulse - Trigger...

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  syncWidth = oslrf.sync_width();
  zeroRise = oslrf.zero_rise();
}

void loop() {
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = oslrf.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.print("cm       "); 

We get the following result...  Very consistent and clean.  

=~=~=~=~=~= PuTTY log 2014.03.09 22:11:53 =~=~=~=~=~=~=~=
Ping: 129cm  
Ping: 82cm     
Ping: 78cm      
Ping: 82cm       
Ping: 82cm      
Ping: 82cm      
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 83cm       
Ping: 82cm       
Ping: 83cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm  
Ping: 82cm      
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 83cm       
Ping: 82cm       
Ping: 83cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm       
Ping: 82cm     

Tonight I will take all of my "commentary" out of the Library code, and push it up to Github for anyone else who wants to play with this Wonderful Laser Rangefinder!

Did I mention it's only $100USD  !!!


Next up:   Writing the code to retrieve and display Cartesian Coordinates of echo returns while scanning.

Next, Next up:   Re-work all of this to fit on an ATtiny84 so I can finish my daughterboard I2C version....







References:
LightWare Optoelectronics ...
Open source, TOF laser rangefinder
 NewPing Library
Google Code: arduino-new-ping
Example of driving ADC and DAC from timer for regular sampling
Advanced Arduino ADC – Faster analogRead()



Monday, 3 March 2014

Short post on data out of OSLRF-01

It's late and I'm going to bed. My eyes are blurry, and I've got a headache... but!!!
I'm getting reliable (for the most part) Distance readings out of the OSLRF-01 as evidenced here in my putty dump.  The "ACTUAL" distance to target was in fact 2.67m.  I've got a fairly consistent reflection or ghost at 0.67 and few more stragglers that I will work to filter, but I'm quite pleased. 

Thank you once again  LightWare Optoelectronics ...
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2014.03.03 22:06:02 =~=~=~=~=~=~=~=~=~=~=~=
RST, Running oslrf01_rawdata - State Machine. 140303
Timebase Control set to 20
12,   zeroCenter = 0    returnCenter = 0    Delta = 0   SyncWidth = 0   Distance = 0.00
114,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21464   Distance = 0.67
215,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19416   Distance = 2.67
317,   zeroCenter = 448    returnCenter = 1008    Delta = 560   SyncWidth = 21464   Distance = 0.48
419,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19432   Distance = 2.67
520,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21480   Distance = 0.67
622,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19424   Distance = 2.67
724,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21480   Distance = 0.67
825,   zeroCenter = 240    returnCenter = 3072    Delta = 2832   SyncWidth = 19432   Distance = 2.67
927,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19432   Distance = 2.67
1028,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 19432   Distance = 0.74
1130,   zeroCenter = 224    returnCenter = 3056    Delta = 784   SyncWidth = 21488   Distance = 0.67
1232,   zeroCenter = 224    returnCenter = 3064    Delta = 2832   SyncWidth = 19432   Distance = 2.67
1333,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19432   Distance = 0.67
1435,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 19432   Distance = 2.67
1536,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19432   Distance = 2.67
1638,   zeroCenter = 240    returnCenter = 1024    Delta = 784   SyncWidth = 21472   Distance = 0.67
1740,   zeroCenter = 240    returnCenter = 3072    Delta = 2832   SyncWidth = 19432   Distance = 2.67
1841,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21480   Distance = 0.67
1943,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19424   Distance = 2.67
2045,   zeroCenter = 240    returnCenter = 1024    Delta = 784   SyncWidth = 21472   Distance = 0.67
2146,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19424   Distance = 2.67
2248,   zeroCenter = 464    returnCenter = 3072    Delta = 2608   SyncWidth = 19424   Distance = 2.46
2349,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21472   Distance = 0.67
2451,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19416   Distance = 2.67
2553,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21464   Distance = 0.67
2654,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19416   Distance = 2.67
2756,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21472   Distance = 0.67
2859,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19416   Distance = 2.67
2961,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21456   Distance = 0.67
3063,   zeroCenter = 456    returnCenter = 1016    Delta = 560   SyncWidth = 19408   Distance = 2.67
3164,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19408   Distance = 2.67
3266,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21472   Distance = 0.67
3368,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19440   Distance = 2.67
3469,   zeroCenter = 240    returnCenter = 1024    Delta = 784   SyncWidth = 21488   Distance = 0.67
3571,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19440   Distance = 2.67
3672,   zeroCenter = 240    returnCenter = 1024    Delta = 784   SyncWidth = 21480   Distance = 0.67
3774,   zeroCenter = 232    returnCenter = 2840    Delta = 2608   SyncWidth = 19424   Distance = 2.46
3876,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21472   Distance = 0.67
3977,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19424   Distance = 2.67
4079,   zeroCenter = 224    returnCenter = 2832    Delta = 2608   SyncWidth = 21472   Distance = 2.23
4182,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 19432   Distance = 0.74
4284,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19432   Distance = 2.67
4386,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21480   Distance = 0.67
4487,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19424   Distance = 2.67
4589,   zeroCenter = 240    returnCenter = 1024    Delta = 784   SyncWidth = 21464   Distance = 0.67
4691,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19416   Distance = 2.67
4792,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21464   Distance = 0.67
4894,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19432   Distance = 2.67
4995,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21488   Distance = 0.67
5097,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19432   Distance = 2.67
5199,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19424   Distance = 2.67
5300,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21480   Distance = 0.67
5402,   zeroCenter = 240    returnCenter = 3072    Delta = 2832   SyncWidth = 19440   Distance = 2.67
5505,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21472   Distance = 0.67
5607,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19424   Distance = 2.67
5709,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21480   Distance = 0.67
5810,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19432   Distance = 2.67
5912,   zeroCenter = 224    returnCenter = 784    Delta = 560   SyncWidth = 21472   Distance = 0.48
6014,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19416   Distance = 2.67
6115,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21480   Distance = 0.67
6217,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19440   Distance = 2.67
6318,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21480   Distance = 0.67
6420,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19440   Distance = 2.67
6522,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21488   Distance = 0.67
6623,   zeroCenter = 240    returnCenter = 3072    Delta = 2832   SyncWidth = 21480   Distance = 2.42
6725,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19424   Distance = 2.67
6828,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 19432   Distance = 0.74
6930,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19424   Distance = 2.67
7032,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21456   Distance = 0.67
7133,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19400   Distance = 2.68
7235,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21448   Distance = 0.67
7337,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 19432   Distance = 0.74
7438,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19464   Distance = 2.67
7540,   zeroCenter = 240    returnCenter = 3056    Delta = 2832   SyncWidth = 19448   Distance = 2.67
7641,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 19432   Distance = 0.74
7743,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19424   Distance = 2.67
7845,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21464   Distance = 0.67
7946,   zeroCenter = 240    returnCenter = 3072    Delta = 2832   SyncWidth = 19424   Distance = 2.67
8048,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21464   Distance = 0.67
8151,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19432   Distance = 2.67
8253,   zeroCenter = 232    returnCenter = 1016    Delta = 784   SyncWidth = 21472   Distance = 0.67
8355,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19416   Distance = 2.67
8456,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 21448   Distance = 2.42
8558,   zeroCenter = 464    returnCenter = 1024    Delta = 560   SyncWidth = 21464   Distance = 0.48
8660,   zeroCenter = 232    returnCenter = 3064    Delta = 2832   SyncWidth = 19416   Distance = 2.67
8761,   zeroCenter = 224    returnCenter = 1008    Delta = 784   SyncWidth = 21456   Distance = 0.67
8863,   zeroCenter = 224    returnCenter = 3056    Delta = 2832   SyncWidth = 19416   Distance = 2.67
8964,   zeroCenter = 232    returnCenter = 1240    Delta = 1008   SyncWidth = 21464   Distance = 0.86

Now... sleep... night all...

Saturday, 1 March 2014

Prototype of OSLRF01 Arduino Scanning LIDAR (Under $150)

I've finally got pictures to show off the OSLRF-01 
 Open Source Laser Range Finder.  

I've mounted it to a sturdy servo, and am running both currently with An Arduino FIO ... simply because that's the only available Arduino I have at the moment.

I am also getting boards made up around the ATtiny84 that will sit as a daughterboard on this unit.   But the FIO prototype is to help me get functional code working NOW...




The Carrier board here simply provides connectivity between the pins on the socketed Arduino Fio, and the OSLRF-01, a panning servo, and an I2C connector to communicate wit the host processor.    It also takes 12v in, feeds it to the Laser, and through a 7805 regulator powers the Arduino.  (Yes, I know the Fio steps it down again to 3.3v)




Although I intend to have a processor board mounted directly on the OSLRF-01, I had to solder on a Molex connector for now to connect it to the Arduino.   Some heavy plastic zip ties hold it in place on the servo pan arm.