Aller au contenu


Photo
- - - - -

Test LD06 library

Ld06 Lidar

  • Veuillez vous connecter pour répondre
17 réponses à ce sujet

#1 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 20 avril 2023 - 04:34

Subject to discuss about the Robot Maker ld06 lidar library : https://github.com/R...Maker-SAS/LD06/

First issue is : https://github.com/R...S/LD06/issues/1
In order to understand what is the origin of the probleme here are some config we should test. 

 
  • First disable filtering with ld06.disableFiltering(); ( Just to be sure that the missing data is not filtered data )
  • Then disable " full scan waiting mode "  ld06.disableFullScan(); This way it will print each data chunk you receive and not wait for a full scan. ( If your board is to slow to process the whole scan it may be a problem )
  • If the problem is still there then you can add a " debug  message" in : ld06.cpp in readDataCRC() function to replace the comment " // TODO Handle CRC error "  in order to verify if missing data is because of CRC error. 
  • If there are some CRC errors you can disable crc control with ld06.disableCRC(); and try to verify if you get corrupted data and what data is corrupted ...
 
Feel free to post your tests !

Best regards.

 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#2 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 23 avril 2023 - 03:12

Many thanks for your message ! 
 

  • I did try disabling filtering : with ld06.disableFiltering() with no change on the result
  • full scan waiting mode  ld06.disableFullScan() : no output at all on the serial monitor !  works : " this is a new scan" 
  • same issue occurs with ld06.disableCRC() : no output on serial monitor
  • ​I did add a serial.print CRC ERR messagein the ld06.cpp in the readDataCRC() function : I do actually get a message at the beginning of each news scan , just after the " this is a new scan" message and the first value received ...

...

​359.35,565

 

This is a new scan!

CRC ERR

0.15,580​
...

 

My current project is to use this small lidar as a   cheap "static" 3D scanner . the Ustepper S32 was for me the way to go because of dimensions / hardware as an all-in-one solution ... 

 

I did test again the lidar with the LDSviewer app. and the Ustepper S32 as serial passthrough , the readings seems to be correct.

 

Best regards, 

 

 

 



#3 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 24 avril 2023 - 01:59

I am sorry ! There was a typo in readDataNoCRC function ( n++ was missing ... ) and the whole block of code handling the disabled full scan mode was missing. 
Last update should have fixed both now!

You can make the test. =) 

By the way with my tests with the teensy4.0 I never had any CRC error ... And since you seems to have CRC error after the " This is a new scan! "
I believe that there is a bottleneck there... I think there are too much points to copy for your board ( Around 450 points to copy ... ) and that it took too much time especially if you use filter mode... And this should have an impact on the Serial readings... 
If this is the problem, I believe that the disabled full scan mode will help a lot in your case ... So let's have a try to confirm it ;) And if this is the problem and that you need the full scan mode I believe that I can optimise the code in order to prevent this issue. 

By the way if there are features you are interested in feel free to ask ;) 
 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#4 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 24 avril 2023 - 11:17

Many thanks !

 

This now works quite perfectly , I just had to ld06.disableFullScan(); 

 

Now I can get all readings on each turn !

 

only one small detail downside  : the "This is a new scan!" message appears on the serial monitor at around 4 to 6° 

 

Regarding my project , I think I could use ld06.isNewScan() every 'n' time to trigger a move of my stepper motor .

One great feature would be to be able to reduce/adjust the lidar speed, in order to get more points scanned on each turn . 

 

Many thanks again !  



#5 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 24 avril 2023 - 05:06

 

 

only one small detail downside  : the "This is a new scan!" message appears on the serial monitor at around 4 to 6° 

 

 

When you disable " full scan " the serial display displays each chunk of data received where each chunks represent 12 points. 

The problem is that a scan closure can happen on any  of these 12 points...  And this is why there is the full scan feature... In order to sort all the points that belong to the same scan.

When you desactivate the " full scan mode " the " isNewScan " is only telling you that there is a scan closure in the last chunk of data ... 


So here are my questions what would it be better when full scan is disabled ? 

=> Always display the 12 points of last data chunk and tell when there is a scan closure in theses points after displaying all points ( This is the solution implemented right now )
=> Display 12 points of last data chunk except when there is a scan closure... In such case only display the ones that belongs to the olded scan, and next displayed scan will not be full either ? 
=> Display a defined numbers of points ( can be more than 12 points ) that is below a max number, and stop either when max number is reach or when ther is a scan closure ?

 

 

 

 

Regarding my project , I think I could use ld06.isNewScan() every 'n' time to trigger a move of my stepper motor .

 

 

