diff --git a/.gitignore b/.gitignore index 259148f..8a883d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +rplidar_sdk/** + # Prerequisites *.d diff --git a/starter.cpp b/starter.cpp new file mode 100644 index 0000000..80ea64e --- /dev/null +++ b/starter.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#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 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; +}