Ok :
Code:
#include "asuro.h"
#define LIMIT 20 // Helligkeitsveraenderung, bei der eine Linie detektiert wird
#define TIEFPASS 50 // grosser Wert=grosse Zeitkonstante
// globale Variablen
uint16_t HellLinks;
uint16_t HellRechts;
/*************************************************************************
uint8_t testhell()
testhell ermittelt die durchschnittliche Helligkeit der beiden
Linienphottransistoren mit Hilfe eines Tiefpassfilters.
Unterschreitet die Helligkeit schlagartig den tiefpassgefilterterten
Wert, wird ein Flag gesetzt.
Ausgabe:
testhell=0: keine Linie
Bit0= Linie links erkannt
Bit1= Linie rechts erkannt
Bit0+Bit1 Linie senkrecht
*************************************************************************/
uint8_t testhell()
{
uint8_t ergebnis=0;
uint16_t lineData[2];
LineData(lineData);
HellLinks=(HellLinks*TIEFPASS+lineData[0])/(TIEFPASS+1);
HellRechts=(HellRechts*TIEFPASS+lineData[1])/(TIEFPASS+1);
StatusLED(YELLOW);
if((lineData[0]+LIMIT)<(HellLinks)) ergebnis|=1;
if((lineData[1]+LIMIT)<(HellRechts)) ergebnis|=2;
void Msleep(int 10);
{
int z;
for(z=0;z<10;z++) Sleep(72);
}
return ergebnis;
}
int main(void)
{
int n;
Init();
StatusLED(RED);
FrontLED(ON);
// mittlere Helligkeit im Stand ermitteln
for(n=0;n<300;n++)
{
testhell();
}
StatusLED(YELLOW);
MotorDir(FWD,FWD);
MotorSpeed(150,150);
while(1)
{
n=testhell();
BackLED(n&0x01,n&0x02);
StatusLED(YELLOW);
if(n!=0) // Falls Linie erkannt, dann drehen und zurück
{
StatusLED(GREEN);
MotorDir(RWD,RWD);
MotorSpeed(150,100);
void Msleep(int 600);
{
int z;
for(z=0;z<600;z++) Sleep(72);
}
MotorDir(RWD,FWD);
MotorSpeed(200,200);
void Msleep(int 600);
{
int z;
for(z=0;z<600;z++) Sleep(72);
}
MotorDir(FWD,FWD);
MotorSpeed(150,150);
}
void Msleep(int 10)
{
int z;
for(z=0;z<10;z++) Sleep(72);
}
}
}
/***************************************************************************
*
* 2007 robo.fr (Nickname) , christoph(at)roboterclub-freiburg.de
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation version 2 of the License, *
* If you extend the program please maintain the list of authors. *
* ( if there is no real name, the nick name has to be mentioned )
* If you want to use this software for commercial purposes and you *
* don't want to make it open source, please contact the authors for *
* licensing. *
***************************************************************************/
Lesezeichen