/* * Final Project: Micro mouse, CS154 Spring 2001 * Name : SooYoung Jung * Date : April, 11, 2001 * File : mm.cc */ /* motor */ int RM = 0; int LM = 1; /* IR sensor */ int IR_B = 0; /* Back */ int IR_B_SEE = 100; int IR_R = 1; /* Right */ int IR_R_SEE = 233; int IR_F = 2; /* Front */ int IR_F_SEE = 145; int IR_L = 3; /* Left */ int IR_L_SEE = 148; int SPEED = 90; int DIRECTION = 0; /* 0: N, 1: E, 2: W, 3: S */ int FOWARD = 0; int BACKWARD = 1; long MOVE18CM = 1000L; long DEGREE90 = 325L; /* mazecell structure 0123456789012345 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : contents, 0: free, 1: wall, 15 : Marked, 0: not visited, 1: visited */ /* 90 deg right turn : 5 {lego0_counts = 0; while(lego0_counts > -5) {motor(0, -100); motor(1, 100);} ao();} 18cm : 10 {lego0_counts = 0; while(lego0_counts < 10) {motor(0, 100); motor(1, 100);} ao();} */ int x = 16; /* current index, start 30 */ int y = 16; /* current index, start 0 */ int arraySize = 31; int mazecell[31][31]; void main() { int i, j; /* init cell */ /* even number index maze cell is all free space * and odd number index is wall or free space */ for (i = 0; i < arraySize; i+=2) for (j = 0; j < arraySize; j++) mazecell[i][j] = 1; /* 0000000000000001 all visited and free space*/ mazecell[arraySize/2 - 1][arraySize/2] = 1; /* Destination */ mazecell[arraySize/2][arraySize/2 - 1] = 1; /* Destination */ mazecell[arraySize/2][arraySize/2 + 1] = 1; /* Destination */ mazecell[arraySize/2 + 1][arraySize/2] = 1; /* Destination */ start_press(); first_run(); ao(); } void first_run() { checkCell(); printf("%d %d %d %d %d %d %d %d \n", mazecell[x-1][y],mazecell[x][y+1], mazecell[x][y-1],mazecell[x+1][y], analog(IR_B), analog(IR_R), analog(IR_F), analog(IR_L)); sleep(3.0); move18(); x--; checkCell(); printf("%d %d %d %d %d %d %d %d \n", mazecell[x-1][y],mazecell[x][y+1], mazecell[x][y-1],mazecell[x+1][y], analog(IR_B), analog(IR_R), analog(IR_F), analog(IR_L)); } void move18() { motor(LM, SPEED); motor(RM, SPEED); msleep(MOVE18CM); ao(); } void checkCell() { /* if it is already visited, then don't do */ if (analog(IR_F) < IR_F_SEE) mazecell[x-1][y] = 3; else mazecell[x-1][y] = 1; if (analog(IR_R) < IR_R_SEE) mazecell[x][y+1] = 3; else mazecell[x][y+1] = 1; if (analog(IR_L) < IR_L_SEE) mazecell[x][y-1] = 3; else mazecell[x][y-1] = 1; if (analog(IR_B) < IR_B_SEE) mazecell[x+1][y] = 3; else mazecell[x+1][y] = 1; } /* mazecell structure 0123456789012345 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : contents, 0: free, 1: wall, 15 : Marked, 0: not visited, 1: visited */