00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038
00039 #include "config.h"
00040 #include "config_util.h"
00041 #include "eventlog.h"
00042 #include "lcmtypes_velodyne_t.h"
00043 #include "lcmtypes_pose_t.h"
00044 #include "small_linalg.h"
00045 #include "velodyne.h"
00046
00047 int main(int argc, char **argv)
00048 {
00049 if(argc < 4) {
00050 fprintf(stderr,
00051 "usage: example4-velodyne <logfile> <start_time> <end time>\n"
00052 "\n"
00053 "start_time and end_time are given in seconds from the\n"
00054 "start of the log file\n");
00055 return 1;
00056 }
00057
00058 lcm_eventlog_t *log = lcm_eventlog_create(argv[1], "r");
00059 if(!log) {
00060 fprintf(stderr, "error opening log file\n");
00061 return 1;
00062 }
00063
00064 double start_time = strtod(argv[2], NULL);
00065 double end_time = strtod(argv[3], NULL);
00066
00067 Config *config = config_parse_default();
00068 if(!config) {
00069 fprintf(stderr, "couldn't find config file\n");
00070 return 1;
00071 }
00072
00073
00074 velodyne_calib_t *vcalib = velodyne_calib_create();
00075
00076
00077 lcm_eventlog_event_t *event = lcm_eventlog_read_next_event(log);
00078 int64_t first_timestamp = event->timestamp;
00079
00080
00081 int64_t start_utime = first_timestamp + (int64_t)(start_time * 1000000);
00082 int64_t end_utime = first_timestamp + (int64_t)(end_time * 1000000);
00083
00084 lcmtypes_pose_t last_pose;
00085 memset(&last_pose, 0, sizeof(last_pose));
00086
00087 while(1) {
00088
00089 lcm_eventlog_free_event(event);
00090
00091
00092 event = lcm_eventlog_read_next_event(log);
00093
00094 if(!event)
00095 break;
00096
00097
00098 if(!strcmp(event->channel, "POSE")) {
00099 if(last_pose.utime)
00100 lcmtypes_pose_t_decode_cleanup(&last_pose);
00101
00102 lcmtypes_pose_t_decode(event->data, 0, event->datalen, &last_pose);
00103 }
00104
00105
00106 if(event->timestamp < start_utime) {
00107 continue;
00108 }
00109
00110
00111 if(event->timestamp >= end_utime) {
00112 break;
00113 }
00114
00115 if(!strcmp(event->channel, "VELODYNE")) {
00116
00117 lcmtypes_velodyne_t vel;
00118 lcmtypes_velodyne_t_decode(event->data, 0, event->datalen,
00119 &vel);
00120
00121
00122
00123
00124
00125
00126 double velodyne_to_local[16];
00127 config_util_sensor_to_local_with_pose (config, "VELODYNE",
00128 velodyne_to_local, &last_pose);
00129
00130
00131 velodyne_decoder_t vdecoder;
00132 velodyne_decoder_init(vcalib, &vdecoder, vel.data, vel.datalen);
00133
00134
00135
00136 velodyne_sample_t vsample;
00137 while (!velodyne_decoder_next(vcalib, &vdecoder, &vsample)) {
00138 if (vsample.range < 0.01) {
00139 continue;
00140 }
00141
00142 double sensor_xyz[4] = {
00143 vsample.xyz[0], vsample.xyz[1], vsample.xyz[2], 1
00144 };
00145 double local_xyz[4];
00146 matrix_vector_multiply_4x4_4d(velodyne_to_local,
00147 sensor_xyz, local_xyz);
00148
00149 printf("%f %f %f\n", local_xyz[0], local_xyz[1], local_xyz[2]);
00150 }
00151
00152 lcmtypes_velodyne_t_decode_cleanup(&vel);
00153 }
00154
00155 }
00156 lcm_eventlog_free_event(event);
00157
00158 lcm_eventlog_destroy(log);
00159
00160 return 0;
00161 }