ich habe es jetz so bearbeitet das es kompilirbar ist abber wen ich es auf den asuro flashe macht er nur die Front led an und die statusled auf orange abber bewegt sich kein stück irgendwo muss sich etwas dagegenstellen das er losfährt ich weis abber nicht was
Code:
/***************************************************************************
* 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 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. *
***************************************************************************/
#include "asuro.h"
#include <stdlib.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 objekt_sichtbar(uint8_t abstand)
Ist ein Objekt in der Entfernung kleiner oder gleich
dem Eingangsparameter "abstand" erkennbar?
objekt_sichtbar(7) liefert TRUE zurück, falls überhaupt
ein Object detektierbar.
abstand:
0: 5cm
1: 7cm
2: 13cm
3: 15cm
4: 16cm
5: 17cm
6: 18cm
7: 22cm
( Testobjekt: Joghurtecher, Umgebungsbeleuchtung: Zimmer )
return: TRUE falls Objekt gefunden
FALSE wenn nicht
Zeitbedarf: 5ms
*************************************************************************/
uint8_t objekt_sichtbar(uint8_t distance)
{
uint16_t j,z;
DDRD |= (1 << DDD1); // Port D1 als Ausgang
PORTD &= ~(1 << PD1); // PD1 auf LOW
OCR2 = 254-distance; // wenn OCR2=0xFE dann Objekt sehr nahe
z=0;
for(j=0;j<30;j++) // loop time: 5ms
{
if (PIND & (1 << PD0))z++;
Sleep(6); // 6*Sleep(6)=1ms
}
if (z>=29) return FALSE; // Objekt nicht gefunden
else return TRUE;
}
/*************************************************************************
uint8_t abstand()
Abstandsermittelung über IR-Sendiode / IR-Empfänger.
0:kleinster Abstand
7:größter Abstand
255: kein Objekt
Zeitbedarf: 5ms*9=45ms
author: robo.fr, christoph ( ät ) roboterclub-freiburg.de
date: 2008
*************************************************************************/
uint8_t abstand()
{
uint8_t k,n;
k=255;
for(n=0;n<8;n++)
{
if (!objekt_sichtbar(n)) k=n; // solange kein Objekt, Distanz erhoehen
}
return k;
}
/*************************************************************************/
unsigned char testhell(void)
{
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;
Msleep(10);
return ergebnis;
}
/*************************************************************************
Hauptprogramm
*************************************************************************/
int main(void)
{
uint8_t 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)
FALSE;
{
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);
Msleep(600);
MotorDir(RWD,FWD);
MotorSpeed(200,200);
Msleep(600);
MotorDir(FWD,FWD);
MotorSpeed(150,150);
}
Msleep(10);
}
TRUE;
{
n=abstand();
StatusLED(OFF);
BackLED(OFF,OFF);
MotorSpeed(200,200);
if(n!=255)
{
if (n<2) MotorSpeed(200,200);
if (n<1) MotorSpeed(200,200);
Msleep(10);
}
}
}
Hilft mir bitte
Gruß
chief 2
Lesezeichen