Revision 138
More progress on charging... Sometimes the token ring drops out.
trunk/code/lib/include/libwireless/wl_defs.h | ||
---|---|---|
2 | 2 |
//#define ROBOT |
3 | 3 |
|
4 | 4 |
//uncomment this line for debug information |
5 |
#define WL_DEBUG |
|
5 |
//#define WL_DEBUG
|
|
6 | 6 |
|
7 | 7 |
// Packet Groups and Types |
8 | 8 |
|
... | ... | |
23 | 23 |
|
24 | 24 |
// timing constants |
25 | 25 |
#define BOM_DELAY 100 |
26 |
#define DEATH_DELAY 3
|
|
26 |
#define DEATH_DELAY 4
|
|
27 | 27 |
#define JOIN_DELAY 8 |
28 | 28 |
|
29 | 29 |
// Recharging group |
trunk/code/lib/include/libwireless/xbee.h | ||
---|---|---|
11 | 11 |
**/ |
12 | 12 |
|
13 | 13 |
/** |
14 |
* The port to use the XBee from on the computer. |
|
15 |
* Also, a backup port if the other is used. |
|
16 |
**/ |
|
17 |
#ifndef ROBOT |
|
18 |
#ifndef XBEE_PORT |
|
19 |
#define XBEE_PORT "/dev/ttyUSB0" |
|
20 |
#endif |
|
21 |
#define XBEE_PORT2 "/dev/tty/USB1" |
|
22 |
#endif |
|
23 |
|
|
24 |
/** |
|
14 | 25 |
* @defgroup xbee XBee |
15 | 26 |
* @brief Interface with the XBee module |
16 | 27 |
* |
trunk/code/lib/src/libwireless/wl_token_ring.c | ||
---|---|---|
346 | 346 |
int i, j; |
347 | 347 |
deathDelay = -1; |
348 | 348 |
|
349 |
WL_DEBUG_PRINT("Received the token, next robot is "); |
|
349 |
WL_DEBUG_PRINT("Received the token from robot"); |
|
350 |
WL_DEBUG_PRINT_INT(source); |
|
351 |
WL_DEBUG_PRINT(", next robot is "); |
|
350 | 352 |
WL_DEBUG_PRINT_INT((int)nextRobot); |
351 | 353 |
WL_DEBUG_PRINT(" \r\n"); |
352 | 354 |
sensor_matrix_set_in_ring(sensorMatrix, source, 1); |
... | ... | |
516 | 518 |
WL_DEBUG_PRINT("Robot "); |
517 | 519 |
WL_DEBUG_PRINT_INT(source); |
518 | 520 |
WL_DEBUG_PRINT(" has flashed its bom.\r\n"); |
521 |
|
|
522 |
//make sure we don't declare the robot dead if it's |
|
523 |
//flashing its BOM |
|
524 |
if (source == wl_token_next_robot) |
|
525 |
deathDelay = DEATH_DELAY; |
|
519 | 526 |
sensor_matrix_set_reading(sensorMatrix, wl_get_xbee_id(), |
520 | 527 |
source, get_max_bom_function()); |
521 | 528 |
} |
trunk/code/lib/src/libwireless/xbee.c | ||
---|---|---|
144 | 144 |
#endif |
145 | 145 |
sei(); |
146 | 146 |
#else |
147 |
xbee_stream = open("/dev/ttyUSB0", O_RDWR);
|
|
147 |
xbee_stream = open(XBEE_PORT, O_RDWR);
|
|
148 | 148 |
if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0) |
149 |
xbee_stream = open("/dev/ttyUSB1", O_RDWR);
|
|
149 |
xbee_stream = open(XBEE_PORT2, O_RDWR);
|
|
150 | 150 |
if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0) |
151 | 151 |
{ |
152 | 152 |
printf("Failed to open connection to XBee.\r\n"); |
trunk/code/lib/src/libwireless/queue.c | ||
---|---|---|
24 | 24 |
Queue* queue_create() |
25 | 25 |
{ |
26 | 26 |
Queue* q = (Queue*)malloc(sizeof(Queue)); |
27 |
|
|
28 |
if (q == NULL) |
|
29 |
{ |
|
30 |
WL_DEBUG_PRINT("Out of memory.\r\n"); |
|
31 |
return NULL; |
|
32 |
} |
|
33 |
|
|
27 | 34 |
q->head = NULL; |
28 | 35 |
q->size = 0; |
29 | 36 |
return q; |
trunk/code/lib/src/libwireless/wireless.c | ||
---|---|---|
84 | 84 |
timer_val.it_interval = interval; |
85 | 85 |
timer_val.it_value = first_time; |
86 | 86 |
if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1) |
87 |
{
|
|
87 |
{ |
|
88 | 88 |
WL_DEBUG_PRINT("Error creating a timer.\r\n"); |
89 | 89 |
perror("Failure's cause"); |
90 | 90 |
exit(1); |
... | ... | |
105 | 105 |
**/ |
106 | 106 |
void wl_terminate() |
107 | 107 |
{ |
108 |
#ifndef ROBOT |
|
109 |
#ifdef _POSIX_TIMERS |
|
110 |
timer_delete(wl_timeout_timer); |
|
111 |
#endif |
|
112 |
#endif |
|
113 |
|
|
114 | 108 |
int i; |
115 | 109 |
for (i = 0; i < WL_MAX_PACKET_GROUPS; i++) |
116 | 110 |
if (wl_packet_groups[i] != NULL && |
... | ... | |
354 | 348 |
{ |
355 | 349 |
WL_DEBUG_PRINT("No response received.\r\n"); |
356 | 350 |
if (wl_buf[2] == 2) |
351 |
{ |
|
357 | 352 |
WL_DEBUG_PRINT("CCA Failure\r\n"); |
353 |
} |
|
358 | 354 |
if (wl_buf[2] == 3) |
355 |
{ |
|
359 | 356 |
WL_DEBUG_PRINT("Purged\r\n"); |
357 |
} |
|
360 | 358 |
} |
361 | 359 |
|
362 | 360 |
if (wl_packet_groups[group] != NULL && |
trunk/code/projects/libwireless/robotTest/main.c | ||
---|---|---|
6 | 6 |
{ |
7 | 7 |
dragonfly_init(ALL_ON); |
8 | 8 |
usb_puts("Start.\r\n"); |
9 |
orb_set_color(GREEN); |
|
9 | 10 |
wl_init(); |
11 |
orb_set_color(YELLOW); |
|
10 | 12 |
usb_puts("Wireless initialized.\n"); |
11 | 13 |
wl_token_ring_register(); |
12 | 14 |
wl_token_ring_join(); |
15 |
orb_set_color(CYAN); |
|
13 | 16 |
while (1) |
14 | 17 |
wl_do(); |
15 | 18 |
} |
trunk/code/projects/libwireless/lib/wl_token_ring.c | ||
---|---|---|
346 | 346 |
int i, j; |
347 | 347 |
deathDelay = -1; |
348 | 348 |
|
349 |
WL_DEBUG_PRINT("Received the token, next robot is "); |
|
349 |
WL_DEBUG_PRINT("Received the token from robot"); |
|
350 |
WL_DEBUG_PRINT_INT(source); |
|
351 |
WL_DEBUG_PRINT(", next robot is "); |
|
350 | 352 |
WL_DEBUG_PRINT_INT((int)nextRobot); |
351 | 353 |
WL_DEBUG_PRINT(" \r\n"); |
352 | 354 |
sensor_matrix_set_in_ring(sensorMatrix, source, 1); |
... | ... | |
516 | 518 |
WL_DEBUG_PRINT("Robot "); |
517 | 519 |
WL_DEBUG_PRINT_INT(source); |
518 | 520 |
WL_DEBUG_PRINT(" has flashed its bom.\r\n"); |
521 |
|
|
522 |
//make sure we don't declare the robot dead if it's |
|
523 |
//flashing its BOM |
|
524 |
if (source == wl_token_next_robot) |
|
525 |
deathDelay = DEATH_DELAY; |
|
519 | 526 |
sensor_matrix_set_reading(sensorMatrix, wl_get_xbee_id(), |
520 | 527 |
source, get_max_bom_function()); |
521 | 528 |
} |
trunk/code/projects/libwireless/lib/wl_defs.h | ||
---|---|---|
23 | 23 |
|
24 | 24 |
// timing constants |
25 | 25 |
#define BOM_DELAY 100 |
26 |
#define DEATH_DELAY 3
|
|
26 |
#define DEATH_DELAY 4
|
|
27 | 27 |
#define JOIN_DELAY 8 |
28 | 28 |
|
29 | 29 |
// Recharging group |
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_token_ring.c | ||
---|---|---|
238 | 238 |
switch (type) |
239 | 239 |
{ |
240 | 240 |
case WL_TOKEN_PASS: |
241 |
usb_puts("received token pass from robot\n"); |
|
242 | 241 |
if (length < 1) |
243 | 242 |
{ |
244 | 243 |
WL_DEBUG_PRINT("Malformed Token Pass packet received.\r\n"); |
... | ... | |
247 | 246 |
wl_token_pass_receive(source, packet[0], packet + 1, length - 1); |
248 | 247 |
break; |
249 | 248 |
case WL_TOKEN_BOM_ON: |
250 |
usb_puts("received bom on from robot\n"); |
|
251 | 249 |
//add the robot to the sensor matrix if it is not already there |
252 | 250 |
wl_token_bom_on_receive(source); |
253 | 251 |
break; |
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_defs.h | ||
---|---|---|
23 | 23 |
|
24 | 24 |
// timing constants |
25 | 25 |
#define BOM_DELAY 200 |
26 |
#define DEATH_DELAY 3
|
|
26 |
#define DEATH_DELAY 5
|
|
27 | 27 |
#define JOIN_DELAY 8 |
28 | 28 |
|
29 | 29 |
// Recharging group |
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wireless.c | ||
---|---|---|
68 | 68 |
//begin timeout timer |
69 | 69 |
#ifdef ROBOT |
70 | 70 |
#ifdef FIREFLY |
71 |
rtc_init(PRESCALE_DIV_128, 32, &wl_do_timeout);
|
|
71 |
rtc_init(PRESCALE_DIV_256, 32, &wl_do_timeout);
|
|
72 | 72 |
#else |
73 | 73 |
rtc_init(HALF_SECOND, &wl_do_timeout); |
74 | 74 |
#endif |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/main.c | ||
---|---|---|
6 | 6 |
|
7 | 7 |
int main(void) |
8 | 8 |
{ |
9 |
dragonfly_init(ALL_ON ^ ORB);
|
|
9 |
dragonfly_init(ALL_ON); |
|
10 | 10 |
usb_puts("Initializing wireless.\n"); |
11 | 11 |
wl_init(); |
12 | 12 |
//orb_set_color(YELLOW); |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/seeking.c | ||
---|---|---|
67 | 67 |
|
68 | 68 |
//check if we can use homing sensor |
69 | 69 |
int widthcount = recharge_i2c_get_homing_reading(); |
70 |
//RECHARGE_DEBUG_PUTI(widthcount); |
|
71 | 70 |
|
72 | 71 |
if(widthcount>= 4) |
73 | 72 |
return SEEK_WITH_HOMING; |
... | ... | |
78 | 77 |
{ |
79 | 78 |
//TODO: create function in homing.h to return LEFT, FORWARD, RIGHT, or NONE |
80 | 79 |
int widthcount = recharge_i2c_get_homing_reading(); |
81 |
RECHARGE_DEBUG_PRINT("Homing sensor: "); |
|
82 |
RECHARGE_DEBUG_PUTI(widthcount); |
|
83 |
RECHARGE_DEBUG_PRINT("\n"); |
|
84 | 80 |
|
85 | 81 |
if (widthcount < LEFT_LOW) //can't use beacon, switch to BOM |
86 | 82 |
return SEEK_WITH_BOM; |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/Makefile | ||
---|---|---|
15 | 15 |
USE_WIRELESS = 1 |
16 | 16 |
|
17 | 17 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
18 |
AVRDUDE_PORT = /dev/ttyUSB0
|
|
18 |
AVRDUDE_PORT = /dev/ttyUSB2
|
|
19 | 19 |
# |
20 | 20 |
# |
21 | 21 |
################################### |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/recharge_i2c.c | ||
---|---|---|
59 | 59 |
if(recharge_i2c_prev_byte == I2C_MSG_HOMING_DATA) |
60 | 60 |
{ |
61 | 61 |
recharge_i2c_homing_sensor_data = i2c_byte; |
62 |
RECHARGE_DEBUG_PRINT("Update"); |
|
63 |
RECHARGE_DEBUG_PUTI(i2c_byte); |
|
64 |
RECHARGE_DEBUG_PRINT("\n"); |
|
65 | 62 |
recharge_i2c_prev_byte = i2c_byte; |
66 | 63 |
return; |
67 | 64 |
} |
Also available in: Unified diff