get_multiecho.c
Go to the documentation of this file.
1 
10 #include "urg_c/urg_sensor.h"
11 #include "urg_c/urg_utils.h"
12 #include "open_urg_sensor.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 
17 static void print_echo_data(long data[], int index)
18 {
19  int i;
20 
21  // [mm]
22  for (i = 0; i < URG_MAX_ECHO; ++i) {
23  printf("%ld, ", data[(URG_MAX_ECHO * index) + i]);
24  }
25 }
26 
27 
28 static void print_data(urg_t *urg, long data[], int data_n, long time_stamp)
29 {
30 #if 1
31  int front_index;
32 
33  (void)data_n;
34 
35  // \~japanese 前方のデータのみを表示
36  front_index = urg_step2index(urg, 0);
37  print_echo_data(data, front_index);
38  printf("%ld\n", time_stamp);
39 
40 #else
41  (void)urg;
42 
43  int i;
44 
45  // \~japanese 全てのデータを表示
46  printf("# n = %d, time_stamp = %ld\n", data_n, time_stamp);
47  for (i = 0; i < data_n; ++i) {
48  print_echo_data(data, i);
49  printf("\n");
50  }
51 #endif
52 }
53 
54 
55 int main(int argc, char *argv[])
56 {
57  enum {
58  CAPTURE_TIMES = 10,
59  };
60  urg_t urg;
61  long *data = NULL;
62  long time_stamp;
63  unsigned long long system_time_stamp;
64  int n;
65  int i;
66 
67  if (open_urg_sensor(&urg, argc, argv) < 0) {
68  return 1;
69  }
70 
71  data = (long *)malloc(urg_max_data_size(&urg) * 3 * sizeof(data[0]));
72  if (!data) {
73  perror("urg_max_index()");
74  return 1;
75  }
76 
77  // \~japanese データ取得
78  urg_start_measurement(&urg, URG_MULTIECHO, CAPTURE_TIMES, 0);
79  for (i = 0; i < CAPTURE_TIMES; ++i) {
80  n = urg_get_multiecho(&urg, data, &time_stamp, &system_time_stamp);
81  if (n <= 0) {
82  printf("urg_get_multiecho: %s\n", urg_error(&urg));
83  free(data);
84  urg_close(&urg);
85  return 1;
86  }
87  print_data(&urg, data, n, time_stamp);
88  }
89 
90  // \~japanese 切断
91  free(data);
92  urg_close(&urg);
93 
94 #if defined(URG_MSC)
95  getchar();
96 #endif
97  return 0;
98 }
int urg_start_measurement(urg_t *urg, urg_measurement_type_t type, int scan_times, int skip_scan)
Definition: urg_sensor.c:877
URG sensor.
Definition: urg_sensor.h:72
URG sensor.
const char * urg_error(const urg_t *urg)
Definition: urg_utils.c:30
void urg_close(urg_t *urg)
Definition: urg_sensor.c:745
static void print_echo_data(long data[], int index)
Definition: get_multiecho.c:17
int main(int argc, char *argv[])
Definition: get_multiecho.c:55
int urg_step2index(const urg_t *urg, int step)
Definition: urg_utils.c:198
int open_urg_sensor(urg_t *urg, int argc, char *argv[])
int urg_get_multiecho(urg_t *urg, long data_multi[], long *time_stamp, unsigned long long *system_time_stamp)
Definition: urg_sensor.c:955
URG sensor utility.
static void print_data(urg_t *urg, long data[], int data_n, long time_stamp)
Definition: get_multiecho.c:28
int urg_max_data_size(const urg_t *urg)
Definition: urg_utils.c:114


urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Wed Jun 10 2020 03:48:10