Project

General

Profile

Revision 337

Minor updates to recharging, but the charging board no longer appears to tell us when we're done.

View differences:

branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wireless.h
1 1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
2 27
 * @file wireless.h
3 28
 * @brief Contains definitions for the wireless library.
4 29
 *
......
93 118
} PacketGroupHandler;
94 119

  
95 120
/**@brief Initialize the wireless library **/
96
void wl_init(void);
121
int wl_init(void);
97 122
/**@brief Uninitialize the wireless library **/
98 123
void wl_terminate(void);
99 124
/**@brief Perform wireless library functionality **/
......
125 150
/**@brief Get the channel we are using **/
126 151
int wl_get_channel(void);
127 152
/**@brief Get the 16-bit address of the XBee module **/
128
unsigned int wl_get_xbee_id(void);
153
int wl_get_xbee_id(void);
154
/**@brief Set the com port on a computer, undefined on the robot.**/
155
void wl_set_com_port(char* port);
129 156

  
130 157
/** @} **/ // end defgroup
131 158

  
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/xbee.c
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file xbee.c
28
 * @brief XBee Interface
29
 *
30
 * Implementation of low level communication with the XBee in API mode.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
1 35
#include "xbee.h"
2 36
#include "wl_defs.h"
3 37

  
......
7 41
#include <unistd.h>
8 42
#include <pthread.h>
9 43
#include <errno.h>
44
#include <termios.h>
10 45

  
11 46
#else
12 47

  
......
19 54
#include <stdlib.h>
20 55
#include <string.h>
21 56

  
22
#include <queue.h>
23

  
24 57
#define XBEE_FRAME_START 0x7E
25 58

  
26 59
/*Frame Types*/
......
49 82
void xbee_enter_command_mode(void);
50 83
void xbee_exit_command_mode(void);
51 84
void xbee_enter_api_mode(void);
85
void xbee_exit_api_mode(void);
52 86
void xbee_wait_for_string(char* s, int len);
53 87
void xbee_wait_for_ok(void);
54 88

  
......
67 101
/*Global Variables*/
68 102

  
69 103
#ifndef ROBOT
104
char* xbee_com_port = XBEE_PORT_DEFAULT;
70 105
int xbee_stream;
71 106
pthread_t* xbee_listen_thread;
72 107
#endif
73 108

  
74
Queue* xbee_queue;
109
// TODO: is this a good size?
110
#define XBEE_BUFFER_SIZE	256
111
// a buffer for data received from the XBee
112
char arrival_buf[XBEE_BUFFER_SIZE];
113
// location of last unread byte in buffer
114
volatile int buffer_last = 0;
115
// first unread byte in buffer
116
volatile int buffer_first = 0;
75 117

  
118

  
76 119
//used to store packets as they are read
77 120
char xbee_buf[128];
78 121
int currentBufPos = 0;
......
90 133

  
91 134
/**
92 135
 * Interrupt for the robot. Adds bytes received from the xbee
93
 * to the queue.
136
 * to the buffer.
94 137
 **/
95 138
#ifndef FIREFLY
96 139
ISR(USART1_RX_vect)
97 140
{
98 141
	char c = UDR1;
99
	queue_add(xbee_queue, (void*)(int)c);
142
	arrival_buf[buffer_last] = c;
143
	int t = buffer_last + 1;
144
	if (t == XBEE_BUFFER_SIZE)
145
		t = 0;
146
	if (t == buffer_first)
147
	{
148
		WL_DEBUG_PRINT("Out of space in buffer.\n");
149
	}
150
	buffer_last = t;
100 151
}
101 152
#else
102 153
SIGNAL(SIG_USART0_RECV)
103 154
{
104 155
	char c = UDR0;
105
	queue_add(xbee_queue, (void*)(int)c);
156
	arrival_buf[buffer_last] = c;
157
	int t = buffer_last + 1;
158
	if (t == XBEE_BUFFER_SIZE)
159
		t = 0;
160
	if (t == buffer_first)
161
	{
162
		WL_DEBUG_PRINT("Out of space in buffer.\n");
163
	}
164
	buffer_last = t;
106 165
}
107 166
#endif
108 167

  
......
117 176
	while (1)
