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.
main.cpp@0:c25c4b67b6a1, 2021-05-03 (annotated)
- Committer:
- yaaqobhpt
- Date:
- Mon May 03 14:49:18 2021 +0000
- Revision:
- 0:c25c4b67b6a1
- Child:
- 2:faef6636d456
ok-V1
Who changed what in which revision?
User | Revision | Line number | New 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 | float odomX, odomY, odomTheta; |
yaaqobhpt | 0:c25c4b67b6a1 | 16 | struct RPLidarMeasurement data; |
yaaqobhpt | 0:c25c4b67b6a1 | 17 | |
yaaqobhpt | 0:c25c4b67b6a1 | 18 | pc.baud(115200); |
yaaqobhpt | 0:c25c4b67b6a1 | 19 | init_communication(&pc); |
yaaqobhpt | 0:c25c4b67b6a1 | 20 | |
yaaqobhpt | 0:c25c4b67b6a1 | 21 | // Lidar initialization |
yaaqobhpt | 0:c25c4b67b6a1 | 22 | rplidar_motor.period(0.001f); |
yaaqobhpt | 0:c25c4b67b6a1 | 23 | rplidar_motor.write(0.5f); |
yaaqobhpt | 0:c25c4b67b6a1 | 24 | lidar.begin(se_lidar); |
yaaqobhpt | 0:c25c4b67b6a1 | 25 | lidar.setAngle(0,360); |
yaaqobhpt | 0:c25c4b67b6a1 | 26 | |
yaaqobhpt | 0:c25c4b67b6a1 | 27 | pc.printf("Program started.\n"); |
yaaqobhpt | 0:c25c4b67b6a1 | 28 | |
yaaqobhpt | 0:c25c4b67b6a1 | 29 | lidar.startThreadScan(); |
yaaqobhpt | 0:c25c4b67b6a1 | 30 | |
yaaqobhpt | 0:c25c4b67b6a1 | 31 | while(1) { |
yaaqobhpt | 0:c25c4b67b6a1 | 32 | // poll for measurements. Returns -1 if no new measurements are available. returns 0 if found one. |
yaaqobhpt | 0:c25c4b67b6a1 | 33 | if(lidar.pollSensorData(&data) == 0) |
yaaqobhpt | 0:c25c4b67b6a1 | 34 | { |
yaaqobhpt | 0:c25c4b67b6a1 | 35 | 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 | 36 | } |
yaaqobhpt | 0:c25c4b67b6a1 | 37 | wait(0.01); |
yaaqobhpt | 0:c25c4b67b6a1 | 38 | } |
yaaqobhpt | 0:c25c4b67b6a1 | 39 | } |