Anyway, keep in mind that since we receive data in chunks of 12 points we can't know exactly when the lidar performed the scan closure ... Even when full scan mode is set; the next scan already started when we display the full scan... 

If you want be 100% sure that your stepper motor is at the correct position when you start a scan I think that you should move your stepper motor when you receive the isNewScan() is true, and skip the whole nex scan ( becaus this scan started before your stepper move... and your stepper is moving during this scan ), and only keep the following scan ( If your stepper movement last less than one scan of course, else keep skipping scans until motor is stopped... ) 

Can you give more details about your project ? I would be glad to see what is your configuration ! you can talk about your project here : https://www.robot-maker.com/forum/167-bancs-de-tests-et-autres-machines-dexperimentations/  ;) 
 

 

 

Many thanks !

 

This now works quite perfectly , I just had to ld06.disableFullScan(); 

 

I am glad to know that we found the problem !
 

 

And if this is the problem and that you need the full scan mode I believe that I can optimise the code in order to prevent this issue. 


 

 

I think that I reduced a lot the bottleneck problem with full scan mode. Can you try the last update in order to confirm that the optimisation is ok and that you can use full scan mode without problems now ? 

 

EDIT : If after testing the new version you still have some problems with full scan mode, we may think about increasing you Serial Baudrate ... The big print is also a bottleneck... print serial data faste can also solve the problem ... 



 

 

 

One great feature would be to be able to reduce/adjust the lidar speed, in order to get more points scanned on each turn . 

 

 

 

I may think about that, but there are already around 450 points per full 360° scan by default, this is quite a lot ... 
According with the documentation, the slowest rotation speed is 5hz... So we may be able to get around 900 points per full 360° scan ... 

I may also add more data conversion to enable 2D point computation conversion...( if you give the x y  and theta position of the lidar ) and even 3D point computation if you know the x y z and the three angular positions of the lidar ... )  I believe this can be usefull in your case ;) 
What kind of 3D representation do you plan to use ?


 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#6 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 25 avril 2023 - 12:35

Just tested the last version , unfortunately I cannot get it to work correctly even with disabling CRC / filtering  / fullscan  .

 

the results are even more inconsistent ...

 

maybe I should switch to Teensy + UstepperS32 .. 

The previous version in my case was a lot better  .

 

 

 

So here are my questions what would it be better when full scan is disabled ? 

 

this is not big issue, as for every moved step of the motor , I do something like 5-10 full scan before moving again . the more points the more "accurate" gets the point cloud  .

 

 

I may think about that, but there are already around 450 points per full 360° scan by default, this is quite a lot ... 
According with the documentation, the slowest rotation speed is 5hz... So we may be able to get around 900 points per full 360° scan ... 

 

again the more points I get the best is the scan , so 360 / 900 gives about 0.4° resolution , which is useful when scanning large rooms . 

 

 

as I'm not able to program , just doing some simple modifications to exiting code ( with a lot of effort on my side :) )  ... I used some code provided from different sources , and got something running I could share with you (PM ? )  , but the issue is about the way the LD06 part works ( array part ) , which gives only 1° resolution , but even with a simple setup , I was able to get a decent pointcloud . 



#7 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 25 avril 2023 - 07:00

ok ... Whatever, I will find a way to have it working correctly.
Can you give more details about inconsistency ? Can you show some data ?  And can you confirm which update you tested ?

Right now there are three updates pushed since you spotted the disable full scan and no crc errors . 

=> "Fix for readDataNoCRC and disabled full scan mode "  ( I think that this is the one you tested and that worked well )

=> "Add serial port to constructor and improve basic example" ( But maybe this is this one ... In this one the led blinking was different with the dedicated toggleBuiltinLed() function ) 

Can you confirm that this update works perfectly for you and that new inconsistencies are here only with the last update 

=> "Buffer optimisation to reduce bottleneck effect in full scan mode" ( Last update, I hope that this is the only one that is causing the problems... ) I will investigate and either provide a fix or remove this update ... 

 

 

The aim with this update was to reduce the problem, if it increase it, there is a problem somewhere ... 

I am waiting for your feedback! =)

 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#8 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 26 avril 2023 - 04:50

Hi Mike, 

 

Thanks again , the inconsistency was not related to your code ! one welding was bad on the data line :( sorry for that. 

 

but the result is still the same, when fullscan is enabled , jumps from 14-16 to 150-160° ... so no change on this side for me ... 

 

I think anyway that I will probably switch to Teensy 4.1 soon, as I should be able to control the UStepper S32 ( and also use a cheaper version / or Chinese) . 

 

Teensy would also give me the possibility to save data directly on a µSD card , and use Ethernet .. to transfer data directly . 

 

Many thanks for your work again this is awesome ! 
 



#9 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 26 avril 2023 - 07:10

Off course it will "run faster" with a " more powerfull horse " but I believe that I will manage to get it working correctly on your board ;) 
I plan many great improvements :) 

