calculate_xy.c
Go to the documentation of this file.
1 
12 #include "urg_c/urg_sensor.h"
13 #include "urg_c/urg_utils.h"
14 #include "open_urg_sensor.h"
15 #include <math.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 
19 
20 int main(int argc, char *argv[])
21 {
22  urg_t urg;
23  long *data;
24  long max_distance;
25  long min_distance;
26  long time_stamp;
27  unsigned long long system_time_stamp;
28  int i;
29  int n;
30 
31  if (open_urg_sensor(&urg, argc, argv) < 0) {
32  return 1;
33  }
34 
35  data = (long *)malloc(urg_max_data_size(&urg) * sizeof(data[0]));
36  if (!data) {
37  perror("urg_max_index()");
38  return 1;
39  }
40 
41  // \~japanese データ取得
43  n = urg_get_distance(&urg, data, &time_stamp, &system_time_stamp);
44  if (n < 0) {
45  printf("urg_get_distance: %s\n", urg_error(&urg));
46  urg_close(&urg);
47  return 1;
48  }
49 
50  // \~japanese X-Y 座標系の値を出力 urg_distance_min_max(&urg, &min_distance, &max_distance); for (i = 0; i < n; ++i) { long distance = data[i]; double radian; long x; long y; if ((distance < min_distance) || (distance > max_distance)) { continue; } radian = urg_index2rad(&urg, i); x = (long)(distance * cos(radian)); y = (long)(distance * sin(radian)); printf("%ld, %ld\n", x, y); } printf("\n"); // \~japanese 切断 free(data); urg_close(&urg); #if defined(URG_MSC) getchar(); #endif return 0; }
51  urg_distance_min_max(&urg, &min_distance, &max_distance);
52  for (i = 0; i < n; ++i) {
53  long distance = data[i];
54  double radian;
55  long x;
56  long y;
57 
58  if ((distance < min_distance) || (distance > max_distance)) {
59  continue;
60  }
61 
62  radian = urg_index2rad(&urg, i);
63  x = (long)(distance * cos(radian));
64  y = (long)(distance * sin(radian));
65 
66  printf("%ld, %ld\n", x, y);
67  }
68  printf("\n");
69 
70  // \~japanese 切断
71  free(data);
72  urg_close(&urg);
73 
74 #if defined(URG_MSC)
75  getchar();
76 #endif
77  return 0;
78 }
urg_t
URG sensor.
Definition: urg_sensor.h:72
urg_sensor.h
URG sensor.
urg_get_distance
int urg_get_distance(urg_t *urg, long data[], long *time_stamp, unsigned long long *system_time_stamp)
Definition: urg_sensor.c:934
open_urg_sensor.h
urg_distance_min_max
void urg_distance_min_max(const urg_t *urg, long *min_distance, long *max_distance)
Definition: urg_utils.c:73
urg_error
const char * urg_error(const urg_t *urg)
Definition: urg_utils.c:30
urg_index2rad
double urg_index2rad(const urg_t *urg, int index)
Definition: urg_utils.c:123
urg_close
void urg_close(urg_t *urg)
Definition: urg_sensor.c:745
URG_DISTANCE
@ URG_DISTANCE
Definition: urg_sensor.h:36
urg_utils.h
URG sensor utility.
open_urg_sensor
int open_urg_sensor(urg_t *urg, int argc, char *argv[])
Definition: open_urg_sensor.c:18
urg_max_data_size
int urg_max_data_size(const urg_t *urg)
Definition: urg_utils.c:114
urg_start_measurement
int urg_start_measurement(urg_t *urg, urg_measurement_type_t type, int scan_times, int skip_scan)
Definition: urg_sensor.c:877
main
int main(int argc, char *argv[])
Definition: calculate_xy.c:20


urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Wed Mar 2 2022 01:08:11