118 177
	{
119 178
		xbee_read(&c, 1);
120
		queue_add(xbee_queue, (void*)(int)c);
179
		arrival_buf[buffer_last] = c;
180
		int t = buffer_last + 1;
181
		if (t == XBEE_BUFFER_SIZE)
182
			t = 0;
183
		if (t == buffer_first)
184
		{
185
			WL_DEBUG_PRINT("Out of space in buffer.\n");
186
		}
187
		buffer_last = t;
121 188
	}
122 189
	return 0;
123 190
}
......
126 193

  
127 194
/**
128 195
 * Initializes the XBee library so that other functions may be used.
129
 *
130
 * @param pan_id the PAN to join initially. Use XBEE_PAN_DEFAULT
131
 * to leave the PAN as it is initially.
132 196
 **/
133
void xbee_lib_init(void)
197
int xbee_lib_init(void)
134 198
{
135
	xbee_queue = queue_create();
136
	
199
	arrival_buf[0] = 'A';
200
	arrival_buf[1] = 'A';
201
	arrival_buf[2] = 'A';
137 202
	#ifdef ROBOT
138 203

  
139 204
	//enable the receiving interrupt
......
144 209
	#endif
145 210
	sei();
146 211
	#else
147
	xbee_stream = open(XBEE_PORT, O_RDWR);
148
	if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0)
149
		xbee_stream = open(XBEE_PORT2, O_RDWR);
150
	if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0)
212
	printf("Connecting to port %s.\n", xbee_com_port);
213
	xbee_stream = open(xbee_com_port, O_RDWR);
214
	if (xbee_stream == -1/* || lockf(xbee_stream, F_TEST, 0) != 0*/)
151 215
	{
152
		printf("Failed to open connection to XBee.\r\n");
153
		exit(0);
216
		printf("Failed to open connection to XBee on port %s\r\n", xbee_com_port);
217
		return -1;
154 218
	}
155
	lockf(xbee_stream, F_LOCK, 0);
156 219
	
220
	// set baud rate, etc. correctly
221
	struct termios options;
222

  
223
	tcgetattr(xbee_stream, &options);
224
	cfsetispeed(&options, B9600);
225
	cfsetospeed(&options, B9600);
226
	options.c_iflag &= ~ICRNL;
227
	options.c_oflag &= ~OCRNL;
228
	options.c_cflag |= (CLOCAL | CREAD);
229
	options.c_cflag &= ~PARENB;
230
	options.c_cflag &= ~CSTOPB;
231
	options.c_cflag &= ~CSIZE;
232
	options.c_cflag |= CS8;
233
	options.c_lflag &= ~ICANON;
234
	options.c_cc[VMIN] = 1;
235
	options.c_cc[VTIME] = 50;
236

  
237
	if (tcsetattr(xbee_stream, TCSANOW, &options))
238
	{
239
		fprintf(stderr, "Error setting attributes.\n");
240
		return -1;
241
	}
242

  
243
	//lockf(xbee_stream, F_LOCK, 0);
244
	
157 245
	xbee_listen_thread =
158 246
		(pthread_t*)malloc(sizeof(pthread_t));
247
	if (xbee_listen_thread == NULL)
248
	{
249
		fprintf(stderr, "%s: Malloc failed.\n", __FUNCTION__);
250
		return -1;
251
	}
159 252
	
160
	int ret = pthread_create(xbee_listen_thread, NULL, 
253
	int ret = pthread_create(xbee_listen_thread, NULL,
161 254
		listen_to_xbee, NULL);
162 255
	if (ret)
163 256
	{
164
		printf("Failed to create listener thread.\r\n");
165
		exit(0);
257
		fprintf(stderr, "Failed to create listener thread.\r\n");
258
		return -1;
166 259
	}
260
	
167 261
	#endif
168 262
	xbee_enter_command_mode();
169 263
	xbee_enter_api_mode();
......
172 266
	
173 267
	//wait to return until the address is set
174 268
	while (xbee_address == 0) xbee_get_packet(NULL);
269

  
270

  
271
	return 0;
175 272
}
176 273

  
177 274
/**
......
186 283
	lockf(xbee_stream, F_ULOCK, 0);
187 284
	close(xbee_stream);
188 285
	#endif
189
	queue_destroy(xbee_queue);
190 286
}
191 287

  
192 288
/**
......
270 366
}
271 367

  
272 368
/**
369
 * Exit API mode. (warning - does not check for response)
370
 **/
