void play_music() { cli(); SPCR = 0; set_output_bit(IO_DISPLAY_RST); activate_output_bit(IO_DISPLAY_RST); clear_output_bit(IO_RESET_CO); activate_output_bit(IO_AUDIO); make_sound(127/4, 15000); delay_ms(10); make_sound(191/4, 15000); delay_ms(10); make_sound(255/4, 10000); delay_ms(10); make_sound(255/4, 10000); delay_ms(10); make_sound(191/4, 15000); delay_ms(1); sei(); bot_init(); deactivate_output_bit(IO_DISPLAY_RST); clear_output_bit(IO_DISPLAY_RST); spi_init(); }
void bot_init(void) { // Reset controllers #ifdef _NIBO_2_ activate_output_bit(IO_RESET_CO); clear_output_bit(IO_RESET_CO); delay(10); set_output_bit(IO_RESET_CO); delay(100); #else activate_output_bit(IO_RESET_5); activate_output_bit(IO_RESET_3); clear_output_bit(IO_RESET_5); clear_output_bit(IO_RESET_3); delay(10); set_output_bit(IO_RESET_5); set_output_bit(IO_RESET_3); delay(100); #endif }
void leds_init(void) { #ifdef _NIBO_2_ activate_output_bit(IO_LED_RG); set_output_bit(IO_LED_RG); #endif activate_output_bit(IO_LED_WHITE); activate_output_bit(IO_DISP_LIGHT); IO_LEDS_RED_DDR = IO_LEDS_RED_MASK; IO_LEDS_GREEN_DDR = IO_LEDS_GREEN_MASK; }
void native_nibo_bot_init(void) { adc_init(AN_VBAT); // Reset controllers activate_output_bit(IO_RESET_CO); clear_output_bit(IO_RESET_CO); delay(10); set_output_bit(IO_RESET_CO); // Initialize communication spi_init(); delay(10); }
// the ctbot class void native_nibo_edgedetector_invoke(u08_t mref) { // JAVA: void update() if(mref == NATIVE_METHOD_update) { activate_output_bit(IO_LINE_FLOOR_EN); clear_output_bit(IO_LINE_FLOOR_EN); delay_us(25); edge_value_off_l = 1023-adc_read(AN_FLOOR_L); edge_value_off_r = 1023-adc_read(AN_FLOOR_R); edge_value_off_r += 1023-adc_read(AN_FLOOR_R); edge_value_off_l += 1023-adc_read(AN_FLOOR_L); set_output_bit(IO_LINE_FLOOR_EN); delay_us(25); edge_value_on_l = 1023-adc_read(AN_FLOOR_L); edge_value_on_r = 1023-adc_read(AN_FLOOR_R); edge_value_on_r += 1023-adc_read(AN_FLOOR_R); edge_value_on_l += 1023-adc_read(AN_FLOOR_L); clear_output_bit(IO_LINE_FLOOR_EN); } // JAVA: int getLeftRel() else if(mref == NATIVE_METHOD_getLeftRel) { nvm_int_t val = edge_value_on_l-edge_value_off_l; stack_push(val); } // JAVA: int getRightRel() else if(mref == NATIVE_METHOD_getRightRel) { nvm_int_t val = edge_value_on_r-edge_value_off_r; stack_push(val); } // JAVA: int getLeftAbs() else if(mref == NATIVE_METHOD_getLeftAbs) { nvm_int_t val = edge_value_on_l; stack_push(val); } // JAVA: int getRightAbs() else if(mref == NATIVE_METHOD_getRightAbs) { nvm_int_t val = edge_value_on_r; stack_push(val); } // ERROR else error(ERROR_NATIVE_UNKNOWN_METHOD); }
void make_sound(int interval, int time) { while (time) { int i=interval; clear_output_bit(IO_AUDIO); while (time && i) { time--; i--; delay_us(10); } i=interval; set_output_bit(IO_AUDIO); while (time && i) { time--; i--; delay_us(10); } } }
/** * Spielt einen Ton ab * Vor der ersten Benutzung einmal sound_init() aufrufen (deklariert in nibo/sound.h) * frequency ist die Frequenz des Tons in Hz (nicht hoeher als 5000 uebergeben!) * duration gibt die Wiedergabedauer des Tons an */ int tone(int frequency, int duration) { int interval = (50000 / frequency); duration = duration * 100; while (duration) { int i = interval; clear_output_bit(IO_AUDIO); while (duration && i) { duration--; i--; delay_us(10); } i = interval; set_output_bit(IO_AUDIO); while (duration && i) { duration--; i--; delay_us(10); } } return 1; }
int main(void) { sei(); // enable interrupts leds_init(); pwm_init(); bot_init(); spi_init(); acquisition_setup(); xbee_set_baudrate(9600); xbee_enable(); if (display_init()!=0) { leds_set_displaylight(1024); if (display_type==2) { gfx_init(); } } eeprom_read_block (acquisition_calibration, persistant.calibration, sizeof(acquisition_calibration)); gfx_fill(0x00); print_prop_text(15, 0, "nibo"); gfx_set_proportional(0); //copro_ir_startMeasure(); delay(10); //motco_setSpeedParameters(5, 4, 6); // ki, kp, kd copro_setSpeedParameters(15, 20, 10); // ki, kp, kd stress = 0; //Setup Jumper... deactivate_output_bit(IO_INPUT_2); activate_output_bit(IO_INPUT_3); set_output_bit(IO_INPUT_2); clear_output_bit(IO_INPUT_3); if (!get_input_bit(IO_INPUT_1)) { behaviour = BEHAVIOUR_CALIB; acquisition_calibration[0]=0x20; acquisition_calibration[1]=0x20; acquisition_calibration[2]=0x20; acquisition_calibration[3]=0x20; print_prop_text(21, 30, "CALIBRATION"); delay(100); // Floor uint16_t values[4]; values[0]=0; values[1]=0; values[2]=0; values[3]=0; for (uint8_t i = 0; i<5; i++) { for (uint8_t j = 0; j<10; j++) { if (j>2) { values[0] += acquisition_getValue(0); values[1] += acquisition_getValue(1); values[2] += acquisition_getValue(2); values[3] += acquisition_getValue(3); } gfx_set_proportional(0); gfx_draw_mode(GFX_DM_JAM2); gfx_move(31, 41); print_hex(acquisition_getValue(AN_FLOOR_R)); gfx_print_char(' '); print_hex(acquisition_getValue(AN_LINE_R)); gfx_print_char(' '); print_hex(acquisition_getValue(AN_LINE_L)); gfx_print_char(' '); print_hex(acquisition_getValue(AN_FLOOR_L)); delay(100); } gfx_move(81+4*i, 30); gfx_print_char('.'); } acquisition_calibration[0] = values[0]/71; acquisition_calibration[1] = values[1]/71; acquisition_calibration[2] = values[2]/71; acquisition_calibration[3] = values[3]/71; eeprom_write_block (acquisition_calibration, persistant.calibration, sizeof(acquisition_calibration)); delay(100); gfx_print_text(" OK"); IO_LEDS_GREEN_PORT = 0xff; while (1) { // Floor gfx_set_proportional(0); gfx_draw_mode(GFX_DM_JAM2); gfx_move(31, 49); print_hex(acquisition_getValue(AN_FLOOR_R)); gfx_print_char(' '); print_hex(acquisition_getValue(AN_LINE_R)); gfx_print_char(' '); print_hex(acquisition_getValue(AN_LINE_L)); gfx_print_char(' '); print_hex(acquisition_getValue(AN_FLOOR_L)); delay(10); } } while (1) { //while (!uart0_rxempty() && !uart0_txfull()) { // uart0_putchar(uart0_getchar()); //} gfx_draw_mode(GFX_DM_JAM2); //* if (xbee_tx_idle()) { transmit_update1(); } //delay(50); //*/ delay(10); // Spannung //bot_update(); char text[20]; float volt = 0.0160 * acquisition_getValue(AN_VBAT); sprintf(text, "%2.1fV ", (double)volt); gfx_move(45, 0); gfx_print_text(text); volt_flt = 0.9*volt_flt+0.1*volt; if (volt_flt<8.0) { show_recharge_screen(); } // Ori gfx_move(0, 25); sprintf(text, "or:%3i ", (int)ori_deg); gfx_print_text(text); sprintf(text, "op:%2i/%2i ", (int)ori_opt, (int)ori); gfx_print_text(text); sprintf(text, "m:%1i", (int)mode); gfx_print_text(text); // Floor gfx_move(31, 49); print_hex(acquisition_getDiff(AN_FLOOR_R)); gfx_print_char(' '); print_hex(acquisition_getDiff(AN_LINE_R)); gfx_print_char(' '); print_hex(acquisition_getDiff(AN_LINE_L)); gfx_print_char(' '); print_hex(acquisition_getDiff(AN_FLOOR_L)); // Distance gfx_move(4, 57); gfx_print_text("R "); print_hex(dist_r); gfx_print_char(' '); print_hex(dist_fr); gfx_print_char(' '); print_hex(dist_f); gfx_print_char(' '); print_hex(dist_fl); gfx_print_char(' '); print_hex(dist_l); gfx_print_text(" L"); //////////////////////////// print_hex16(0, 33, copro_ticks_r); print_hex16(105, 33, copro_ticks_l); print_hex16(0, 41, copro_speed_r); print_hex16(105, 41, copro_speed_l); print_hex16(0, 49, copro_current_r); print_hex16(105, 49, copro_current_l); } }