Go to the documentation of this file.00001
00010 #include "urg_c/urg_sensor.h"
00011 #include "urg_c/urg_utils.h"
00012 #include "open_urg_sensor.h"
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015
00016
00017 static void print_data(urg_t *urg, long data[], unsigned short intensity[],
00018 int data_n, long time_stamp)
00019 {
00020 #if 1
00021 int front_index;
00022 (void)data_n;
00023
00024
00025 front_index = urg_step2index(urg, 0);
00026 printf("%ld [mm], %d [1], (%ld [msec])\n",
00027 data[front_index], intensity[front_index], time_stamp);
00028
00029 #else
00030 (void)urg;
00031
00032 int i;
00033
00034
00035 printf("# n = %d, time_stamp = %ld\n", data_n, time_stamp);
00036 for (i = 0; i < data_n; ++i) {
00037 printf("%d, %ld, %d\n", i, data[i], intensity[i]);
00038 }
00039 #endif
00040 }
00041
00042
00043 int main(int argc, char *argv[])
00044 {
00045 enum {
00046 CAPTURE_TIMES = 10,
00047 };
00048 urg_t urg;
00049 int max_data_size;
00050 long *data = NULL;
00051 unsigned short *intensity = NULL;
00052 long time_stamp;
00053 unsigned long long system_time_stamp;
00054 int n;
00055 int i;
00056
00057 if (open_urg_sensor(&urg, argc, argv) < 0) {
00058 return 1;
00059 }
00060
00061 max_data_size = urg_max_data_size(&urg);
00062 data = (long *)malloc(max_data_size * sizeof(data[0]));
00063 if (!data) {
00064 perror("urg_max_index()");
00065 return 1;
00066 }
00067 intensity = malloc(max_data_size * sizeof(intensity[0]));
00068 if (!intensity) {
00069 perror("urg_max_index()");
00070 return 1;
00071 }
00072
00073
00074 urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, CAPTURE_TIMES, 0);
00075 for (i = 0; i < CAPTURE_TIMES; ++i) {
00076 n = urg_get_distance_intensity(&urg, data, intensity, &time_stamp, &system_time_stamp);
00077 if (n <= 0) {
00078 printf("urg_get_distance_intensity: %s\n", urg_error(&urg));
00079 free(data);
00080 urg_close(&urg);
00081 return 1;
00082 }
00083 print_data(&urg, data, intensity, n, time_stamp);
00084 }
00085
00086
00087 free(intensity);
00088 free(data);
00089 urg_close(&urg);
00090
00091 #if defined(URG_MSC)
00092 getchar();
00093 #endif
00094 return 0;
00095 }