int main(void) { m_red(ON); m_usb_init(); while(!m_usb_isconnected()); // wait for a serial msg m_red(OFF); m_clockdivide(0); // set clock frequency to 16MHz adc_setup(); m_disableJTAG(); set(ADCSRA,ADEN);//enable ADC sei();//enable global interrupts set(ADCSRA,ADSC);//start conversion while(1){ if(FLAG){ // compare readings and move motor accordingly m_green(TOGGLE); clear(ADCSRA,ADEN); // Disable ADC m_usb_tx_string("\nF0:"); m_usb_tx_int(ir[0]); m_usb_tx_string("\tF1: "); m_usb_tx_int(ir[1]); m_usb_tx_string("\tF4: "); m_usb_tx_int(ir[2]); FLAG = 0; set(ADCSRA,ADEN); // enable ADC again set(ADCSRA,ADSC);//start next conversion } } }
void goalie(){ init_all();//initializing all the rest //displaying two flashes to know robot is ready and waiting for start m_red(ON); m_green(ON); m_wait(750); m_green(OFF); m_red(OFF); m_wait(750); m_red(ON); m_green(ON); m_wait(750); m_red(OFF); m_green(OFF); wait(1); //initializing center ice set_position(1024/2,768/2); get_position(blobs, &x_center, &y_center, &theta_zero); // set voltage reference to 5V clear(ADMUX, REFS1); set(ADMUX, REFS0); m_disableJTAG();//allowing gpio of F pins //setting ADC prescaler set(ADCSRA,ADPS2); set(ADCSRA,ADPS1); set(ADCSRA,ADPS0); //setting pins to turn off digital circuitry set(DIDR0,ADC4D);//setting F4 set(DIDR0,ADC6D);//setting F6 set(DIDR2,ADC8D);//setting D4 set(DIDR2,ADC9D);//setting D6 set(ADCSRA,ADATE);//setting triggering to free running //setting pins for output & setting pins high to supply power to phototransistors set(DDRF,5);//F5 set(PORTF,5); set(DDRF,7);//F7 set(PORTF,7); set(DDRB,3);//B3 set(PORTB,3); set(DDRD,3);//D3 set(PORTD,3); set(DDRF,0);//setting pins to turn the sprinner motors set(PORTF,0); set(DDRF,1); set(PORTF,1); int adc = 0;//declaring integer for adc status; int adc_values[4];//declaring adc array state_before_game(); }
void init() { m_clockdivide(0); m_disableJTAG(); movement_init(); sensor_init(); }
int main(void) { m_disableJTAG(); m_clockdivide(2); setup_pins(); if (debug_fire|| RF_debug) {setupUSB();} setup_timer_1(); setup_timer_3(); m_bus_init(); m_rf_open(chan,RX_add,p_length); int timer_3_cnt = 0; //sei(); set_motors(0,0); while (1){ if (check(TIFR3,OCF3A)){ set(TIFR3, OCF3A); timer_3_cnt++; if(fired){ since_fired++; if (debug_fire){ m_usb_tx_string(" its been\t"); m_usb_tx_int(since_fired); m_usb_tx_string(" milisec\n\r"); } } if (since_fired>10){ clear(PORTF,5); since_fired=0; fired = false; if (debug_fire){m_usb_tx_string(" its been 100 sec\n\r");} } if ( fire && check(PINB,3)){ fire=false; fired=true; since_fired=0; if (debug_fire){m_usb_tx_string(" portb 3 is high\n\r");} } // m_rf_open(chan,RX_add,p_length); m_green(TOGGLE); m_rf_init(); if ( timer_3_cnt == 10){ m_red(2); timer_3_cnt=0; m_rf_open(chan,RX_add,p_length); } } if(new){ turretDrive(); if(RF_debug){ debug_rf(); } if ((receive_buffer[0] == 1 || receive_buffer[1]==1) && !fire){FIRE();} } //TODO fill in timer code for the firing mechanism } }
void sniper() { init_all(); // set voltage reference to 5V clear(ADMUX, REFS1); set(ADMUX, REFS0); m_disableJTAG();//allowing gpio of F pins //setting ADC prescaler set(ADCSRA,ADPS2); set(ADCSRA,ADPS1); set(ADCSRA,ADPS0); //setting pins to turn off digital circuitry set(DIDR0,ADC1D);//setting F1 set(DIDR0,ADC4D);//setting F4 set(DIDR0,ADC5D);//setting F5 set(DIDR0,ADC6D);//setting F6 set(DIDR0,ADC7D);//setting F7 set(ADCSRA, ADEN); play_state = 1; set_position(1024/2, 768/2); first = true; //state_before_game(); //state_play(); m_usb_init(); /* while(!m_usb_isconnected()); m_green(ON); */ set_left(30); set_right(100); while(1) { adc(); // m_usb_tx_string("left: "); //m_usb_tx_int(a_left); wait(1); } }
void mode_init() { clear(DDRB,0); clear(DDRB,1); clear(DDRB,2); clear(DDRB,3); // Input m_disableJTAG(); clear(DDRD,7); clear(DDRF,5); clear(DDRF,6); clear(DDRF,7); clear(PORTF, 5); clear(PORTF, 6); clear(PORTF, 7); // Output signal for shooting set(DDRD,4); }
int main() { m_red(ON); m_clockdivide(0); m_disableJTAG(); m_bus_init(); m_rf_open(1, 0xD1, 10); m_red(OFF); char buf[10] = {0x08, 10, 10, 0, 0, 0, 0, 0, 0, 0}; while(1) { m_green(ON); m_rf_send(0xDA, buf, 10); buf[1] += 5; if(buf[1] >= 220) buf[1] = 10; m_green(OFF); m_wait(500); } return 0; }
int main(void) { m_disableJTAG(); m_red(ON); m_clockdivide(0); // clock speed 16 MHz sei(); // enable global interrups // initialize m_bus communications // start wireless communications // and open wii camera m_bus_init(); m_wii_open(); m_usb_init(); m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); setup(); // motor setup ADC_setup(); int position[3]; // array for robot position int x_curr; int y_curr; int theta_curr; int i; int a; int x_pos[11]; int y_pos[11]; int theta[11]; // main LOOP while(1) { // for (i=0; i < 11; i++) // { // current_location(position); // x_pos[i] = position[0]; // y_pos[i] = position[1]; // theta[i] = position[2]; // } // // calculate positions // filter(x_pos,y_pos,theta); // x_curr = x_pos[11]; // y_curr = y_pos[11]; // theta_curr = theta[11]; // Read in values // ADC0(); // int D6 = ADC; // // ADC1(); // int F1 = ADC; // // ADC4(); // int F4 = ADC; // // ADC5(); // int F5 = ADC; // // ADC6(); // int F6 = ADC; // // ADC7(); // int F7 = ADC; // // ADC8(); // int D7 = ADC; // follow_puck(); m_green(TOGGLE); // // usb prinitng // m_usb_tx_string("D6: "); // m_usb_tx_int(D6); // m_usb_tx_string(" "); // m_usb_tx_string("F1: "); // m_usb_tx_int(F1); // m_usb_tx_string(" "); // m_usb_tx_string("F4: "); // m_usb_tx_int(F4); // m_usb_tx_string(" "); // m_usb_tx_string("F5: "); // m_usb_tx_int(F5); // m_usb_tx_string(" "); // m_usb_tx_string("F6: "); // m_usb_tx_int(F6); // m_usb_tx_string(" "); // m_usb_tx_string("F7: "); // m_usb_tx_int(F7); // m_usb_tx_string(" "); // m_usb_tx_string("D7: "); // m_usb_tx_int(D7); // m_usb_tx_string(" "); // m_usb_tx_string("\n"); a = state(buffer1); a = 2; // COMM TEST if (a == 1) { // ADD CODE } // PLAY if (a == 2) { } // PAUSE, HALF TIME, GAME OVER if (a == 5 || a == 6 || a == 7) { // STOP ROBOT turn_robot(0,0,0,0); m_red(OFF); } else {} } }
int main(void) { m_clockdivide(0); m_bus_init(); m_usb_init(); m_rf_open(CHANNEL,RXADDRESS,LENGTH); m_wii_open(); sei(); OCR1A = 31999; OCR1B = 0; OCR1C = 0; m_disableJTAG(); clear(ADMUX,REFS1); // Setting the reference voltage for the ADC to Vcc set(ADMUX,REFS0); // ^ set(ADCSRA,ADPS2); // set ADC prescaler to 128 set(ADCSRA,ADPS1); // ^ set(ADCSRA,ADPS0); //^ set(DIDR0,ADC0D); // disable digital on F0 (ADC0) set(DIDR0,ADC1D); // disable digital to F1 set(DIDR0,ADC4D); //disable digital to F4 set(DIDR0,ADC5D); //disable digital to F5 set(DIDR0,ADC6D); //disable digital to F6 set(DIDR0,ADC7D); //disable digital to F7 set(ADMUX,REFS0); // set ADC reference to Vcc set(ADCSRA,ADIE); //Enables interrups when conversion finishes // clear(ADMUX,MUX2); // This is the front right. Range 50-1023. Port is F1 // set(ADMUX,MUX0); set(TCCR1B,WGM13); // Mode 15: up to OCR1A, PWM, single slope set(TCCR1B,WGM12); // ^ set(TCCR1A,WGM11); // ^ set(TCCR1A,WGM10); // ^ set(TCCR1A,COM1B1); //clear at OCR1B, set at rollover clear(TCCR1A,COM1B0); // ^ set(TCCR1A,COM1C1); // clear at OCR1C, set at rollover clear(TCCR1A,COM1C0); clear(TCCR1B,CS12); // set clock pre-scaler to /1 clear(TCCR1B,CS11); // ^ set(TCCR1B,CS10); // ^ m_port_init(0x20); // Initializes the port expander and sets all of the G pins as outputs m_port_set(0x20, DDRG,0); m_port_set(0x20, DDRG,1); m_port_set(0x20, DDRG,2); m_port_set(0x20, DDRG,3); m_port_set(0x20, DDRG,4); m_port_set(0x20, DDRG,5); m_port_set(0x20, DDRG,6); m_port_set(0x20, DDRG,7); clearDisplay(); // Set motor output ports set(DDRB,6); set(DDRB,7); set(DDRB,5); set(DDRB,3); // Turn off motors clear(PORTB,6); clear(PORTB,7); set(ADCSRA,ADEN); // enable ADC subsystem set(ADCSRA,ADSC); // start ADC conversion while(1){ switch(state){ case COMM: commtestf(); break; case PAUSE: pausef(); break; case PLAY: playf(); localizef(); defendf(); //puckfindf(); break; case GOTOGOAL: gotogoalf(); case HALFTIME: pausef(); break; case GOALA: pausef(); break; case GOALB: pausef(); break; case GAMEOVER: pausef(); break; default: break; } defendf(); m_usb_tx_int(photo1); m_usb_tx_string(" "); m_usb_tx_int(photo2); m_usb_tx_string(" "); m_usb_tx_int(photo3); m_usb_tx_string(" "); m_usb_tx_int(photo4); m_usb_tx_string(" "); m_usb_tx_int(photo5); m_usb_tx_string("\n"); } }
/*char isStuck() { m_wait(100); //localize(data); distfrombound = data[1] + ((float)BOUNDARYTHRESHOLD)*sin((data[2]+90.0)*3.14/180.0*-1.0); if (distfrombound > 60.0 || distfrombound < -60.0) { return 1; } m_usb_tx_int((int)distfrombound); m_usb_tx_char('\n'); } long loccounter = 0; float prevx = 0.0; float prevy = 0.0; */ int main(void) { //goal side clear(DDRB,1); clear(PORTB,1); if (check(PINB,1)) { goal = 1; } set(DDRB,0); set(PORTB,0); set(DDRD,5); set(DDRD,3); //wireless stuffs m_bus_init(); m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); int counter = 0; // //m_num_init(); int flag; m_clockdivide(0); m_disableJTAG(); //TIMER 0: For Controlling the solenoid // // set(TCCR0B, WGM02); // set(TCCR0A, WGM01); // set(TCCR0A, WGM01); // // set(TCCR0A, COM0B1); // clear(TCCR0A, COM0B0); // // set(TCCR0B, CS02); // set(TCCR0B, CS01); // set(TCCR0B, CS00); // set(DDRB,7); // OCR0A = 0xFF; // OCR0B = 0xff; // //TIMER 1: For Controlling the left wheel set(TCCR1B, WGM13); set(TCCR1B, WGM12); set(TCCR1A, WGM11); set(TCCR1A, WGM10); set(TCCR1A, COM1B1); clear(TCCR1A, COM1B0); clear(TCCR1B, CS12); clear(TCCR1B, CS11); set(TCCR1B, CS10); set(DDRB,6); OCR1A = 0xFFFF; OCR1B = 0; //TIMER 3: For Controlling the right wheel //up to ICR3, clear at OCR3A & set at rollover set(TCCR3B, WGM33); set(TCCR3B, WGM32); set(TCCR3A, WGM31); clear(TCCR3A, WGM30); set(TCCR3A, COM3A1); clear(TCCR3A, COM3A0); clear(TCCR3B, CS32); clear(TCCR3B, CS31); set(TCCR3B, CS30); ICR3 = 0xFFFF; OCR3A = 0; // //Set TCNT0 to go up to OCR0A // clear(TCCR0B, WGM02); // set (TCCR0A, WGM01); // clear(TCCR0A, WGM00); // // // Don't change pin upon hitting OCR0B // clear(TCCR0A, COM0A1); // clear(TCCR0A, COM0A0); // // // Set clock scale to /1024 // set(TCCR0B, CS02); // clear(TCCR0B, CS01); // set(TCCR0B, CS00); // // // Set Frequency of readings to 1/SAMPLERATE; dt = 1/SAMPLERATE // OCR0A = (unsigned int) ((float) F_CPU / 1024 / REPORTRATE); // OCR0B = 1; // Set up interrupt for reading values at sampling rate //Pin for controlling solenoid pulse set(DDRB,7); //Pins for controlling speed of left and right wheel set(DDRB,6); set(DDRC,6); //Pins for determining direction of wheels set(DDRB,2); set(DDRB,3); //Blue LED for Comm Test //set(DDRB,5); //ADC's sei(); //Set up interrupts set(ADCSRA, ADIE); clear(ADMUX, REFS1); //Voltage reference is AR pin (5V) clear(ADMUX, REFS0); //^ set(ADCSRA, ADPS2); //Set scale to /128 set(ADCSRA, ADPS1); //^ set(ADCSRA, ADPS0); //^ set(DIDR0, ADC0D); //Disable digital input for F0 set(DIDR0, ADC1D), set(DIDR0, ADC4D); set(DIDR0, ADC5D); set(DIDR0, ADC6D); set(DIDR0, ADC7D); set(DIDR2, ADC8D); set(DIDR2, ADC9D); set(ADCSRA, ADATE); //Set trigger to free-running mode chooseInput(0); set(ADCSRA, ADEN); //Enable/Start conversion set(ADCSRA, ADSC); //^ set(ADCSRA, ADIF); //Enable reading results //Limit Switch stuffs // clear(DDRB,0); //set to input, RIGHT LIMIT SWITCH // clear(DDRB,1); //set to input, LEFT LIMIT SWITCH // // clear(PORTB,0); //disable internal pull up resistor // clear(PORTB,1); //disable internal pull up resistor //int state; // state variable state = 0; //set state play = 0; long count = 0; if (state == 70) { m_usb_init(); // connect usb while(!m_usb_isconnected()); //wait for connection } //m_bus_init(); m_wii_open(); //m_usb_init(); m_red(ON); local_init(); localize(data); m_red(OFF); //set(TIMSK0, OCIE0A); while(1) { if (play) {m_red(ON);} else {m_red(OFF);} // m_wait(100); // m_red(TOGGLE); // localize(data); /*if (loccounter == LOCCOUNT) { if (sqrt((data[0]-prevx)*(data[0]-prevx)+(data[1]-prevy)-(data[1]-prevy)) < 1.0) { m_red(ON); reverse(); m_wait(100); state = 6; } else { m_red(OFF); state = 2; } prevx = data[0]; prevy = data[1]; loccounter = 0; }*/ //loccounter++; // localize(data); // locdata[1] = (char)data[0]; // locdata[2] = (char)data[1]; // toggle(PORTD,3); changedState = 0; angle_dif = 0; //Detect weather we have the puck getADC(); //if (!play) game_pause(); if (ADCarr[7] > 500) { //set(PORTD,5); //set(PORTD,5); iHaveThePuck = 1; m_green(ON); if (play && goal == A) state = 3; if (play && goal == B) state = 4; } else { //clear(PORTD,5); iHaveThePuck = 0; m_green(OFF); if (play) state = 2; } if(iHaveThePuck && state == 2) { //set(PORTB,5); //drive_to_goalA(); } else { //clear(PORTB,5); //if (state != 0) state = 2; } // if(isStuck()) { // //set(PORTD,5);u // } // else { // //clear(PORTD,5); // } //localize(data); // if (check(PINB,0)) { // set(PORTD,5); // state = 0x1A; // } else { // clear(PORTD,5); // state = 2; // } if (!play) state = buffer[0]; //switch states switch (state) { case -2: getADC(); if (ADCarr[0] > 500) { m_green(ON); } else {m_green(OFF)} break; case -1: //test Limit switches //m_green(ON); if (check(PINB,1)) { m_green(ON); } else if (check(PINB,0)) { m_red(ON); } else { m_red(OFF); m_green(OFF); } break; case 0: //drive_to_point2(-100,0); game_pause(); break; case 1: findPuck(); break; case 2: //m_red(ON); if (!iHaveThePuck) { if (play) drive_to_puck(); } break; case 3: if (play) drive_to_goalA(); break; case 4: if (play) drive_to_goalB(); break; case 5: getADC(); if (ADCarr[7] > 500) { //set(PORTD,5); } else { //clear(PORTD,5); } break; case 6: if (data[2] > 0) { rotate(RIGHT,1); } else { rotate(LEFT,1); } break; case 7: drive_to_point2(-50,0); break; case 0xA0: comm_test(); break; case 0xA1: play = 1; drive_to_puck(); break; case 0xA2: play = 0; game_pause(); break; case 0xA3: play = 0; game_pause(); break; case 0xA4: play = 0; game_pause(); break; case 0xA6: play = 0; game_pause(); break; case 0xA7: game_pause(); break; case 69: set(PORTB,2); set(PORTB,3); OCR1B = OCR1A; OCR3A = ICR3; break; case 70: reportADC(); break; default: game_pause(); break; } } }
//c7 red /// e6 blue int main(void) { m_disableJTAG(); // Turn off JTAG //m_red(ON); // check code runs m_clockdivide(0); // clock speed 16 MHz m_bus_init(); // initialize m_bus communications m_usb_init(); // USB COM setup(); // motor setup ADC_setup(); // setup anlog conversions // start wireless communications m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); m_wii_open(); // and open wii camera sei(); // enable global interrups set(DDRC,7); set(DDRB,7); int position[3]; // array for robot position int x_curr; // current x position int y_curr; // current y position int theta_curr; // current angle int i; int a; // x, y and theta values int x_pos[11]; int y_pos[11]; int theta[11]; char send[10]; int side; int x1; // calculate initial positions int status; // int x; // int y; // int theta1; int hasPuck = 0; // main LOOP while(1) { if (flag) { m_rf_read(buffer1, PACKET_LENGTH); testing = (unsigned char)buffer1[0]; a = state(testing); // m_rf_read(buffer, PACKET_LENGTH); // x = (unsigned char)buffer[0]; // y = (unsigned char)buffer[1]; // theta1 = (unsigned char)buffer[2]; if (flag1){ for(i = 0; i<10; i++) { current_location(position); x1 = position[0]; } // figure out what side robot starts on if (x1 > 0) { side = -1; } else { side = 1; } } flag = 0; } // m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH); // store 10 most recent position readings for (i=0; i < 11; i++) { current_location(position); x_pos[i] = position[0]; y_pos[i] = position[1]; theta[i] = position[2]; } // filter position filter(x_pos,y_pos,theta); // current position x_curr = x_pos[11]; y_curr = y_pos[11]; theta_curr = theta[11]; if (x_curr > 0) { m_red(ON); } else if (x_curr<0) { m_red(OFF); } if (y_curr > 0) { m_green(ON); } else if (y_curr<0) { m_green(OFF); } // send[0] = x_curr;//(char) x_curr; // send[1] = y_curr;//(char) y_curr; // send[2] = theta_curr;//(char) theta_curr; // status = m_rf_send(TXaddress, send, PACKET_LENGTH); // if (status){m_red(TOGGLE)}; // m_usb_tx_string("X Pos: "); // m_usb_tx_int(x); // m_usb_tx_string(" "); // m_usb_tx_string("Y POSITION: "); // m_usb_tx_int(y); // m_usb_tx_string(" "); // m_usb_tx_string("ANGLE: "); // m_usb_tx_int(theta1); // m_usb_tx_string(" "); // m_usb_tx_string("\n"); a = 2; // COMM TEST if (a == 1) { // ADD CODE // m_red(ON); if (side == 1) { set(PORTC,7); } else { set(PORTB,7); } } // PLAY GAME else if (a == 2) { // m_red(OFF); //int hasPuck = follow_puck(); //hasPuck = 1; // goalie(x_curr, y_curr, theta_curr, side); if(hasPuck) { //score_goal(x_curr, y_curr, theta_curr, side); //turn_robot(0,0,0,0); } } // GOAL R else if (a == 3) { //side = 1; //m_green(TOGGLE); } // GOAL B else if ( a == 4) { //side = -1; //m_green(TOGGLE); } else if(a == 5) { turn_robot(0,0,0,0); // m_red(ON); } // PAUSE, HALF TIME, GAME OVER if (a == 6 || a == 7) { // STOP ROBOT turn_robot(0,0,0,0); m_red(ON); } else {} // // COMM PROTOCOL INSTRUCTIONS // m_usb_tx_string("STATE: "); // m_usb_tx_int(a); // m_usb_tx_string(" "); // m_usb_tx_string("FLAG: "); // m_usb_tx_int(flag); // m_usb_tx_string(" "); // m_usb_tx_string("TESTING: "); // m_usb_tx_int(testing); // m_usb_tx_string(" "); // m_usb_tx_string("\n"); } }