int main() { //initialize all necessary sensors and utilities lcd_init(); timer1_init(); timer3_init(); move_servo(90); ADC_init(); USART_Init(MYUBRR); init_push_buttons(); oi_t *sensor_data = oi_alloc(); oi_init(sensor_data); audioInit(sensor_data); //oi_play_song(1); while(1) { //empty currentObjects before proceeding by setting all stored objects to "invalid" - ignored by later checks for (int i = 0; i < 20; i++) { currentObjects[i].isValid = 0; } char received = serial_getc(); //take keyboard input from putty takeDirectionInput(received, currentObjects); //translate keyboard input into functionality } return 0; }
int main(int argc) { // Allocate memory and setup sensorData struct sensorData = oi_alloc(); initAll(sensorData); serial_puts("Press 's' to initiate connection with robot\n\r"); while(start != 's') // Wait for Start Command { start = serial_getc(); } serial_puts("Robot communication initiated.\n\r\n\r"); display_help(); running_LED(); while(1) { read_user_input_string(sensorData); } //START TRAVERSING CODE while("NOT DONE") //While the robot is not in the Final Zone { //TODO Interface and Movement } //TODO FLASH LEDS WHEN DONE }
/** * Initializes everything on the robot * @author Group B1 * @param oi The open interface of the robot * @date 12/4/2012 */ void init_all(oi_t *oi) { oi = oi_alloc(); oi_init(oi); init_buttons(); init_usart(); lcd_init(); timer3_init(); ADC_init(); init_printf(0,write_one_char); move_servo(0); wait_ms(1000); printf("\n"); printf("\n"); }
/** * * Function to initialize the timers, registers, etc. for the ir, ping, servo, lcd */ void initialize() { // Initialize Serial Communication serial_init(57600); // initialize timers for use by ping sensor and servo timer3_init(); timer_init(); // initialize ADC for use by IR sensor ADC_init(); // Initialize Open Interface and sensor data sensor_data = oi_alloc(); oi_init(sensor_data); // initialize LCD lcd_init(); load_songs(); }
/** * The main loop which waits for commands via blue tooth and * then acts based on commands received. * * @author Jacob Moyer, * Ed Droesch, * Aaron Pederson, & * Matthew Backes * * @date 12/13/2013 */ void main() { ///Initializes the open_interface struct to be used throughout the program. oi_t *sensor_data = oi_alloc(); oi_init(sensor_data); initializer(); char key =0; ///Waits for commands from the USART connection, ///Then performs the command and returns that the command was performed. while(1) { char message[32] = ""; key = USART_Receive(); ///Returns what the current tape sensor is reading. if (key == 'p') { oi_update(sensor_data); sprintf(message,"sensor->signal =%d\r\n",(int)sensor_data->cliff_frontleft_signal); string_tran(message); } ///Moves the servo motor to the 0 degree position. if(key == 'c') { calibrate_servo(0); } ///Scans 0 - 180 degrees in front of the robot and returns the readings, ///it also guesses where objects are and returns their angle and width. if(key == 'j') { fullScan(); string_tran("Scan Complete.\r\n"); } ///Moves FORWARD_DISTANCE centimeters forward. if(key =='w') { sprintf(message,"Moved %d\r\n",move(sensor_data, FORWARD_DISTANCE,&sensors)); string_tran(message); } ///Moves BACKWARD_DISTANCE centimeters backwards. if(key=='s') { sprintf(message,"Moved %d\r\n",move(sensor_data, BACKWARD_DISTANCE,&sensors)); string_tran(message); } ///Rotates ROTATE_DEGREES counterclockwise. if(key=='a') { turn_CCW(sensor_data,ROTATE_DEGREES); sprintf(message,"Rotated %d\r\n",ROTATE_DEGREES); string_tran(message); } ///Rotates ROTATE_DEGREES clockwise. if(key=='d') { turn_CCW(sensor_data,-ROTATE_DEGREES); sprintf(message,"Rotated %d\r\n",-ROTATE_DEGREES); string_tran(message); } ///Plays the Morrowind theme song. if(key=='r') { play_morrowind(); string_tran("Playing song."); } } }
/** * Used to control the robot. * Receive and transmit data, measure the distance from object and navigate to the retrieval zone. **/ int main(void) { lcd_init(); timer3_init(); timer_init(); ADC_init(); USART_Init(); oi_t *sensor_data = oi_alloc(); oi_init(sensor_data);//should turn the iRobot Create's power LED yellow lcd_init(); serial_puts("Start"); //USART_Transmit(13); //USART_Transmit(10); int TempAngle[4] = {0,0,0,0}; int TempIR[4] = {0,0,0,0}; int pos[4] = {0,0,0,0}; int AddIR[4] = {0,0,0,0}; int count[4] = {0,0,0,0}; int found = 0; int x1 = 0; int x2 = 0; int x3 = 0; int x4 = 0; unsigned angle = 0; unsigned char IR = 0; volatile int i=0; volatile int x = 0; char command; char display[100]; char display1[20]; char display2[20]; char display3[20]; char display4[20]; char display5[100]; char display6[100]; while (1) { command = USART_Recieve(); USART_Transmit(command); //USART_Transmit(13); //USART_Transmit(10); if (command == '1') { found = 0; angle = 0; int t; int TempAngle[6] = {0, 0,0,0,0,0}; int TempIR[6] = {0, 0,0,0,0,0}; int pos[6] = {0, 0,0,0,0,0}; int AddIR[6] = {0, 0, 0,0,0,0}; int count[6] = {0, 0, 0,0,0,0}; for (angle = 0;angle < 181;angle++) { move_servo(angle); wait_ms(20); IR = 0; IR = 42800*pow(ADC_read(2),-1.23); sprintf(display6, "Angle: %5d IR: %5d",angle,IR); serial_puts(display6); if (IR < 80) { TempAngle[found]++; count[found]++; AddIR[found]+=IR; TempIR[found]=AddIR[found]/count[found]; } else { if(TempAngle[found] < 5) { TempAngle[found] = 0; } else { pos[found] = angle- TempAngle[found]/2; if (TempIR[found]*TempAngle[found]< 460) { USART_Transmit(13); USART_Transmit(10); for (int i = 0;i<strlen(s8);i++) { USART_Transmit(s8[i]); } sprintf(display5, "object position: %5d",pos[found]); serial_puts(display5); } sprintf(display, "object position: %5d IR: %5d object size: %5d",pos[found],TempIR[found],TempAngle[found]); serial_puts(display); USART_Transmit(13); USART_Transmit(10); found++; } } } OCR3B = 1000-1; //return to 0 degree } if (command == 'w') { move_forward(sensor_data,20); } if (command == 's') { move_backforward(sensor_data,20); } if (command == 'a') { turn_clockwise(sensor_data,82); } if (command == 'd') { turn_counterclockwise(sensor_data,82); } if (command == 'q') { turn_clockwise(sensor_data,38); } if (command == 'e') { turn_counterclockwise(sensor_data, 38); } if (command == '8') { move_forward(sensor_data,5); } if (command == '5') { move_backforward(sensor_data,5); } if (command == 'p') { oi_t* sensor = oi_alloc(); oi_init(sensor); load_songs(); oi_play_song(songings); } if(command == 'k') { oi_update(sensor_data); x1 = sensor_data->cliff_left_signal; x2 = sensor_data->cliff_right_signal; x3 = sensor_data->cliff_frontleft_signal; x4 = sensor_data->cliff_frontright_signal; sprintf (display1, "left = %d",x1); sprintf (display2, "right = %d",x2); sprintf (display3, "front left = %d",x3); sprintf (display4, "front right = %d",x4); USART_Transmit(13); USART_Transmit(10); serial_puts(display1); serial_puts(display3); serial_puts(display4); serial_puts(display2); if (x1>500||x2>500||x3>500||x4>500) { USART_Transmit(13); USART_Transmit(10); for (int i=0;i<strlen(s6);i++) { USART_Transmit(s6[i]); } } } } }