Revision 340
We're ready to do a two robot autonomous recharging video with run around, aside from some docking problems. There seem to be wireless issues with three robots, however.
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/wl_recharge_group.c | ||
---|---|---|
353 | 353 |
if (recharge_state == NOT_RECHARGING) |
354 | 354 |
wl_recharge_begin(); |
355 | 355 |
break; |
356 |
case 10: |
|
357 |
if (recharge_state == DOCKED) |
|
358 |
wl_recharge_depart(); |
|
359 |
break; |
|
356 | 360 |
default: |
357 | 361 |
RECHARGE_DEBUG_PRINT("Error packet of unknown type received.\n"); |
358 | 362 |
break; |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/departing.c | ||
---|---|---|
31 | 31 |
**/ |
32 | 32 |
int depart_station(void) |
33 | 33 |
{ |
34 |
//TODO: use rangefinders to depart |
|
35 | 34 |
int front_distance = range_read_distance(IR2); |
36 | 35 |
|
37 | 36 |
if(front_distance != -1 && front_distance < 160) |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/main.c | ||
---|---|---|
18 | 18 |
wl_init(); |
19 | 19 |
usb_puts("Wireless initialized!\n"); |
20 | 20 |
wl_set_channel(0xE); |
21 |
//orb_set_color(YELLOW); |
|
22 | 21 |
wl_token_ring_register(); |
23 |
//wl_token_ring_set_bom_functions(do_nothing2, do_nothing2, get_nothing2); |
|
24 | 22 |
wl_token_ring_join(); |
25 |
//usb_puts("Wireless initialized.\n"); |
|
26 | 23 |
recharge_init(); |
27 |
//usb_puts("Recharging initialized.\n");
|
|
28 |
//run_around_init();
|
|
24 |
usb_puts("Recharging initialized.\n"); |
|
25 |
run_around_init(); |
|
29 | 26 |
while (1) |
30 | 27 |
{ |
31 | 28 |
wl_do(); |
32 | 29 |
int charging = recharge_do(); |
33 |
//if (!charging) |
|
34 |
//{ |
|
35 |
//analog8(IR1); |
|
36 |
//run_around_FSM(); |
|
37 |
//} |
|
30 |
if (!charging) |
|
31 |
{ |
|
32 |
run_around_FSM(); |
|
33 |
} |
|
38 | 34 |
} |
39 | 35 |
|
40 | 36 |
return 0; |
branches/autonomous_recharging/code/projects/autonomous_recharging/dragonfly/recharge_defs.h | ||
---|---|---|
1 |
#define RECHARGE_DEBUG |
|
1 |
//#define RECHARGE_DEBUG
|
|
2 | 2 |
|
3 | 3 |
#ifdef RECHARGE_DEBUG |
4 | 4 |
#define RECHARGE_DEBUG_PRINT( s ) usb_puts( s ) |
branches/autonomous_recharging/code/projects/libwireless/test/test.c | ||
---|---|---|
10 | 10 |
|
11 | 11 |
int main(int argc, char** argv) |
12 | 12 |
{ |
13 |
int robot = atoi(argv[1]); |
|
13 |
char c = argv[1][0]; |
|
14 |
int robot = atoi(argv[2]); |
|
15 |
wl_set_com_port("/dev/ttyUSB0"); |
|
14 | 16 |
wl_init(); |
15 | 17 |
wl_set_channel(0xE); |
16 | 18 |
printf("Wireless initialized.\n"); |
17 | 19 |
printf("Packet groups initialized.\n"); |
18 | 20 |
|
19 |
wl_send_robot_to_robot_global_packet(3, 9, NULL, 0, robot, 0); |
|
21 |
if (c == 'g') |
|
22 |
wl_send_robot_to_robot_global_packet(3, 9, NULL, 0, robot, 0); |
|
23 |
if (c == 'd') |
|
24 |
wl_send_robot_to_robot_global_packet(3, 10, NULL, 0, robot, 0); |
|
20 | 25 |
|
21 | 26 |
wl_terminate(); |
22 | 27 |
|
branches/autonomous_recharging/code/projects/libwireless/test/Makefile | ||
---|---|---|
4 | 4 |
all: test |
5 | 5 |
|
6 | 6 |
test: *.c ../lib/*.c |
7 |
$(CC) $(CFLAGS) *.c -L../lib -o test -pthread -lrt -lwireless |
|
7 |
$(CC) $(CFLAGS) *.c -L../lib -I../lib -o test -pthread -lrt -lwireless
|
|
8 | 8 |
|
9 | 9 |
clean: |
10 | 10 |
rm *.o test ../lib/*.o |
branches/autonomous_recharging/code/projects/libwireless/lib/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> |
... | ... | |
6 | 40 |
#include <wl_defs.h> |
7 | 41 |
#include <wireless.h> |
8 | 42 |
#include <sensor_matrix.h> |
9 |
#include <queue.h> |
|
10 | 43 |
|
11 | 44 |
#ifdef ROBOT |
12 | 45 |
#ifndef FIREFLY |
... | ... | |
44 | 77 |
|
45 | 78 |
/*Packet Handling Routines*/ |
46 | 79 |
void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength); |
47 |
void wl_token_interrupt_request_receive(int source, int robot); |
|
48 |
void wl_token_interrupt_pass_receive(int source, int robot); |
|
49 | 80 |
void wl_token_bom_on_receive(int source); |
50 | 81 |
void wl_token_join_receive(int source); |
51 | 82 |
void wl_token_join_accept_receive(int source); |
... | ... | |
69 | 100 |
int deathDelay = -1; |
70 | 101 |
//the counter for joining, before we form our own token ring |
71 | 102 |
int joinDelay = -1; |
72 |
//queue containing ids of interruption requests |
|
73 |
Queue* interrupting = NULL; |
|
74 | 103 |
|
75 | 104 |
//current robot to check in the iterator |
76 | 105 |
int iteratorCount = 0; |
77 | 106 |
|
107 |
// the amount of time a robot has had its BOM on for |
|
108 |
int bom_on_count = 0; |
|
109 |
|
|
78 | 110 |
void do_nothing(void) {} |
79 | 111 |
int get_nothing(void) {return -1;} |
80 | 112 |
|
... | ... | |
116 | 148 |
} |
117 | 149 |
|
118 | 150 |
sensorMatrix = sensor_matrix_create(); |
119 |
interrupting = queue_create(); |
|
120 | 151 |
//add ourselves to the sensor matrix |
121 | 152 |
sensor_matrix_set_in_ring(sensorMatrix, wl_get_xbee_id(), 0); |
122 | 153 |
|
... | ... | |
157 | 188 |
void wl_token_ring_cleanup() |
158 | 189 |
{ |
159 | 190 |
sensor_matrix_destroy(sensorMatrix); |
160 |
queue_destroy(interrupting); |
|
161 | 191 |
} |
162 | 192 |
|
163 | 193 |
/** |
... | ... | |
176 | 206 |
WL_DEBUG_PRINT("Robot "); |
177 | 207 |
WL_DEBUG_PRINT_INT(wl_token_next_robot); |
178 | 208 |
WL_DEBUG_PRINT(" has died.\r\n"); |
209 |
wl_token_next_robot = -1; |
|
210 |
deathDelay = DEATH_DELAY; |
|
179 | 211 |
} |
180 | 212 |
|
181 | 213 |
// we may have been dropped from the ring when this is received |
... | ... | |
209 | 241 |
deathDelay--; |
210 | 242 |
if (joinDelay >= 0) |
211 | 243 |
joinDelay--; |
244 |
if (bom_on_count >= 0) |
|
245 |
bom_on_count++; |
|
212 | 246 |
} |
213 | 247 |
|
214 | 248 |
/** |
... | ... | |
249 | 283 |
//add the robot to the sensor matrix if it is not already there |
250 | 284 |
wl_token_bom_on_receive(source); |
251 | 285 |
break; |
252 |
case WL_TOKEN_INTERRUPT_REQUEST: |
|
253 |
wl_token_interrupt_request_receive(source, packet[0]); |
|
254 |
break; |
|
255 |
case WL_TOKEN_INTERRUPT_PASS: |
|
256 |
wl_token_interrupt_pass_receive(source, packet[0]); |
|
257 |
break; |
|
258 | 286 |
case WL_TOKEN_JOIN: |
259 | 287 |
wl_token_join_receive(source); |
260 | 288 |
break; |
... | ... | |
276 | 304 |
{ |
277 | 305 |
WL_DEBUG_PRINT("Joining the token ring.\r\n"); |
278 | 306 |
ringState = JOINING; |
279 |
joinDelay = JOIN_DELAY;
|
|
307 |
joinDelay = DEATH_DELAY * 2;
|
|
280 | 308 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_JOIN, |
281 | 309 |
NULL, 0, 0); |
282 | 310 |
} |
... | ... | |
292 | 320 |
} |
293 | 321 |
|
294 | 322 |
/** |
295 |
* Requests that the specified robot be given the token and |
|
296 |
* allowed to flash its BOM. After its BOM is flashed, the |
|
297 |
* token will return to the robot who sent it. |
|
298 |
* |
|
299 |
* @param robot the ID of the robot which should flash its BOM |
|
300 |
**/ |
|
301 |
void wl_token_request(int robot) |
|
302 |
{ |
|
303 |
char buf[1]; |
|
304 |
buf[0] = robot; |
|
305 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_INTERRUPT_REQUEST, |
|
306 |
buf, 1, 0); |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 | 323 |
* Returns the BOM reading robot source has for robot dest. |
311 | 324 |
* |
312 | 325 |
* @param source the robot that made the BOM reading |
... | ... | |
317 | 330 |
**/ |
318 | 331 |
int wl_token_get_sensor_reading(int source, int dest) |
319 | 332 |
{ |
320 |
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; |
|
321 | 337 |
} |
322 | 338 |
|
323 | 339 |
/** |
... | ... | |
344 | 360 |
void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength) |
345 | 361 |
{ |
346 | 362 |
int i, j; |
363 |
|
|
364 |
// this prevents two tokens from being passed around at a time (second clause is in case we are joining) |
|
365 |
if (source != wl_token_next_robot && bom_on_count <= DEATH_DELAY / 2 && |
|
366 |
ringState != ACCEPTED) |
|
367 |
{ |
|
368 |
WL_DEBUG_PRINT("Received token pass when a robot should not have died yet.\n"); |
|
369 |
WL_DEBUG_PRINT("There are probably two tokens going around, packet ignored.\n"); |
|
370 |
return; |
|
371 |
} |
|
372 |
|
|
373 |
bom_on_count = -1; |
|
347 | 374 |
deathDelay = -1; |
348 |
|
|
349 |
WL_DEBUG_PRINT("Received the token, next robot is "); |
|
375 |
WL_DEBUG_PRINT("Received the token from robot"); |
|
376 |
WL_DEBUG_PRINT_INT(source); |
|
377 |
WL_DEBUG_PRINT(", next robot is "); |
|
350 | 378 |
WL_DEBUG_PRINT_INT((int)nextRobot); |
351 | 379 |
WL_DEBUG_PRINT(" \r\n"); |
352 | 380 |
sensor_matrix_set_in_ring(sensorMatrix, source, 1); |
... | ... | |
516 | 544 |
WL_DEBUG_PRINT("Robot "); |
517 | 545 |
WL_DEBUG_PRINT_INT(source); |
518 | 546 |
WL_DEBUG_PRINT(" has flashed its bom.\r\n"); |
547 |
|
|
548 |
bom_on_count = 0; |
|
549 |
|
|
519 | 550 |
sensor_matrix_set_reading(sensorMatrix, wl_get_xbee_id(), |
520 | 551 |
source, get_max_bom_function()); |
521 | 552 |
} |
... | ... | |
536 | 567 |
wl_get_xbee_id(), 1); |
537 | 568 |
WL_DEBUG_PRINT("Now a member of the token ring.\r\n"); |
538 | 569 |
ringState = MEMBER; |
570 |
joinDelay = -1; |
|
539 | 571 |
} |
540 | 572 |
|
541 | 573 |
if (ringState == LEAVING || ringState == NONMEMBER) |
... | ... | |
548 | 580 |
return; |
549 | 581 |
} |
550 | 582 |
|
551 |
//check for interruption requests |
|
552 |
if (queue_size(interrupting) > 0) |
|
553 |
{ |
|
554 |
char buf[1]; |
|
555 |
buf[0] = (char)(int)queue_remove(interrupting); |
|
556 |
|
|
557 |
//in case this robot has requested multiple times |
|
558 |
queue_remove_all(interrupting, (void*)(int)buf[0]); |
|
559 |
|
|
560 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_INTERRUPT_PASS, |
|
561 |
buf, 1, 0); |
|
562 |
|
|
563 |
deathDelay = DEATH_DELAY; |
|
564 |
wl_token_next_robot = buf[0]; |
|
565 |
return; |
|
566 |
} |
|
567 |
|
|
568 | 583 |
WL_DEBUG_PRINT("Our BOM has been flashed.\r\n"); |
569 | 584 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_BOM_ON, |
570 | 585 |
NULL, 0, 0); |
... | ... | |
578 | 593 |
if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id())) |
579 | 594 |
{ |
580 | 595 |
WL_DEBUG_PRINT("Removed from sensor matrix while flashing BOM.\r\n"); |
596 |
return; |
|
581 | 597 |
} |
582 | 598 |
|
583 | 599 |
wl_token_pass_token(); |
... | ... | |
631 | 647 |
WL_DEBUG_PRINT_INT(source); |
632 | 648 |
WL_DEBUG_PRINT(" into the token ring.\r\n"); |
633 | 649 |
|
634 |
joinDelay = -1; |
|
635 |
|
|
636 | 650 |
// the token ring has not started yet |
637 | 651 |
if (sensor_matrix_get_joined(sensorMatrix) == 1) |
638 | 652 |
wl_token_pass_token(); |
... | ... | |
650 | 664 |
WL_DEBUG_PRINT("Accepted into the token ring by robot "); |
651 | 665 |
WL_DEBUG_PRINT_INT(source); |
652 | 666 |
WL_DEBUG_PRINT(".\r\n"); |
653 |
joinDelay = -1;
|
|
667 |
joinDelay = JOIN_DELAY;
|
|
654 | 668 |
ringState = ACCEPTED; |
655 | 669 |
acceptor = source; |
656 | 670 |
|
... | ... | |
659 | 673 |
} |
660 | 674 |
|
661 | 675 |
/** |
662 |
* Called when we receive a packet passing the token and interrupting |
|
663 |
* the token ring. |
|
664 |
* If the token has been passed to us, we flash our BOM |
|
665 |
* and pass it back. |
|
666 |
* |
|
667 |
* @param source the robot who sent the interrupt packet |
|
668 |
* @param robot the robot the token has been passed to |
|
669 |
**/ |
|
670 |
void wl_token_interrupt_pass_receive(int source, int robot) |
|
671 |
{ |
|
672 |
if (wl_get_xbee_id() != robot) |
|
673 |
{ |
|
674 |
queue_remove_all(interrupting, (void*)robot); |
|
675 |
wl_token_next_robot = robot; |
|
676 |
deathDelay = DEATH_DELAY + rand() / (RAND_MAX / (2 * DEATH_DELAY)); |
|
677 |
return; |
|
678 |
} |
|
679 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_BOM_ON, |
|
680 |
NULL, 0, 0); |
|
681 |
|
|
682 |
bom_on_function(); |
|
683 |
#ifdef ROBOT |
|
684 |
delay_ms(BOM_DELAY); |
|
685 |
#endif |
|
686 |
bom_off_function(); |
|
687 |
|
|
688 |
//we don't include ourself, only if we are in the ring |
|
689 |
int packetSize = 1 + 2 * (sensor_matrix_get_joined(sensorMatrix) - 1); |
|
690 |
if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id())) |
|
691 |
packetSize += 2; |
|
692 |
char* buf = (char*)malloc(packetSize * sizeof(char)); |
|
693 |
if (!buf) |
|
694 |
{ |
|
695 |
WL_DEBUG_PRINT("Out of memory - pass_receive.\r\n"); |
|
696 |
return; |
|
697 |
} |
|
698 |
|
|
699 |
//return the token to where we got it from |
|
700 |
buf[0] = source; |
|
701 |
|
|
702 |
int i = 0, j = 0; |
|
703 |
for (i = 0; i < sensor_matrix_get_size(sensorMatrix); i++) |
|
704 |
if (sensor_matrix_get_in_ring(sensorMatrix, i) && i != wl_get_xbee_id()) |
|
705 |
{ |
|
706 |
buf[2*j + 1] = i; |
|
707 |
buf[2*j + 2] = sensor_matrix_get_reading(sensorMatrix, wl_get_xbee_id(), i); |
|
708 |
j++; |
|
709 |
} |
|
710 |
|
|
711 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_PASS, |
|
712 |
buf, packetSize, 0); |
|
713 |
|
|
714 |
wl_token_next_robot = source; |
|
715 |
deathDelay = DEATH_DELAY; |
|
716 |
free(buf); |
|
717 |
} |
|
718 |
|
|
719 |
/** |
|
720 | 676 |
* Returns the number of robots in the token ring. |
721 | 677 |
* |
722 | 678 |
* @return the number of robots in the token ring |
... | ... | |
752 | 708 |
i++; |
753 | 709 |
if (i == sensor_matrix_get_size(sensorMatrix)) |
754 | 710 |
i = -1; |
711 |
iteratorCount = i; |
|
755 | 712 |
} |
756 | 713 |
|
757 | 714 |
/** |
... | ... | |
765 | 722 |
**/ |
766 | 723 |
int wl_token_iterator_has_next(void) |
767 | 724 |
{ |
768 |
return iteratorCount == -1;
|
|
725 |
return iteratorCount != -1;
|
|
769 | 726 |
} |
770 | 727 |
|
771 | 728 |
/** |
... | ... | |
791 | 748 |
} |
792 | 749 |
|
793 | 750 |
/** |
794 |
* Called when we receive a request to interrupt the token ring. |
|
795 |
* We add the robot to our list of interrupt requests, |
|
796 |
* and will send the token to this robot when we next receive the |
|
797 |
* token, unless someone else does so first. |
|
751 |
* Returns the number of robots currently in the token ring. |
|
798 | 752 |
* |
799 |
* @param source the robot requesting interruption |
|
800 |
* @param robt the robot requested to interrupt the token ring |
|
753 |
* @return the number of robots in the token ring |
|
801 | 754 |
**/ |
802 |
void wl_token_interrupt_request_receive(int source, int robot)
|
|
755 |
int wl_token_get_num_robots(void)
|
|
803 | 756 |
{ |
804 |
queue_add(interrupting, (void*)robot);
|
|
757 |
return sensor_matrix_get_joined(sensorMatrix);
|
|
805 | 758 |
} |
806 | 759 |
|
807 |
int wl_token_get_num_robots(void){ |
|
808 |
return sensor_matrix_get_joined(sensorMatrix); |
|
760 |
/** |
|
761 |
* Returns the number of robots in the sensor matrix. |
|
762 |
* |
|
763 |
* @return the number of robots in the sensor matrix |
|
764 |
**/ |
|
765 |
int wl_token_get_matrix_size(void) |
|
766 |
{ |
|
767 |
return sensor_matrix_get_size(sensorMatrix); |
|
809 | 768 |
} |
810 | 769 |
|
811 |
int wl_token_get_matrix_size(void){ |
|
812 |
return sensor_matrix_get_size(sensorMatrix); |
|
813 |
} |
branches/autonomous_recharging/code/projects/libwireless/lib/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 |
* |
... | ... | |
7 | 32 |
* @author Brian Coltin, Colony Project, CMU Robotics Club |
8 | 33 |
**/ |
9 | 34 |
|
35 |
#ifndef SENSOR_MATRIX_H |
|
36 |
#define SENSOR_MATRIX_H |
|
37 |
|
|
38 |
|
|
10 | 39 |
/** |
11 | 40 |
* @defgroup sensormatrix Sensor Matrix |
12 | 41 |
* @brief the robot sensor matrix |
... | ... | |
27 | 56 |
/** |
28 | 57 |
* The size of the sensor matrix. |
29 | 58 |
**/ |
30 |
unsigned int size;
|
|
59 |
int size; |
|
31 | 60 |
/** |
32 | 61 |
* The matrix. Each row represents the readings of one |
33 | 62 |
* robot. |
... | ... | |
49 | 78 |
/**@brief Destroy a sensor matrix **/ |
50 | 79 |
void sensor_matrix_destroy(SensorMatrix* m); |
51 | 80 |
/**@brief Add a robot to a sensor matrix **/ |
52 |
void sensor_matrix_add_robot(SensorMatrix* m, unsigned int id);
|
|
81 |
void sensor_matrix_add_robot(SensorMatrix* m, int id); |
|
53 | 82 |
/**@brief Remove a robot from a sensor matrix **/ |
54 |
void sensor_matrix_remove_robot(SensorMatrix* m, unsigned int id);
|
|
83 |
void sensor_matrix_remove_robot(SensorMatrix* m, int id); |
|
55 | 84 |
/**@brief Set a reading in a sensor matrix **/ |
56 | 85 |
void sensor_matrix_set_reading(SensorMatrix* m, int observer, int robot, int reading); |
57 | 86 |
/**@brief Get a reading in a sensor matrix **/ |
... | ... | |
67 | 96 |
|
68 | 97 |
/** @} **/ //end defgroup |
69 | 98 |
|
99 |
|
|
100 |
#endif |
branches/autonomous_recharging/code/projects/libwireless/lib/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 |
* |
... | ... | |
6 | 31 |
* |
7 | 32 |
* @author Brian Coltin, Colony Project, CMU Robotics Club |
8 | 33 |
**/ |
34 |
|
|
35 |
#ifndef WIRELESS_H |
|
36 |
#define WIRELESS_H |
|
9 | 37 |
|
10 | 38 |
//Note: If this is raised above 16, we will need to do |
11 | 39 |
//something about frame numbers for TX Status packets. |
... | ... | |
90 | 118 |
} PacketGroupHandler; |
91 | 119 |
|
92 | 120 |
/**@brief Initialize the wireless library **/ |
93 |
void wl_init(void);
|
|
121 |
int wl_init(void);
|
|
94 | 122 |
/**@brief Uninitialize the wireless library **/ |
95 | 123 |
void wl_terminate(void); |
96 | 124 |
/**@brief Perform wireless library functionality **/ |
... | ... | |
122 | 150 |
/**@brief Get the channel we are using **/ |
123 | 151 |
int wl_get_channel(void); |
124 | 152 |
/**@brief Get the 16-bit address of the XBee module **/ |
125 |
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); |
|
126 | 156 |
|
127 | 157 |
/** @} **/ // end defgroup |
128 | 158 |
|
159 |
#endif |
|
160 |
|
branches/autonomous_recharging/code/projects/libwireless/lib/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("/dev/ttyUSB0", O_RDWR); |
|
148 |
if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0) |
|
149 |
xbee_stream = open("/dev/ttyUSB1", 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 |
} |
... | ... | |
514 | 628 |
|| currentBufPos < len + 4) |
515 | 629 |
{ |
516 | 630 |
if (currentBufPos == 3) |
631 |
{ |
|
517 | 632 |
len = (int)xbee_buf[2] + ((int)xbee_buf[1] << 8); |
518 |
if (queue_is_empty(xbee_queue)) |
|
633 |
if (len > 120) |
|
634 |
{ |
|
635 |
WL_DEBUG_PRINT("Packet too large. Probably error in XBee transmission.\n"); |
|
636 |
currentBufPos = 0; |
|
637 |
return -1; |
|
638 |
} |
|
639 |
} |
|
640 |
// check if buffer is empty |
|
641 |
if (buffer_first == buffer_last) |
|
519 | 642 |
return -1; |
520 |
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; |
|
521 | 646 |
} |
522 | 647 |
|
523 | 648 |
currentBufPos = 0; |
... | ... | |
740 | 865 |
return xbee_address; |
741 | 866 |
} |
742 | 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/libwireless/lib/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 |
* |
... | ... | |
7 | 32 |
* @author Brian Coltin, Colony Project, CMU Robotics Club |
8 | 33 |
**/ |
9 | 34 |
|
35 |
#ifndef WL_TOKEN_RING_H |
|
36 |
#define WL_TOKEN_RING_H |
|
37 |
|
|
10 | 38 |
/** |
11 | 39 |
* @defgroup tokenring Token Ring |
12 | 40 |
* @brief Wireless library token ring implementation |
... | ... | |
30 | 58 |
void wl_token_ring_join(void); |
31 | 59 |
/**@brief Leave the token ring **/ |
32 | 60 |
void wl_token_ring_leave(void); |
33 |
/**@brief Request a BOM flash from the specified robot **/ |
|
34 |
void wl_token_request(int robot); |
|
35 | 61 |
|
36 | 62 |
/**@brief Return the number of robots in the token ring **/ |
37 | 63 |
int wl_token_get_robots_in_ring(void); |
... | ... | |
56 | 82 |
|
57 | 83 |
/** @} **/ //end token ring group |
58 | 84 |
|
85 |
#endif |
branches/autonomous_recharging/code/projects/libwireless/lib/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/libwireless/lib/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 |
|
|
36 |
#ifndef WL_DEFS_H |
|
37 |
#define WL_DEFS_H |
|
38 |
|
|
1 | 39 |
//comment out this line if using a computer hooked up to an xbee |
2 | 40 |
//#define ROBOT |
3 | 41 |
|
4 | 42 |
//uncomment this line for debug information |
5 |
#define WL_DEBUG |
|
43 |
//#define WL_DEBUG
|
|
6 | 44 |
|
7 | 45 |
// Packet Groups and Types |
8 | 46 |
|
... | ... | |
16 | 54 |
|
17 | 55 |
#define WL_TOKEN_PASS 1 |
18 | 56 |
#define WL_TOKEN_BOM_ON 2 |
19 |
#define WL_TOKEN_INTERRUPT_REQUEST 3 |
|
20 |
#define WL_TOKEN_INTERRUPT_PASS 4 |
|
21 |
#define WL_TOKEN_JOIN 5 |
|
22 |
#define WL_TOKEN_JOIN_ACCEPT 6 |
|
57 |
#define WL_TOKEN_JOIN 3 |
|
58 |
#define WL_TOKEN_JOIN_ACCEPT 4 |
|
23 | 59 |
|
24 | 60 |
// timing constants |
61 |
#ifndef FIREFLY |
|
25 | 62 |
#define BOM_DELAY 100 |
26 |
#define DEATH_DELAY 3 |
|
63 |
#else |
|
64 |
#define BOM_DELAY 200 |
|
65 |
#endif |
|
66 |
|
|
67 |
#define DEATH_DELAY 4 |
|
27 | 68 |
#define JOIN_DELAY 8 |
28 | 69 |
|
29 | 70 |
// Recharging group |
... | ... | |
63 | 104 |
|
64 | 105 |
#endif |
65 | 106 |
|
107 |
#endif |
|
108 |
|
branches/autonomous_recharging/code/projects/libwireless/lib/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 |
* |
... | ... | |
10 | 35 |
* @author Brian Coltin, Colony Project, CMU Robotics Club |
11 | 36 |
**/ |
12 | 37 |
|
38 |
#ifndef XBEE_H |
|
39 |
#define XBEE_H |
|
40 |
|
|
13 | 41 |
/** |
42 |
* The port to use the XBee from on the computer. |
|
43 |
* Also, a backup port if the other is used. |
|
44 |
**/ |
|
45 |
#ifndef ROBOT |
|
46 |
#define XBEE_PORT_DEFAULT "/dev/ttyUSB1" |
|
47 |
#endif |
|
48 |
|
|
49 |
/** |
|
14 | 50 |
* @defgroup xbee XBee |
15 | 51 |
* @brief Interface with the XBee module |
16 | 52 |
* |
... | ... | |
38 | 74 |
#define XBEE_RX 0x81 |
39 | 75 |
|
40 | 76 |
/**@brief Initialize the XBee library **/ |
41 |
void xbee_lib_init(void);
|
|
77 |
int xbee_lib_init(void);
|
|
42 | 78 |
/**@brief Uninitialize the XBee library **/ |
43 | 79 |
void xbee_terminate(void); |
44 | 80 |
/**@brief Get a packet from the XBee **/ |
... | ... | |
56 | 92 |
int xbee_get_channel(void); |
57 | 93 |
/**@brief Get the XBee's 16-bit address **/ |
58 | 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); |
|
59 | 97 |
|
60 | 98 |
/**@}**/ //end defgroup |
61 | 99 |
|
100 |
#endif |
branches/autonomous_recharging/code/projects/libwireless/lib/Makefile | ||
---|---|---|
155 | 155 |
|
156 | 156 |
# Combine all necessary flags and optional flags. |
157 | 157 |
# Add target processor to flags. |
158 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
|
158 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) -Wall $(GENDEPFLAGS)
|
|
159 | 159 |
ALL_ASFLAGS = rcs |
160 | 160 |
|
161 | 161 |
# Default target. |
... | ... | |
176 | 176 |
$(AR) $(ALL_ASFLAGS) $(TARGET).a $(OBJ) |
177 | 177 |
|
178 | 178 |
computer: |
179 |
gcc *.c -g -I. -c |
|
179 |
gcc *.c -Wall -g -I. -c
|
|
180 | 180 |
ar rcs $(TARGET).a $(OBJ) |
181 | 181 |
|
182 |
colonet: |
|
183 |
g++ -Wall -Wshadow -Wextra *.c -g -I. -c |
|
184 |
ar rcs $(TARGET).a $(OBJ) |
|
185 |
|
|
182 | 186 |
# Eye candy. |
183 | 187 |
# AVR Studio 3.x does not check make's exit code but relies on |
184 | 188 |
# the following magic strings to be generated by the compile job. |
branches/autonomous_recharging/code/projects/libwireless/lib/wl_error_group.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_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 |
|
|
35 |
#ifndef WL_ERROR_GROUP_H |
|
36 |
#define WL_ERROR_GROUP_H |
|
37 |
|
|
38 |
/** |
|
39 |
* @file wl_error_group.h |
|
3 | 40 |
* @brief A packet group for error messages. |
4 | 41 |
* |
5 | 42 |
* A packet group for sending and receiving error |
... | ... | |
26 | 63 |
|
27 | 64 |
/** @} **/ // end defgroup |
28 | 65 |
|
66 |
#endif |
branches/autonomous_recharging/code/projects/libwireless/lib/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> |
... | ... | |
19 | 53 |
SensorMatrix* m; |
20 | 54 |
int i; |
21 | 55 |
|
22 |
m = malloc(sizeof(SensorMatrix)); |
|
56 |
m = (SensorMatrix*)malloc(sizeof(SensorMatrix));
|
|
23 | 57 |
if (!m) |
24 | 58 |
{ |
25 | 59 |
WL_DEBUG_PRINT("Out of memory - create sensor matrix.\r\n"); |
26 | 60 |
return NULL; |
27 | 61 |
} |
28 | 62 |
m->size = DEFAULT_SENSOR_MATRIX_SIZE; |
29 |
m->matrix = malloc(m->size * sizeof(int*)); |
|
30 |
m->joined = malloc(m->size * sizeof(int)); |
|
63 |
m->matrix = (int**)malloc(m->size * sizeof(int*));
|
|
64 |
m->joined = (int*)malloc(m->size * sizeof(int));
|
|
31 | 65 |
m->numJoined = 0; |
32 | 66 |
if (!(m->matrix) || !(m->joined)) |
33 | 67 |
{ |
... | ... | |
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) |
... | ... | |
73 | 107 |
if (m->matrix[id] != NULL) |
74 | 108 |
return; |
75 | 109 |
|
76 |
m->matrix[id] = malloc(m->size * sizeof(int)); |
|
110 |
m->matrix[id] = (int*)malloc(m->size * sizeof(int));
|
|
77 | 111 |
if (!(m->matrix[id])) |
78 | 112 |
{ |
79 | 113 |
WL_DEBUG_PRINT("Out of memory - add robot.\r\n"); |
... | ... | |
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 |
|
... | ... | |
125 | 159 |
int i, j; |
126 | 160 |
WL_DEBUG_PRINT("Expanding sensor matrix.\r\n"); |
127 | 161 |
|
128 |
int** tempMatrix = malloc(nextSize * sizeof(int*)); |
|
162 |
int** tempMatrix = (int**)malloc(nextSize * sizeof(int*));
|
|
129 | 163 |
if (!tempMatrix) |
130 | 164 |
{ |
131 | 165 |
WL_DEBUG_PRINT("Out of memory - expand matrix.\r\n"); |
... | ... | |
139 | 173 |
for (i = 0; i < m->size; i++) |
140 | 174 |
if (m->matrix[i] != NULL) |
141 | 175 |
{ |
142 |
tempMatrix[i] = malloc(nextSize * sizeof(int));
|
|
176 |
tempMatrix[i] = (int *)malloc(nextSize * sizeof(int));
|
|
143 | 177 |
if (!tempMatrix[i]) |
144 | 178 |
{ |
145 | 179 |
WL_DEBUG_PRINT("Out of memory - expand matrix 2.\r\n"); |
... | ... | |
158 | 192 |
m->size = nextSize; |
159 | 193 |
|
160 | 194 |
//expand the size of joined |
161 |
int* tempJoined = malloc(nextSize * sizeof(int)); |
|
195 |
int* tempJoined = (int *)malloc(nextSize * sizeof(int));
|
|
162 | 196 |
if (!tempJoined) |
163 | 197 |
{ |
164 | 198 |
WL_DEBUG_PRINT("Out of memory - expand matrix 3.\r\n"); |
branches/autonomous_recharging/code/projects/libwireless/lib/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> |
... | ... | |
6 | 40 |
#include "wl_defs.h" |
7 | 41 |
|
8 | 42 |
#ifndef ROBOT |
9 |
#include <time.h> |
|
43 |
#include <sys/time.h>
|
|
10 | 44 |
#include <signal.h> |
11 | 45 |
#else |
12 | 46 |
#include <time.h> |
... | ... | |
34 | 68 |
PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS]; |
35 | 69 |
|
36 | 70 |
#ifndef ROBOT |
37 |
timer_t wl_timeout_timer; |
|
38 | 71 |
|
39 | 72 |
//called when we time out, or receive interrupt |
40 | 73 |
void sig_handler(int signo) |
... | ... | |
51 | 84 |
} |
52 | 85 |
return; |
53 | 86 |
} |
87 |
#else |
|
88 |
|
|
89 |
//called when the timer ticks |
|
90 |
void timer_handler(void) |
|
91 |
{ |
|
92 |
wl_timeout = 1; |
|
93 |
} |
|
94 |
|
|
54 | 95 |
#endif |
55 | 96 |
|
56 | 97 |
/** |
57 | 98 |
* Initializes the wireless library. Must be called before any |
58 | 99 |
* other function. |
59 | 100 |
**/ |
60 |
void wl_init()
|
|
101 |
int wl_init()
|
|
61 | 102 |
{ |
62 | 103 |
int i; |
63 | 104 |
for (i = 0; i < WL_MAX_PACKET_GROUPS; i++) |
64 | 105 |
wl_packet_groups[i] = NULL; |
65 | 106 |
|
66 |
xbee_lib_init(); |
|
67 |
|
|
107 |
if (xbee_lib_init() == -1) { |
|
108 |
return -1; |
|
109 |
} |
|
110 |
|
|
68 | 111 |
//begin timeout timer |
69 | 112 |
#ifdef ROBOT |
70 | 113 |
#ifdef FIREFLY |
71 |
rtc_init(PRESCALE_DIV_128, 32, &wl_do_timeout);
|
|
114 |
rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
|
|
72 | 115 |
#else |
Also available in: Unified diff