Robot C-program for Group C-2 (temp), E5 Fall 2002

Sally Hall

Mark Piper

Simeon Realov

```#define FWD0 30
#define FWD1 30
#define BKWD0 -50
#define BKWD1 -50
#define TTURN45 1.0
#define INTERVAL 1.0

void straight(void)
{
motor(0,FWD0);
motor(1,FWD1);
}

void back (void)
{
motor (0, BKWD0);
motor (1, BKWD1);
}

void left(void)
{
motor(0,FWD0);
motor(1,BKWD1);
sleep(TTURN45);
}

void right(void)
{
motor(0,BKWD0);
motor(1,FWD1);
sleep(TTURN45);
}

void bumpright(void)
{
back();
sleep (INTERVAL);
left();left();
}

void bumpleft (void)
{
back();
sleep(INTERVAL);
right();right();
}

int high (int x, int y)
{
if (x>y) return x;
return y;
}

void maximum(int a,int b)
{
if((a-20)>b)
{
left();
}
else if(a<(b-20))
{
right();
}
}

void jamesbond(void)
{
int a;
for(a=0;a<2;a++)
{
tone(329.63, 0.5);
tone(369.99, 0.25);
tone(369.99, 0.25);
tone(369.99, 0.5);
tone(369.99, 1.0);
tone(329.63, 0.5);
tone(329.63, 0.5);
tone(329.63, 0.5);
tone(329.63, 0.5);
tone(392.00, 0.25);
tone(392.00, 0.25);
tone(392.00, 0.5);
tone(392.00, 1.0);
tone(369.99, 0.5);
tone(369.99, 0.5);
tone(369.99, 0.5);
}
beep();
}

void main(void)
{
int a,b,max,counter=1;
while(!stop_button())
{
a=analog(2);
b=analog(3);
printf("\nL=%d R=%d;       BL=%d BR=%d",a,b,digital(7),digital(8));
sleep(0.3);
}
max=high(a,b);
while(!start_button())
{
}
while(!stop_button())
{
if(!digital(7))
{
bumpleft();
}
else if(!digital(8))
{
bumpright();
}
else
{
a=analog(2);
b=analog(3);
if(a>(max-10)||b>(max-10))
{
printf("\nYou're there!!!");
break;
}
else if(counter==3)
{
printf("\nL=%d R=%d;       BL=%d
BR=%d",a,b,digital(7),digital(8));
maximum(a,b);
straight();
sleep(INTERVAL);
counter=1;
}
else
{
counter++;
}
}
}
ao();
jamesbond();
}```