Apollo  6.0
Open source self driving car software
driver.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_DRIVER_H_
18 #define LIDAR_HESAI_DRIVER_H_
19 
20 #include <atomic>
21 #include <condition_variable>
22 #include <deque>
23 #include <functional>
24 #include <list>
25 #include <memory>
26 #include <mutex>
27 #include <string>
28 #include <thread>
29 #include <vector>
30 
31 #include "modules/drivers/lidar/proto/config.pb.h"
32 
33 #include "cyber/cyber.h"
38 
39 namespace apollo {
40 namespace drivers {
41 namespace hesai {
42 
44  public:
45  HesaiDriver(const std::shared_ptr<::apollo::cyber::Node>& node,
46  const ::apollo::drivers::lidar::config& conf)
47  : node_(node), conf_(conf.hesai()) {}
48  HesaiDriver(const std::shared_ptr<::apollo::cyber::Node>& node,
49  const ::apollo::drivers::hesai::Config& conf)
50  : node_(node), conf_(conf) {}
51  ~HesaiDriver() { Stop(); }
52  bool Init() override;
53 
54  private:
55  std::shared_ptr<::apollo::cyber::Node> node_ = nullptr;
56  Config conf_;
57  std::shared_ptr<Parser> parser_ = nullptr;
58  std::shared_ptr<Input> input_ = nullptr;
59  std::shared_ptr<::apollo::cyber::Writer<HesaiScan>> scan_writer_ = nullptr;
60  std::mutex packet_mutex_;
61  std::condition_variable packet_condition_;
62  std::thread poll_thread_;
63  std::thread process_thread_;
64  std::atomic<bool> running_ = {true};
65  std::deque<std::shared_ptr<HesaiScan>> scan_buffer_;
66  int scan_buffer_size_ = 10;
67  int index_ = 0;
68  int tz_second_ = 0;
69  std::vector<std::shared_ptr<HesaiPacket>> pkt_buffer_;
70  int pkt_index_ = 0;
71  int pkt_buffer_capacity_ = 0;
72  std::list<std::shared_ptr<HesaiPacket>> pkt_queue_;
73 
74  private:
75  void PollThread();
76  void ProcessThread();
77  void ProcessGps(const HesaiPacket& pkt);
78 
79  void Stop() {
80  AINFO << "driver stoping...";
81  running_.store(false);
82  packet_condition_.notify_all();
83  if (poll_thread_.joinable()) {
84  poll_thread_.join();
85  }
86  if (process_thread_.joinable()) {
87  process_thread_.join();
88  }
89  }
90 };
91 
92 } // namespace hesai
93 } // namespace drivers
94 } // namespace apollo
95 
96 #endif
~HesaiDriver()
Definition: driver.h:51
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool Init() override
Initialize the lidar driver.
The class which defines the lidar driver .
Definition: driver_base.h:45
Defines the CanFrame struct and CanClient interface.
Definition: type_defs.h:27
HesaiDriver(const std::shared_ptr<::apollo::cyber::Node > &node, const ::apollo::drivers::hesai::Config &conf)
Definition: driver.h:48
HesaiDriver(const std::shared_ptr<::apollo::cyber::Node > &node, const ::apollo::drivers::lidar::config &conf)
Definition: driver.h:45
#define AINFO
Definition: log.h:42