1: /* Arlotto 2004 : pgm test robot chenille */ 2: 3: #include 4: #include 5: #define __DEBUG // à commenter pour mode autonome 6: 7: #ifdef __DEBUG 8: __CONFIG (0x3739); 9: #else 10: __CONFIG(0x3D39); 11: #endif 12: #include "biosdem.h" 13: #include "hardware.h" 14: #include "move.h" 15: #include "compass.h" 16: #include "sonar.h" 17: #include "serial.h" 18: #include "tempo.h" 19: bank1 int bearing ; 20: bank1 int distance ; 21: extern volatile unsigned int direction,vitesse ; // modifiable n'importe où dans le programme 22: extern volatile signed char angle,speed ; 23: extern volatile unsigned char move_state,turn_state; 24: void main (void) 25: { 26: LEDS_DIR_INIT; 27: LEDS_ON; 28: SWITCH_DIR_INIT; 29: init_move(); 30: init_serial(); 31: init_compass(); 32: init_tempo0(); 33: DelayMs(250); 34: DelayMs(250); 35: DelayMs(250); 36: DelayMs(250); 37: LEDS_OFF; 38: serial_puts("Hello This is Achille v0.1 !!\r"); 39: PEIE=1; 40: GIE = 1 ; 41: switch (SW_VALUE) 42: { 43: case 0 : // avance tant que d >70 puis tourne 44: 45: for ( ; ; ) 46: { 47: 48: distance = read_distance(); 49: if( distance > 70) 50: { 51: angle=0; 52: speed = 10; 53: RightLed = 1 ; 54: } 55: else 56: { 57: speed =10 ; 58: angle=90; 59: RightLed=0; 60: while( turn_state!=TURN_DONE); 61: angle=0; 62: DelayMs(200); // attend une it tmr0 63: } 64: 65: } 66: case 1 : 67: for ( ; ; ) 68: { 69: distance = read_distance(); 70: if( distance > 70) 71: { 72: angle=0; 73: speed = 10; 74: RightLed = 1 ; 75: } 76: else 77: { 78: if ( distance < 20 ) 79: { 80: angle=0; 81: speed = -40 ; 82: while(read_distance()<70); 83: } 84: else 85: { 86: speed =10 ; 87: angle=90; 88: RightLed=0; 89: while( turn_state!=TURN_DONE); 90: angle=0; 91: DelayMs(200); // attend une it tmr0 92: } 93: } 94: } 95: case 2 : 96: for ( ; ; ) 97: { 98: distance = read_distance(); 99: if( distance > 70) 100: { 101: angle=0; 102: speed = 10; 103: RightLed = 1 ; 104: } 105: else 106: { 107: if ( distance < 20 ) 108: { 109: angle=0; 110: speed = -40 ; 111: BackRightLed = 0 ; 112: start_tempo0(1500); 113: while((read_distance()<70)&&(!tempo0_done())); 114: if ( tempo0_done() ) 115: { 116: BackRightLed = 1 ; 117: speed =10 ; 118: angle=-90; 119: RightLed=0; 120: while( turn_state!=TURN_DONE); 121: angle=0; 122: DelayMs(200); // attend une it tmr0 123: } 124: } 125: else 126: { 127: speed =10 ; 128: angle=90; 129: RightLed=0; 130: while( turn_state!=TURN_DONE); 131: angle=0; 132: DelayMs(200); // attend une it tmr0 133: } 134: } 135: } 136: } 137: 138: }