get_multiecho_intensity.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[], unsigned short intensity[],
18  int index)
19 {
20  int i;
21 
22  // [mm]
23  for (i = 0; i < URG_MAX_ECHO; ++i) {
24  printf("%ld, ", data[(URG_MAX_ECHO * index) + i]);
25  }
26 
27  // [1]
28  for (i = 0; i < URG_MAX_ECHO; ++i) {
29  printf("%d, ", intensity[(URG_MAX_ECHO * index) + i]);
30  }
31 }
32 
33 
34 // \~japanese 距離、強度のデータを表示する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; // \~japanese 前方のデータのみを表示 front_index = urg_step2index(urg, 0); print_echo_data(data, intensity, front_index); printf("%ld\n", time_stamp); #else (void)urg; int i; // \~japanese 全てのデータを表示 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, }; urg_t urg; int max_data_size; long *data = NULL; unsigned short *intensity = NULL; long time_stamp; unsigned long long system_time_stamp; int n; int i; if (open_urg_sensor(&urg, argc, argv) < 0) { return 1; } max_data_size = urg_max_data_size(&urg); data = (long *)malloc(max_data_size * 3 * sizeof(data[0])); intensity = (unsigned short *)malloc(max_data_size * 3 * sizeof(intensity[0])); if (!data) { perror("urg_max_index()"); return 1; } // \~japanese データ取得 urg_start_measurement(&urg, URG_MULTIECHO_INTENSITY, CAPTURE_TIMES, 0); for (i = 0; i < CAPTURE_TIMES; ++i) { n = urg_get_multiecho_intensity(&urg, data, intensity, &time_stamp, &system_time_stamp); if (n <= 0) { printf("urg_get_multiecho_intensity: %s\n", urg_error(&urg)); free(data); free(intensity); urg_close(&urg); return 1; } print_data(&urg, data, intensity, n, time_stamp); } // \~japanese 切断 free(data); free(intensity); urg_close(&urg); #if defined(URG_MSC) getchar(); #endif return 0; }
35 static void print_data(urg_t *urg, long data[],
36  unsigned short intensity[], int data_n, long time_stamp)
37 {
38 #if 1
39  int front_index;
40 
41  (void)data_n;
42 
43  // \~japanese 前方のデータのみを表示
44  front_index = urg_step2index(urg, 0);
45  print_echo_data(data, intensity, front_index);
46  printf("%ld\n", time_stamp);
47 
48 #else
49  (void)urg;
50  int i;
51 
52  // \~japanese 全てのデータを表示
53  printf("# n = %d, time_stamp = %ld\n", data_n, time_stamp);
54  for (i = 0; i < data_n; ++i) {
55  print_echo_data(data, intensity, i);
56  printf("\n");
57  }
58 #endif
59 }
60 
61 
62 int main(int argc, char *argv[])
63 {
64  enum {
65  CAPTURE_TIMES = 10,
66  };
67  urg_t urg;
68  int max_data_size;
69  long *data = NULL;
70  unsigned short *intensity = NULL;
71  long time_stamp;
72  unsigned long long system_time_stamp;
73  int n;
74  int i;
75 
76  if (open_urg_sensor(&urg, argc, argv) < 0) {
77  return 1;
78  }
79 
80  max_data_size = urg_max_data_size(&urg);
81  data = (long *)malloc(max_data_size * 3 * sizeof(data[0]));
82  intensity = (unsigned short *)malloc(max_data_size * 3 *
83  sizeof(intensity[0]));
84 
85  if (!data) {
86  perror("urg_max_index()");
87  return 1;
88  }
89 
90  // \~japanese データ取得
91  urg_start_measurement(&urg, URG_MULTIECHO_INTENSITY, CAPTURE_TIMES, 0);
92  for (i = 0; i < CAPTURE_TIMES; ++i) {
93  n = urg_get_multiecho_intensity(&urg, data, intensity, &time_stamp, &system_time_stamp);
94  if (n <= 0) {
95  printf("urg_get_multiecho_intensity: %s\n", urg_error(&urg));
96  free(data);
97  free(intensity);
98  urg_close(&urg);
99  return 1;
100  }
101  print_data(&urg, data, intensity, n, time_stamp);
102  }
103 
104  // \~japanese 切断
105  free(data);
106  free(intensity);
107  urg_close(&urg);
108 
109 #if defined(URG_MSC)
110  getchar();
111 #endif
112  return 0;
113 }
int urg_start_measurement(urg_t *urg, urg_measurement_type_t type, int scan_times, int skip_scan)
Definition: urg_sensor.c:877
static void print_echo_data(long data[], unsigned short intensity[], int index)
URG sensor.
Definition: urg_sensor.h:72
URG sensor.
int main(int argc, char *argv[])
const char * urg_error(const urg_t *urg)
Definition: urg_utils.c:30
void urg_close(urg_t *urg)
Definition: urg_sensor.c:745
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_intensity(urg_t *urg, long data_multi[], unsigned short intensity_multi[], long *time_stamp, unsigned long long *system_time_stamp)
Definition: urg_sensor.c:965
URG sensor utility.
int urg_max_data_size(const urg_t *urg)
Definition: urg_utils.c:114
static void print_data(urg_t *urg, long data[], unsigned short intensity[], int data_n, long time_stamp)


urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Thu Jun 6 2019 19:27:49