00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00033 #ifndef _VELODYNE_H 00034 #define _VELODYNE_H 00035 00036 #include <stdint.h> 00037 #include <math.h> 00038 00043 #define VELODYNE_NUM_LASERS 64 00044 00045 typedef struct velodyne_decoder velodyne_decoder_t; 00046 struct velodyne_decoder 00047 { 00048 uint8_t *data; 00049 uint8_t *p; 00050 int data_remaining; 00051 00052 int i; // which laser within the current block are we processing? 00053 int laser_offset; 00054 double ctheta, sin_ctheta, cos_ctheta; 00055 00056 int32_t revolution_count; 00057 char version_string[16]; 00058 }; 00059 00060 typedef struct velodyne_sample velodyne_sample_t; 00061 struct velodyne_sample 00062 { 00063 double xyz[3]; // calibrated, projected into velodyne coordinate system 00064 double raw_range; // raw return directly from sensor 00065 double range; // corrected range 00066 double ctheta; // theta of sensor head at time of sample, **always [0, 2*PI)** 00067 double theta; // calibrated theta (horizontal/yaw angle) **always [0, 2*PI)** 00068 double phi; // calibrated phi (veritcle/pitch angle) 00069 double intensity; // normalized intensity [0, 1] 00070 int physical; // physical laser number (0-31 lower, 32-63 upper) 00071 int logical; // logical laser number (in order of increasing pitch) 00072 }; 00073 00074 struct velodyne_laser_calib 00075 { 00076 double rcf; // radians (rotational/yaw offset) 00077 double vcf; // radians (vertical offset) 00078 double hcf; // meters (horizontal off-axis offset) 00079 double range_offset; // meters 00080 double range_scale_offset; // (scalar) 00081 }; 00082 00083 typedef struct 00084 { 00085 struct velodyne_laser_calib lasers[VELODYNE_NUM_LASERS]; // physical idx 00086 int physical2logical[VELODYNE_NUM_LASERS]; 00087 int logical2physical[VELODYNE_NUM_LASERS]; 00088 double sincos[VELODYNE_NUM_LASERS][2]; 00089 } velodyne_calib_t; 00090 00091 void velodyne_dump_calib(velodyne_calib_t *v); 00092 00093 00094 // Velodyne lidars are numbered in two different ways: 00095 // Physical: The order given by the hardware. 00096 // Logical: In order of increasing phi 00097 00098 velodyne_calib_t *velodyne_calib_create(); 00099 00100 // NOT REENTRANT. 00101 // Compute the logical laser numbers given the current phi angles 00102 // (necessary before calls to p2l or l2p) 00103 int velodyne_calib_precompute(velodyne_calib_t *v); 00104 00105 static inline int velodyne_physical_to_logical(velodyne_calib_t *v, int phys) 00106 { 00107 return v->physical2logical[phys]; 00108 } 00109 00110 static inline int velodyne_logical_to_physical(velodyne_calib_t *v, int logical) 00111 { 00112 return v->logical2physical[logical]; 00113 } 00114 00115 // return an upper bound on the # of samples in this message 00116 int velodyne_decoder_estimate_samples(velodyne_calib_t *v, const void *_data, int datalen); 00117 00118 int velodyne_decoder_init(velodyne_calib_t *v, velodyne_decoder_t *vd, const void *_data, int datalen); 00119 int velodyne_decoder_next(velodyne_calib_t *v, velodyne_decoder_t *vd, struct velodyne_sample *sample); 00120 00121 #endif 00122