Project

General

Profile

Revision 1529

Added by John Sexton over 14 years ago

Merged new function to print BOM intensity histogram into the trunk.

View differences:

trunk/code/projects/libdragonfly/bom.c
228 228
}
229 229

  
230 230
/** 
231
 * Print a histogram which shows the current BOM intensity values for each of the 16 BOM IR
232
 *		sensors. The function will attempt to send the histogram data over USB.
233
 *
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
 **/
238
void bom_print_usb(int* usrBOMvals) {
239

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

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

  
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 {
254
		/* Refresh and make sure the table is updated */
255
		bom_refresh(BOM_ALL);
256

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

  
264
		/* Use the current set of collected values */
265
		prtValPtr = curVals;
266
	}
267

  
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');
275

  
276
		for (j = 0; j < (int)((max - prtValPtr[i]) / 5); j++) {
277
			usb_putc('#');
278
		}
279
		usb_puts("\r\n");
280
	}
281
	usb_puts("\r\n");
282

  
283
}
284

  
285
/** 
231 286
 * Computes the weighted average of all the bom readings to estimate the position (and distance) of another robot.
232 287
 *
233 288
 * @pre must call bom refresh
trunk/code/projects/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

  

Also available in: Unified diff