Revision 1349
re-wrote joystick remote control code to use packets instead of single bytes over wireless. still needs to be cleaned up. TODO: figure out why robots stops responding to commands.
trunk/code/projects/colonet/robot/joystick/discrete_control/joystick.c | ||
---|---|---|
32 | 32 |
int joystick_status (void); |
33 | 33 |
int joystick_change (int old, int new); |
34 | 34 |
|
35 |
PacketGroupHandler cntlHandler = {4, NULL, NULL, NULL, NULL}; |
|
36 |
|
|
35 | 37 |
int main (void) { |
36 | 38 |
dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG); |
37 | 39 |
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); |
38 |
xbee_init(); |
|
40 |
//xbee_init(); |
|
41 |
wl_init(); |
|
42 |
wl_register_packet_group(&cntlHandler); |
|
39 | 43 |
|
40 | 44 |
orb_set_color(BLUE); |
41 | 45 |
|
... | ... | |
48 | 52 |
cur_status = joystick_status(); |
49 | 53 |
change = joystick_change(last_status, cur_status); |
50 | 54 |
|
51 |
char buf[100]; |
|
55 |
/* char buf[100];
|
|
52 | 56 |
sprintf(buf, "status: %d\n", cur_status); |
53 | 57 |
usb_puts(buf); |
54 |
|
|
58 |
*/ |
|
55 | 59 |
if (change & MOVED_UP) { |
56 | 60 |
orb_set_color(GREEN); |
57 |
xbee_putc('f'); |
|
61 |
//xbee_putc('f'); |
|
62 |
wl_send_global_packet(4, 'f', NULL, 0, 0); |
|
63 |
usb_putc('f'); |
|
58 | 64 |
} |
59 | 65 |
if (change & MOVED_Y_CENTER) { |
60 | 66 |
orb_set_color(RED); |
61 |
xbee_putc('s'); |
|
67 |
//xbee_putc('s'); |
|
68 |
wl_send_global_packet(4, 's', NULL, 0, 0); |
|
69 |
usb_putc('s'); |
|
62 | 70 |
} |
63 | 71 |
if (change & MOVED_DOWN) { |
64 | 72 |
orb_set_color(BLUE); |
65 |
xbee_putc('b'); |
|
73 |
//xbee_putc('b'); |
|
74 |
wl_send_global_packet(4, 'b', NULL, 0, 0); |
|
75 |
usb_putc('b'); |
|
66 | 76 |
} |
67 | 77 |
if (change & MOVED_LEFT) { |
68 | 78 |
orb_set_color(ORANGE); |
69 |
xbee_putc('l'); |
|
79 |
//xbee_putc('l'); |
|
80 |
wl_send_global_packet(4, 'l', NULL, 0, 0); |
|
81 |
usb_putc('l'); |
|
70 | 82 |
} |
71 | 83 |
if (change & MOVED_X_CENTER) { |
72 | 84 |
orb_set_color(RED); |
73 |
xbee_putc('s'); |
|
85 |
//xbee_putc('s'); |
|
86 |
wl_send_global_packet(4, 's', NULL, 0, 0); |
|
87 |
usb_putc('s'); |
|
74 | 88 |
} |
75 | 89 |
if (change & MOVED_RIGHT) { |
76 | 90 |
orb_set_color(YELLOW); |
77 |
xbee_putc('r'); |
|
91 |
//xbee_putc('r'); |
|
92 |
wl_send_global_packet(4, 'r', NULL, 0, 0); |
|
93 |
usb_putc('r'); |
|
78 | 94 |
} |
79 | 95 |
if (change & TRIGGER_PRESSED) { |
80 | 96 |
orb_set_color(PURPLE); |
81 |
xbee_putc('t'); |
|
97 |
//xbee_putc('t'); |
|
98 |
wl_send_global_packet(4, 't', NULL, 0, 0); |
|
82 | 99 |
} |
83 | 100 |
if (change & BUTTON_PRESSED) { |
84 | 101 |
orb_set_color(YELLOW); |
85 |
xbee_putc('u'); |
|
102 |
//xbee_putc('u'); |
|
103 |
wl_send_global_packet(4, 's', NULL, 0, 0); |
|
86 | 104 |
} |
87 | 105 |
delay_ms(100); |
88 | 106 |
} |
... | ... | |
162 | 180 |
|
163 | 181 |
return trigger_status | button_status | x_status | y_status; |
164 | 182 |
} |
183 |
|
trunk/code/projects/colonet/robot/joystick/simple_slave/slave.c | ||
---|---|---|
2 | 2 |
#include <wireless.h> |
3 | 3 |
#include "../../../common/colonet_defs.h" |
4 | 4 |
|
5 |
void packet_receive (char type, int source, unsigned char* packet, int length); |
|
5 | 6 |
|
7 |
PacketGroupHandler packetHandler = {4, NULL, NULL, &packet_receive, NULL}; |
|
6 | 8 |
|
7 | 9 |
int main (void) { |
8 | 10 |
dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG | MOTORS | BUZZER); |
9 | 11 |
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); |
10 |
xbee_init(); |
|
12 |
//xbee_init(); |
|
13 |
wl_init(); |
|
14 |
wl_register_packet_group(&packetHandler); |
|
11 | 15 |
orb_set_color(PURPLE); |
12 | 16 |
|
13 |
char buf[100]; |
|
14 |
char c; |
|
17 |
/*char buf[100];
|
|
18 |
char c;*/
|
|
15 | 19 |
while (1) { |
16 |
c = xbee_getc(); |
|
17 |
orb_set_color(GREEN); |
|
18 |
sprintf(buf, "got char: %c\n", c); |
|
19 |
usb_puts(buf); |
|
20 |
//usb_puts("entering while loop\n"); |
|
21 |
wl_do(); |
|
22 |
// c = xbee_getc(); |
|
23 |
// orb_set_color(GREEN); |
|
24 |
// sprintf(buf, "got char: %c\n", c); |
|
25 |
// usb_puts(buf); |
|
20 | 26 |
|
21 |
if (c == 'f') { |
|
27 |
/*if (c == 'f') {
|
|
22 | 28 |
orb_set_color(GREEN); |
23 | 29 |
motor1_set(1, 250); |
24 | 30 |
motor2_set(1, 250); |
... | ... | |
52 | 58 |
buzzer_chirp(1000, A4); |
53 | 59 |
} |
54 | 60 |
|
55 |
delay_ms(100); |
|
61 |
delay_ms(100);*/
|
|
56 | 62 |
} |
57 | 63 |
|
58 | 64 |
} |
59 | 65 |
|
66 |
void packet_receive (char type, int source, unsigned char* packet, int length) { |
|
67 |
switch (type) { |
|
68 |
case 'f': |
|
69 |
orb_set_color(GREEN); |
|
70 |
motor1_set(1, 250); |
|
71 |
motor2_set(1, 250); |
|
72 |
break; |
|
73 |
case 's': |
|
74 |
orb_set_color(RED); |
|
75 |
motor1_set(0, 0); |
|
76 |
motor2_set(0, 0); |
|
77 |
break; |
|
78 |
case 'b': |
|
79 |
orb_set_color(BLUE); |
|
80 |
motor1_set(0, 250); |
|
81 |
motor2_set(0, 250); |
|
82 |
break; |
|
83 |
case 'l': |
|
84 |
orb_set_color(ORANGE); |
|
85 |
motor1_set(0, 250); |
|
86 |
motor2_set(1, 250); |
|
87 |
break; |
|
88 |
case 'r': |
|
89 |
orb_set_color(YELLOW); |
|
90 |
motor1_set(1, 250); |
|
91 |
motor2_set(0, 250); |
|
92 |
break; |
|
93 |
case 't': |
|
94 |
orb_set_color(PURPLE); |
|
95 |
buzzer_chirp(1000, C5); |
|
96 |
break; |
|
97 |
case 'u': |
|
98 |
orb_set_color(YELLOW); |
|
99 |
buzzer_chirp(1000, A4); |
|
100 |
break; |
|
101 |
default: |
|
102 |
orb_set_color(RED); |
|
103 |
motor1_set(0, 0); |
|
104 |
motor2_set(0, 0); |
|
105 |
break; |
|
106 |
} |
|
107 |
} |
|
108 |
|
Also available in: Unified diff