Revision 1524
Added comments to circle formation code
circle.c | ||
---|---|---|
1 | 1 |
#include <dragonfly_lib.h> |
2 | 2 |
#include <encoders.h> |
3 | 3 |
|
4 |
// TODO: |
|
5 |
// Check BOM more often and before final stop |
|
6 |
// Make BOM check more comprehensively |
|
7 |
// Use the center bot to check distances |
|
8 |
// Count them ("spam" method) |
|
9 |
// Use beacon to find relative positions |
|
10 |
// Beacon tells them how to move to be at the right distance |
|
11 |
// Wireless communication, initialization |
|
4 |
/* |
|
5 |
This program is used to make robots target a center (leader) robot using the BOM, |
|
6 |
then drive toward it and stop at a certain distance away. |
|
7 |
|
|
8 |
The distance will eventually be adjustable. |
|
12 | 9 |
|
13 |
void forward(int speed){ |
|
10 |
With adjustment, the leader robot will be able to turn and use its standardized |
|
11 |
rangefinder to reposition or space the robots evenly. |
|
12 |
|
|
13 |
AuTHORS: Niko, Alex, Reva, Echo |
|
14 |
*/ |
|
15 |
|
|
16 |
|
|
17 |
/* |
|
18 |
TODO: |
|
19 |
Check BOM more often and before final stop |
|
20 |
Make BOM check more comprehensively |
|
21 |
Use the center bot to check distances |
|
22 |
Count them ("spam" method) |
|
23 |
Use beacon to find relative positions |
|
24 |
Beacon tells them how to move to be at the right distance |
|
25 |
Wireless communication, initialization |
|
26 |
*/ |
|
27 |
|
|
28 |
void forward(int speed){ // set the motors to this forward speed. |
|
14 | 29 |
motor_l_set(FORWARD,speed); |
15 | 30 |
motor_r_set(FORWARD,speed); |
16 | 31 |
} |
17 |
void left(int speed){ |
|
32 |
void left(int speed){ // turn left at this speed.
|
|
18 | 33 |
motor_l_set(FORWARD,speed); |
19 | 34 |
motor_r_set(BACKWARD,speed); |
20 | 35 |
} |
... | ... | |
22 | 37 |
motor_l_set(BACKWARD,speed); |
23 | 38 |
motor_r_set(FORWARD,speed); |
24 | 39 |
} |
25 |
void stop(void){ |
|
40 |
void stop(void){ // could be set to motors_off(), or just use this as an alternative.
|
|
26 | 41 |
motor_l_set(BACKWARD,0); |
27 | 42 |
motor_r_set(FORWARD,0); |
28 | 43 |
} |
... | ... | |
34 | 49 |
motor_l_set(BACKWARD, speed); |
35 | 50 |
motor_r_set(BACKWARD, speed); |
36 | 51 |
} |
37 |
int get_distance(void){ |
|
38 |
int temp,distance,kk=5; |
|
52 |
int get_distance(void){ // takes an averaged reading of the front rangefinder
|
|
53 |
int temp,distance,kk=5; // kk sets this to 5 readings.
|
|
39 | 54 |
distance =0; |
40 | 55 |
for (int i=0; i<kk; i++){ |
41 | 56 |
temp = range_read_distance(IR2); |
... | ... | |
59 | 74 |
} |
60 | 75 |
} |
61 | 76 |
|
62 |
void turn_to_beacon2(int max){ |
|
77 |
void turn_to_beacon2(int max){ // like the previous but no stop() call
|
|
63 | 78 |
if (max>-1 && max<16){ |
64 | 79 |
int index = (max+12)%16; |
65 | 80 |
if (index==0) { |
... | ... | |
89 | 104 |
delay_ms(22); |
90 | 105 |
} |
91 | 106 |
} |
92 |
void go_straight(void){ |
|
107 |
void go_straight(void){ // drives forward a hardcoded distance. May not be useful.
|
|
93 | 108 |
forward(200); |
94 | 109 |
encoder_rst_dx(LEFT); |
95 | 110 |
encoder_rst_dx(RIGHT); |
... | ... | |
97 | 112 |
int x_left = encoder_get_x(LEFT), x_right = encoder_get_x(RIGHT); |
98 | 113 |
int count = 0; |
99 | 114 |
int d; |
100 |
while (count<25){ //count = 25 when bot6; count <12
|
|
115 |
while (count<25){ //count = 25 when bot6; count <12
|
|
101 | 116 |
x_left = encoder_get_x(LEFT); |
102 | 117 |
x_right = encoder_get_x(RIGHT); |
103 | 118 |
d = x_right-x_left; |
... | ... | |
111 | 126 |
count++; |
112 | 127 |
} |
113 | 128 |
} |
114 |
void go_straight_onefoot(void){ |
|
129 |
void go_straight_onefoot(void){ // essentially, another name for the above. Should be removed.
|
|
115 | 130 |
go_straight(); |
116 | 131 |
} |
117 | 132 |
|
... | ... | |
121 | 136 |
/* Initialize dragonfly board */ |
122 | 137 |
dragonfly_init(ALL_ON); |
123 | 138 |
encoders_init(); |
124 |
/*******CODE HERE ***** */ |
|
125 | 139 |
|
126 |
int distance=1000; |
|
127 |
int onefoot=300, speed=200; //one foot is 490 for bot 1; one foot is 200 for bot6
|
|
140 |
int distance=1000; // how far away to stop.
|
|
141 |
int onefoot=300, speed=200; // one foot is 490 for bot 1; one foot is 200 for bot6
|
|
128 | 142 |
orient(); |
129 | 143 |
forward(speed); |
130 | 144 |
range_init(); |
... | ... | |
141 | 155 |
stop(); |
142 | 156 |
orient(); |
143 | 157 |
|
144 |
//button1_wait (); |
|
158 |
//button1_wait (); // code for lab1.
|
|
145 | 159 |
//go_straight_onefoot(); |
146 | 160 |
stop(); |
147 | 161 |
/* ****** CODE HERE ******* */ |
Also available in: Unified diff