uyvug
Dependencies: Adafruit-16-Ch-PWM-Servo-Driver HCSR04 PID PololuQik2 QEI Sharp mbed-rtos
Fork of theRobot by
ShapeDetect.cpp@14:784acd735b8c, 2014-04-02 (annotated)
- Committer:
- tashworth
- Date:
- Wed Apr 02 03:36:49 2014 +0000
- Revision:
- 14:784acd735b8c
- Parent:
- 13:529323807361
- Child:
- 15:78f5e937f6ab
4-1-14 10:40pm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tashworth | 0:1b64a0cedc5d | 1 | #include "mbed.h" |
tashworth | 0:1b64a0cedc5d | 2 | #include "ShapeDetect.h" |
tashworth | 0:1b64a0cedc5d | 3 | |
tashworth | 0:1b64a0cedc5d | 4 | LocalFileSystem local("local"); |
tashworth | 6:75259c3306dd | 5 | Serial lrf(p13,p14); //LaserRangeFinder Camera |
tashworth | 0:1b64a0cedc5d | 6 | extern Serial pc; |
tashworth | 0:1b64a0cedc5d | 7 | |
tashworth | 0:1b64a0cedc5d | 8 | |
tashworth | 0:1b64a0cedc5d | 9 | /* variables used */ |
tashworth | 6:75259c3306dd | 10 | |
tashworth | 6:75259c3306dd | 11 | //IMAGE PROCESSING |
tashworth | 6:75259c3306dd | 12 | unsigned char image[120][160]; //image array |
tashworth | 6:75259c3306dd | 13 | unsigned char pixel; |
tashworth | 6:75259c3306dd | 14 | |
tashworth | 0:1b64a0cedc5d | 15 | char lrfchar=0; |
tashworth | 0:1b64a0cedc5d | 16 | unsigned int s_pixel[8]; |
tashworth | 0:1b64a0cedc5d | 17 | int num_edges = 0, i=0, j=0; |
tashworth | 0:1b64a0cedc5d | 18 | int mm_range=0; |
tashworth | 0:1b64a0cedc5d | 19 | |
tashworth | 0:1b64a0cedc5d | 20 | int s_pixel_sum = 0; |
tashworth | 0:1b64a0cedc5d | 21 | char min; |
tashworth | 0:1b64a0cedc5d | 22 | char max; |
tashworth | 0:1b64a0cedc5d | 23 | |
tashworth | 0:1b64a0cedc5d | 24 | int xcoord_val; |
tashworth | 0:1b64a0cedc5d | 25 | int ycoord_val; |
tashworth | 0:1b64a0cedc5d | 26 | int s_area_val; |
tashworth | 0:1b64a0cedc5d | 27 | |
tashworth | 0:1b64a0cedc5d | 28 | |
tashworth | 0:1b64a0cedc5d | 29 | /********************************************** |
tashworth | 0:1b64a0cedc5d | 30 | * |
tashworth | 0:1b64a0cedc5d | 31 | * Initializes the LRF |
tashworth | 0:1b64a0cedc5d | 32 | * |
tashworth | 0:1b64a0cedc5d | 33 | ***********************************************/ |
tashworth | 0:1b64a0cedc5d | 34 | |
tashworth | 0:1b64a0cedc5d | 35 | void lrf_baudCalibration(void){ |
tashworth | 0:1b64a0cedc5d | 36 | wait(2.5); |
tashworth | 3:b7b4780a7f6e | 37 | //lrf.baud(115200); |
tashworth | 0:1b64a0cedc5d | 38 | do { |
tashworth | 0:1b64a0cedc5d | 39 | lrf.putc('U'); |
tashworth | 0:1b64a0cedc5d | 40 | pc.putc('.'); |
tashworth | 0:1b64a0cedc5d | 41 | wait(.2); |
tashworth | 0:1b64a0cedc5d | 42 | if (lrf.readable()) lrfchar = lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 43 | } while (lrfchar != ':'); |
tashworth | 0:1b64a0cedc5d | 44 | pc.printf("\n\r"); |
tashworth | 0:1b64a0cedc5d | 45 | // clear out any extra characters - just in case |
tashworth | 0:1b64a0cedc5d | 46 | while (lrf.readable()) { |
tashworth | 0:1b64a0cedc5d | 47 | lrfchar = lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 48 | } |
tashworth | 0:1b64a0cedc5d | 49 | } |
tashworth | 0:1b64a0cedc5d | 50 | |
tashworth | 0:1b64a0cedc5d | 51 | |
tashworth | 0:1b64a0cedc5d | 52 | |
tashworth | 0:1b64a0cedc5d | 53 | /********************************************** |
tashworth | 0:1b64a0cedc5d | 54 | * Turns all pixels to a value and stores in |
tashworth | 0:1b64a0cedc5d | 55 | * image array |
tashworth | 0:1b64a0cedc5d | 56 | * |
tashworth | 0:1b64a0cedc5d | 57 | * input arrayType_a: |
tashworth | 0:1b64a0cedc5d | 58 | * 1 = BINARY ( 1 or 0 ) |
tashworth | 0:1b64a0cedc5d | 59 | * 2 = GREYSCALE (greyscale value 0x00 to 0xFF) |
tashworth | 0:1b64a0cedc5d | 60 | * |
tashworth | 0:1b64a0cedc5d | 61 | ***********************************************/ |
tashworth | 0:1b64a0cedc5d | 62 | void ImageToArray(int arrayType_a){ |
tashworth | 0:1b64a0cedc5d | 63 | lrf.putc('G'); |
tashworth | 13:529323807361 | 64 | pc.printf("Capturing Image\n\r"); |
tashworth | 0:1b64a0cedc5d | 65 | // Fill the data with values |
tashworth | 0:1b64a0cedc5d | 66 | switch(arrayType_a){ |
tashworth | 0:1b64a0cedc5d | 67 | |
tashworth | 0:1b64a0cedc5d | 68 | case 1: |
tashworth | 0:1b64a0cedc5d | 69 | for(int i=0; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 70 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 71 | pixel = lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 72 | if (pixel < THRESHOLD){ |
tashworth | 0:1b64a0cedc5d | 73 | image[i][j] = 1; |
tashworth | 0:1b64a0cedc5d | 74 | } else {image[i][j] = 0;} |
tashworth | 0:1b64a0cedc5d | 75 | }// end j for loop |
tashworth | 0:1b64a0cedc5d | 76 | }// end i for loop |
tashworth | 0:1b64a0cedc5d | 77 | break; |
tashworth | 0:1b64a0cedc5d | 78 | |
tashworth | 0:1b64a0cedc5d | 79 | case 2: |
tashworth | 0:1b64a0cedc5d | 80 | for(int i=0; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 81 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 82 | image[i][j] = lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 83 | }// j |
tashworth | 0:1b64a0cedc5d | 84 | }// i |
tashworth | 0:1b64a0cedc5d | 85 | break; |
tashworth | 0:1b64a0cedc5d | 86 | |
tashworth | 0:1b64a0cedc5d | 87 | default: |
tashworth | 0:1b64a0cedc5d | 88 | for(int i=0; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 89 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 90 | pixel = lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 91 | if (pixel < THRESHOLD){ |
tashworth | 0:1b64a0cedc5d | 92 | image[i][j] = 1; |
tashworth | 0:1b64a0cedc5d | 93 | } else {image[i][j] = 0;} |
tashworth | 0:1b64a0cedc5d | 94 | }// j |
tashworth | 0:1b64a0cedc5d | 95 | }// i |
tashworth | 0:1b64a0cedc5d | 96 | }//switch |
tashworth | 0:1b64a0cedc5d | 97 | } |
tashworth | 0:1b64a0cedc5d | 98 | |
tashworth | 0:1b64a0cedc5d | 99 | |
tashworth | 0:1b64a0cedc5d | 100 | /*************************************************** |
tashworth | 0:1b64a0cedc5d | 101 | * prints 160x120 image array to files (.txt & .dat) |
tashworth | 0:1b64a0cedc5d | 102 | * |
tashworth | 0:1b64a0cedc5d | 103 | * stores on the mbed locally |
tashworth | 0:1b64a0cedc5d | 104 | * |
tashworth | 0:1b64a0cedc5d | 105 | * input arrayType_f: |
tashworth | 0:1b64a0cedc5d | 106 | * 1 = BINARY (1 or 0) |
tashworth | 0:1b64a0cedc5d | 107 | * 2 = GREYSCALE (greyscale value 0x00 to 0xFF) |
tashworth | 0:1b64a0cedc5d | 108 | * 3 = DECIMAL (greyscale value 0 - 255) |
tashworth | 0:1b64a0cedc5d | 109 | * |
tashworth | 0:1b64a0cedc5d | 110 | ****************************************************/ |
tashworth | 0:1b64a0cedc5d | 111 | |
tashworth | 0:1b64a0cedc5d | 112 | |
tashworth | 0:1b64a0cedc5d | 113 | void printImageToFile(int arrayType_f){ |
tashworth | 0:1b64a0cedc5d | 114 | |
tashworth | 0:1b64a0cedc5d | 115 | // Write to local files |
tashworth | 0:1b64a0cedc5d | 116 | FILE *fp = fopen("/local/image.dat", "w"); |
tashworth | 0:1b64a0cedc5d | 117 | FILE *fp2 = fopen("/local/image.txt", "w"); |
tashworth | 0:1b64a0cedc5d | 118 | |
tashworth | 0:1b64a0cedc5d | 119 | for (int i=0; i<120; i++) { |
tashworth | 0:1b64a0cedc5d | 120 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 121 | switch (arrayType_f){ |
tashworth | 0:1b64a0cedc5d | 122 | |
tashworth | 0:1b64a0cedc5d | 123 | //BINARY OUTPUT |
tashworth | 0:1b64a0cedc5d | 124 | case 1: |
tashworth | 0:1b64a0cedc5d | 125 | fprintf(fp, "%d",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 126 | fprintf(fp2, "%d",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 127 | break; |
tashworth | 0:1b64a0cedc5d | 128 | |
tashworth | 0:1b64a0cedc5d | 129 | //GREYSCALE OUTPUT 00 to FF |
tashworth | 0:1b64a0cedc5d | 130 | case 2: |
tashworth | 0:1b64a0cedc5d | 131 | fprintf(fp, "%02X ",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 132 | fprintf(fp2, "%02X ",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 133 | break; |
tashworth | 0:1b64a0cedc5d | 134 | |
tashworth | 0:1b64a0cedc5d | 135 | //DECIMAL OUTPUT |
tashworth | 0:1b64a0cedc5d | 136 | case 3: |
tashworth | 0:1b64a0cedc5d | 137 | fprintf(fp, "%3d ",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 138 | fprintf(fp2, "%3d ",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 139 | break; |
tashworth | 0:1b64a0cedc5d | 140 | |
tashworth | 0:1b64a0cedc5d | 141 | default: |
tashworth | 0:1b64a0cedc5d | 142 | fprintf(fp, "%02h",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 143 | fprintf(fp2, "%02h",image[i][j]); |
tashworth | 0:1b64a0cedc5d | 144 | break; |
tashworth | 0:1b64a0cedc5d | 145 | } |
tashworth | 0:1b64a0cedc5d | 146 | } |
tashworth | 0:1b64a0cedc5d | 147 | fprintf(fp, "\n"); |
tashworth | 0:1b64a0cedc5d | 148 | fprintf(fp2, "\n"); |
tashworth | 0:1b64a0cedc5d | 149 | } |
tashworth | 0:1b64a0cedc5d | 150 | fclose(fp); |
tashworth | 0:1b64a0cedc5d | 151 | } |
tashworth | 0:1b64a0cedc5d | 152 | |
tashworth | 0:1b64a0cedc5d | 153 | |
tashworth | 0:1b64a0cedc5d | 154 | /********************************************** |
tashworth | 0:1b64a0cedc5d | 155 | * edgeDetection |
tashworth | 0:1b64a0cedc5d | 156 | * |
tashworth | 0:1b64a0cedc5d | 157 | * outputs the number of edges detected |
tashworth | 0:1b64a0cedc5d | 158 | * |
tashworth | 0:1b64a0cedc5d | 159 | * |
tashworth | 0:1b64a0cedc5d | 160 | ***********************************************/ |
tashworth | 0:1b64a0cedc5d | 161 | int edgeDetection(void){ |
tashworth | 0:1b64a0cedc5d | 162 | |
tashworth | 0:1b64a0cedc5d | 163 | ImageToArray(BINARY); |
tashworth | 0:1b64a0cedc5d | 164 | |
tashworth | 0:1b64a0cedc5d | 165 | for(int i=0; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 166 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 167 | s_pixel_sum = 0; |
tashworth | 0:1b64a0cedc5d | 168 | //stores the value of 8 surrounding pixels |
tashworth | 0:1b64a0cedc5d | 169 | s_pixel[0] = image[i-1][j-1]; |
tashworth | 0:1b64a0cedc5d | 170 | s_pixel[1] = image[i-1][j]; |
tashworth | 0:1b64a0cedc5d | 171 | s_pixel[2] = image[i-1][j+1]; |
tashworth | 0:1b64a0cedc5d | 172 | s_pixel[3] = image[i][j-1]; |
tashworth | 0:1b64a0cedc5d | 173 | s_pixel[4] = image[i][j+1]; |
tashworth | 0:1b64a0cedc5d | 174 | s_pixel[5] = image[i+1][j-1]; |
tashworth | 0:1b64a0cedc5d | 175 | s_pixel[6] = image[i+1][j]; |
tashworth | 0:1b64a0cedc5d | 176 | s_pixel[7] = image[i+1][j+1]; |
tashworth | 0:1b64a0cedc5d | 177 | |
tashworth | 0:1b64a0cedc5d | 178 | //get the sum of the pixels |
tashworth | 0:1b64a0cedc5d | 179 | for (int k=0; k<8; k++){ |
tashworth | 0:1b64a0cedc5d | 180 | s_pixel_sum+=s_pixel[k]; |
tashworth | 0:1b64a0cedc5d | 181 | } |
tashworth | 0:1b64a0cedc5d | 182 | |
tashworth | 0:1b64a0cedc5d | 183 | if ((s_pixel_sum < 5) && (s_pixel_sum > 2)) { |
tashworth | 0:1b64a0cedc5d | 184 | image[i][j] = 1; |
tashworth | 0:1b64a0cedc5d | 185 | } else { |
tashworth | 0:1b64a0cedc5d | 186 | image[i][j] = 0; |
tashworth | 0:1b64a0cedc5d | 187 | } |
tashworth | 0:1b64a0cedc5d | 188 | |
tashworth | 0:1b64a0cedc5d | 189 | |
tashworth | 0:1b64a0cedc5d | 190 | }// for j for loop |
tashworth | 0:1b64a0cedc5d | 191 | }// end i for loop |
tashworth | 0:1b64a0cedc5d | 192 | //fill image array with buffer values |
tashworth | 0:1b64a0cedc5d | 193 | |
tashworth | 0:1b64a0cedc5d | 194 | |
tashworth | 0:1b64a0cedc5d | 195 | |
tashworth | 0:1b64a0cedc5d | 196 | /// DO EDGE CALCULATION HERE |
tashworth | 0:1b64a0cedc5d | 197 | return num_edges; |
tashworth | 0:1b64a0cedc5d | 198 | } // end function |
tashworth | 0:1b64a0cedc5d | 199 | |
tashworth | 0:1b64a0cedc5d | 200 | |
tashworth | 0:1b64a0cedc5d | 201 | |
tashworth | 0:1b64a0cedc5d | 202 | /********************************************** |
tashworth | 0:1b64a0cedc5d | 203 | * center of mass coordinates |
tashworth | 0:1b64a0cedc5d | 204 | * |
tashworth | 0:1b64a0cedc5d | 205 | * outputs the coordinmates |
tashworth | 0:1b64a0cedc5d | 206 | * |
tashworth | 0:1b64a0cedc5d | 207 | ***********************************************/ |
tashworth | 0:1b64a0cedc5d | 208 | |
tashworth | 0:1b64a0cedc5d | 209 | void centerMass(int *xcoord, int *ycoord, int *s_area){ |
tashworth | 0:1b64a0cedc5d | 210 | ImageToArray(BINARY); |
tashworth | 11:8d2455e383ce | 211 | //printImageToFile(BINARY); |
tashworth | 13:529323807361 | 212 | clearBounds(); |
tashworth | 0:1b64a0cedc5d | 213 | int count = 0; |
tashworth | 0:1b64a0cedc5d | 214 | int sumi = 0; |
tashworth | 0:1b64a0cedc5d | 215 | int sumj = 0; |
tashworth | 0:1b64a0cedc5d | 216 | for(int i=0; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 217 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 218 | if(image[i][j] == 1){ |
tashworth | 0:1b64a0cedc5d | 219 | sumi += i; |
tashworth | 0:1b64a0cedc5d | 220 | sumj += j; |
tashworth | 0:1b64a0cedc5d | 221 | count++; |
tashworth | 0:1b64a0cedc5d | 222 | } |
tashworth | 0:1b64a0cedc5d | 223 | }// j |
tashworth | 0:1b64a0cedc5d | 224 | }// i |
tashworth | 0:1b64a0cedc5d | 225 | |
tashworth | 0:1b64a0cedc5d | 226 | int x_2coord = sumj / count; |
tashworth | 0:1b64a0cedc5d | 227 | int y_2coord = sumi / count; |
tashworth | 0:1b64a0cedc5d | 228 | *xcoord = x_2coord; |
tashworth | 0:1b64a0cedc5d | 229 | *ycoord = y_2coord; |
tashworth | 0:1b64a0cedc5d | 230 | image[x_2coord][x_2coord] = 8; |
tashworth | 0:1b64a0cedc5d | 231 | |
tashworth | 0:1b64a0cedc5d | 232 | int s_2area = 0; |
tashworth | 0:1b64a0cedc5d | 233 | for(int i=0; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 234 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 235 | if ( image[i][j] == 1 ){ |
tashworth | 0:1b64a0cedc5d | 236 | s_2area++; |
tashworth | 0:1b64a0cedc5d | 237 | } |
tashworth | 0:1b64a0cedc5d | 238 | |
tashworth | 0:1b64a0cedc5d | 239 | }// j |
tashworth | 0:1b64a0cedc5d | 240 | }// i |
tashworth | 0:1b64a0cedc5d | 241 | *s_area = s_2area; |
tashworth | 0:1b64a0cedc5d | 242 | } |
tashworth | 0:1b64a0cedc5d | 243 | /*********************************************** |
tashworth | 0:1b64a0cedc5d | 244 | * |
tashworth | 0:1b64a0cedc5d | 245 | * clears edges for more accurate area counting |
tashworth | 0:1b64a0cedc5d | 246 | * |
tashworth | 0:1b64a0cedc5d | 247 | * |
tashworth | 0:1b64a0cedc5d | 248 | ************************************************/ |
tashworth | 0:1b64a0cedc5d | 249 | void clearBounds(void){ |
tashworth | 0:1b64a0cedc5d | 250 | //top 20 pixels |
tashworth | 12:284be46593ae | 251 | for(int i=0; i<5; i++){ |
tashworth | 0:1b64a0cedc5d | 252 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 253 | image[i][j] = 0; |
tashworth | 0:1b64a0cedc5d | 254 | |
tashworth | 0:1b64a0cedc5d | 255 | }// j |
tashworth | 0:1b64a0cedc5d | 256 | }// i |
tashworth | 0:1b64a0cedc5d | 257 | |
tashworth | 0:1b64a0cedc5d | 258 | //bottom 20 pixels |
tashworth | 12:284be46593ae | 259 | for(int i=114; i<120; i++){ |
tashworth | 0:1b64a0cedc5d | 260 | for(int j=0; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 261 | image[i][j] = 0; |
tashworth | 0:1b64a0cedc5d | 262 | }// j |
tashworth | 0:1b64a0cedc5d | 263 | }// i |
tashworth | 0:1b64a0cedc5d | 264 | //left 20 pixels |
tashworth | 0:1b64a0cedc5d | 265 | for(int i=0; i<120; i++){ |
tashworth | 12:284be46593ae | 266 | for(int j=0; j<20; j++){ |
tashworth | 0:1b64a0cedc5d | 267 | image[i][j] = 0; |
tashworth | 0:1b64a0cedc5d | 268 | }// j |
tashworth | 0:1b64a0cedc5d | 269 | }// i |
tashworth | 0:1b64a0cedc5d | 270 | //right 20 pixels |
tashworth | 0:1b64a0cedc5d | 271 | for(int i=0; i<120; i++){ |
tashworth | 12:284be46593ae | 272 | for(int j=139; j<160; j++){ |
tashworth | 0:1b64a0cedc5d | 273 | image[i][j] = 0; |
tashworth | 0:1b64a0cedc5d | 274 | }// j |
tashworth | 0:1b64a0cedc5d | 275 | }// i |
tashworth | 0:1b64a0cedc5d | 276 | //clear bounds of detected blacks |
tashworth | 0:1b64a0cedc5d | 277 | } |
tashworth | 0:1b64a0cedc5d | 278 | |
tashworth | 3:b7b4780a7f6e | 279 | |
tashworth | 6:75259c3306dd | 280 | int shapeDetection(void) |
tashworth | 3:b7b4780a7f6e | 281 | { |
tashworth | 3:b7b4780a7f6e | 282 | |
tashworth | 8:77a57909aa15 | 283 | centerMass(&xcoord_val, &ycoord_val, &s_area_val); |
tashworth | 3:b7b4780a7f6e | 284 | pc.printf("\ncentriod calculated\n\r"); |
tashworth | 13:529323807361 | 285 | pc.printf("Center of Mass is at X: %d Y: %d\n\r", xcoord_val, ycoord_val, s_area_val); |
tashworth | 13:529323807361 | 286 | pc.printf("The area of the Mass is: %d\n\r", s_area_val); |
tashworth | 13:529323807361 | 287 | |
tashworth | 13:529323807361 | 288 | if( (s_area_val > (SQUARE_AREA - AREA_TOLERANCE)) && (s_area_val < (SQUARE_AREA + AREA_TOLERANCE)) ) { |
tashworth | 0:1b64a0cedc5d | 289 | pc.printf("\nSQUARE DETECTECD\n\r"); |
tashworth | 6:75259c3306dd | 290 | return 1; |
tashworth | 14:784acd735b8c | 291 | } else if ((s_area_val > (TRIANGLE_AREA - AREA_TOLERANCE)) && (s_area_val < (TRIANGLE_AREA + AREA_TOLERANCE)) ) { |
tashworth | 3:b7b4780a7f6e | 292 | pc.printf("\nTRIANGLE DETECTECD\n\r"); |
tashworth | 6:75259c3306dd | 293 | return 2; |
tashworth | 3:b7b4780a7f6e | 294 | } else { |
tashworth | 3:b7b4780a7f6e | 295 | pc.printf("\nCIRCLE DETECTECD\n\r"); |
tashworth | 6:75259c3306dd | 296 | return 3; |
tashworth | 0:1b64a0cedc5d | 297 | } |
tashworth | 3:b7b4780a7f6e | 298 | } |
tashworth | 3:b7b4780a7f6e | 299 | |
tashworth | 12:284be46593ae | 300 | |
tashworth | 3:b7b4780a7f6e | 301 | int getDistance(void){ |
tashworth | 0:1b64a0cedc5d | 302 | lrf.putc('B'); //Take Binary range reading |
tashworth | 0:1b64a0cedc5d | 303 | // read in the four bytes for the range in mm (MSB first) |
tashworth | 0:1b64a0cedc5d | 304 | mm_range=0; |
tashworth | 0:1b64a0cedc5d | 305 | mm_range=lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 306 | mm_range=(mm_range<<8)|lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 307 | mm_range=(mm_range<<8)|lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 308 | mm_range=(mm_range<<8)|lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 309 | //eat CR & ":" command prompt |
tashworth | 0:1b64a0cedc5d | 310 | do { |
tashworth | 0:1b64a0cedc5d | 311 | lrfchar=lrf.getc(); |
tashworth | 0:1b64a0cedc5d | 312 | } while (lrfchar != ':'); |
tashworth | 3:b7b4780a7f6e | 313 | return mm_range; |
tashworth | 0:1b64a0cedc5d | 314 | } |
tashworth | 3:b7b4780a7f6e | 315 | |
tashworth | 6:75259c3306dd | 316 | |
tashworth | 11:8d2455e383ce | 317 | int get_com_x(void) |
tashworth | 11:8d2455e383ce | 318 | { |
tashworth | 6:75259c3306dd | 319 | |
tashworth | 11:8d2455e383ce | 320 | return xcoord_val; |
tashworth | 11:8d2455e383ce | 321 | } |
tashworth | 11:8d2455e383ce | 322 | int get_com_y(void) |
tashworth | 11:8d2455e383ce | 323 | { |
tashworth | 11:8d2455e383ce | 324 | return ycoord_val; |
tashworth | 11:8d2455e383ce | 325 | } |
tashworth | 11:8d2455e383ce | 326 | |
tashworth | 11:8d2455e383ce | 327 | int get_com_a(void) |
tashworth | 11:8d2455e383ce | 328 | { |
tashworth | 11:8d2455e383ce | 329 | return s_area_val; |
tashworth | 11:8d2455e383ce | 330 | } |
tashworth | 11:8d2455e383ce | 331 |