By the way I tested the pwm control and it works great. I manage to get around 1150 pts / scan with 4hz rotation frequency, and 0.32° angular resolution.
I will soon add an example showing how to use it but since setting pwm frequency can highly depend on the kind of board you are using I think that I will keep this in the example and not directly in the lib ... 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#10 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 27 avril 2023 - 08:00

Great News !  thanks again , I will also read on my side about STM32 PWM ... to try to sort it out . 
 



#11 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 06 mai 2023 - 03:03

Ok ... I finally had some time to proceed with the latest version : 

 

Results are not good , I definitely think the Stepper S32 is not powerful enough  , in full scan mode still skipping points in the usual range , no change .. 

 

when fullscan is disabled strange things happen , it's worse .. only a few points ... 1-5° then skip to 355-359 .. 

 

I had no chance to try PWM , there a library for STM32 ( STM32_PWM ) , will try it separately to see what I can do with it :) 

 

For now I will concentrate on modelling the 3D part for my project and do some 3D printing . and I think ordering a Teensy 4.1 will solve my problems . 



#12 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 08 mai 2023 - 03:10

 

 

when fullscan is disabled strange things happen , it's worse .. only a few points ... 1-5° then skip to 355-359 .. 

I think there is a mistake somewhere , it's only reporting one packet ( 12 points each time ) entered around 0° . 

 

I did enable afterward : 
-  getSpeed() : reporting ~3600 ( 10hz )

- getAngleStep()about 0.8°

- getNbPointsInScan() : is reporting always  12 points only not a full 360 

 

 

Your code looks very promising with so many features to explore :) 

 

I tried PWM some dedicated code on my Ustepper with no luck , no error but no speed change .. 
 

#define pin PA6 // Pin for PWM
void setup() {

  // no need to configure pin, it will be done by HardwareTimer configuration
  pinMode(pin, OUTPUT);

  // Automatically retrieve TIM instance and channel associated to pin
  // This is used to be compatible with all STM32 series automatically.
  TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), PinMap_PWM);
  uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), PinMap_PWM));


  // Instantiate HardwareTimer object. Thanks to 'new' instantiation, HardwareTimer is not destructed when setup() function is finished.
  HardwareTimer *MyTim = new HardwareTimer(Instance);

  // Configure and start PWM
  // MyTim->setPWM(channel, pin, 5, 10, NULL, NULL); // No callback required, we can simplify the function call
  MyTim->setPWM(channel, pin, 30000, 10); // 30 Khz, 10% dutycycle
}



#13 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 08 mai 2023 - 07:14

When full scan is disabled and there is no filtering there is allways 12 points received since the lidar send packets of 12 points.

But I will check it. 

I guess that some of my last improvements for readability are not working well with your board. 

Anyway I am still 100% interested in having a lib that will work well for your board as well as for teensy and others ... 

Here are the few things you can try. 

First you can try the last version I just pushed. 
If not working well you can go in ld06.h and comment the line " #define LD06_COMPUTE_XY " 

comment this line  should provide a huge boost in you case! 

Another thing you can try :

 

Ok ... I finally had some time to proceed with the latest version : 

 

Results are not good , I definitely think the Stepper S32 is not powerful enough  , in full scan mode still skipping points in the usual range , no change .. 

Can you try each version starting from last one and tell me which version works for you and wich don't ? 

Because at some point it seems that it was working great : 
 

 

Many thanks !

 

This now works quite perfectly , I just had to ld06.disableFullScan(); 

 

Many thanks again !  

I would like to know what change caused your problems.

Thank you!


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#14 lebearnais

lebearnais

    Nouveau membre

  • Membres
  • 5 messages

Posté 18 février 2024 - 09:56

Bonjour

 

existe t il la version pour arduino pour pouvoir discuter avec un arduino?

Donner par exemple les seuils de distance de détection. Ca retourne les angles qui ont capté.

 

Merci



#15 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 27 février 2024 - 03:03

Après quelques tests plus approfondis je confirme un des points que j'ai évoqué plus tôt, en utilisant des microcontrôleurs moins puissant que la teensy 4.0 les codes actuel est trop gourmand en ressource surtout avec l'affichage des données ...  
Il faut pour le moment utiliser à minima l'équivalent d'une teensy 3.2 et encore, certains ajustements / compromis sont à faire ... 
Pour le moment le code actuel de la librairie est surtout adapté à la teensy 4 / 4.1 ... 

