Notifications
Clear all

[Solved] TF Luna Lidar with ESP32-S3 UART Data Issues

2 Posts
1 Users
0 Reactions
2,738 Views
huckOhio
(@huckohio)
Member
Joined: 6 years ago
Posts: 322
Topic starter  

I am working on my first robotic car and I am using three TF Luna Lidar sensors for obstacle avoidance.  All three sensors have been tested using the windows application provided by Benewake.  I also tested the using Bill's recent video which uses the I2C interface.  Both tests were successful and I was able to see immediate distance changes as I moved the Lidar around.

The documentation recommended using the serial (UART) interface if using more than one sensor.  I am working with the ESP32 UART example that Benewake provides and I am receiving distance data, but also many checksum errors.  

I have two questions:

First, how can I eliminate/reduce the checksum errors?  I can run a string of error that last several seconds which my not be reasonable for obstacle avoidance.

Second, how can I improve the responsiveness?  While testing the Lidar I notice there is a 5-6 second delay in seeing the new distance even without checksum errors.

The code is below:

#include <HardwareSerial.h> // Reference the ESP32 built-in serial port library
HardwareSerial lidarSerial(1); // Using serial port 2
#define RXD2 16
#define TXD2 17

void setup() {
  Serial.begin(115200); // Initializing serial port
  lidarSerial.begin(115200, SERIAL_8N1, RXD2, TXD2); // Initializing serial port
}

void loop() {
  uint8_t buf[9] = {0}; // An array that holds data
  if (lidarSerial.available() >= 9) {
    //Serial.println("LIDAR Available");
    lidarSerial.readBytes(buf, 9); // Read 9 bytes of data
    delay(15);
    if( buf[0] == 0x59 && buf[1] == 0x59)
    {
      uint16_t distance = buf[2] + buf[3] * 256;
      uint16_t distance2 = buf[2] | (buf[3] << 8);
      Serial.print("capture distance "); Serial.println(distance2);
      uint16_t strength = buf[4] + buf[5] * 256;
      int16_t temperature = buf[6] + buf[7] * 256;
      Serial.print("Distance: ");
      Serial.print(distance);
      Serial.print(" cm, strength: ");
      Serial.print(strength);
      Serial.print(", temperature: ");
      Serial.println(temperature / 8.0 - 256.0);
    }
    else {
    Serial.print(buf[0]); Serial.print("  "); Serial.println(buf[1]);
    }
  }
  delay(50); 
}

 Here is an example from the serial output (the two numbers on a line are the first two bytes that need to match for a valid message):

0  187
0  193
0  185
0  183
0  189
capture distance 131
Distance: 131 cm, strength: 1981, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1978, temperature: 42.00
capture distance 132
Distance: 132 cm, strength: 1977, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1983, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1986, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1982, temperature: 42.00
80  9
80  9
80  9
80  9
80  9
80  9
80  9
80  9
80  9
80  9
80  9
capture distance 131
Distance: 131 cm, strength: 1976, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1979, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1973, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1980, temperature: 42.00
capture distance 131
Distance: 131 cm, strength: 1982, temperature: 42.00

I have limited experience working with UART interfaces.

Thanks

Mike



   
Quote
huckOhio
(@huckohio)
Member
Joined: 6 years ago
Posts: 322
Topic starter  

Looks like this is a common issue when using UART.  I changed the approach to using I2C and now have all three Lidars working with the ESP32-S3.



   
ReplyQuote