Leddar Library for Arduino
Author:  Pier-Olivier Hamel
Contact: support@leddartech.com

Leddar Library for Arduino

Contents

History

ReleaseDateChanges
1.022/01/2014Initial release.
1.030/06/2014Added support for RS485 shields which do not have automatic direction control.

Background

LeddarTM (Light Emitting Diode Detection and Ranging) is a novel detection and ranging technology created by LeddarTech that performs detection and ranging by time-of-flight measurement using pulses from infrared LEDs. While ultrasonic sensors are typically limited in their range of detection, LeddarTM Technology can detect and locate objects at a distance of up to 50 meters under the harshest conditions.

By using an area sensor as the collecting device of the reflected beam, the sensor simultaneously provides a given number of range values for different parts of the scene without any moving parts as generally used for area scanning.

Illumination Area and Detection Zone

Description

This library enables an Arduino board equiped with a RS-485 shield to communicate with any Leddar device via Modbus protocol and parse the information into simple data structures. For optimization purposes, this library only implements the necessary Modbus functions to work with a Leddar. This is not a Modbus Library.

Download

Download Here: http://share.leddartech.com/ArduinoLeddar.zip

Classes

Detection

Methods

  • Detection();
Default constructor

Variables

  • unsigned char Segment;
Channel number corresponding to this detection (0-baseed)

  • unsigned int Distance;
Distance (in cm) from the Leddar to the object

  • unsigned int Amplitude;
Ammount of light reflected, will usually not exceed 512

Leddar

Methods

  • Leddar();
Default constructor, sets communication to 115200bps and slave ID to 1 (Leddar factory defaults)

  • Leddar( unsigned long Baud, unsigned char Addr );
Constructor, creates a Leddar structure with the desired Baud rate and Slave ID

  • init();
Initializes the serial port for communication

  • getDetections();
Retrieves detections from the Leddar, stores them in the Detections[] array.

Variables

  • unsigned char NbDet;
Number of detections returned by the Leddar

  • Detection Detections[50];
Array containing the channel number, distance (in cm) and amplitude for each detection.
Note: While not very common, it is possible for a channel to have multiple detections if multiple objects are present in the field of view, and a modbus packet will transmit a maximum of 50 detections.

  • unsigned long TimeStamp;
Timestamp of the last acquisition.. The timestamp is expressed as the number of milliseconds since the Leddar was powered up.

  • unsigned char LEDPower;
Current LED power as a percentage of maximum.

  • unsigned char Status;
Acquisition statuses. This is a 8-bit field with 2 bits currently defined: bit 0 indicates that automatic LED intensity is enabled if 1, bit 2 indicates that object demerging is enabled if 1.

Example

  1. /*
  2.  Simple Leddar(TM) Example
  3.  Language: Arduino
  4.  
  5.  This program displays on a LCD screen the distance
  6.  and returned signal amplitude of the first detection
  7.  in channel #8 of a Leddar(TM)
  8.  
  9.  
  10.    Shields used:
  11.  * RS-485 Shield
  12.  * LCD Keypad Shield
  13.  
  14.  Created 21 Jan. 2014
  15.  by Pier-Olivier Hamel
  16.  
  17.  
  18.  This example code is in the public domain.
  19.  
  20.  */
  21. #include <Leddar.h>
  22. #include <LiquidCrystal.h>
  23.  
  24.  
  25.  
  26. Leddar Leddar1(115200,1);
  27. //Baudrate = 115200
  28. //Modbus slave ID = 01
  29.  
  30. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  31.  
  32.  
  33. void setup()
  34. {
  35.  
  36.   // Initialize LCD
  37.   lcd.begin(16, 2);
  38.  
  39.   //Initialize Leddar
  40.   Leddar1.init();
  41.  
  42. }
  43.  
  44.  
  45.  
  46. void loop()
  47. {
  48.   unsigned int Distance = 0;
  49.   unsigned int Amplitude = 0;
  50.  
  51.   if (Leddar1.getDetections() >= 0)
  52.   {
  53.  
  54.     for (int i = 0; i < Leddar1.NbDet; i++)
  55.     {
  56.       if (Leddar1.Detections[i].Segment == 8)
  57.       {
  58.         Distance = Leddar1.Detections[i].Distance;
  59.         Amplitude = Leddar1.Detections[i].Amplitude;
  60.         break;
  61.       }
  62.     }  
  63.  
  64.     lcd.setCursor(0,0);
  65.     lcd.print("Distance:        ");
  66.     lcd.setCursor(10,0);
  67.     lcd.print(Distance);
  68.     lcd.setCursor(0,1);
  69.     lcd.print("Amplitude:        ");
  70.     lcd.setCursor(11,1);
  71.     lcd.print(Amplitude);    
  72.   }
  73.   else
  74.   {
  75.     lcd.setCursor(0,0);
  76.     lcd.print("Error:         ");
  77.     lcd.setCursor(0,1);
  78.     lcd.print("No Leddar Found");
  79.   }
  80.  
  81.   //pause 50ms
  82.   delay(50);
  83.  
  84. }

Useful Links

Share