Hallo!
Lesen kann ich, was soll das also?
Hier mal ein Video:
http://www.youtube.com/watch?v=SjmQ5mHueG8
1. Durchdrehen
2. Stoppen an einem Isolierband
Falls es jemand interessiert, der Code
Viele Grüße Lisbeth2010Code:/* Laufstall 04.12.2010 - IW Boden: Fliese hellgrau Umrandung: schwarzes Isolierband 15 mm breit nur innerhalb der Umrandung rumfahren */ #include <avr/interrupt.h> #include <nibo/niboconfig.h> #include <nibo/iodefs.h> #include <nibo/bot.h> #include <nibo/i2cmaster.h> #include <nibo/leds.h> #include <nibo/delay.h> #include <nibo/motco.h> #include <nibo/irco.h> #include <nibo/floor.h> #include <nibo/adc.h> /* eigene Funktion Zahlausgabe binär 0..63 */ int16_t wert; void zahlausgabe(int16_t wert) { if ((wert - 32) > 0) { leds_set_status(LEDS_GREEN, 5); wert = wert - 32; } else { leds_set_status(LEDS_OFF, 5); } if ((wert - 16) > 0) { leds_set_status(LEDS_GREEN, 4); wert = wert - 16; } else { leds_set_status(LEDS_OFF, 4); } if ((wert - 8) > 0) { leds_set_status(LEDS_GREEN,3); wert = wert - 8; } else { leds_set_status(LEDS_OFF,3); } if ((wert - 4)> 0) { leds_set_status(LEDS_GREEN,2); wert = wert - 4; } else { leds_set_status(LEDS_OFF,2); } if ((wert - 2)> 0) { leds_set_status(LEDS_GREEN,1); wert = wert - 2; } else { leds_set_status(LEDS_OFF,1); } if ((wert - 1)> 0) { leds_set_status(LEDS_GREEN,0); } else { leds_set_status(LEDS_OFF,0); } } // end Zahlausgabe /* eigene Funktion floor_measure() 2x wg. erster AD-Wandlung */ int16_t floor_mw[4]; void floor_measure_iw() { floor_enable_ir(); floor_mw[0] = 1023-adc_read(0); // Bodensensor von oben in Fahrtrichtung rechts floor_mw[1] = 1023-adc_read(1); // Bodensensor von oben in Fahrtrichtung links floor_mw[2] = 1023-adc_read(2); // Liniensensor von oben in Fahrtrichtung links floor_mw[3] = 1023-adc_read(3); // Liniensensor von oben in Fahrtrichtung rechts //nochmal, wir haben ja Zeit... floor_mw[0] = 1023-adc_read(0); // Bodensensor von oben in Fahrtrichtung rechts floor_mw[1] = 1023-adc_read(1); // Bodensensor von oben in Fahrtrichtung links floor_mw[2] = 1023-adc_read(2); // Liniensensor von oben in Fahrtrichtung links floor_mw[3] = 1023-adc_read(3); // Liniensensor von oben in Fahrtrichtung rechts floor_disable_ir(); } /*-----------*/ /* Laufstall */ /*-----------*/ uint8_t speed_left = 100; // Ticks/Sekunde Testwert uint8_t speed_right = 100; // Ticks/Sekunde Testwert uint16_t floor_left; uint16_t floor_right; void laufstall() { floor_left = floor_mw[1]/16; floor_right = floor_mw[0]/16; //zahlausgabe(floor_right); // da kein Display! keine negativen Werte! // floor_left auf gelb: 7, auf schwarz: 0, auf Fliese 6, auf Fuge 3 // floor_right auf gelb: 8, auf schwarz: 0, auf Fliese 6, auf Fuge 3 if ((floor_left < 2) || (floor_right < 2)) { //ABGRUND: STOP leds_set_status(LEDS_ORANGE,0); leds_set_status(LEDS_ORANGE,5); motco_stop(); motco_update(); delay(1000); motco_setSpeed(-50, -50); motco_update(); delay(1000); motco_stop(); motco_update(); } else { leds_set_status(LEDS_GREEN,0); leds_set_status(LEDS_GREEN,5); motco_setSpeed(speed_left,speed_right); motco_update(); } } // end laufstall #define WHILE_1_TIME_GRID 10 uint8_t counter_2ms; // ------------------------------------------------------------ // ---------- init timer2 ------------------------------------- // ------------------------------------------------------------ void init_timer2(void) { TCCR2 = 0x00; // normal port operation TCNT2 = 0x83; // set count value (131) } // ------------------------------------------------------------ // ---------- start timer2 ------------------------------------ // ------------------------------------------------------------ void start_timer2(void) { cli(); // disable global interrupts counter_2ms = 0; // Datenblatt falsch!! S. 106 Table 56 TCCR2 |= 0x04; // CS02 = 1; CS01 = 0; CS00 = 1 -> clk/256 TIMSK |= (1<<TOIE2); //0x01; // enable timer overflow interrupt sei(); // enable global interrupts } // ------------------------------------------------------------ // ---------- stop timer2 ------------------------------------- // ------------------------------------------------------------ void stop_timer2(void) { cli(); // disable global interrupts TCCR2 &= ~0x05; // stop timer TIMSK &= ~(1<<TOIE2); // disable timer overflow interrupt sei(); // enable global interrupts } // ------------------------------------------------------------ // ---------- timer2 ISR -------------------------------------- // ------------------------------------------------------------ ISR(TIMER2_OVF_vect) { // timer2 overflow // reload counter value high byte; 0x83 corresponds to 1ms // clk/128 entspricht 125 kHz entspricht 8 us // Datenblatt falsch! clk/256 = 0x04 0 => 2ms TCNT2 = 0x83; // 131 bis 256 also 125 mal 16 us counter_2ms++; if (counter_2ms >= WHILE_1_TIME_GRID) { stop_timer2(); // Zeitdauer unbekannt, deshalb stoppen // Bodensensoren messen (2 mal) floor_measure_iw(); // schwarz = 0, weiß = 1023 bzw. 63=1023/16 Integer! laufstall(); counter_2ms = 0; start_timer2(); // alles abgearbeitet } // end if counter } // end ISR /* die main */ int main() { sei(); bot_init(); i2c_init(); leds_init(); floor_init(); init_timer2(); leds_set_status(LEDS_GREEN,5); delay(2000); // damit er nicht gleich losrast! leds_set_status(LEDS_OFF,5); motco_setSpeedParameters(5,4,6); // Empfehlung vom "Chef" start_timer2(); while (1) { // tu was.. oder nix delay(10000); } return 0; }







Zitieren

Lesezeichen