final project  1
main.c
Go to the documentation of this file.
1 
10 #include "main.h"
11 
13 
16 void show_help() {
17  uart_sendStr("\n\r\n\rw = forward 10cm\n\r");
18  uart_sendStr("W = forward 20cm\n\r");
19  uart_sendStr("a = left 15deg\n\r");
20  uart_sendStr("s = reverse 5cm\n\r");
21  uart_sendStr("d = right 15deg\n\r");
22  uart_sendStr("e = sweep servo\n\r");
23  uart_sendStr("h = help menu\n\r");
24  uart_sendStr("m = play music!\n\r");
25  uart_sendStr("\n\rWhen moving forward, data returned is:\n\r");
26  uart_sendStr(" 1000's = bumpers, 1->left, 2->right\n\r");
27  uart_sendStr(" 100's = ground sensors (1->4 = hole left->right, 5->8 = tape left->right\n\r");
28  uart_sendStr(" 10's, 1's = distance\n\r\n\r\n\r");
29 }
30 
32 
35 void main() {
36  uart_init();
39  timer_init();
40  sweep_init();
41 
42  oi_t *sensors = oi_alloc();
43  oi_init(sensors);
44  uart_sendStr("\n\r\n\rSave the blind people (from zombies)!\n\r");
45 
46  char command = '_';
47  char sendData[50];
48  short dist = 0;
49 
50  show_help();
51 
52 
53  while(1) {
54  command = uart_receive();
55  switch (command) {
56  case 'a':
57  //turn left 15deg
58  turn_left(sensors, 15);
59  uart_sendStr("left 15deg\n\r");
60  break;
61 
62  case 'w':
63  //forward 10cm
64  dist = move_forward(sensors, 10);
65  sprintf(sendData, "Forward %d\n\r", dist);
66  uart_sendStr(sendData);
67  break;
68 
69  case 'W':
70  //forward 20cm
71  dist = move_forward(sensors, 20);
72  sprintf(sendData, "Forward %d\n\r", dist);
73  uart_sendStr(sendData);
74  break;
75 
76  case 'd':
77  //turn right 15deg
78  turn_right(sensors, 15);
79  uart_sendStr("right 15deg\n\r");
80  break;
81 
82  case 's':
83  //reverse 5cm
84  dist = move_back(sensors, 5);
85  sprintf(sendData, "Reverse %d\n\r", dist);
86  uart_sendStr(sendData);
87  break;
88 
89  case 'e':
90  //sweep servo
91  sweep();
92  uart_sendStr("Swept\n\r");
93  break;
94  case 'h':
95  show_help();
96  break;
97  case 'm':
98  playMusic();
99  uart_sendStr("Done!");
100  break;
101 
102  default:
103  stopmoving();
104  break;
105 
106  }
107  }
108 }
109 
void sweep()
sweeps from 0 to 180 degrees, reads and sends data
Definition: sweep.c:60
void turn_left(oi_t *sensor, int degrees)
Turns the robot left.
Definition: drive.c:49
void uart_init(void)
sets all necessary registers to enable the uart 1 module.
Definition: uart.c:16
int uart_receive(void)
polling receive an 8 bit character over uart 1 module.
Definition: uart.c:63
short move_back(oi_t *sensor, short cm)
Moves the robot back.
Definition: drive.c:67
the main code for the robot to interact with the user
void main()
main method to run for robot control
Definition: main.c:35
void timer_init()
initializes the timer for the servo
Definition: servo.c:34
short move_forward(oi_t *sensor, short cm)
Moves the robot forward.
Definition: drive.c:84
void playMusic()
plays music
Definition: music.c:29
void sweep_init()
initializes the sweep modules
Definition: sweep.c:44
iRobot Create Sensor Data
void stopmoving()
Stops robot from moving.
Definition: drive.c:132
void turn_right(oi_t *sensor, int degrees)
Turns the robot right.
Definition: drive.c:32
void show_help()
shows the help menu
Definition: main.c:16
void clock_timer_init(void)
intializes the clock timer
Definition: servo.c:55
void groundSensor_init()
initializes the ground sensors
Definition: groundSensor.c:21
void uart_sendStr(const char *data)
sends an entire string of character over uart 1 module
Definition: uart.c:75