371
void xbee_exit_api_mode()
372
{
373
	xbee_send_string("ATAP 0\r");
374
}
375

  
376
/**
273 377
 * Wait until the string "OK\r" is received from the XBee.
274 378
 **/
275 379
void xbee_wait_for_ok()
......
289 393
	char* curr = s;
290 394
	while (curr - s < len)
291 395
	{
292
		if (queue_is_empty(xbee_queue))
396
		// check if buffer is empty
397
		if (buffer_last == buffer_first)
293 398
			continue;
294
		char c = (char)(int)queue_remove(xbee_queue);
399
		char c = arrival_buf[buffer_first++];
400
		if (buffer_first == XBEE_BUFFER_SIZE)
401
			buffer_first = 0;
295 402
		if (c == *curr)
296 403
			curr++;
297 404
		else
......
499 606
	if (currentBufPos == 0)
500 607
	{
501 608
		do
502
			if (queue_is_empty(xbee_queue))
609
		{
610
			if (buffer_first == XBEE_BUFFER_SIZE)
611
				buffer_first = 0;
612
			// check if buffer is empty
613
			if (buffer_first == buffer_last)
503 614
				return -1;
504
		while ((char)(int)queue_remove(xbee_queue) != XBEE_FRAME_START);
615
		}
616
		while (arrival_buf[buffer_first++] != XBEE_FRAME_START);
617
		if (buffer_first == XBEE_BUFFER_SIZE)
618
			buffer_first = 0;
505 619
		xbee_buf[0] = XBEE_FRAME_START;
506 620
		currentBufPos++;
507 621
	}
......
523 637
				return -1;
524 638
			}
525 639
		}
526
		if (queue_is_empty(xbee_queue))
640
		// check if buffer is empty
641
		if (buffer_first == buffer_last)
527 642
			return -1;
528
		xbee_buf[currentBufPos++] = (char)(int)queue_remove(xbee_queue);
643
		xbee_buf[currentBufPos++] = arrival_buf[buffer_first++];
644
		if (buffer_first == XBEE_BUFFER_SIZE)
645
			buffer_first = 0;
529 646
	}
530 647
	
531 648
	currentBufPos = 0;
......
748 865
	return xbee_address;
749 866
}
750 867

  
868
#ifndef ROBOT
869
void xbee_set_com_port(char* port)
870
{
871
	xbee_com_port = port;
872
}
873
#endif
874

  
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/xbee.h
1 1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
2 27
 * @file xbee.h
3 28
 * @brief Contains definitions for using the XBee
4 29
 *
......
18 43
 * Also, a backup port if the other is used.
19 44
 **/
20 45
#ifndef ROBOT
21
#ifndef XBEE_PORT
22
#define XBEE_PORT "/dev/ttyUSB1"
46
#define XBEE_PORT_DEFAULT "/dev/ttyUSB1"
23 47
#endif
24
#define XBEE_PORT2 "/dev/ttyUSB0"
25
#endif
26 48

  
27 49
/**
28 50
 * @defgroup xbee XBee
......
52 74
#define XBEE_RX 0x81
53 75

  
54 76
/**@brief Initialize the XBee library **/
55
void xbee_lib_init(void);
77
int xbee_lib_init(void);
56 78
/**@brief Uninitialize the XBee library **/
57 79
void xbee_terminate(void);
58 80
/**@brief Get a packet from the XBee **/
......
70 92
int xbee_get_channel(void);
71 93
/**@brief Get the XBee's 16-bit address **/
72 94
unsigned int xbee_get_address(void);
95
/**@brief Set the com port on a computer, undefined on the robot**/
96
void xbee_set_com_port(char* port);
73 97

  
74 98
/**@}**/ //end defgroup
75 99

  
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/Makefile
202 202
AVRDUDE_PROGRAMMER = avrisp
203 203

  
204 204
# com1 = serial port. Use lpt1 to connect to parallel port.
205
AVRDUDE_PORT = /dev/ttyUSB2
205
AVRDUDE_PORT = /dev/ttyUSB1
206 206
# programmer connected to serial device
207 207

  
208 208
AVRDUDE_WRITE_FLASH = -b 9600 -U flash:w:$(TARGET).hex
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/sensor_matrix.c
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file sensor_matrix.c
28
 * @brief Sensor Matrix implementation
29
 *
30
 * Implementation of a sensor matrix for storing localization implementation.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
