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 #include <string.h>
00016
00017
00018 static void print_data(urg_t *urg, long data[], unsigned short intensity[],
00019 int data_n, long time_stamp)
00020 {
00021 #if 1
00022 int front_index;
00023 (void)data_n;
00024
00025
00026 front_index = urg_step2index(urg, 0);
00027 printf("%ld [mm], %d [1], (%ld [msec])\n",
00028 data[front_index], intensity[front_index], time_stamp);
00029
00030 #else
00031 (void)urg;
00032
00033 int i;
00034
00035
00036 printf("# n = %d, time_stamp = %ld\n", data_n, time_stamp);
00037 for (i = 0; i < data_n; ++i) {
00038 printf("%d, %ld, %d\n", i, data[i], intensity[i]);
00039 }
00040 #endif
00041 }
00042
00043
00044 int main(int argc, char *argv[])
00045 {
00046 enum {
00047 CAPTURE_TIMES = 10,
00048 };
00049 urg_t urg;
00050 int max_data_size;
00051 long *data = NULL;
00052 unsigned short *intensity = NULL;
00053 long time_stamp;
00054 unsigned long long system_time_stamp;
00055 int n;
00056 int i;
00057
00058 if (open_urg_sensor(&urg, argc, argv) < 0) {
00059 return 1;
00060 }
00061
00062
00063 if (!strstr(urg_sensor_product_type(&urg),"UXM-30LX")) {
00064 fprintf(stderr,"Distance Intensity not supported on %s\n",
00065 urg_sensor_product_type(&urg));
00066 return 1;
00067 }
00068
00069 max_data_size = urg_max_data_size(&urg);
00070 data = (long *)malloc(max_data_size * sizeof(data[0]));
00071 if (!data) {
00072 perror("urg_max_index()");
00073 return 1;
00074 }
00075 intensity = malloc(max_data_size * sizeof(intensity[0]));
00076 if (!intensity) {
00077 perror("urg_max_index()");
00078 return 1;
00079 }
00080
00081
00082 urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, CAPTURE_TIMES, 0);
00083 for (i = 0; i < CAPTURE_TIMES; ++i) {
00084 n = urg_get_distance_intensity(&urg, data, intensity, &time_stamp, &system_time_stamp);
00085 if (n <= 0) {
00086 printf("urg_get_distance_intensity: %s\n", urg_error(&urg));
00087 free(data);
00088 urg_close(&urg);
00089 return 1;
00090 }
00091 print_data(&urg, data, intensity, n, time_stamp);
00092 }
00093
00094
00095 free(intensity);
00096 free(data);
00097 urg_close(&urg);
00098
00099 #if defined(URG_MSC)
00100 getchar();
00101 #endif
00102 return 0;
00103 }