get_distance_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 #include <string.h>
16 
17 
18 static void print_data(urg_t *urg, long data[], unsigned short intensity[],
19  int data_n, long time_stamp)
20 {
21 #if 1
22  int front_index;
23  (void)data_n;
24 
25  // \~japanese 前方のデータのみを表示
26  front_index = urg_step2index(urg, 0);
27  printf("%ld [mm], %d [1], (%ld [msec])\n",
28  data[front_index], intensity[front_index], time_stamp);
29 
30 #else
31  (void)urg;
32 
33  int i;
34 
35  // \~japanese 全てのデータを表示
36  printf("# n = %d, time_stamp = %ld\n", data_n, time_stamp);
37  for (i = 0; i < data_n; ++i) {
38  printf("%d, %ld, %d\n", i, data[i], intensity[i]);
39  }
40 #endif
41 }
42 
43 
44 int main(int argc, char *argv[])
45 {
46  enum {
47  CAPTURE_TIMES = 10,
48  };
49  urg_t urg;
50  int max_data_size;
51  long *data = NULL;
52  unsigned short *intensity = NULL;
53  long time_stamp;
54  unsigned long long system_time_stamp;
55  int n;
56  int i;
57 
58  if (open_urg_sensor(&urg, argc, argv) < 0) {
59  return 1;
60  }
61 
62  // Distance Intensity reading only (?) on UXM-30LX
63  if (!strstr(urg_sensor_product_type(&urg),"UXM-30LX")) {
64  fprintf(stderr,"Distance Intensity not supported on %s\n",
66  return 1;
67  }
68 
69  max_data_size = urg_max_data_size(&urg);
70  data = (long *)malloc(max_data_size * sizeof(data[0]));
71  if (!data) {
72  perror("urg_max_index()");
73  return 1;
74  }
75  intensity = malloc(max_data_size * sizeof(intensity[0]));
76  if (!intensity) {
77  perror("urg_max_index()");
78  return 1;
79  }
80 
81  // \~japanese データ取得
82  urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, CAPTURE_TIMES, 0);
83  for (i = 0; i < CAPTURE_TIMES; ++i) {
84  n = urg_get_distance_intensity(&urg, data, intensity, &time_stamp, &system_time_stamp);
85  if (n <= 0) {
86  printf("urg_get_distance_intensity: %s\n", urg_error(&urg));
87  free(data);
88  urg_close(&urg);
89  return 1;
90  }
91  print_data(&urg, data, intensity, n, time_stamp);
92  }
93 
94  // \~japanese 切断
95  free(intensity);
96  free(data);
97  urg_close(&urg);
98 
99 #if defined(URG_MSC)
100  getchar();
101 #endif
102  return 0;
103 }
urg_sensor_product_type
const char * urg_sensor_product_type(urg_t *urg)
Definition: urg_sensor.c:1180
urg_t
URG sensor.
Definition: urg_sensor.h:72
urg_sensor.h
URG sensor.
open_urg_sensor.h
urg_step2index
int urg_step2index(const urg_t *urg, int step)
Definition: urg_utils.c:198
urg_get_distance_intensity
int urg_get_distance_intensity(urg_t *urg, long data[], unsigned short intensity[], long *time_stamp, unsigned long long *system_time_stamp)
Definition: urg_sensor.c:943
urg_error
const char * urg_error(const urg_t *urg)
Definition: urg_utils.c:30
urg_close
void urg_close(urg_t *urg)
Definition: urg_sensor.c:745
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
print_data
static void print_data(urg_t *urg, long data[], unsigned short intensity[], int data_n, long time_stamp)
Definition: get_distance_intensity.c:18
URG_DISTANCE_INTENSITY
@ URG_DISTANCE_INTENSITY
Definition: urg_sensor.h:37
main
int main(int argc, char *argv[])
Definition: get_distance_intensity.c:44


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