1 35
#include <stdlib.h>
2 36
#include <stdio.h>
3 37
#include <wl_defs.h>
......
65 99
 * @param m the sensor matrix
66 100
 * @param id the XBee ID of the robot to add
67 101
 **/
68
void sensor_matrix_add_robot(SensorMatrix* m, unsigned int id)
102
void sensor_matrix_add_robot(SensorMatrix* m, int id)
69 103
{
70 104
	int i;
71 105
	if (id >= m->size)
......
92 126
 * @param m the sensor matrix
93 127
 * @param id the XBee ID of the robot to remove
94 128
 **/
95
void sensor_matrix_remove_robot(SensorMatrix* m, unsigned int id)
129
void sensor_matrix_remove_robot(SensorMatrix* m, int id)
96 130
{
97 131
	int i;
98 132

  
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_token_ring.c
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_token_ring.c
28
 * @brief Token Ring Implementation
29
 *
30
 * Implementation of the token ring packet group.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
1 35
#include <wl_token_ring.h>
2 36

  
3 37
#include <stdlib.h>
......
296 330
 **/
297 331
int wl_token_get_sensor_reading(int source, int dest)
298 332
{
299
	return sensor_matrix_get_reading(sensorMatrix, source, dest);
333
	if (wl_token_is_robot_in_ring(dest) &&
334
			(source == wl_get_xbee_id() || wl_token_is_robot_in_ring(source)))
335
		return sensor_matrix_get_reading(sensorMatrix, source, dest);
336
	return -1;
300 337
}
301 338

  
302 339
/**
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/sensor_matrix.h
1 1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
2 27
 * @file sensor_matrix.h
3 28
 * @brief Definitions for sensor matrices
4 29
 *
......
31 56
	/**
32 57
	 * The size of the sensor matrix.
33 58
	**/
34
	unsigned int size;
59
	int size;
35 60
	/**
36 61
	 * The matrix. Each row represents the readings of one
37 62
	 * robot.
......
53 78
/**@brief Destroy a sensor matrix **/
54 79
void sensor_matrix_destroy(SensorMatrix* m);
55 80
/**@brief Add a robot to a sensor matrix **/
56
void sensor_matrix_add_robot(SensorMatrix* m, unsigned int id);
81
void sensor_matrix_add_robot(SensorMatrix* m, int id);
57 82
/**@brief Remove a robot from a sensor matrix **/
58
void sensor_matrix_remove_robot(SensorMatrix* m, unsigned int id);
83
void sensor_matrix_remove_robot(SensorMatrix* m, int id);
59 84
/**@brief Set a reading in a sensor matrix **/
60 85
void sensor_matrix_set_reading(SensorMatrix* m, int observer, int robot, int reading);
61 86
/**@brief Get a reading in a sensor matrix **/
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_token_ring.h
1 1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
2 27
 * @file wl_token_ring.h
3 28
 * @brief Declarations for the token ring packet group
4 29
 * 
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_error_group.c
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_error_group.h
28
 * @brief Error Packets
29
 *
30
 * A wireless group for sending error packets.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
1 35
#include "wl_error_group.h"
2 36

  
3 37
#include <wireless.h>
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_error_group.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_error_group.h
28
 * @brief Error Packets
29
 *
30
 * A packet group for sending error packets.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
1 35
#ifndef WL_ERROR_GROUP_H
2 36
#define WL_ERROR_GROUP_H
3 37

  
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/main.c
18 18

  
19 19
	usb_puts("Initializing wireless.\n");
20 20
	wl_init();
21
	wl_set_channel(0xA);
21
	wl_set_channel(0xE);
22 22
	usb_puts("Wireless initialized.\n");
23 23
	wl_token_ring_register();
24 24
	wl_token_ring_join();
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_defs.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wl_defs.h
28
 * @brief Definitions for Wireless
29
 *
30
 * Contains definitions for wireless packet groups, packet types,
31
 * debugging information, etc.
32
 *
33
 * @author Brian Coltin, Colony Project, CMU Robotics Club
34
 **/
35

  
1 36
#ifndef WL_DEFS_H
2 37
#define WL_DEFS_H
3 38

  
......
24 59

  
25 60
// timing constants
26 61
#ifndef FIREFLY
27
#define BOM_DELAY 50
62
#define BOM_DELAY 100
28 63
#else
29
#define BOM_DELAY 100
64
#define BOM_DELAY 200
30 65
#endif
31 66

  
32 67
#define DEATH_DELAY 4
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wireless.c
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * @file wireless.c
28
 * @brief Wireless Library Implementation
29
 *
30
 * Implementation of the wireless library.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
1 35
#include "wireless.h"
2 36
#include "xbee.h"
3 37
#include <stdlib.h>
......
64 98
 * Initializes the wireless library. Must be called before any
65 99
 * other function.
66 100
 **/
67
void wl_init()
101
int wl_init()
68 102
{
69 103
	int i;
70 104
	for (i = 0; i < WL_MAX_PACKET_GROUPS; i++)
71 105
		wl_packet_groups[i] = NULL;
72 106

  
73
	xbee_lib_init();
74
	
107
	if (xbee_lib_init() == -1) {
108
	  return -1;
109
	}
110

  
75 111
	//begin timeout timer
76 112
	#ifdef ROBOT
77 113
	#ifdef FIREFLY
78 114
	rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
79 115
	#else
80
	rtc_init(HALF_SECOND, &timer_handler); 
116
	rtc_init(HALF_SECOND, &timer_handler);
81 117
	#endif
82 118
	#else
83
  
119

  
84 120
	//create our timer
85 121
	struct itimerval timer_val;
86 122
	struct timeval interval;
......
93 129
	timer_val.it_value = first_time;
94 130
	if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1)
95 131
	{
96
		WL_DEBUG_PRINT("Error creating a timer.\r\n"); 
132
		WL_DEBUG_PRINT("Error creating a timer.\r\n");
97 133
		perror("Failure's cause");
98
		exit(1); 
134
		exit(1);
99 135
	}
100 136

  
101 137
	//create signal handler
......
106 142
	sigaction(SIGALRM, &wl_sig_act, 0);
107 143
	sigaction(SIGINT, &wl_sig_act, 0);
108 144
	#endif
145

  
146
	return 0;
109 147
}
110 148

  
111 149
/**
......
118 156
		if (wl_packet_groups[i] != NULL &&
119 157
			wl_packet_groups[i]->unregister != NULL)
120 158
			wl_packet_groups[i]->unregister();
121
	
159

  
122 160
	xbee_terminate();
123 161
}
124 162

  
......
175 213
 *
176 214
 * @return the 16-bit address of the XBee module.
177 215
 **/
178
unsigned int wl_get_xbee_id()
216
int wl_get_xbee_id()
179 217
{
180 218
	return xbee_get_address();
181 219
}
......
242 280
void wl_send_pan_packet(char group, char type,
243 281
		char* data, int len, char frame)
244 282
{
245
	wl_send_packet(group, type, data, len, XBEE_BROADCAST, 
283
	wl_send_packet(group, type, data, len, XBEE_BROADCAST,
246 284
			XBEE_OPTIONS_NONE, frame);
247 285
}
248 286

  
......
295 333

  
296 334
/**
297 335
 * Unregister a packet group from the wireless library.
298
 * 
336
 *
299 337
 * @param h the packet group to remove
300 338
 **/
301 339
void wl_unregister_packet_group(PacketGroupHandler* h)
......
333 371
		wl_do_timeout();
334 372
		wl_timeout = 0;
335 373
	}
336
	
374

  
337 375
	int len = xbee_get_packet(wl_buf);
338 376
	if (len < 0)//no packet received
339 377
		return;
340
	
378

  
341 379
	if (wl_buf[0] == XBEE_TX_STATUS)
342 380
	{
343 381
		if (len != 3)
......
345 383
			WL_DEBUG_PRINT("Transmit Status packet should be of length 3.\r\n");
346 384
			return;
347 385
		}
348
		
386

  
349 387
		//the first four bits are the packet group
350 388
		//this only works with under 16 groups
351 389
		int group = (int)(wl_buf[1] >> 4);
......
364 402
				WL_DEBUG_PRINT("Purged\r\n");
365 403
			}
