Project

General

Profile

Revision 1528

Added by John Sexton over 14 years ago

Finished function which prints the BOM intensity histogram over USB. Will print nicely in both windows and linux (uses "\r\n"). Will accept an array
pointer to print values already collected, or it will recollect current values and print.

View differences:

branches/bom_refactor/code/behaviors/template/main.c
12 12
#include <dragonfly_lib.h>
13 13
#include <wl_basic.h>
14 14

  
15
/* Time delay which determines how long the robot circles before it
16
 * changes direction. */
17
#define TIME_DELAY 5000
18

  
19 15
int main (void) {
20 16

  
21 17
	/* Initialize the dragonfly boards, the xbee, and the encoders */
22 18
	dragonfly_init(ALL_ON);
23 19
	xbee_init();
24 20
	encoders_init();
21

  
22
	int vals[16];
23
	int i;
24

  
25
	while(1) {
26

  
27
		bom_refresh(BOM_ALL);
28
		for (i = 0; i < 16; i++) {
29
			vals[i] = bom_get(i);
30
		}
25 31
	
26
	while (1) {
27
		/* Drive left, set orbs, and wait */
28
		orbs_set_color(RED, GREEN);
29
		motor_l_set(FORWARD, 160);
30
		motor_r_set(FORWARD, 255);
31
		delay_ms(TIME_DELAY);
32

  
33
		/* Drive right, change orb colors, and wait */
34
		orbs_set_color(PURPLE, BLUE);
35
		motor_l_set(FORWARD, 255);
36
		motor_r_set(FORWARD, 160);
37
		delay_ms(TIME_DELAY);
32
		bom_print_usb(vals);
33
		delay_ms(100);
38 34
	}
39 35

  
40 36
}
branches/bom_refactor/code/lib/include/libdragonfly/bom.h
68 68
/** @brief Compares all the values in bom_val[] and returns the index to the highest value element. **/
69 69
int bom_get_max(void);
70 70

  
71
/** @brief Print snapshot of BOM intensity histogram over USB connection **/
72
void bom_print_usb(int*);
73

  
71 74
/** @brief Computes the weighted average of all the bom readings to estimate the position and distance of another robot. **/
72 75
int bom_get_max10(int *dist);
73 76

  
branches/bom_refactor/code/projects/libdragonfly/bom.c
231 231
 * Print a histogram which shows the current BOM intensity values for each of the 16 BOM IR
232 232
 *		sensors. The function will attempt to send the histogram data over USB.
233 233
 *
234
 * @param curBOMvals  Pointer to an array of the current BOM values. Use this to print values
235
 *		you have already collected. Otherwise pass in NULL and bom_refresh() will be called and
236
 *		the current BOM intensity values will be collected.
234
 * @param curBOMvals  Pointer to an array of the current BOM values (the array must have
235
 *		length 16). Use this to print values you have already collected. Otherwise pass in NULL
236
 *		and bom_refresh() will be called and the current BOM intensity values will be collected.
237 237
 **/
238
void bom_print_usb(int* curBOMvals) {
238
void bom_print_usb(int* usrBOMvals) {
239 239

  
240 240
	int i, j, max = -1;
241
	int vals[16];
241
	int curVals[16];
242
	int* prtValPtr;
242 243

  
243
	if (curBOMvals) {
244
	if (usrBOMvals) {
245
		/* Use BOM values collected by user */
246
		prtValPtr = usrBOMvals;
244 247

  
245
	}
246

  
248
		/* Find max BOM value from users values */
249
		for (i = 0; i < 16; i++) {
250
			if (max < prtValPtr[i])
251
				max = prtValPtr[i];
252
		}
253
	} else {
247 254
		/* Refresh and make sure the table is updated */
248 255
		bom_refresh(BOM_ALL);
249
		delay_ms(100);
250 256

  
251 257
		/* Record values into an array */
252 258
		for (i = 0; i < 16; i++) {
253
			vals[i] = bom_get(i);
254
			if (max < vals[i])
255
				max = vals[i];
259
			curVals[i] = bom_get(i);
260
			if (max < curVals[i])
261
				max = curVals[i];
256 262
		}
257 263

  
258
		/* Display results */
259
		for (i = 0; i < 16; i++) {
260
			
261
			usb_puti(vals[i]);
262
			usb_putc('\t');
264
		/* Use the current set of collected values */
265
		prtValPtr = curVals;
266
	}
263 267

  
264
			for (j = 0; j < (int)((max - vals[i]) / 5); j++) {
265
				usb_putc('#');
266
			}
268
	/* Display results */
269
	for (i = 0; i < 16; i++) {
270
		
271
		usb_puti(i);
272
		usb_puts(": ");
273
		usb_puti(prtValPtr[i]);
274
		usb_putc('\t');
267 275

  
268
			usb_putc('\n');
269

  
276
		for (j = 0; j < (int)((max - prtValPtr[i]) / 5); j++) {
277
			usb_putc('#');
270 278
		}
271

  
272
		usb_puts("Max: ");
273
		usb_puti(bom_get_max());
274
		usb_putc('\n');
275
		usb_putc('\n');
276

  
277
		delay_ms(400);
278

  
279
		usb_puts("\r\n");
279 280
	}
280

  
281
	usb_puts("\r\n");
281 282

  
282 283
}
283 284

  

Also available in: Unified diff