Apollo 10.0
自动驾驶开放平台
lslidarCH120_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 last_packet_time = 0;
27}
28
30 const std::shared_ptr<LslidarScan>& scan_msg,
31 const std::shared_ptr<PointCloud>& out_msg) {
32 // allocate a point cloud with same time and frame ID as raw data
33 out_msg->mutable_header()->set_timestamp_sec(
34 scan_msg->basetime() / 1000000000.0);
35 out_msg->mutable_header()->set_module_name(
36 scan_msg->header().module_name());
37 out_msg->mutable_header()->set_frame_id(scan_msg->header().frame_id());
38 out_msg->set_height(1);
39 out_msg->set_measurement_time(scan_msg->basetime() / 1000000000.0);
40 out_msg->mutable_header()->set_sequence_num(
41 scan_msg->header().sequence_num());
42 gps_base_usec_ = scan_msg->basetime();
43
44 packets_size = scan_msg->firing_pkts_size();
45
46 for (size_t i = 0; i < packets_size; ++i) {
47 Unpack(static_cast<int>(i),
48 scan_msg->firing_pkts(static_cast<int>(i)),
49 out_msg);
50 last_time_stamp_ = out_msg->measurement_time();
51 ADEBUG << "stamp: " << std::fixed << last_time_stamp_;
52 }
53
54 if (out_msg->point().empty()) {
55 // we discard this pointcloud if empty
56 AERROR << "All points is NAN!Please check lslidar:" << config_.model();
57 }
58 // set default width
59 out_msg->set_width(out_msg->point_size());
60}
61
66void LslidarCH120Parser::Unpack(
67 int num,
68 const LslidarPacket& pkt,
69 std::shared_ptr<PointCloud> pc) {
70 float x, y, z;
71 uint64_t packet_end_time;
72 double z_sin_altitude = 0.0;
73 double z_cos_altitude = 0.0;
74 const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
75 time_last = 0;
76
77 packet_end_time = pkt.stamp();
78
79 for (int point_idx1 = 0; point_idx1 < POINTS_PER_PACKET; point_idx1++) {
80 firings[point_idx1].vertical_line
81 = raw->points[point_idx1].vertical_line;
82 two_bytes point_amuzith;
83 point_amuzith.bytes[0] = raw->points[point_idx1].azimuth_2;
84 point_amuzith.bytes[1] = raw->points[point_idx1].azimuth_1;
85 firings[point_idx1].azimuth
86 = static_cast<double>(point_amuzith.uint * 0.01 * DEG_TO_RAD);
87 four_bytes point_distance;
88 point_distance.bytes[0] = raw->points[point_idx1].distance_3;
89 point_distance.bytes[1] = raw->points[point_idx1].distance_2;
90 point_distance.bytes[2] = raw->points[point_idx1].distance_1;
91 point_distance.bytes[3] = 0;
92 firings[point_idx1].distance = static_cast<double>(point_distance.uint)
93 * DISTANCE_RESOLUTION2;
94 firings[point_idx1].intensity = raw->points[point_idx1].intensity;
95 }
96
97 for (int point_idx = 0; point_idx < POINTS_PER_PACKET; point_idx++) {
98 LaserCorrection& corrections
100 .laser_corrections_[firings[point_idx].vertical_line];
101
102 if (config_.calibration())
103 firings[point_idx].distance
104 = firings[point_idx].distance + corrections.dist_correction;
105
106 if (firings[point_idx].distance > config_.max_range()
107 || firings[point_idx].distance < config_.min_range())
108 continue;
109
110 z_sin_altitude = sin(
111 (-13 + 0.167 * firings[point_idx].vertical_line) * DEG_TO_RAD);
112 z_cos_altitude = sqrt(1 - z_sin_altitude * z_sin_altitude);
113 x = firings[point_idx].distance * z_cos_altitude
114 * cos(firings[point_idx].azimuth);
115 y = firings[point_idx].distance * z_cos_altitude
116 * sin(firings[point_idx].azimuth);
117 z = firings[point_idx].distance * z_sin_altitude;
118
119 // Compute the time of the point
120 uint64_t point_time
121 = packet_end_time - 1282 * (POINTS_PER_PACKET - point_idx - 1);
122 if (time_last < point_time && time_last > 0) {
123 point_time = time_last + 1282;
124 }
125 time_last = point_time;
126
127 PointXYZIT* point = pc->add_point();
128 point->set_timestamp(point_time);
129 point->set_intensity(firings[point_idx].intensity);
130
131 if (config_.calibration()) {
133 firings[point_idx].vertical_line,
134 CH120,
135 firings[point_idx].distance,
136 &corrections,
137 firings[point_idx].azimuth,
138 point);
139
140 } else {
141 if ((y >= config_.bottom_left_x() && y <= config_.top_right_x())
142 && (-x >= config_.bottom_left_y()
143 && -x <= config_.top_right_y())) {
144 point->set_x(nan);
145 point->set_y(nan);
146 point->set_z(nan);
147 point->set_timestamp(point_time);
148 point->set_intensity(0);
149 } else {
150 point->set_x(y);
151 point->set_y(-x);
152 point->set_z(z);
153 }
154 }
155 }
156}
157
158void LslidarCH120Parser::Order(std::shared_ptr<PointCloud> cloud) {}
159
160} // namespace parser
161} // namespace lslidar
162} // namespace drivers
163} // namespace apollo
std::map< int, LaserCorrection > laser_corrections_
Definition calibration.h:72
void Order(std::shared_ptr< PointCloud > cloud)
void GeneratePointcloud(const std::shared_ptr< LslidarScan > &scan_msg, const std::shared_ptr< PointCloud > &out_msg)
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 CH120
class register implement
Definition arena_queue.h:37
used for unpacking the first two data bytes in a block