Measure distance data
- Author
- Satofumi KAMIMURA
- Id:
- get_distance.c,v 586c4fa697ef 2011/01/24 08:50:01 Satofumi
#include "open_urg_sensor.h"
#include <stdlib.h>
#include <stdio.h>
static void print_data(
urg_t *urg,
long data[],
int data_n,
long time_stamp)
{
#if 1
int front_index;
(void)data_n;
printf("%ld [mm], (%ld [msec])\n", data[front_index], time_stamp);
#else
(void)time_stamp;
int i;
long min_distance;
long max_distance;
for (i = 0; i < data_n; ++i) {
long l = data[i];
double radian;
long x;
long y;
if ((l <= min_distance) || (l >= max_distance)) {
continue;
}
x = (long)(l * cos(radian));
y = (long)(l * sin(radian));
printf("(%ld, %ld), ", x, y);
}
printf("\n");
#endif
}
int main(int argc, char *argv[])
{
enum {
CAPTURE_TIMES = 10,
};
long *data = NULL;
long time_stamp;
int n;
int i;
if (open_urg_sensor(&urg, argc, argv) < 0) {
return 1;
}
if (!data) {
perror("urg_max_index()");
return 1;
}
#if 0
#endif
for (i = 0; i < CAPTURE_TIMES; ++i) {
if (n <= 0) {
printf(
"urg_get_distance: %s\n",
urg_error(&urg));
free(data);
return 1;
}
print_data(&urg, data, n, time_stamp);
}
free(data);
#if defined(URG_MSC)
getchar();
#endif
return 0;
}