Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:c25c4b67b6a1
- Child:
- 2:faef6636d456
diff -r 000000000000 -r c25c4b67b6a1 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 03 14:49:18 2021 +0000 @@ -0,0 +1,39 @@ +// Coded by Luís Afonso 11-04-2019 +#include "mbed.h" +#include "BufferedSerial.h" +#include "rplidar.h" +#include "Robot.h" +#include "Communication.h" + +Serial pc(SERIAL_TX, SERIAL_RX); +RPLidar lidar; +BufferedSerial se_lidar(PA_9, PA_10); +PwmOut rplidar_motor(D3); + +int main() +{ + float odomX, odomY, odomTheta; + struct RPLidarMeasurement data; + + pc.baud(115200); + init_communication(&pc); + + // Lidar initialization + rplidar_motor.period(0.001f); + rplidar_motor.write(0.5f); + lidar.begin(se_lidar); + lidar.setAngle(0,360); + + pc.printf("Program started.\n"); + + lidar.startThreadScan(); + + while(1) { + // poll for measurements. Returns -1 if no new measurements are available. returns 0 if found one. + if(lidar.pollSensorData(&data) == 0) + { + pc.printf("%f\t%f\t%d\t%c\n", data.distance, data.angle, data.quality, data.startBit); // Prints one lidar measurement. + } + wait(0.01); + } +}