à l'occasion je vais essayer de refaire une passe sur le code de la librairie pour l'optimiser d'avantage pour que cela puisse passe sans problème sur une teensy 3.2 ou équivalent ... Par contre je pense pas que j'arriverais à faire fonctionner correctement le code sur une arduino uno par exemple ...

En attendant voici un code de test qui fonctionne correctement sur une teensy3.2 

 

// Configuration

#define LD06SERIAL Serial1
#define LD06_COMPUTE_XY     // Comment this line if you don't want x and y coordinates

bool _upsideDown = false;   // Set true if lidar is upside down reversed

// If used on a moving robot
int16_t _xPosition = 0;     // mm Position of the moving robot
int16_t _yPosition = 0;     // mm Position of the moving robot
float _angularPosition = 0; // ° Position of the moving robot
int16_t _xOffset = 0;       // mm Offset on the moving robot
int16_t _yOffset = 0;       // mm Offset on the moving robot
float _angularOffset = 0;   // ° Offset on the moving robot

bool _useFiltering = false; // Set true if you want filter data ( test with false first )
// Filtering Settings test with default config first, modify according your needs, but don't forget to enable filtering if you want use it
uint16_t _minDist = 0;      // Minimum Distance mm default 0
uint16_t _maxDist = 12000;  // Maximum Distance mm default 12000
uint16_t _minAngle = 0;     // Minimum angle ° default 0
uint16_t _maxAngle = 360;   // Maximum angle ° default 360
uint16_t _threshold = 0;    // Minimum point intensity 0-255 default 0

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  LD06SERIAL.begin(230400);
}

void loop() {
  // Put your main code here, to run repeatedly:
  readLd06(); // will call newPoint() function for each lidar point if no filtering or for each point that pass the filter if filter is enabled.
}

// Structure that store your lidar point's data
struct DataPoint {
  uint16_t distance = 0;  // mm
  float angle = 0;        // degrees
#ifdef LD06_COMPUTE_XY
  int16_t x = 0;          // mm
  int16_t y = 0;          // mm
#endif
  uint8_t intensity = 0;  // 0-255
} point;

// This function is automaticalled by readLd06() for each lidar point if no filtering or for each point that pass the filter if filter is enabled.
// Modify this function according to your need. 
void newPoint() {
  // Do what you want with each point here ... For example you can print them
  Serial.print(point.angle);
  Serial.print(",");
  Serial.print(point.distance);
  Serial.print(",");
#ifdef LD06_COMPUTE_XY
  point.x = _xPosition + _xOffset * cos(_angularPosition) - _yOffset * sin(_angularPosition) + point.distance * cos((point.angle + _angularPosition + _angularOffset) * PI / 180);
  point.y = _yPosition + _xOffset * sin(_angularPosition) + _yOffset * cos(_angularPosition) - point.distance * sin((point.angle + _angularPosition + _angularOffset) * PI / 180);
  Serial.print(point.x);
  Serial.print(",");
  Serial.print(point.y);
  Serial.print(",");
#endif
  Serial.println(point.intensity);
}



// LD06 Handler read and decoding functions... 
// Nothing to modify below this line except if you want try to modify core decoding ( optimize code, check crc or stuff like that ) 

// Packets size
const uint8_t LD06_PACKET_SIZE = 47;   // Note: 1(Start)+1(Datalen)+2(Speed)+2(SAngle)+36(DataByte)+2(EAngle)+2(TimeStamp)+1(CRC)
const uint8_t LD06_PTS_PER_PACKETS = 12;
const uint8_t LD06_MEASURE_SIZE = 3;
const uint8_t LD06_ANGLE_STEP_MAX = 5;

// Headers
const uint8_t LD06_HEADER = 0x54;
const uint8_t LD06_VER_SIZE = 0x2c;

// Data structures
struct LD06Measure {
  union {
    struct {
      uint16_t distance;  // Unit is mm
      uint8_t intensity;  // Unsigned value 0-255}
    } __attribute__((packed));
    uint8_t bytes[LD06_MEASURE_SIZE];
  };
} __attribute__((packed));

