![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sra-romi
Dependencies: BufferedSerial Matrix
main.cpp@0:2b691d200d6f, 2019-04-09 (annotated)
- Committer:
- LuisRA
- Date:
- Tue Apr 09 17:53:31 2019 +0000
- Revision:
- 0:2b691d200d6f
- Child:
- 1:dc87724abce8
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LuisRA | 0:2b691d200d6f | 1 | #include "mbed.h" |
LuisRA | 0:2b691d200d6f | 2 | #include "BufferedSerial.h" |
LuisRA | 0:2b691d200d6f | 3 | #include "rplidar.h" |
LuisRA | 0:2b691d200d6f | 4 | |
LuisRA | 0:2b691d200d6f | 5 | Serial pc(SERIAL_TX, SERIAL_RX, 1000000); |
LuisRA | 0:2b691d200d6f | 6 | RPLidar lidar; |
LuisRA | 0:2b691d200d6f | 7 | BufferedSerial se_lidar(PA_9, PA_10); |
LuisRA | 0:2b691d200d6f | 8 | PwmOut rplidar_motor(A3); |
LuisRA | 0:2b691d200d6f | 9 | |
LuisRA | 0:2b691d200d6f | 10 | |
LuisRA | 0:2b691d200d6f | 11 | |
LuisRA | 0:2b691d200d6f | 12 | int main() |
LuisRA | 0:2b691d200d6f | 13 | { |
LuisRA | 0:2b691d200d6f | 14 | |
LuisRA | 0:2b691d200d6f | 15 | pc.baud(1000000);//115200); |
LuisRA | 0:2b691d200d6f | 16 | pc.printf("main\n"); |
LuisRA | 0:2b691d200d6f | 17 | wait(1); |
LuisRA | 0:2b691d200d6f | 18 | |
LuisRA | 0:2b691d200d6f | 19 | rplidar_motor.period(0.001f); |
LuisRA | 0:2b691d200d6f | 20 | lidar.begin(se_lidar); |
LuisRA | 0:2b691d200d6f | 21 | lidar.setAngle(0,360); |
LuisRA | 0:2b691d200d6f | 22 | |
LuisRA | 0:2b691d200d6f | 23 | |
LuisRA | 0:2b691d200d6f | 24 | pc.printf("Program started.\n"); |
LuisRA | 0:2b691d200d6f | 25 | |
LuisRA | 0:2b691d200d6f | 26 | |
LuisRA | 0:2b691d200d6f | 27 | lidar.startThreadScan(); |
LuisRA | 0:2b691d200d6f | 28 | |
LuisRA | 0:2b691d200d6f | 29 | |
LuisRA | 0:2b691d200d6f | 30 | while(1) { |
LuisRA | 0:2b691d200d6f | 31 | struct RPLidarMeasurement data; |
LuisRA | 0:2b691d200d6f | 32 | // poll for measurements. Returns -1 if no new measurements are available. returns 0 if found one. |
LuisRA | 0:2b691d200d6f | 33 | if(lidar.pollSensorData(&data) == 0) |
LuisRA | 0:2b691d200d6f | 34 | { |
LuisRA | 0:2b691d200d6f | 35 | pc.printf("%f\t%f\t%d\t%c\n", data.distance, data.angle, data.quality, data.startBit); |
LuisRA | 0:2b691d200d6f | 36 | } |
LuisRA | 0:2b691d200d6f | 37 | wait(0.1); |
LuisRA | 0:2b691d200d6f | 38 | } |
LuisRA | 0:2b691d200d6f | 39 | } |