Robot C-program for Group B-4 (temp), E5 Fall 2002
Adem Kader
David Lovit
Frank Kyei-Manu
Melonie Jalloh
#include <stdlib.h>
#include <math.h>
#define SLEEPTIME 4.0
#define DRIVERANGE 3
#define RIGHT 2
#define LEFT 3
#define RANGE 15
#define LEFTMOTOR 1
#define RIGHTMOTOR 0
#define BACKTIME 1.0
#define TURNTIME 0.8
int abs(int i){
if(i<0)
return -i;
else
return i;
}
int currentTemp ()
{
int currentTemp;
currentTemp = (analog(RIGHT)+analog(LEFT));
return currentTemp;
}
int normal(int probemax){
int i;
while(1){
if(!digital(7) || !digital(8))
turnAround();
if(stop_button())
return 0;
if (currentTemp()>((probemax-RANGE)*2) )
return 1;
i = probecheck();
drive(i);
}
}
void turnAround(){
motor(LEFTMOTOR, -100);
motor(RIGHTMOTOR, -100);
sleep(BACKTIME);
motor(LEFTMOTOR, 100);
sleep(TURNTIME);
ao();
}
int initialize(){
int probemax;
while(!start_button()){
if(analog(RIGHT) > analog (LEFT))
probemax = analog(RIGHT);
else
probemax = analog(LEFT);
printf("\nright= %d, left= %d", analog(RIGHT), analog(LEFT));
sleep(0.3);
}
return probemax;
}
int probecheck(){
int tempdiffer;
tempdiffer =(analog(RIGHT) - analog(LEFT));
return tempdiffer;
}
void drive(int i){
if (i<-DRIVERANGE){
motor(LEFTMOTOR,0);
motor(RIGHTMOTOR,75);
}
else if (i>DRIVERANGE){
motor(LEFTMOTOR,75);
motor(RIGHTMOTOR,0);
}
else{
motor(RIGHTMOTOR, 75);
motor(LEFTMOTOR, 75);
}
return;
}
void main() {
int probemax = initialize();
sleep(SLEEPTIME);
printf("\ninitialization done");
sleep(SLEEPTIME-1.0);
printf("\nlooking for hot stuff");
while (1){
if (normal(probemax)== 1)
{
ao();
printf("\nmission accomplished");
tone(174.61,.125);
tone(174.61,.125);
tone(174.61,.125);
tone(233.08,.75);
tone(349.23,.75);
tone(311.13,.125);
tone(293.66,.125);
tone(261.63,.125);
tone(466.16,.75);
tone(349.23,.375);
tone(311.13,.125);
tone(293.66,.125);
tone(261.63,.125);
tone(466.16,.75);
tone(349.23,.375);
tone(311.13,.125);
tone(293.66,.125);
tone(311.13,.125);
tone(261.63,.75);
return;
}
if (stop_button())
break;
}
ao();
return;
}