Revision 1947
Added the logic tester. It still needs development, and won't compile with most library functions. Don't use yet.
trunk/code/projects/logic_tester/cTest.c | ||
---|---|---|
1 |
/* cTest.c |
|
2 |
* C debug library file for Colony |
|
3 |
* By Benjamin Wasserman |
|
4 |
* Colony Project |
|
5 |
*/ |
|
6 |
|
|
7 |
#include "cTest.h" |
|
8 |
|
|
9 |
short robotID, lastRangefinderVal[5] = {-1, -1, -1, -1, -1}, lastBomMax, |
|
10 |
lastBomVal[16] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, |
|
11 |
lastWheel; |
|
12 |
|
|
13 |
// Dragonfly |
|
14 |
void init_debug(int which){ |
|
15 |
short numRobots; |
|
16 |
|
|
17 |
printf("Please use nice values for inputs. I haven't had time to make this debugger resistant to stupid. Thanks. -HAL9000\n\n\n"); |
|
18 |
printf("P.S. Keep in mind this is only to help you find logic errors. Other errors may show due to running on the robots."); |
|
19 |
printf("Enter number of robots in test: "); |
|
20 |
scanf("%hi", &numRobots); |
|
21 |
if(numRobots < 1){ |
|
22 |
numRobots = 1; |
|
23 |
} |
|
24 |
robotID = numRobots; |
|
25 |
for(; numRobots >1; numRobots--){ |
|
26 |
if(fork() == 0){ |
|
27 |
robotID = numRobots; |
|
28 |
break; |
|
29 |
} |
|
30 |
} |
|
31 |
printf("\nDragonFly Initialized: %hi for robot %hi\n", which, robotID); |
|
32 |
} |
|
33 |
|
|
34 |
int getRobotID(){ |
|
35 |
return robotID; |
|
36 |
} |
|
37 |
|
|
38 |
// Motors |
|
39 |
|
|
40 |
// Orbs |
|
41 |
|
|
42 |
// Rangefinders |
|
43 |
int getRangefinderVal(int which){ |
|
44 |
short numRead, val; |
|
45 |
switch(which){ |
|
46 |
case IR1: which = 1; break; |
|
47 |
case IR2: which = 2; break; |
|
48 |
case IR3: which = 3; break; |
|
49 |
case IR4: which = 4; break; |
|
50 |
case IR5: which = 5; break; |
|
51 |
default: |
|
52 |
printf("Error in input. Returning -1\n"); |
|
53 |
return -1; |
|
54 |
} |
|
55 |
printf("Enter value for rangefinder %hi. Note: No value will return last entry: ", which); |
|
56 |
numRead = scanf("%hi", &val); |
|
57 |
if(numRead == 0){ |
|
58 |
return lastRangefinderVal[which - 1]; |
|
59 |
} |
|
60 |
lastRangefinderVal[which - 1] = val; |
|
61 |
printf("Rangefinder %hi reports value %hi\n", which, val); |
|
62 |
return val; |
|
63 |
} |
|
64 |
|
|
65 |
// BOM |
|
66 |
int getBomVal(int which){ |
|
67 |
short val, numRead; |
|
68 |
printf("Enter value for BOM LED %hi. Note: No value will return last entry: ", which); |
|
69 |
numRead = scanf("%hi", &val); |
|
70 |
if(numRead == 0){ |
|
71 |
return lastBomVal[which - 1]; |
|
72 |
} |
|
73 |
lastBomVal[which - 1] = val; |
|
74 |
return val; |
|
75 |
} |
|
76 |
|
|
77 |
int getBomMax(){ |
|
78 |
short val, numRead; |
|
79 |
printf("Enter value for BOM max. Note: No value will return last entry: "); |
|
80 |
numRead = scanf("%hi", &val); |
|
81 |
if(numRead == 0){ |
|
82 |
return lastBomMax; |
|
83 |
} |
|
84 |
lastBomMax = val; |
|
85 |
return val; |
|
86 |
} |
|
87 |
|
|
88 |
// Encoders |
|
89 |
|
|
90 |
// Buttons |
|
91 |
int getButton1(){ |
|
92 |
short val, numRead; |
|
93 |
printf("Enter value for Button 1 (0 or 1). Note: No value will return 0: "); |
|
94 |
numRead = scanf("%hi", &val); |
|
95 |
if(numRead == 0){ |
|
96 |
return 0; |
|
97 |
} |
|
98 |
return val; |
|
99 |
} |
|
100 |
|
|
101 |
int getButton2(){ |
|
102 |
short val, numRead; |
|
103 |
printf("Enter value for Button 2. Note: No value will return 0: "); |
|
104 |
numRead = scanf("%hi", &val); |
|
105 |
if(numRead == 0){ |
|
106 |
return 0; |
|
107 |
} |
|
108 |
return val; |
|
109 |
} |
|
110 |
|
|
111 |
// Wheel |
|
112 |
int getWheel(){ |
|
113 |
short val, numRead; |
|
114 |
printf("Enter value for Wheel. Note: No value will return last entry: "); |
|
115 |
numRead = scanf("%hi", &val); |
|
116 |
if(numRead == 0){ |
|
117 |
return lastWheel; |
|
118 |
} |
|
119 |
lastWheel = val; |
|
120 |
printf("Wheel has value %hi\n", val); |
|
121 |
return val; |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
// USB |
|
127 |
|
|
128 |
// Wireless (old) |
|
129 |
|
|
130 |
|
|
131 |
// Wireless (new) |
|
132 |
|
|
133 |
// Time |
|
134 |
|
|
135 |
// Math |
|
136 |
|
trunk/code/projects/logic_tester/cTest.h | ||
---|---|---|
1 |
/* cTest.h |
|
2 |
* C debug library file for Colony |
|
3 |
* By Benjamin Wasserman |
|
4 |
* Colony Project |
|
5 |
*/ |
|
6 |
|
|
7 |
#include <stdlib.h> |
|
8 |
#include <stdio.h> |
|
9 |
#include <math.h> |
|
10 |
|
|
11 |
|
|
12 |
// Types |
|
13 |
#define int int16_t |
|
14 |
#define short int16_t |
|
15 |
|
|
16 |
// includes |
|
17 |
|
|
18 |
// Dragonfly |
|
19 |
#define ALL_ON 0x07FF |
|
20 |
|
|
21 |
#define dragonfly_init(which) init_debug(which) |
|
22 |
#define get_robotid() getRobotID() |
|
23 |
|
|
24 |
// Motors |
|
25 |
#define FORWARD 1 |
|
26 |
#define BACKWARD 0 |
|
27 |
|
|
28 |
#define motor_l_set(d, s) printf("Motor L set to dir %u speed %u\n", d, s%255) |
|
29 |
#define motor_r_set(d, s) printf("Motor R set to dir %u speed %hi\n", d, s%255) |
|
30 |
|
|
31 |
// Orbs |
|
32 |
#define RED 0xE0 |
|
33 |
#define ORANGE 0xE4 |
|
34 |
#define YELLOW 0xE8 |
|
35 |
#define LIME 0x68 |
|
36 |
#define GREEN 0x1C |
|
37 |
#define CYAN 0x1F |
|
38 |
#define BLUE 0x03 |
|
39 |
#define PINK 0xA6 |
|
40 |
#define PURPLE 0x41 |
|
41 |
#define MAGENTA 0xE3 |
|
42 |
#define WHITE 0xFE |
|
43 |
#define ORB_OFF 0x00 |
|
44 |
|
|
45 |
#define orb1_set_color(c) printf("Orb 1 set to color %i\n", c%255) |
|
46 |
#define orb2_set_color(c) printf("Orb 2 set to color %i\n", c%255) |
|
47 |
#define orb1_set(r, g, b) printf("Orb 1 set to color r:%i g:%i b:%i\n", r%255, g%255, b%255) |
|
48 |
#define orb2_set(r, g, b) printf("Orb 2 set to color r:%i g:%i b:%i\n", r%255, g%255, b%255) |
|
49 |
|
|
50 |
// Rangefinders |
|
51 |
#define IR1 6 |
|
52 |
#define IR2 5 |
|
53 |
#define IR3 4 |
|
54 |
#define IR4 3 |
|
55 |
#define IR5 2 |
|
56 |
|
|
57 |
#define range_init() printf("Rangefinders initialized\n") |
|
58 |
#define range_read_distance(rf) getRangefinderVal(rf) |
|
59 |
|
|
60 |
// BOM |
|
61 |
#define BOM_ALL 0xFFFF |
|
62 |
#define BOM10 0 |
|
63 |
#define BOM15 1 |
|
64 |
#define RBOM 2 |
|
65 |
|
|
66 |
#define bom_init(t) printf("BOM type %c initialized\n", t) |
|
67 |
#define bom_refresh() printf("BOM refreshed\n") |
|
68 |
#define bom_on() printf("BOM is on\n") |
|
69 |
#define bom_off() printf("BOM is off\n") |
|
70 |
#define bom_get(which) getBomVal(which) |
|
71 |
#define bom_get_max() getBomMax() |
|
72 |
|
|
73 |
// Encoders |
|
74 |
#define encoders_init() printf("Encoders initialized\n") |
|
75 |
|
|
76 |
// Buttons |
|
77 |
#define button1_click() printf("Checked for button 1 to be clicked\n") |
|
78 |
#define button2_click() printf("Checked for button 2 to be clicked\n") |
|
79 |
|
|
80 |
// Wheel |
|
81 |
#define wheel() getWheel() |
|
82 |
|
|
83 |
// USB |
|
84 |
#define usb_puts(s) printf("%s\n", s) |
|
85 |
#define usb_puti(i) printf("%i\n", i) |
|
86 |
#define usb_putc(c) printf("%c\n", c) |
|
87 |
|
|
88 |
// Buzzer |
|
89 |
#define buzzer_chirp(t, f) printf("Buzzer played note %i for %i ms. I hate you.\n", f, t) |
|
90 |
|
|
91 |
// Wireless (old) |
|
92 |
#define xbee_intit() printf("XBee initialized\n") |
|
93 |
#define wl_basic_init_default() printf("Old WL library intitalized\n") |
|
94 |
#define wl_set_channel(c) printf("WL channel set to %i\n", c) |
|
95 |
#define wl_basic_send_global_packet(n, b, l) printf("WL Sent basic packet datap: %p, length %i\n", b, l) |
|
96 |
#define wl_basic_do_default(l) printf("WL checked for basic packet lengthp: %p\n", l) |
|
97 |
|
|
98 |
// Wireless (new) |
|
99 |
|
|
100 |
// Linefollowing |
|
101 |
|
|
102 |
// Time |
|
103 |
#define rtc_init(tc, fn) printf("RTC initialized: time: %i fn: %p\n", tc, fn) |
|
104 |
#define rtc_reset() printf("RTC reset\n") |
|
105 |
#define rtc_get() printf("RTC polled\n") |
|
106 |
#define delay_ms(t) printf("Delaying for %i ms\n", t) |
|
107 |
|
|
108 |
// Math |
trunk/code/projects/logic_tester/README.txt | ||
---|---|---|
1 |
Written by bwasserm and mjmckay |
|
2 |
|
|
3 |
|
Also available in: Unified diff