struct LD06Packet {
  union {
    struct {
      uint8_t header;                              // LD06_HEADER
      uint8_t version_size;                        // LD06_VER_SIZE
      uint16_t lidarSpeed;                         // Degrees ° / second
      uint16_t startAngle;                         // Unit is 0.01 Degree°
      LD06Measure measures[LD06_PTS_PER_PACKETS];  // 12 distances data distance + intensity
      uint16_t endAngle;                           // Unit is 0.01 Degree°
      uint16_t timeStamp;                          // Unit id ms (max value is 30000)
      uint8_t crc;                                 // Checksum
    } __attribute__((packed));
    uint8_t bytes[LD06_PACKET_SIZE];
  };
} __attribute__((packed));

struct LD06PacketHandler {
  LD06Packet packet;
  uint8_t computedCrc;
  uint8_t index;
};

bool filter () {
  bool distanceFilter = point.distance <= _maxDist && point.distance >= _minDist;
  bool intensityFilter = point.intensity >= _threshold;
  bool angularFilter;
  if (_minAngle <= _maxAngle) {
    angularFilter = point.angle <= _maxAngle && point.angle >= _minAngle;
  } else {
    angularFilter = point.angle <= _maxAngle || point.angle >= _minAngle;
  }
  return distanceFilter && intensityFilter && angularFilter;
}

LD06PacketHandler _receivedData;


float getAngleStep() {
  float fsa = (float)_receivedData.packet.startAngle / 100.0;
  float lsa = (float)_receivedData.packet.endAngle / 100.0;

  float range = lsa - fsa;
  if (range < 0)
    range += 360;

  float angleStep = range / (LD06_PTS_PER_PACKETS - 1);
  return angleStep;
}

void readLd06() {
  while (LD06SERIAL.available()) {
    uint8_t current = LD06SERIAL.read();
    if (_receivedData.index > 1 || (_receivedData.index == 0 && current == LD06_HEADER) || (_receivedData.index == 1 && current == LD06_VER_SIZE)) {
      _receivedData.packet.bytes[_receivedData.index] = current;
      _receivedData.index++;
      if (_receivedData.index == LD06_PACKET_SIZE - 1) {
        computeData();
        _receivedData.index = 0;
      }
    } else
      _receivedData.index = 0;
  }
}

void computeData() {
  float angleStep = getAngleStep();
  if (angleStep > LD06_ANGLE_STEP_MAX)  // Should not be possible,
  {
    Serial.println("error : data not decoded correctly");
    return;
  }

  int8_t reverse = (_upsideDown ? -1 : 1);
  float fsa = _receivedData.packet.startAngle / 100.0;

  for (uint16_t i = 0; i < LD06_PTS_PER_PACKETS; i++) {
    float raw_deg = fsa + i * angleStep;

    point.angle = (raw_deg <= 360 ? raw_deg : raw_deg - 360) * reverse;
    point.distance = _receivedData.packet.measures[i].distance;
    point.intensity = _receivedData.packet.measures[i].intensity;
    if (!_useFiltering || filter()) {
#ifdef LD06_COMPUTE_XY
      point.x = _xPosition + _xOffset * cos(_angularPosition) - _yOffset * sin(_angularPosition) + point.distance * cos((point.angle + _angularPosition + _angularOffset) * PI / 180);
      point.y = _yPosition + _xOffset * sin(_angularPosition) + _yOffset * cos(_angularPosition) - point.distance * sin((point.angle + _angularPosition + _angularOffset) * PI / 180);
#endif
      newPoint();
    }
  }
}

@OliveaCaen if you read this, can you try the code above with your board and confirm that you can read a full scan ?
 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#16 lebearnais

lebearnais

    Nouveau membre

  • Membres
  • 5 messages

Posté 02 mars 2024 - 05:10

Merci @Mike118, le code fonctionne super bien sur un esp32 en utilisant le deuxième UART. 

Dans mon cas, j'ai utilié un ESP WROOM 32 (HW-665) avec la pin GPIO10 comme RX.

J'ai du remplacé la ligne LD06SERIAL.begin(230400); par LD06SERIAL.begin(230400,SERIAL_8N1,10);

 
Maintenant, je n'ai plus qu'à jouer et me faire un logiciel pour déplacer mon robot en utilisant le LIDAR


#17 OliveaCaen

OliveaCaen

    Nouveau membre

  • Membres
  • 8 messages
  • Gender:Male
  • Location:Caen

Posté 03 mars 2024 - 04:43

@mike118
Merci pour la mise à jour , je ferais un test dès que possible !

#18 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 969 messages
  • Gender:Male
  • Location:Anglet

Posté 04 mars 2024 - 10:10

Je n'ai pas encore mis à jour la librairie... Je prends un peu de temps pour voir comment l'optimiser au mieux...


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 






0 utilisateur(s) li(sen)t ce sujet

0 members, 0 guests, 0 anonymous users