|
#include <tjpbase.h>
#include <stdio.h>
int geradeaus(int laenge);
void main() {
int stop = 0;
/* Sensoren und Eingänge initialisieren */
init_analog();
init_motortjp();
init_clocktjp();
IRE_ON;
START; /*Heck-Bumper drücken um zu starten*/
wait(2000);
/* So lange geradeaus fahren bis Wand kommt */
while (!stop) {
stop = geradeaus(100);
}
}
/* Laenge in cm */
int geradeaus(int laenge)
{
int irl,irr,boden,bump,n=1;
int stop=0;
if (laenge < 0) {
motorp(RIGHT_MOTOR,-MAX_SPEED);
motorp(LEFT_MOTOR,-(MAX_SPEED*0.46)); /* 46 */
laenge = laenge*(-1);
} else {
motorp(RIGHT_MOTOR,MAX_SPEED);
motorp(LEFT_MOTOR,(MAX_SPEED*0.46)); /* 46 */
}
do {
wait(400/9);
irl = LEFT_IR;
irr = RIGHT_IR;
bump = BUMPER;
if ((irl > 98) || (irr > 98)) {
stop = 1;
}
if (bump >= 10) {
stop = 1;
}
} while ((!stop) && (n++ < laenge));
motorp(RIGHT_MOTOR,0);
motorp(LEFT_MOTOR,0);
return stop;
}
|
|