Project

General

Profile

Revision 1524

Added by Alex Zirbel over 14 years ago

Added comments to circle formation code

View differences:

trunk/code/behaviors/formation_control/circle/circle.c
3 3

  
4 4
#define RADIUS 300
5 5

  
6
/*
7
	This is a PREVIOUS VERSION of circle2.  Circle2 uses Echo's more exact code, while this uses a different method which is more buggy.
8
	This code has been kept for the time being, in case some of the code is useful for recylcling (the control loop, for instance) - without
9
	reverting the entire repositiory.
10
	
11
	This program is used to make robots target a center (leader) robot using the BOM,
12
	then drive toward it and stop at a certain distance away.
13
	
14
	The distance will eventually be adjustable.
15

  
16
	With adjustment, the leader robot will be able to turn and use its standardized
17
	rangefinder to reposition or space the robots evenly.
18
	
19
	AuTHORS: Niko, Alex
20
*/
21

  
6 22
extern void blink(int);
7 23
extern void search(void);
8 24
extern void approach(void);
......
29 45

  
30 46

  
31 47

  
32
void blink(int num)
33
{
48
void blink(int num)						// blinks the number of times specifed, with the orbs.
49
{										// useful for error checking.
34 50
	for(int i = 0; i<num; i++)
35 51
	{
36 52
		orb_set_color(ORB_OFF);
......
63 79
	}
64 80
	motors_off();
65 81
}
66
void approach()
82
void approach()					// drives to the right distance.
67 83
{
68 84
	int dist = 0;
69 85
	int temp = 0;
70 86
	int counter = 0;
71 87
//	int correct = 0;
72 88
	
73
	while(dist != RADIUS)	//puts the robots in the given distance RADIUS
89
	while(dist != RADIUS)		//puts the robots in the given distance RADIUS
74 90
	{
75 91
		temp=0;
76 92
		counter = 0;
77 93
		
78
		while(counter<8)
94
		while(counter<8)		// averages the first 8 legitimate (non -1) readings
79 95
		{
80 96
			if(range_read_distance(IR2) == -1){}
81 97
			
......
102 118
			top = bom_get_max();
103 119
		}	
104 120
		
105
		if ( dist<(RADIUS+30) && dist>(RADIUS-30)) {	// the dead zone
121
		if ( dist<(RADIUS+30) && dist>(RADIUS-30)) {	// defines the dead zone +- 30 from the given radius
106 122
			orb_set_color(RED);
107 123
			break;
108 124
		}
......
144 160
	usb_puti(range_read_distance(IR2));
145 161
	usb_puts("\n\r");*/
146 162
}
147
void lastDrive()
163
void lastDrive()					// used for the final drive in lab1 and not useful here; control loop code may be recycled.
148 164
{
149 165
	int lspeed = 190;
150 166
	int rspeed = 190;
......
170 186
		usb_puti(rvel);
171 187
		usb_puts("\n\r\n\r");
172 188
		
173
		if (rvel<lvel)
189
		if (rvel<lvel)					// adjust the speeds if the encoders have a mismatch.
174 190
		{
175 191
			rspeed += 1;
176 192
			lspeed -= 1;
trunk/code/behaviors/formation_control/circle2/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