example4velodyne.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 
39 #include "config.h"
40 #include "config_util.h"
41 #include "eventlog.h"
42 #include "lcmtypes_velodyne_t.h"
43 #include "lcmtypes_pose_t.h"
44 #include "small_linalg.h"
45 #include "velodyne.h"
46 
47 int main(int argc, char **argv)
48 {
49  if(argc < 4) {
50  fprintf(stderr,
51  "usage: example4-velodyne <logfile> <start_time> <end time>\n"
52  "\n"
53  "start_time and end_time are given in seconds from the\n"
54  "start of the log file\n");
55  return 1;
56  }
57 
58  lcm_eventlog_t *log = lcm_eventlog_create(argv[1], "r");
59  if(!log) {
60  fprintf(stderr, "error opening log file\n");
61  return 1;
62  }
63 
64  double start_time = strtod(argv[2], NULL);
65  double end_time = strtod(argv[3], NULL);
66 
67  Config *config = config_parse_default();
68  if(!config) {
69  fprintf(stderr, "couldn't find config file\n");
70  return 1;
71  }
72 
73  // load the velodyne sensor calibration
75 
76  // read the first timestamp of the log file
78  int64_t first_timestamp = event->timestamp;
79 
80  // compute the desired start and end timestamps
81  int64_t start_utime = first_timestamp + (int64_t)(start_time * 1000000);
82  int64_t end_utime = first_timestamp + (int64_t)(end_time * 1000000);
83 
84  lcmtypes_pose_t last_pose;
85  memset(&last_pose, 0, sizeof(last_pose));
86 
87  while(1) {
88  // release the last event
90 
91  // read an event
92  event = lcm_eventlog_read_next_event(log);
93 
94  if(!event)
95  break;
96 
97  // always keep track of the current pose
98  if(!strcmp(event->channel, "POSE")) {
99  if(last_pose.utime)
100  lcmtypes_pose_t_decode_cleanup(&last_pose);
101 
102  lcmtypes_pose_t_decode(event->data, 0, event->datalen, &last_pose);
103  }
104 
105  // ignore other messages until the desired start time
106  if(event->timestamp < start_utime) {
107  continue;
108  }
109 
110  // quit if we're done
111  if(event->timestamp >= end_utime) {
112  break;
113  }
114 
115  if(!strcmp(event->channel, "VELODYNE")) {
116  // parse the LCM packet into a velodyne data packet.
118  lcmtypes_velodyne_t_decode(event->data, 0, event->datalen,
119  &vel);
120 
121  // compute the velodyne-to-local transformation matrix
122  //
123  // This is an approximation because we're using the last recorded
124  // pose. A more accurate projection might be to project the
125  // vehicle's pose forward based on its last measured velocity.
126  double velodyne_to_local[16];
127  config_util_sensor_to_local_with_pose (config, "VELODYNE",
128  velodyne_to_local, &last_pose);
129 
130  // parse the velodyne data packet
131  velodyne_decoder_t vdecoder;
132  velodyne_decoder_init(vcalib, &vdecoder, vel.data, vel.datalen);
133 
134  // project each sample in the velodyne data packet into the local
135  // frame
136  velodyne_sample_t vsample;
137  while (!velodyne_decoder_next(vcalib, &vdecoder, &vsample)) {
138  if (vsample.range < 0.01) {
139  continue;
140  }
141 
142  double sensor_xyz[4] = {
143  vsample.xyz[0], vsample.xyz[1], vsample.xyz[2], 1
144  };
145  double local_xyz[4];
146  matrix_vector_multiply_4x4_4d(velodyne_to_local,
147  sensor_xyz, local_xyz);
148 
149  printf("%f %f %f\n", local_xyz[0], local_xyz[1], local_xyz[2]);
150  }
151 
153  }
154 
155  }
157 
159 
160  return 0;
161 }
convenience functions for small linear algebra operations
int lcmtypes_velodyne_t_decode(const void *buf, int offset, int maxlen, lcmtypes_velodyne_t *p)
Config * config_parse_default(void)
Definition: config.cpp:603
int lcmtypes_pose_t_decode_cleanup(lcmtypes_pose_t *p)
header file to config.cpp Check the LCM instructions for more info
THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY BY HAND!! Generated by LCM.
void lcm_eventlog_destroy(lcm_eventlog_t *l)
Definition: eventlog.cpp:74
lcm_eventlog_event_t * lcm_eventlog_read_next_event(lcm_eventlog_t *l)
Definition: eventlog.cpp:80
header file for eventlog.cpp Check the LCM instructions for more info
header file with velodyne types
velodyne_calib_t * velodyne_calib_create()
Definition: velodyne.cpp:273
int velodyne_decoder_init(velodyne_calib_t *v, velodyne_decoder_t *vd, const void *_data, int datalen)
Definition: velodyne.cpp:61
int main(int argc, char **argv)
int lcmtypes_pose_t_decode(const void *buf, int offset, int maxlen, lcmtypes_pose_t *p)
static void matrix_vector_multiply_4x4_4d(const double m[16], const double v[4], double result[4])
Definition: small_linalg.h:106
int velodyne_decoder_next(velodyne_calib_t *v, velodyne_decoder_t *vd, struct velodyne_sample *sample)
Definition: velodyne.cpp:87
THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY BY HAND!! Generated by LCM.
int lcmtypes_velodyne_t_decode_cleanup(lcmtypes_velodyne_t *p)
int config_util_sensor_to_local_with_pose(Config *cfg, const char *name, double m[16], lcmtypes_pose_t *p)
void lcm_eventlog_free_event(lcm_eventlog_event_t *le)
Definition: eventlog.cpp:118
header file for config_util.cpp Check the LCM instructions for more info
lcm_eventlog_t * lcm_eventlog_create(const char *path, const char *mode)
Definition: eventlog.cpp:61
double xyz[3]
Definition: velodyne.h:63
double range
Definition: velodyne.h:65


mit_darpa_logs_player
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:15