garmin / LIDARLite_Arduino_Library

High-performance optical distance sensing.
Apache License 2.0
181 stars 84 forks source link

Too many blocking code:( #2

Closed VigibotDev closed 7 years ago

VigibotDev commented 7 years ago

Hello,

Very good spec sensor but the lib is useless for serious application. There is too many blocking code inside it :

while(busyFlag != 0) // Loop until device is not busy { ... update busyFlag ... }

delay(1); // 1 ms delay for robustness with successive reads and writes

You can't do this on a microcontroller 1ms is a huge waste like many years lol.

My project need a serious non blocking code, I must rewrite this unusable lib :(

Pascal

nseverson commented 7 years ago

Hi Pascal,

Thanks for your interest in LIDAR-Lite! The purpose of this library is to help people get started using the sensor with an easy to understand interface. It is written for the Arduino platform because many people are already familiar with it, and it is intentionally as simple as possible.

User AlexisTM has written a robust LIDAR-Lite library for Arduino that uses a non-blocking interface. This may be useful for your project.

Regards,

Neil Severson

VigibotDev commented 7 years ago

Amazing !!! Thanks a lot for the AlexisTM information !!! (I not found with my google request)

AlexisTM commented 7 years ago

Indeed, I am actually the last library from the search "lidarlite" :(

VigibotDev commented 7 years ago

AlexisTM, a minimalist example is required inside your lib. Because no one can buy 5 or more Lidars to test it:) I open a doc issue when I make my first one lidar sample:) Also is architecture agnostic : I compile it for PIC32MX - chipKit/core

AlexisTM commented 7 years ago

Here it is : https://github.com/AlexisTM/LIDAREnhanced/blob/master/example/OneLaser/OneLaser.ino

I never tried on other chips... and I include Arduino.h to make continuous integration easier.

VigibotDev commented 7 years ago

Very easy to integrate this lib inside my projet:) thanks a lot. My project is a public web controlled robot online here : http://www.serveurperso.com/?page=robot

AlexisTM commented 7 years ago

I am happy it worked so well :D

Anf that's a funny project (I just checked it)

VigibotDev commented 7 years ago

// Trigger pin, can be unplugged

define Z1_LASER_TRIG 11

// Enable pin, IMPORTANT

define Z1_LASER_EN 12

// Mode pin, can be unplugged

define Z1_LASER_PIN 13

... LZ1.begin(Z1_LASER_EN, Z1_LASER_PIN, Z1_LASER_TRIG, Z1_LASER_AD, 2, DISTANCE, 'A');

Why you assign useless pin ? How I can get sure they are never used (if use near all I/O on my PIC32MX in future) ?

Your lib is energy efficient for my battery (you use the "Enable" pin this is a very good idea) How to sleep it ?

If I stop to call the Controller ?

Edit : C++ code is well documented and answer all

AlexisTM commented 7 years ago

Hi, indeed, there are missing documentation as I am currently the only one using it, I have no feedback yet. :octocat:

NOTE : The Trigger pin & Mode pin are not yet used. It could be useful for someone who wants to take measurements with PWM. Plus, I tried taking measurements with the "continuous" mode of the lasers (with trigger & mode pin), but it was strangely slower. Therefore, the mode pin & trigger pin are never used.

VigibotDev commented 7 years ago

At this time I get a spinOnce freeze with wire on PIC32 last chipkit Core. I temporarily run the lidar on 3.3v (not recommended) because there is no 5VDC line on my robot at this time. (High efficiency & large current DC-DC converters)

Debug enabled :

setup() loop() Laser 0 SHUTING_DOWN Laser 0 NEED_RESET Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 RESET_PENDING Laser 0 ACQUISITION_IN_PROGRESS

VigibotDev commented 7 years ago

Same problem with a new 5V 1A Tracopower DC-DC. The stock lidar lib (this one) work. Freeze : SDL/SDA pins low Enable pin high (3.3)

#include <Wire.h>
#include <I2CFunctions.h>
#include <LidarObject.h>
#include <LidarController.h>

#define DEBUG Serial
#define MODEM Serial1

#define LIDARI2CADDRESS 0x62
#define LIDARTRIGGERPIN 75            // Dummy
#define LIDARENABLEPIN 75             // C13
#define LIDARMODEPIN 75               // Dummy

LidarController lidarcontroller;
LidarObject lidar;

void setup() {
 DEBUG.begin(115200);
 DEBUG.println("setup()");
 MODEM.begin(115200);

 lidar.begin(LIDARENABLEPIN, LIDARMODEPIN, LIDARTRIGGERPIN, LIDARI2CADDRESS, 2, DISTANCE, 'A');
 lidar.setCallbackDistance(&lidarcallback);
 lidarcontroller.add(&lidar, 0);

 delay(100);
 lidarcontroller.begin();
 delay(100);

 DEBUG.println("loop()");
}

void lidarcallback(LidarObject* self) {
 DEBUG.println(self->distance);
}

void loop() {
 lidarcontroller.spinOnce();

}
VigibotDev commented 7 years ago

Now it work !!!

      //Wire.requestFrom(Device, uint8_t(2), uint8_t(1)); // AVR Arduino
      Wire.requestFrom(Device, uint8_t(2)); // PIC32 chipKIT Core
      data[0] = Wire.read();
      data[1] = Wire.read();

I make a mistake I swapped uint8_t(2) and uint8_t(1) for readWord() / readByte() when I solved a requestFrom compatibility problem lol

VigibotDev commented 7 years ago

It work for a time and freeze:(

EDIT : To solve the problem I must comment the servo lib. There is a conflict with I2C and servo lib on chipKIT Core API !!!

EDIT2 : But I found a random performance drop with the lib, I call the spin each millisec.

:(

AlexisTM commented 7 years ago

I agree for Wire ... Especially for the Arduino Due.

There are probably already Wire replacement libraries for your chip! (Note: did you tested with 100kHz I2C instead of 400kHz?)

If you need to modify I2C functions, almost all are in the I2CFunctions file and there is one occurrence in Controller::begin, which start Wire.

https://github.com/AlexisTM/LIDAREnhanced/blob/master/I2CFunctions.h

Le dim. 4 déc. 2016 01:15, Pascal notifications@github.com a écrit :

It work for a time and freeze:( Wire is unreliable I must rewrite this directly in PIC32 DTWI to bypass the crap wire wrapper from chipKIT:'(

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/garmin/LIDARLite_v3_Arduino_Library/issues/2#issuecomment-264674864, or mute the thread https://github.com/notifications/unsubscribe-auth/AGp06Lv2Q9BBDHGQekUdWEUIZEh47lynks5rEgYagaJpZM4LAqwY .

VigibotDev commented 7 years ago

Yes I run I2C @ 400KHz I already commented out the low level configuration line inside your code. Because I have a define in my Digilent DTWI header.

There is a I2C vs another library conflict and a timer/interrupt problem.

VigibotDev commented 7 years ago

I opened an issue on chipKIT Core API https://github.com/chipKIT32/chipKIT-core/issues/312