24 :
VelodyneParser(config), previous_packet_stamp_(0), gps_base_usec_(0) {
30 const std::shared_ptr<VelodyneScan>& scan_msg,
31 std::shared_ptr<PointCloud> out_msg) {
33 out_msg->mutable_header()->set_frame_id(scan_msg->header().frame_id());
34 out_msg->set_height(1);
35 out_msg->mutable_header()->set_sequence_num(
36 scan_msg->header().sequence_num());
37 gps_base_usec_ = scan_msg->basetime();
39 size_t packets_size = scan_msg->firing_pkts_size();
40 for (
size_t i = 0; i < packets_size; ++i) {
41 Unpack(scan_msg->firing_pkts(
static_cast<int>(i)), out_msg);
46 if (out_msg->point().empty()) {
52 out_msg->set_width(out_msg->point_size());
55uint64_t Velodyne16Parser::GetTimestamp(
double base_time,
float time_offset,
57 double t = base_time - time_offset;
68void Velodyne16Parser::Unpack(
const VelodynePacket& pkt,
69 std::shared_ptr<PointCloud> pc) {
70 float azimuth_diff = 0.0f;
71 float last_azimuth_diff = 0.0f;
72 float azimuth_corrected_f = 0.0f;
73 int azimuth_corrected = 0;
76 const RawPacket* raw = (
const RawPacket*)pkt.data().c_str();
77 double basetime = raw->gps_timestamp;
80 float azimuth =
static_cast<float>(raw->blocks[block].rotation);
83 static_cast<float>((36000 + raw->blocks[block + 1].rotation -
84 raw->blocks[block].rotation) %
86 last_azimuth_diff = azimuth_diff;
88 azimuth_diff = last_azimuth_diff;
91 for (
int firing = 0, k = 0; firing < VLP16_FIRINGS_PER_BLOCK; ++firing) {
92 for (
int dsr = 0; dsr < VLP16_SCANS_PER_FIRING;
93 ++dsr, k += RAW_SCAN_SIZE) {
97 union RawDistance raw_distance;
98 raw_distance.bytes[0] = raw->blocks[block].data[k];
99 raw_distance.bytes[1] = raw->blocks[block].data[k + 1];
103 azimuth_corrected_f =
104 azimuth + (azimuth_diff *
105 ((
static_cast<float>(dsr) * VLP16_DSR_TOFFSET) +
106 (
static_cast<float>(firing) * VLP16_FIRING_TOFFSET)) /
107 VLP16_BLOCK_TDURATION);
109 static_cast<int>(round(fmod(azimuth_corrected_f, 36000.0)));
113 uint64_t timestamp = GetTimestamp(
115 (*
inner_time_)[block][firing * VLP16_SCANS_PER_FIRING + dsr],
119 firing == VLP16_FIRINGS_PER_BLOCK - 1 &&
120 dsr == VLP16_SCANS_PER_FIRING - 1) {
122 pc->set_measurement_time(
static_cast<double>(timestamp) / 1e9);
125 float real_distance = raw_distance.raw_distance * DISTANCE_RESOLUTION;
126 float distance = real_distance + corrections.dist_correction;
128 if (raw_distance.raw_distance == 0 ||
132 PointXYZIT* point = pc->add_point();
136 point->set_timestamp(timestamp);
137 point->set_intensity(0);
142 PointXYZIT* point = pc->add_point();
143 point->set_timestamp(timestamp);
146 static_cast<uint16_t
>(azimuth_corrected), point);
147 point->set_intensity(raw->blocks[block].data[k + 2]);
150 if (block == 0 && firing == 0) {
151 ADEBUG <<
"point x:" << point->x() <<
" y:" << point->y()
152 <<
" z:" << point->z()
153 <<
" intensity:" << int(point->intensity());
162 cloud->set_width(width);
163 int height = cloud->point_size() / cloud->width();
164 cloud->set_height(height);
166 std::shared_ptr<PointCloud> cloud_origin = std::make_shared<PointCloud>();
167 cloud_origin->CopyFrom(*cloud);
169 for (
int i = 0; i < width; ++i) {
172 for (
int j = 0; j < height; ++j) {
174 int target_index = j * width + i;
175 int origin_index = j * width + col;
176 cloud->mutable_point(target_index)
177 ->CopyFrom(cloud_origin->point(origin_index));
std::map< int, LaserCorrection > laser_corrections_
void GeneratePointcloud(const std::shared_ptr< VelodyneScan > &scan_msg, std::shared_ptr< PointCloud > out_msg)
Set up for data processing.
void Order(std::shared_ptr< PointCloud > cloud)
Velodyne16Parser(const Config &config)
Velodyne data conversion class
const float(* inner_time_)[12][32]
bool is_scan_valid(int rotation, float distance)
uint64_t GetGpsStamp(double current_stamp, double *previous_stamp, uint64_t *gps_base_usec)
bool need_two_pt_correction_
void ComputeCoords(const float &raw_distance, const LaserCorrection &corrections, const uint16_t rotation, PointXYZIT *point)
Compute coords with the data in block
const float INNER_TIME_16[12][32]
const int ORDER_16[16]
Order array for re-ordering point cloud.
constexpr int BLOCKS_PER_PACKET
Velodyne HDL-64E 3D LIDAR data accessors