366 404
		}
367
		
405

  
368 406
		if (wl_packet_groups[group] != NULL &&
369 407
					wl_packet_groups[group]->handle_response != NULL)
370 408
			wl_packet_groups[group]->handle_response(
371 409
					(int)wl_buf[1] & 0x0F, success);
372 410
		return;
373 411
	}
374
	
412

  
375 413
	if (wl_buf[0] == XBEE_RX)
376 414
	{
377 415
		if (len < 7)
......
379 417
			WL_DEBUG_PRINT("Packet is too small.\r\n");
380 418
			return;
381 419
		}
382
		
420

  
383 421
		int source = ((int)wl_buf[1] << 8) + ((int)wl_buf[2]);
384
		
422

  
385 423
		/*
386 424
		//unused for now
387 425
		int signalStrength = wl_buf[3];
388 426
		//1 for Address broadcast, 2 for PAN broadcast
389 427
		int options = wl_buf[4];
390 428
		*/
391
		
429

  
392 430
		int group = wl_buf[5];
393 431
		int type = wl_buf[6];
394 432
		int packetLen = len - 7;
395
		
433

  
396 434
		if (wl_packet_groups[group] != NULL
397 435
				&& wl_packet_groups[group]->handle_receive != NULL)
398
			wl_packet_groups[group]->handle_receive(type, source, 
436
			wl_packet_groups[group]->handle_receive(type, source,
399 437
				wl_buf + 7, packetLen);
400 438
		return;
401 439
	}
