Search This Blog

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()



4 comments:

  1. When you get this working, can I help you mass produce to sell online?

    My store is http://marginallyclelver.com/ I would love to have something as awesome as this made available for everyone.

    ReplyDelete
  2. Hi,

    I tried using your code and I can't get correct readings. I placed an object about 10cm, 20cm, and 30cm and I keep getting about 30cm for all three. I am using an arduino UNO running at 16 Mhz. I figured that the uno was running twice as fast as the FIO that you were using, so I divided the results by 2. I just opened the NewPingExample.ino that you included on your Git Hub page. I also tried using the code that is posted on this page. Would you happen to have any ideas on why it's not working? I would greatly appreciate it. Thank you.

    ReplyDelete
    Replies
    1. I've replied to your email, however, the OSLRF is not designed for less than about 50cm ranging due to the lens parallax. I augment mine with a Sharp IR for the 8-100cm range.

      Delete
  3. Do you by any chance still have the schematic for the OSLRF01? I would love to look at it, but the dev went commercial and took all the design info down.

    ReplyDelete