Project

General

Profile

Revision 1955

Status bot works!! The main function will listen and print to USB all wireless packets on whatever channel it is set to. The second function is still untested.

View differences:

trunk/code/projects/statusbot/main.c
1 1
#include <dragonfly_lib.h>
2
#include <wl_basic.h>
2 3

  
3 4
int main(void)
4 5
{
5 6

  
7
  char *packet;
8
  int length, byte;
9

  
10

  
6 11
	/* initialize components, set wireless channel */
7 12
	dragonfly_init(ALL_ON);
8
	lineFollow_init();
9
	int barCode;
10
	while(1)
11
	{
13
  wl_basic_init_default();
14
  //REMEMBER to change this to whatever channel your program uses
15
  wl_set_channel(15);
12 16

  
13
		for(int q=0; q<500; q++)
14
			barCode = lineFollow(200);
15
		while(mergeLeft());
16
		for(int q=0; q<1000; q++)
17
            lineFollow(200);
18
		
19
		continue;
17
  while(1){
18
    packet = wl_basic_do_default(&length);
19
    if(length > 0){
20
      usb_puts("\r\n");
21
      orb1_set_color(BLUE);
22
      usb_puti(length);
23
      usb_puts(" bytes: ");
24
    }
25
    for(byte = 0; byte < length; byte++){
26
      usb_puti(packet[byte]);
27
      usb_putc(' ');
28
    }
29
    orb1_set_color(ORB_OFF);
30
    length = 0;
20 31

  
21
		if(barCode==-25)
22
            while(turnRight());
32
  }
23 33

  
24
		continue;
25

  
26
		if(barCode != -2 && barCode != LINELOST)
27
		{
28
			usb_puti(barCode);
29
			usb_putc('\n');
30
		}
31
/*		
32

  
33
		switch (barCode)
34
		{	
35

  
36
		
37
			case 0: orb_set_color(RED); break;
38
			case 1: orb_set_color(ORANGE); break;
39
			case 2: orb_set_color(YELLOW); break;
40
			case 3: orb_set_color(LIME); break;
41
			case 4: orb_set_color(GREEN); break;
42
			case 5: orb_set_color(CYAN); break;
43
			case 6: orb_set_color(BLUE); break;
44
			case 7: orb_set_color(PINK); break;
45
			case 8: orb_set_color(PURPLE); break;
46
			case 9: orb_set_color(MAGENTA); break;
47
			default: orb_set_color(WHITE); break;
48
	
49
			case 0:
50
				straight();
51
				turnRight();
52
				break;
53
                        case 2:
54
	                        straight();
55
        	                break;
56
                        case 3:
57
	                        straight();
58
				turnLeft();
59
        	                break;
60
		
61
		}
62
*/	
63
	}
64 34
	return 0;
65 35
}
66 36

  
67
void right()
68
{
69
motor_r_set(BACKWARD, 200);
70
motor_l_set(FORWARD, 200);
71
delay_ms(400);
72
}
37
/* Copy this function into your program whever you want to report the status of the robot
38
 * Edit the parameters to contain all the variables you want to send from your program
39
 */
40
void send_status(char var1, char var2){
41
  int length = 3;//Set this to the number of bytes you want to report
42
  char buffer[length];
73 43

  
74
void straight()
75
{
76
motor_r_set(FORWARD, 210);
77
motor_l_set(FORWARD, 210);
78
delay_ms(200);
79
move(0,0);
80
delay_ms(2000);
81
}
44
  //Copy all variables into the buffer
45
  buffer[0] = get_robotid();
46
  buffer[1] = var1;
47
  buffer[2] = var2;
82 48

  
83
void left()
84
{
85
motor_l_set(BACKWARD, 200);
86
motor_r_set(FORWARD, 200);
87
delay_ms(400);
49
  wl_basic_send_global_packet(42, buffer, length);
50

  
88 51
}

Also available in: Unified diff