Created
March 30, 2017 02:57
-
-
Save tina1998612/c210ba415e1764fa4e93c37cf3d8b1bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void in_round_turn(){ | |
if(!inAuto) return; | |
if(!in_round) { | |
if(center[1]>40 && center[2]>40) setServoDegree(-30), in_round = 1; // turn right if top center line is on the right side | |
else setServoDegree(30), in_round = 2; // else turn left | |
} else{ // if in round && center line points to black img | |
switch(in_round){ | |
case 1: | |
setServoDegree(-30); | |
break; | |
case 2: | |
setServoDegree(30); | |
break; | |
} | |
in_round = 0; | |
} | |
} | |
void about_centerline(const Byte* camPtr){ | |
for(int line=0,x=0;line<60;line++){ | |
sideL[line] = 0; sideR[line] = 60; maybe_black_img_in_track = 0; black_img_in_trackL[line]=0; black_img_in_trackR[line]=0; | |
if(!image[line][0]) find_sideL = 1; | |
for(int i=0; i<10; i++){ | |
for(int j=7; j>=0; j--){ | |
if(((*(camPtr+line*10+i))>>j)&1==1) image[line][x++] = 1; | |
else image[line][x++] = 0; | |
if(x>1){ | |
if(image[line][x-2] && !image[line][x-1] && !image[line][x]){ // BWW | |
if(maybe_black_img_in_track){ | |
maybe_black_img_in_track=0; | |
black_img_in_trackR[line] = x-1; | |
} else{ | |
if(!find_sideL){ | |
sideL[line] = x-1; | |
find_sideL = 1; | |
} else { // if left edge exists | |
if(!image[line][x-2] && image[line][x-1] && image[line][x]){ // WBB | |
maybe_black_img_in_track = 1; | |
black_img_in_trackL[line] = x-1; | |
sideR[line] = x-1; // find the right most edge | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
if(black_img_in_trackR[line]){ // if black img in track | |
// roundabout or obstacles detected | |
if(sideR[line]-sideL[line] > track_size){ // roundabout | |
in_round_turn(); | |
} else{ //obstacle | |
if(black_img_in_trackL[line]-sideL[line] > sideR[line]-black_img_in_trackR[line]){ // left road width > right | |
sideR[line] = black_img_in_trackL[line]; | |
} else{ | |
sideL[line] = black_img_in_trackR[line]; | |
} | |
} | |
} | |
center[line] = (sideL[line]+sideR[line])/2; | |
} | |
track_size = sideR[58]-sideL[58]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment