Apollo 10.0
自动驾驶开放平台
lslidarCH64_parser.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19namespace apollo {
20namespace drivers {
21namespace lslidar {
22namespace parser {
23
25 LslidarParser(config), previous_packet_stamp_(0), gps_base_usec_(0) {}
26
28 const std::shared_ptr<LslidarScan>& scan_msg,
29 const std::shared_ptr<PointCloud>& out_msg) {
30 // allocate a point cloud with same time and frame ID as raw data
31 out_msg->mutable_header()->set_timestamp_sec(
32 scan_msg->basetime() / 1000000000.0);
33 out_msg->mutable_header()->set_module_name(
34 scan_msg->header().module_name());
35 out_msg->mutable_header()->set_frame_id(scan_msg->header().frame_id());
36 out_msg->set_height(1);
37 out_msg->set_measurement_time(scan_msg->basetime() / 1000000000.0);
38 out_msg->mutable_header()->set_sequence_num(
39 scan_msg->header().sequence_num());
40 gps_base_usec_ = scan_msg->basetime();
41
42 packets_size = scan_msg->firing_pkts_size();
43
44 for (size_t i = 0; i < packets_size; ++i) {
45 Unpack(static_cast<int>(i),
46 scan_msg->firing_pkts(static_cast<int>(i)),
47 out_msg);
48 last_time_stamp_ = out_msg->measurement_time();
49 ADEBUG << "stamp: " << std::fixed << last_time_stamp_;
50 }
51
52 if (out_msg->point().empty()) {
53 // we discard this pointcloud if empty
54 AERROR << "All points is NAN!Please check lslidar:" << config_.model();
55 }
56
57 // set default width
58 out_msg->set_width(out_msg->point_size());
59}
60
65void LslidarCH64Parser::Unpack(
66 int num,
67 const LslidarPacket& pkt,
68 std::shared_ptr<PointCloud> pc) {
69 float x, y, z;
70 uint64_t point_time;
71 uint64_t packet_end_time;
72 double z_sin_altitude = 0.0;
73 double z_cos_altitude = 0.0;
74 time_last = 0;
75 const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
76
77 packet_end_time = pkt.stamp();
78
79 for (size_t point_idx = 0; point_idx < POINTS_PER_PACKET; point_idx++) {
80 firings[point_idx].vertical_line = raw->points[point_idx].vertical_line;
81 two_bytes point_amuzith;
82 point_amuzith.bytes[0] = raw->points[point_idx].azimuth_2;
83 point_amuzith.bytes[1] = raw->points[point_idx].azimuth_1;
84 firings[point_idx].azimuth
85 = static_cast<double>(point_amuzith.uint) * 0.01 * DEG_TO_RAD;
86 four_bytes point_distance;
87 point_distance.bytes[0] = raw->points[point_idx].distance_3;
88 point_distance.bytes[1] = raw->points[point_idx].distance_2;
89 point_distance.bytes[2] = raw->points[point_idx].distance_1;
90 point_distance.bytes[3] = 0;
91 firings[point_idx].distance = static_cast<double>(point_distance.uint)
92 * DISTANCE_RESOLUTION2;
93 firings[point_idx].intensity = raw->points[point_idx].intensity;
94 }
95
96 for (size_t point_idx = 0; point_idx < POINTS_PER_PACKET; point_idx++) {
97 LaserCorrection& corrections
99 .laser_corrections_[firings[point_idx].vertical_line];
100
101 if (config_.calibration())
102 firings[point_idx].distance
103 = firings[point_idx].distance + corrections.dist_correction;
104
105 if (firings[point_idx].distance > config_.max_range()
106 || firings[point_idx].distance < config_.min_range())
107 continue;
108
109 int line_num = firings[point_idx].vertical_line;
110
111 // Convert the point to xyz coordinate
112 if (line_num % 8 == 0 || line_num % 8 == 1 || line_num % 8 == 2
113 || line_num % 8 == 3) {
114 z_sin_altitude = sin(-13.33 * DEG_TO_RAD
115 + floor(line_num / 4) * 1.33 * DEG_TO_RAD)
116 + 2
117 * cos(firings[point_idx].azimuth / 2
118 + 1.05 * DEG_TO_RAD)
119 * sin((line_num % 4) * 0.33 * DEG_TO_RAD);
120
121 } else if (
122 line_num % 8 == 4 || line_num % 8 == 5 || line_num % 8 == 6
123 || line_num % 8 == 7) {
124 z_sin_altitude = sin(-13.33 * DEG_TO_RAD
125 + floor(line_num / 4) * 1.33 * DEG_TO_RAD)
126 + 2
127 * cos(firings[point_idx].azimuth / 2
128 - 1.05 * DEG_TO_RAD)
129 * sin((line_num % 4) * 0.33 * DEG_TO_RAD);
130 }
131
132 z_cos_altitude = sqrt(1 - z_sin_altitude * z_sin_altitude);
133 x = firings[point_idx].distance * z_cos_altitude
134 * cos(firings[point_idx].azimuth);
135 y = firings[point_idx].distance * z_cos_altitude
136 * sin(firings[point_idx].azimuth);
137 z = firings[point_idx].distance * z_sin_altitude;
138
139 // Compute the time of the point
140 point_time
141 = packet_end_time - 1726 * (POINTS_PER_PACKET - point_idx - 1);
142 if (time_last < point_time && time_last > 0) {
143 point_time = time_last + 1726;
144 }
145 time_last = point_time;
146
147 PointXYZIT* point = pc->add_point();
148 point->set_timestamp(point_time);
149 point->set_intensity(firings[point_idx].intensity);
150
151 if (config_.calibration()) {
153 firings[point_idx].vertical_line,
154 CH64,
155 firings[point_idx].distance,
156 &corrections,
157 firings[point_idx].azimuth,
158 point);
159
160 } else {
161 if ((y >= config_.bottom_left_x() && y <= config_.top_right_x())
162 && (-x >= config_.bottom_left_y()
163 && -x <= config_.top_right_y())) {
164 point->set_x(nan);
165 point->set_y(nan);
166 point->set_z(nan);
167 point->set_timestamp(point_time);
168 point->set_intensity(0);
169 } else {
170 point->set_x(y);
171 point->set_y(-x);
172 point->set_z(z);
173 }
174 }
175 }
176}
177
178void LslidarCH64Parser::Order(std::shared_ptr<PointCloud> cloud) {}
179
180} // namespace parser
181} // namespace lslidar
182} // namespace drivers
183} // namespace apollo
std::map< int, LaserCorrection > laser_corrections_
Definition calibration.h:72
void GeneratePointcloud(const std::shared_ptr< LslidarScan > &scan_msg, const std::shared_ptr< apollo::drivers::PointCloud > &out_msg)
Set up for data processing.
void Order(std::shared_ptr< apollo::drivers::PointCloud > cloud)
void ComputeCoords2(int Laser_ring, int Type, const float &raw_distance, LaserCorrection *corrections, const double rotation, PointXYZIT *point)
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
These classes Unpack raw Lslidar LIDAR packets into several useful formats.
#define DEG_TO_RAD
#define CH64
class register implement
Definition arena_queue.h:37
used for unpacking the first two data bytes in a block