Tiago Correia / Mbed OS SRA2020-2021

Dependencies:   BufferedSerial

Committer:
yaaqobhpt
Date:
Wed May 05 14:14:28 2021 +0000
Revision:
2:faef6636d456
Parent:
0:c25c4b67b6a1
dada

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yaaqobhpt 0:c25c4b67b6a1 1 // Coded by Luís Afonso 11-04-2019
yaaqobhpt 0:c25c4b67b6a1 2 #include "mbed.h"
yaaqobhpt 0:c25c4b67b6a1 3 #include "BufferedSerial.h"
yaaqobhpt 0:c25c4b67b6a1 4 #include "rplidar.h"
yaaqobhpt 0:c25c4b67b6a1 5 #include "Robot.h"
yaaqobhpt 0:c25c4b67b6a1 6 #include "Communication.h"
yaaqobhpt 0:c25c4b67b6a1 7
yaaqobhpt 0:c25c4b67b6a1 8 Serial pc(SERIAL_TX, SERIAL_RX);
yaaqobhpt 0:c25c4b67b6a1 9 RPLidar lidar;
yaaqobhpt 0:c25c4b67b6a1 10 BufferedSerial se_lidar(PA_9, PA_10);
yaaqobhpt 0:c25c4b67b6a1 11 PwmOut rplidar_motor(D3);
yaaqobhpt 0:c25c4b67b6a1 12
yaaqobhpt 0:c25c4b67b6a1 13 int main()
yaaqobhpt 0:c25c4b67b6a1 14 {
yaaqobhpt 0:c25c4b67b6a1 15 struct RPLidarMeasurement data;
yaaqobhpt 0:c25c4b67b6a1 16
yaaqobhpt 0:c25c4b67b6a1 17 pc.baud(115200);
yaaqobhpt 0:c25c4b67b6a1 18 init_communication(&pc);
yaaqobhpt 0:c25c4b67b6a1 19
yaaqobhpt 0:c25c4b67b6a1 20 // Lidar initialization
yaaqobhpt 2:faef6636d456 21 rplidar_motor.period(0.0005f);
yaaqobhpt 0:c25c4b67b6a1 22 lidar.begin(se_lidar);
yaaqobhpt 0:c25c4b67b6a1 23 lidar.setAngle(0,360);
yaaqobhpt 0:c25c4b67b6a1 24
yaaqobhpt 0:c25c4b67b6a1 25 pc.printf("Program started.\n");
yaaqobhpt 0:c25c4b67b6a1 26
yaaqobhpt 0:c25c4b67b6a1 27 lidar.startThreadScan();
yaaqobhpt 0:c25c4b67b6a1 28
yaaqobhpt 0:c25c4b67b6a1 29 while(1) {
yaaqobhpt 0:c25c4b67b6a1 30 // poll for measurements. Returns -1 if no new measurements are available. returns 0 if found one.
yaaqobhpt 0:c25c4b67b6a1 31 if(lidar.pollSensorData(&data) == 0)
yaaqobhpt 0:c25c4b67b6a1 32 {
yaaqobhpt 0:c25c4b67b6a1 33 pc.printf("%f\t%f\t%d\t%c\n", data.distance, data.angle, data.quality, data.startBit); // Prints one lidar measurement.
yaaqobhpt 0:c25c4b67b6a1 34 }
yaaqobhpt 0:c25c4b67b6a1 35 wait(0.01);
yaaqobhpt 0:c25c4b67b6a1 36 }
yaaqobhpt 0:c25c4b67b6a1 37 }