void countLines(void){ updateSensorsWhite(); if(sensor[LEFT_BACK] == 0 && linel == 0 && liner == 0 && akt_time()>=nachkurvetimeout && akt_time()>=sperrtimeout){ linel = 1; }else if(sensor[LEFT_BACK] == 1 && linel == 1 && liner == 0){ count++; linel =0; liner =0; sperrtimeout = akt_time() + LINESPERR; // lcd_cls(); // lcd_uint(kurven); setting = 0; } if(sensor[RIGHT_BACK] == 0 && liner == 0 && linel == 0 && akt_time()>=nachkurvetimeout && akt_time()>=sperrtimeout){ liner = 1; }else if(sensor[RIGHT_BACK] == 1 && liner == 1 && linel == 0){ count++; linel =0; liner =0; sperrtimeout = akt_time() + LINESPERR; // lcd_cls(); // lcd_uint(kurven); setting = 0; } }
//Methode zum starten(warten auf Startlampe) void starting(void){ servo_arc(0, 54); if (analog(LEFT_BACK)>WHITE){ //wenn links schwarz start = 'l'; }else if (analog(RIGHT_BACK)>WHITE){ //wenn rechts schwarz start = 'r'; } motPowLeft=8; motPowRight=8; lcd_putchar(start); while(analog(9)>100); timeoutAt = akt_time() + RUNTIME; setMotPow(motPowLeft,motPowRight); //Gas geben:-) sperrtimeout = akt_time() + 400; //Sperrzeit zum Linienzählen }
//Rotation um 90° um eine Ecke auf der Streckenmarkierung, Übergabe der Richtung als deutsches Wort links/rechts in einem String void rotate(unsigned char richtung){ //nach rechts?? if(richtung == 'rechts'){ setMotPow(motPowLeft,0); setMotGear(forward,backward); setMotPow(motPowLeft,10); sleep(500); do{ updateSensorsWhite(); }while(sensor[MID_RIGHT]); setMotPow(motPowLeft,0); setMotGear(forward,forward); setMotPow(motPowLeft,motPowRight); //nach links?? }else if (richtung == 'links'){ setMotPow(0,motPowRight); setMotGear(backward,forward); setMotPow(10,motPowRight); sleep(500); do{ updateSensorsWhite(); }while(sensor[MID_LEFT]); setMotPow(0,motPowRight); setMotGear(forward,forward); setMotPow(motPowLeft,motPowRight); } followLine(); kurven++; count = 0; // lcd_cls(); // lcd_uint(count); nachkurvetimeout = akt_time() + KURVSPERR; }
void timer_check() { int i = 0; unsigned long cur_time = akt_time(); for (i = 0; i < TIMER_NUM; i++) { if (cur_time > timer_list[i].timeout) *(timer_list[i].flag) = 0; } }
unsigned long timer_reset(unsigned char index, unsigned long timeout, unsigned char *flag) { if (index < TIMER_NUM) { *flag = 1; timer_list[index].flag = flag; timer_list[index].timeout = akt_time() + timeout; return timer_list[index].timeout; } return 0; //Error }
void rotateFrei(unsigned char richtung){ //nach rechts?? if(richtung == 'rechts'){ messung_start = akt_time() + messung-25; setMotPow(motPowLeft,0); setMotGear(forward,backward); setMotPow(motPowLeft,10); sleep(500); do{ }while(akt_time()<=messung_start); setMotPow(motPowLeft,0); setMotGear(forward,forward); setMotPow(motPowLeft,motPowRight); //nach links?? }else if (richtung == 'links'){ messung_start = akt_time() + messung + 60; setMotPow(0,motPowRight); setMotGear(backward,forward); setMotPow(10,motPowRight); sleep(500); do{ }while(akt_time()<=messung_start); setMotPow(0,motPowRight); setMotGear(forward,forward); //motPowLeft=motPowLeft-1; setMotPow(motPowLeft,motPowRight); } followLine(); kurven++; count = 0; //lcd_cls(); //lcd_uint(count); nachkurvetimeout = akt_time() + KURVSPERR; }
void AksenMain(void) { starting(); do { if (akt_time() >= timeoutAt) { setMotPow(0,0); break; } if(kurven == 8 && sensor[MID_MID] == 1 && sensor[MID_LEFT] == 1 && sensor[MID_RIGHT] == 1){ setMotPow(0,0); break; } followLine(); countLines(); manage(start); }while(1); while(1); }