Hallo!
Probiert mal folgendes Programm:
Code:
/*******************************************************************************
*
* Description: Asuro fährt geradeaus
*
*****************************************************************************/
#include "asuro.h"
#include <stdlib.h>
int main(void)
{
unsigned char speed, flagl=FALSE, flagr=FALSE;
unsigned int data[2];
int wegl, wegr, diff;
int speedLeft,speedRight;
Init();
MotorDir(FWD,FWD);
StatusLED(GREEN);
speed = 150;
speedLeft = speedRight = speed;
wegl=0; wegr=0;
while(wegl<333){
OdometrieData(data);
if ((data[0] < 550) && (flagl == TRUE)) {flagl = FALSE; wegl++;}
if ((data[0] > 650) && (flagl == FALSE)) {flagl = TRUE; wegl++;}
if ((data[1] < 550) && (flagr == TRUE)) {flagr = FALSE; wegr++;}
if ((data[1] > 650) && (flagr == FALSE)) {flagr = TRUE; wegr++;}
diff=wegr-wegl;
if (diff>0) speedRight--; // fahre geradeaus
else if (diff<0) speedLeft--;
else {speedRight=speed; speedLeft=speed;}
if (speedRight<0) {speedRight=0;}
if (speedLeft<0) {speedLeft=0;}
MotorSpeed(speedLeft,speedRight);
}
MotorDir(BREAK,BREAK);
while(1);
return 0;
}
Damit fährt mein Asuro schön geradeaus.
Gruss Waste
Lesezeichen