Skocz do zawartości

RPLidar A2M12 >> probelm z uruchomieniem


robo1973

Pomocna odpowiedź

Witam !!

Czy ktoś z kolegów uruchomił RPLidar nową wersję A2 pod esp32 ?
Poniższy kod nie działa Nie łączy się
 

/*
       RPLidar on ESP32
     
    */     
    //#include <HardwareSerial.h>
    //HardwareSerial LiSerial(1);
    #include "esp32-hal-ledc.h"
     
    // This sketch code is based on the RPLIDAR driver library provided by RoboPeak
    #include <RPLidar.h>
     
    // You need to create an driver instance
    RPLidar lidar;
     
    #define RPLIDAR_MOTOR 32 // The PWM pin for control the speed of RPLIDAR's motor.
     
    // setting PWM properties
    const int freq = 10000;
    const int ledChannel = 4;
    const int resolution = 8;
     
    void setup() {
      Serial.begin(115200);
      delay(300);
      Serial2.begin(256000);
      
     //LiSerial.begin(115200, SERIAL_8N1,2,15);// RX, TX
      // bind the RPLIDAR driver to the ESP32 hardware serial2
      lidar.begin(Serial2);
     
      // configure LED PWM functionalitites
      ledcSetup(ledChannel, freq, resolution);
     
      // attach the channel to the GPIO to be controlled
      ledcAttachPin(RPLIDAR_MOTOR, ledChannel);
     
      // set pin modes
      pinMode(RPLIDAR_MOTOR, OUTPUT);
     
    }
     
    void loop() {
      
        if (IS_OK(lidar.waitPoint())) {
          float distance = lidar.getCurrentPoint().distance; //distance value in mm unit
          float angle    = lidar.getCurrentPoint().angle; //anglue value in degree
          bool  startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
          byte  quality  = lidar.getCurrentPoint().quality; //quality of the current measurement
     
          //perform data processing here...
          Serial.println("Lidar Get info...");
     
        } else {
          ledcWrite(RPLIDAR_MOTOR, 0);
          delay(15);
          // try to detect RPLIDAR...
          rplidar_response_device_info_t info;
          if (IS_OK(lidar.getDeviceInfo(info, 100))) {
             // detected...
             Serial.println("Lidar Detected...");
             lidar.startScan();
     
             // start motor rotating at max allowed speed
             ledcWrite(RPLIDAR_MOTOR, 255);
             delay(1000);
          }
        }
        Serial.println(lidar.getCurrentPoint().distance);
    }

 

Edytowano przez robo1973
Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.