Skip to content

Too many blocking code:( #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ServeurpersoCom opened this issue Nov 30, 2016 · 16 comments
Closed

Too many blocking code:( #2

ServeurpersoCom opened this issue Nov 30, 2016 · 16 comments

Comments

@ServeurpersoCom
Copy link

ServeurpersoCom commented Nov 30, 2016

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
Copy link

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

@ServeurpersoCom
Copy link
Author

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

@AlexisTM
Copy link

AlexisTM commented Dec 2, 2016

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

@ServeurpersoCom
Copy link
Author

ServeurpersoCom commented Dec 2, 2016

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
Copy link

AlexisTM commented Dec 2, 2016

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.

@ServeurpersoCom
Copy link
Author

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
Copy link

AlexisTM commented Dec 3, 2016

I am happy it worked so well :D

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

@ServeurpersoCom
Copy link
Author

ServeurpersoCom commented Dec 3, 2016

// 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
Copy link

AlexisTM commented Dec 3, 2016

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

  • You can "shutdown" the laser by calling Controller::resetLidar(0);. Once you'll call Controller.spinOnce again, it will start the procedure to wakeup the laser.
  • Otherwise, If you do not call "Controller.spinOnce()", the laser will NOT take any acquisition.
  • I do not know (not tested) how much energy it consumes.
  • The "2" is the configuration, forked from the original library.
  • The 'A' is the name of the laser, allowing to know which laser called the callback (if(self->name == 'A'))
  • The DISTANCE is a "to implement" enum, that would allow to take velocity measurements by replacing DISTANCE by VELOCITY or DISTANCE_AND_VELOCITY.

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.

@ServeurpersoCom
Copy link
Author

ServeurpersoCom commented Dec 3, 2016

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

@ServeurpersoCom
Copy link
Author

ServeurpersoCom commented Dec 3, 2016

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

@ServeurpersoCom
Copy link
Author

ServeurpersoCom commented Dec 4, 2016

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

@ServeurpersoCom
Copy link
Author

ServeurpersoCom commented Dec 4, 2016

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
Copy link

AlexisTM commented Dec 4, 2016 via email

@ServeurpersoCom
Copy link
Author

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.

@ServeurpersoCom
Copy link
Author

I opened an issue on chipKIT Core API
chipKIT32/chipKIT-core#312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants