12 volatile int overflow;
13 volatile int rise_time;
14 volatile int fall_time;
17 volatile float servo_angle;
21 float distancePing = 0;
22 unsigned char angle = 0;
23 unsigned char tempAngle1 = 0;
24 unsigned char tempAngle2 = 0;
25 float tempDistance = 0;
31 unsigned char theta = 0;
50 sensor_data = oi_alloc();
65 unsigned char note[1] = { 60 };
66 unsigned char length[1] = { 64 };
67 oi_loadSong(0, 1, note, length);
70 for (l = 0; l < 5; l++)
78 for (i = 0; i <= 90; i++)
91 ADC0_PSSI_R = ADC_PSSI_SS0;
94 while ((ADC0_RIS_R & ADC_RIS_INR0) == 0)
98 Qval = ADC0_SSFIFO0_R;
101 timer_waitMillis(25);
103 Distance = 130885 * pow(Qval, -1.184);
117 if (((prevDist - Distance) > 25) && angle > 5 && flag == 0)
120 tempDistance = distancePing / 10.0;
125 else if (flag && ((Distance == 150) || (Distance - prevDist > 25)))
129 theta = tempAngle2 - tempAngle1;
130 width = tempDistance * tan((theta * (3.14 / 180.0)));
136 distances[count - 1] = tempDistance;
137 angles[count - 1] = tempAngle2 - (theta);
138 widths[count - 1] = width;
141 if (theta > 2 && distances[count - 1] < 120) {
142 sprintf(obj,
"dist: %.2f\tangl: %.2f\twdth: %.2f\ttheta: %d\n\r", distances[count - 1], angles[count - 1], widths[count - 1], theta);
void sweep()
sweeps from 0 to 180 degrees, reads and sends data
void servo_setAngle(double degrees)
sets the servo angle
the main code for the robot to interact with the user
double time2dist(int time)
convert a sonar pulse width time to a distance
void ping_init()
initializes ping sensor
int ping_read()
reads the response pulse from the ping sensor
void ADC_init()
initializes the registers and timers needed for the ADC
void sweep_init()
initializes the sweep modules
iRobot Create Sensor Data
void clock_timer_init3(void)
initializes a clock timer
void clock_timer_init(void)
intializes the clock timer
void servo_init()
initializes the servo motor
void uart_sendStr(const char *data)
sends an entire string of character over uart 1 module