402
	
440

  
403 441
	WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n");
404 442
	return;
405 443
}
406 444

  
445

  
446
#ifndef ROBOT
447
void wl_set_com_port(char* port)
448
{
449
	xbee_set_com_port(port);
450
}
451
#endif
452

  
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/homing.c
1 1
#include "homing.h"
2 2
#include "recharge_defs.h"
3 3

  
4
#include <serial.h>
5

  
4 6
// values for homing sensor readings
5 7
#define LEFT_LOW    6
6 8
#define LEFT_HIGH   8
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/main.c
12 12
int main(void)
13 13
{
14 14
	dragonfly_init(ALL_ON);
15
	//range_init();
16
	//orb_enable();
15
	range_init();
16
	orb_enable();
17 17
	usb_puts("Turned on!\n");
18 18
	wl_init();
19 19
	usb_puts("Wireless initialized!\n");
20
	wl_set_channel(0xA);
20
	wl_set_channel(0xE);
21 21
	//orb_set_color(YELLOW);
22 22
	wl_token_ring_register();
23 23
	//wl_token_ring_set_bom_functions(do_nothing2, do_nothing2, get_nothing2); 
24 24
	wl_token_ring_join();
25 25
	//usb_puts("Wireless initialized.\n");
26
	//recharge_init();
26
	recharge_init();
27 27
	//usb_puts("Recharging initialized.\n");
28
	run_around_init();
28
	//run_around_init();
29 29
	while (1)
30 30
	{
31 31
		wl_do();
32
		int i;
33
		for (i = 6; i > 0; i--)
34
		{
35
			usb_puti(analog_get8(i));
36
			usb_putc(' ');
37
		}
38
		usb_putc('\n');
39
		//int charging = recharge_do();
32
		int charging = recharge_do();
40 33
		//if (!charging)
41 34
		//{
42 35
			//analog8(IR1);
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/smart_run_around_fsm.c
55 55
  temp=range_read_distance(IR5);
56 56
  d5=(temp == -1) ? d5 : temp;
57 57
  
58
  usb_puti(d1);
59
  usb_putc(' ');
60
  usb_puti(d2);
61
  usb_putc(' ');
62
  usb_puti(d3);
63
  usb_putc('\n');
64
  
65 58
  //If the crazy count is in it's >>3 range, it acts crazy.
66 59
  if(crazy_count<=(CRAZY_MAX>>3))
67 60
  {
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/smart_run_around_fsm.h
16 16
#define BACKUP_MAX 20
17 17
#define CRAZY_MAX 200       //The number of counts between "crazy moments"
18 18
#define STRAIT_SPEED 185    //The speed when going strait or backing up.
19
#define TURN_CONSTANT 2
19
#define TURN_CONSTANT 4
20 20
#define PCONTROL_CRAZY_LIMIT 80
21 21

  
22 22
int avoid_state;    /*State machine variable.*/
branches/autonomous_recharging/code/projects/libwireless/test/test.c
12 12
{
13 13
	int robot = atoi(argv[1]);
14 14
	wl_init();
15
	wl_set_channel(0xA);
15
	wl_set_channel(0xE);
16 16
	printf("Wireless initialized.\n");
17 17
	printf("Packet groups initialized.\n");
18 18

  

Also available in: Unified diff