Skocz do zawartości

RPLidar A2M12 >> probelm z uruchomieniem


Pomocna odpowiedź

Napisano (edytowany)

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

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...