First test : start/stop motor & laser

This commit is contained in:
Allan Cueff
2024-01-15 21:49:17 +01:00
committed by GitHub
parent 5e0c9564a0
commit 580f12b8a4
2 changed files with 47 additions and 0 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
rplidar_sdk/**
# Prerequisites
*.d

45
starter.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "sl_lidar.h"
#include "sl_lidar_driver.h"
using namespace sl;
static inline void delay(sl_word_size_t ms){
while (ms>=1000){
usleep(1000*1000);
ms-=1000;
};
if (ms!=0)
usleep(ms*1000);
}
int main(int argc, const char * argv[]) {
Result<IChannel*> channel = createSerialPortChannel("/dev/ttyUSB0", 115200);
ILidarDriver * drv = *createLidarDriver();
auto res = drv->connect(*channel);
if(SL_IS_OK(res)){
drv->startScan(0,1);
delay(10000);
drv->stop();
drv->setMotorSpeed(0);
delay(10000);
drv->startScan(0,1);
delay(10000);
drv->stop();
drv->setMotorSpeed(0);
drv->disconnect();
}
delete *channel;
delete drv;
drv = nullptr;
return 0;
}