Project

General

Profile

Revision 1349

Added by Chris Mar about 15 years ago

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.

View differences:

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