Calculate X-Y grid points
Outputs the distance data position on the front sensor is considered Cartesian coordinate axis direction X.
- Author
- Satofumi KAMIMURA
- Id:
- calculate_xy.c,v 586c4fa697ef 2011/01/24 08:50:01 Satofumi
#include "open_urg_sensor.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
long *data;
long max_distance;
long min_distance;
long time_stamp;
int i;
int n;
if (open_urg_sensor(&urg, argc, argv) < 0) {
return 1;
}
if (!data) {
perror("urg_max_index()");
return 1;
}
if (n < 0) {
printf(
"urg_get_distance: %s\n",
urg_error(&urg));
return 1;
}
for (i = 0; i < n; ++i) {
long distance = data[i];
double radian;
long x;
long y;
if ((distance < min_distance) || (distance > max_distance)) {
continue;
}
x = (long)(distance * cos(radian));
y = (long)(distance * sin(radian));
printf("%ld, %ld\n", x, y);
}
printf("\n");
free(data);
#if defined(URG_MSC)
getchar();
#endif
return 0;
}