#include "open_urg_sensor.h"
#include <stdio.h>
#include <stdlib.h>
static void print_echo_data(long data[], unsigned short intensity[],
int index)
{
int i;
printf("%ld, ", data[(URG_MAX_ECHO * index) + i]);
}
printf("%d, ", intensity[(URG_MAX_ECHO * index) + i]);
}
}
static void print_data(
urg_t *urg,
long data[],
unsigned short intensity[], int data_n, long time_stamp)
{
#if 1
int front_index;
(void)data_n;
print_echo_data(data, intensity, front_index);
printf("%ld\n", time_stamp);
#else
(void)urg;
int i;
printf("# n = %d, time_stamp = %ld\n", data_n, time_stamp);
for (i = 0; i < data_n; ++i) {
print_echo_data(data, intensity, i);
printf("\n");
}
#endif
}
int main(int argc, char *argv[])
{
enum {
CAPTURE_TIMES = 10,
};
int max_data_size;
long *data = NULL;
unsigned short *intensity = NULL;
long time_stamp;
int n;
int i;
if (open_urg_sensor(&urg, argc, argv) < 0) {
return 1;
}
data = (
long *)malloc(max_data_size *
URG_MAX_ECHO *
sizeof(data[0]));
intensity = (unsigned short *)malloc(max_data_size *
if (!data) {
perror("urg_max_index()");
return 1;
}
for (i = 0; i < CAPTURE_TIMES; ++i) {
if (n <= 0) {
printf(
"urg_get_multiecho_intensity: %s\n",
urg_error(&urg));
free(data);
free(intensity);
return 1;
}
print_data(&urg, data, intensity, n, time_stamp);
}
free(data);
free(intensity);
#if defined(URG_MSC)
getchar();
#endif
return 0;
}