svoe
Dependencies: mbed mbed-STM32F103C8T6 MPU6050_1
Diff: echo.h
- Revision:
- 17:bd6b6ac89e0e
- Parent:
- 4:904b737ef08a
- Child:
- 19:2fe650d29823
diff -r 6ec1aa32cf1f -r bd6b6ac89e0e echo.h --- a/echo.h Sat Dec 01 14:31:24 2018 +0000 +++ b/echo.h Sun Feb 10 12:05:16 2019 +0000 @@ -1,4 +1,7 @@ +int obstacle_glaz[100];//13 steps [-90;+90] by 15 deg +int obstacle_echo[100];//13 steps [-90;+90] by 15 deg int obstacle[100];//13 steps [-90;+90] by 15 deg +int corrected_obstacle [100]; int echo_current_step;//[0;36], (step=18) => 0 deg int echo_old_step; int echo_old_old_step; @@ -39,7 +42,10 @@ void echo_transmit(int steps_number) { //printf is not recommended for interrupts int tmstep; wifi.putc(0xff); //sync symbol - for(tmstep=0;tmstep<steps_number;tmstep++){wifi.putc((obstacle[tmstep]<500) ? obstacle[tmstep]/2 : 250);} + //for(tmstep = 0; tmstep < steps_number; tmstep ++){wifi.putc((obstacle_glaz[tmstep] < 500) ? obstacle_glaz[tmstep]/2 : 250);} + //for(tmstep = 0; tmstep < steps_number; tmstep ++){wifi.putc((obstacle_echo[tmstep] < 500) ? obstacle_echo[tmstep]/2 : 250);} + for(tmstep = 0; tmstep < steps_number; tmstep ++){wifi.putc((obstacle[tmstep] < 500) ? obstacle[tmstep]/2 : 250);} + for(tmstep = 0; tmstep < steps_number; tmstep ++){wifi.putc((corrected_obstacle[tmstep] < 500) ? corrected_obstacle[tmstep]/2 : 250);} } void echo_scan(){ // rewrite with argument: n or step //will not work in interrupt ?? @@ -50,11 +56,11 @@ wait_ms(50); echo_start(); wait_ms(50); - obstacle[point]=echo_cm;} + obstacle[point] = echo_cm;} } void echo_step(bool transmit = 0){ - obstacle[echo_old_old_step]=echo_cm; + obstacle[echo_old_old_step] = echo_cm; //echo_transmit(echo_current_step); echo_old_old_step = echo_old_step; echo_old_step = echo_current_step; @@ -64,17 +70,18 @@ serva(echo_current_step*5-90); echo_start(); //the last to exit ticker interrupt ASAP } - -bool analyze_obstacle(){ - min_dist = 400;max_dist = 0; front_dist = 400; - for(int point = 0;point <= 12;point ++){ - if(obstacle[point]<min_dist) {min_dist=obstacle[point];min_dist_angle = point*15-90;} - if(obstacle[point]>max_dist) {max_dist=obstacle[point];max_dist_angle = point*15-90;} - if((obstacle[point]*abs(point-6)*3<15)&&(obstacle[point]<front_dist)) {front_dist=obstacle[point];} - } - if(front_dist < 20) return(1); else return(0); - } - + void echo_full_scan(int steps){ //scan by wheels (calculate speed) + } + +void glaz_init(){ + glaz.setTimeout(500); + if (!glaz.init()) + { + wifi.printf("Failed to detect and initialize sensor!"); + } + glaz.setDistanceMode(VL53L1X::Long); + glaz.setMeasurementTimingBudget(50000); + glaz.startContinuous(50); } \ No newline at end of file