Leddar Library for Arduino
Author: Pier-Olivier Hamel
Contact: support@leddartech.com
Leddar Library for Arduino
Contents
History
Release | Date | Changes |
1.0 | 22/01/2014 | Initial release. |
1.1 | 30/06/2014 | Added support for RS485 shields which do not have automatic direction control. |
1.2 | 12/03/2015 | Corrected a minor compatibility issue |
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
Default constructor
Variables
Channel number corresponding to this detection (0-baseed)
Distance (in cm) from the Leddar to the object
Ammount of light reflected, will usually not exceed 512
Leddar
Methods
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
Initializes the serial port for communication
Retrieves detections from the Leddar, stores them in the Detections[] array.
Variables
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.
Timestamp of the last acquisition.. The timestamp is expressed as the number of milliseconds since the Leddar was powered up.
Current LED power as a percentage of maximum.
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
/*
Simple Leddar(TM) Example
Language: Arduino
This program displays on a LCD screen the distance
and returned signal amplitude of the first detection
in channel #8 of a Leddar(TM)
Shields used:
* RS-485 Shield
* LCD Keypad Shield
Created 21 Jan. 2014
by Pier-Olivier Hamel
This example code is in the public domain.
*/
#include <Leddar.h>
#include <LiquidCrystal.h>
Leddar Leddar1(115200,1);
//Baudrate = 115200
//Modbus slave ID = 01
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
// Initialize LCD
lcd.begin(16, 2);
//Initialize Leddar
Leddar1.init();
}
void loop()
{
unsigned int Distance = 0;
unsigned int Amplitude = 0;
if (Leddar1.getDetections() >= 0)
{
for (int i = 0; i < Leddar1.NbDet; i++)
{
if (Leddar1.Detections[i].Segment == 8)
{
Distance = Leddar1.Detections[i].Distance;
Amplitude = Leddar1.Detections[i].Amplitude;
break;
}
}
lcd.setCursor(0,0);
lcd.print("Distance: ");
lcd.setCursor(10,0);
lcd.print(Distance);
lcd.setCursor(0,1);
lcd.print("Amplitude: ");
lcd.setCursor(11,1);
lcd.print(Amplitude);
}
else
{
lcd.setCursor(0,0);
lcd.print("Error: ");
lcd.setCursor(0,1);
lcd.print("No Leddar Found");
}
//pause 50ms
delay(50);
}
Useful Links