Apollo  6.0
Open source self driving car software
parser.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 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 
17 #ifndef LIDAR_HESAI_SRC_PARSE_H
18 #define LIDAR_HESAI_SRC_PARSE_H
19 
20 #include <deque>
21 #include <memory>
22 #include <string>
23 #include <thread>
24 #include <vector>
25 
26 #include "modules/drivers/lidar/proto/hesai_config.pb.h"
27 #include "modules/drivers/lidar/proto/hesai.pb.h"
28 #include "modules/drivers/proto/pointcloud.pb.h"
29 
30 #include "cyber/cyber.h"
33 
34 namespace apollo {
35 namespace drivers {
36 namespace hesai {
37 
38 inline double degreeToRadian(double degree) { return degree * PI / 180; }
39 
40 class Parser {
41  public:
42  Parser(const std::shared_ptr<::apollo::cyber::Node>& node,
43  const Config& conf);
44  virtual ~Parser();
45  void Parse(const uint8_t* data, int size, bool* is_end);
46  bool Parse(const std::shared_ptr<HesaiScan>& scan);
47  bool Init();
48 
49  private:
50  std::thread online_calibration_thread_;
51  void GetCalibrationThread();
52  bool CheckIsEnd(bool is_end);
53  void LoadCalibrationThread();
54  bool LoadCalibration(const std::string& content);
55  bool LoadCalibration(const char* path_file);
56  void PublishRawPointCloud(int ret = -1);
57 
58  bool inited_ = false;
59  void Stop();
60  std::atomic<bool> running_ = {true};
61 
62  protected:
63  virtual void ParseRawPacket(const uint8_t* buf, const int len,
64  bool* is_end) = 0;
65  void CheckPktTime(double time_sec);
66  void ResetRawPointCloud();
67 
68  bool is_calibration_ = false;
69  std::shared_ptr<::apollo::cyber::Node> node_;
70  Config conf_;
71  std::shared_ptr<::apollo::cyber::Writer<PointCloud>> raw_pointcloud_writer_;
72  int pool_size_ = 8;
73  int pool_index_ = 0;
74  uint64_t raw_last_time_ = 0;
75  int seq_index_ = 0;
76  std::deque<std::shared_ptr<PointCloud>> raw_pointcloud_pool_;
77  // std::shared_ptr<CCObjectPool<PointCloud>> raw_pointcloud_pool_ = nullptr;
78  std::shared_ptr<PointCloud> raw_pointcloud_out_ = nullptr;
79 
80  int last_azimuth_ = 0;
81  int tz_second_ = 0;
82  int start_angle_ = 0;
85  uint32_t packet_nums_ = 0;
86 
89 };
90 
91 } // namespace hesai
92 } // namespace drivers
93 } // namespace apollo
94 
95 #endif
std::shared_ptr<::apollo::cyber::Node > node_
Definition: parser.h:69
uint64_t raw_last_time_
Definition: parser.h:74
std::shared_ptr< PointCloud > raw_pointcloud_out_
Definition: parser.h:78
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int last_azimuth_
Definition: parser.h:80
Definition: parser.h:40
virtual void ParseRawPacket(const uint8_t *buf, const int len, bool *is_end)=0
uint32_t packet_nums_
Definition: parser.h:85
uint32_t min_packets_
Definition: parser.h:83
std::deque< std::shared_ptr< PointCloud > > raw_pointcloud_pool_
Definition: parser.h:76
const double PI
Definition: const_var.h:77
int pool_index_
Definition: parser.h:73
int pool_size_
Definition: parser.h:72
int tz_second_
Definition: parser.h:81
Parser(const std::shared_ptr<::apollo::cyber::Node > &node, const Config &conf)
void Parse(const uint8_t *data, int size, bool *is_end)
double horizatal_azimuth_offset_map_[LASER_COUNT_L64]
Definition: parser.h:88
const int LASER_COUNT_L64
Definition: const_var.h:52
std::shared_ptr<::apollo::cyber::Writer< PointCloud > > raw_pointcloud_writer_
Definition: parser.h:71
int start_angle_
Definition: parser.h:82
uint32_t max_packets_
Definition: parser.h:84
const int HESAI40_MIN_PACKETS
Definition: const_var.h:32
double elev_angle_map_[LASER_COUNT_L64]
Definition: parser.h:87
void CheckPktTime(double time_sec)
int seq_index_
Definition: parser.h:75
bool is_calibration_
Definition: parser.h:68
const int HESAI40_MAX_PACKETS
Definition: const_var.h:31
Config conf_
Definition: parser.h:70
double degreeToRadian(double degree)
Definition: parser.h:38