Project

General

Profile

Revision 1424

Added by John Sexton over 13 years ago

Includes working naive version of Target Practice

View differences:

trunk/code/projects/targetPractice/targetBot/main.c
1 1
#include <dragonfly_lib.h>
2
#include <encoders.h>
2 3

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

  
7
	int maxBOM, rangeVal;
8

  
6 9
	dragonfly_init(ALL_ON);
10
	encoders_init();
7 11
	
8
	int i, j, max = -1;
9
	int vals[16];
10

  
11
	orbs_set_color(RED, RED);
12
	delay_ms(2000);
12
	orbs_set_color(GREEN, RED);
13
	delay_ms(500);
14
	orbs_set_color(RED, GREEN);
15
	delay_ms(500);
13 16
	orbs_set_color(GREEN, GREEN);
14 17

  
15 18
	while (1) {
16

  
17
		/* Refresh and make sure the table is updated */
19
		
18 20
		bom_refresh(BOM_ALL);
19 21
		delay_ms(100);
22
		maxBOM = bom_get_max();
23
		usb_puti(maxBOM);
24
		usb_putc('\n');
25
		if (maxBOM == 4) {
26
			motors_off();
27
			break;
28
		}
20 29

  
21
		/* Record values into an array */
22
		for (i = 0; i < 16; i++) {
23
			vals[i] = bom_get(i);
24
			if (max < vals[i])
25
				max = vals[i];
30
		motor_l_set(BACKWARD, 175);
31
		motor_r_set(FORWARD, 175);
32

  
33
	}
34

  
35
	while (1) {
36

  
37
		rangeVal = range_read_distance(IR2);
38
		usb_puti(rangeVal);
39
		usb_putc('\n');
40
		if (rangeVal < 500 && rangeVal > 20) {
41
			motors_off();
42
			orbs_set_color(RED, RED);
43
			break;
26 44
		}
27 45

  
28
		/* Display results */
29
		for (i = 0; i < 16; i++) {
30
			
31
			usb_puti(vals[i]);
32
			usb_putc('\t');
46
		motor_l_set(FORWARD, 175);
47
		motor_r_set(FORWARD, 175);
33 48

  
34
			for (j = 0; j < (int)((max - vals[i]) / 5); j++) {
35
				usb_putc('#');
36
			}
49
	}
37 50

  
38
			usb_putc('\n');
51
	button2_wait();
39 52

  
53
	motor_l_set(FORWARD, 175);
54
	motor_r_set(FORWARD, 175);
55

  
56
	while (1) {
57
		if (encoder_get_x(LEFT) > 500) {
58
			motors_off();
59
			break;
40 60
		}
61
	}
41 62

  
42
		usb_puts("Max: ");
43
		usb_puti(bom_get_max());
44
		usb_putc('\n');
45
		usb_putc('\n');
63
	while (1) {
46 64

  
47
		delay_ms(400);
65
		orbs_set_color(BLUE, GREEN);
66
		delay_ms(500);
67
		orbs_set_color(GREEN, BLUE);
68
		delay_ms(500);
48 69

  
49 70
	}
50 71

  
72
	while (1); /* END HERE */
73

  
51 74
	return 0;
52 75
}
53 76

  
trunk/code/projects/libdragonfly/bom.c
79 79
#define MONK3 _PIN_E6     //blue
80 80
#define MONK2 _PIN_E7     //white
81 81

  
82
#define BOM_VALUE_THRESHOLD 120 //200
82
#define BOM_VALUE_THRESHOLD 150 //200
83 83
#define NUM_BOM_LEDS 16
84 84

  
85 85
/*

Also available in: Unified diff