le programme de est du lidar

Dependencies:   mbed

Committer:
GaspardD
Date:
Sun Sep 09 12:55:53 2018 +0000
Revision:
0:2ba98068bc41
pour omar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GaspardD 0:2ba98068bc41 1 #include "mbed.h"
GaspardD 0:2ba98068bc41 2
GaspardD 0:2ba98068bc41 3 Serial pc(USBTX, USBRX); // tx, rx
GaspardD 0:2ba98068bc41 4 Serial device(A4,A5); // tx, rx
GaspardD 0:2ba98068bc41 5
GaspardD 0:2ba98068bc41 6 int dist;// LiDAR actually measured distance value
GaspardD 0:2ba98068bc41 7 int strength;// LiDAR signal strength
GaspardD 0:2ba98068bc41 8 int check;// check numerical value storage
GaspardD 0:2ba98068bc41 9 int i;
GaspardD 0:2ba98068bc41 10 int uart[9];// store data measured by LiDAR
GaspardD 0:2ba98068bc41 11 const int HEADER=0x59;// data package frame header
GaspardD 0:2ba98068bc41 12
GaspardD 0:2ba98068bc41 13 int main()
GaspardD 0:2ba98068bc41 14 {
GaspardD 0:2ba98068bc41 15 pc.baud(115200);
GaspardD 0:2ba98068bc41 16 device.baud(115200);
GaspardD 0:2ba98068bc41 17 int i=0;
GaspardD 0:2ba98068bc41 18 pc.printf("Hello \n");
GaspardD 0:2ba98068bc41 19 while(1) {
GaspardD 0:2ba98068bc41 20 if (device.readable()) { //check whether the serial port has data input
GaspardD 0:2ba98068bc41 21 if(device.getc()==HEADER) { // determine data package frame header 0x59
GaspardD 0:2ba98068bc41 22 uart[0]=HEADER;
GaspardD 0:2ba98068bc41 23 if(device.getc()==HEADER) { //determine data package frame header 0x59
GaspardD 0:2ba98068bc41 24 uart[1]=HEADER;
GaspardD 0:2ba98068bc41 25 for(i=2; i<9; i++) { // store data to array
GaspardD 0:2ba98068bc41 26 uart[i]=device.getc();
GaspardD 0:2ba98068bc41 27 }
GaspardD 0:2ba98068bc41 28 check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
GaspardD 0:2ba98068bc41 29 if(uart[8]==(check&0xff)) { // check the received data as per protocols
GaspardD 0:2ba98068bc41 30 dist=uart[2]+uart[3]*256;// calculate distance value
GaspardD 0:2ba98068bc41 31 strength=uart[4]+uart[5]*256;// calculate signal strength value
GaspardD 0:2ba98068bc41 32 pc.printf("\rdist = %d strength = %d ",dist,strength);// output signal strength value
GaspardD 0:2ba98068bc41 33 }
GaspardD 0:2ba98068bc41 34 }
GaspardD 0:2ba98068bc41 35 }
GaspardD 0:2ba98068bc41 36 }
GaspardD 0:2ba98068bc41 37 }
GaspardD 0:2ba98068bc41 38 }
GaspardD 0:2ba98068bc41 39