You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i just upload code without lidar and serial monitor appeared "⸮⸮YDLIDAR get DeviceInfo Error!"
then i plug lidar to arduino, it spin little second and stop. alos monitor appeared nothing. how can i do?
hear my code
#include <YDLidar.h>
// You need to create an driver instance
YDLidar lidar;
bool isScanning = false;
#define YDLIDAR_MOTOR_SCTP 2 // The PWM pin for control the speed of YDLIDAR's motor.
#define YDLIDAR_MOTRO_EN 22 // The ENABLE PIN for YDLIDAR's motor
void setup() {
//f4,s4:115200
//g4:230400
//x4:128000
// bind the YDLIDAR driver to the arduino hardware serial
lidar.begin(Serial, 9600);
//output mode
pinMode(YDLIDAR_MOTOR_SCTP, OUTPUT);
pinMode(YDLIDAR_MOTRO_EN, OUTPUT);
while(Serial.read() >= 0){};
}
void loop() {
if(isScanning){
if (lidar.waitScanDot() == RESULT_OK) {
float distance = lidar.getCurrentScanPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentScanPoint().angle; //anglue value in degree
byte quality = lidar.getCurrentScanPoint().quality; //quality of the current measurement
bool startBit = lidar.getCurrentScanPoint().startBit;
Serial.print("current angle:");
Serial.println(angle, DEC);
Serial.print("current distance:");
Serial.println(distance, DEC);
}else{
Serial.println(" YDLIDAR get Scandata fialed!!");
}
}else{
//stop motor
digitalWrite(YDLIDAR_MOTRO_EN, LOW);
setMotorSpeed(0);
restartScan();
}
}
i just upload code without lidar and serial monitor appeared "⸮⸮YDLIDAR get DeviceInfo Error!"
then i plug lidar to arduino, it spin little second and stop. alos monitor appeared nothing. how can i do?
hear my code
#include <YDLidar.h>
// You need to create an driver instance
YDLidar lidar;
bool isScanning = false;
#define YDLIDAR_MOTOR_SCTP 2 // The PWM pin for control the speed of YDLIDAR's motor.
#define YDLIDAR_MOTRO_EN 22 // The ENABLE PIN for YDLIDAR's motor
void setup() {
//f4,s4:115200
//g4:230400
//x4:128000
// bind the YDLIDAR driver to the arduino hardware serial
lidar.begin(Serial, 9600);
//output mode
pinMode(YDLIDAR_MOTOR_SCTP, OUTPUT);
pinMode(YDLIDAR_MOTRO_EN, OUTPUT);
while(Serial.read() >= 0){};
}
void loop() {
if(isScanning){
if (lidar.waitScanDot() == RESULT_OK) {
float distance = lidar.getCurrentScanPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentScanPoint().angle; //anglue value in degree
byte quality = lidar.getCurrentScanPoint().quality; //quality of the current measurement
bool startBit = lidar.getCurrentScanPoint().startBit;
Serial.print("current angle:");
Serial.println(angle, DEC);
Serial.print("current distance:");
Serial.println(distance, DEC);
}else{
Serial.println(" YDLIDAR get Scandata fialed!!");
}
}else{
//stop motor
digitalWrite(YDLIDAR_MOTRO_EN, LOW);
setMotorSpeed(0);
restartScan();
}
}
void setMotorSpeed(float vol){
uint8_t PWM = (uint8_t)(51*vol);
analogWrite(YDLIDAR_MOTOR_SCTP, PWM);
}
void restartScan(){
device_info deviceinfo;
if (lidar.getDeviceInfo(deviceinfo, 100) == RESULT_OK) {
int _samp_rate=6;
String model;
float freq = 7.0f;
switch(deviceinfo.model){
case 1:
model="F4";
_samp_rate=4;
freq = 7.0;
break;
case 4:
model="S4";
_samp_rate=4;
freq = 7.0;
break;
case 5:
model="G4";
_samp_rate=9;
freq = 7.0;
break;
case 6:
model="X4";
_samp_rate=5;
freq = 7.0;
break;
default:
model = "Unknown";
}
}
The text was updated successfully, but these errors were encountered: