//#pragma SRC //#define DEBUGGING #include #define NULL 0 #define INT_UART 4 /* 0x23 */ #define SENT_LEN 55 #define DIST_THRESHOLD 5 // < 30' feet #define DIST_SLOW 10 // < 60' feet // C routines void start_motors(); void stop_motors(); void motors_half_speed(); void turn(unsigned char from, unsigned char to); unsigned char desired_bearing(); unsigned int dist_to_waypoint(); unsigned int get_int_val(unsigned char start, unsigned char len); char char_buf[SENT_LEN+1]="GPRMC,tttttt,A,dd12337,N,ddd12851,W,s010,150h,mmddyy,"; unsigned char char_buf_ptr; extern void asm_set_servo(unsigned char c_a, unsigned char servo_data); extern void asm_get_waypoint(void); extern void asm_send_waypoint(void); extern void asm_init(void); extern void asm_lcd_print(void); extern unsigned int data d_lon; extern unsigned int data d_lat; extern char data message[16]; unsigned int data current_lat; unsigned int data current_lng; unsigned char data current_spd; unsigned char data current_head; unsigned int work_lat; unsigned int work_lng; // This is _the_ pilot. It tells all of its minions what to do //* MAIN PILOT CODE ******************************************************************* void main() { unsigned char current_b, b_to_target; asm_init(); #ifndef DEBUGGING stop_motors(); #endif // c_init() RCAP2H = 0xFF; // 4807 Baud RCAP2L = 0x30; T2MOD = 0x02; // Enable timer 2 output T2CON = 0x34; // Set up timer 2 and start baud generator IE = 0x90; // Disable tiemr 2 ints, enable serial ints SCON = 0x70; // Set up ser. register & enable // end c_init() do { #ifndef DEBUGGING asm_get_waypoint(); // <- Pilot blocks here while navigator/bomber does task start_motors(); #endif message[0] = ' '; message[1] = ' '; message[2] = ' '; message[3] = ' '; message[4] = ' '; message[5] = ' '; message[11] = (d_lat & 0x00FF); message[12] = (d_lat & 0xFF00) >> 8; message[13] = (d_lon & 0x00FF); message[14] = (d_lon & 0xFF00) >> 8; message[15] = 0; do { IE &= 0x7F; // Disable interrupts work_lng = current_lng; // Make a local copy of all the shared data work_lat = current_lat; current_b = current_head; message[6] = (work_lat & 0x00FF); message[7] = (work_lat & 0xFF00) >> 8; message[8] = (work_lng & 0x00FF); message[9] = (work_lng & 0xFF00) >> 8; message[10] = '>'; IE |= 0x80; // Enable interrupts again asm_lcd_print(); #ifndef DEBUGGING if (dist_to_waypoint() < DIST_SLOW) { message[0] = 'O'; message[1] = 'K'; message[2] = 0; motors_half_speed(); } #endif // Figure out if we're headed in the right direction b_to_target = desired_bearing(); //Decide which direction to turn and turn rudder #ifndef DEBUGGING turn(current_b, b_to_target); #endif } while (dist_to_waypoint() > DIST_THRESHOLD); #ifndef DEBUGGING stop_motors(); #endif d_lat = current_lat; d_lon = current_lng; #ifndef DEBUGGING asm_send_waypoint(); // <- Returns as soon as message is finished. #endif } while (1); } // **********************************************************************************/ /************************** TEST COMM CODE ***************************************** void main() { //unsigned char b_to_target, current_b; asm_init(); // c_init() RCAP2H = 0xFF; // 4807 Baud RCAP2L = 0x30; T2MOD = 0x02; // Enable timer 2 output T2CON = 0x34; // Set up timer 2 and start baud generator IE = 0x90; // Disable tiemr 2 ints, enable serial ints SCON = 0x70; // Set up ser. register & enable // end c_init() do { asm_get_waypoint(); // <- Pilot blocks here while navigator/bomber does task message[1] = (d_lat & 0xFF00) >> 8; message[0] = (d_lat & 0x00FF); message[3] = (d_lon & 0xFF00) >> 8; message[2] = (d_lon & 0x00FF); message[4] = 0; asm_lcd_print(); d_lat = 12345; d_lon = 10101; asm_send_waypoint(); // <- Returns as soon as message is finished. } while (1); } // *****************************************************************************/ /******************* GPS TEST CODE ********************************************* void main() { unsigned char current_b; asm_init(); // c_init() RCAP2H = 0xFF; // 4807 Baud RCAP2L = 0x30; T2MOD = 0x02; // Enable timer 2 output T2CON = 0x34; // Set up timer 2 and start baud generator IE = 0x90; // Disable tiemr 2 ints, enable serial ints SCON = 0x70; // Set up ser. register & enable // end c_init() do { IE &= 0x7F; // Disable interrupts work_lng = current_lng; // Make a local copy of all the shared data work_lat = current_lat; current_b = current_head; IE |= 0x80; // Enable interrupts again message[0] = (work_lat & 0x00FF); message[1] = (work_lat & 0xFF00) >> 8; message[2] = 32; message[3] = (work_lng & 0x00FF); message[4] = (work_lng & 0xFF00) >> 8; message[5] = 32; message[6] = current_b; message[7] = 0; asm_lcd_print(); } while (1); } //*************************************************************************************/ //---------------------------------------------------------------------------- unsigned int get_int_val(unsigned char start, unsigned char len) { unsigned int rv; unsigned int twice_old_val; unsigned char c; rv = 0; for (c=0;c