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 #pragma once
17 #include <memory>
18 #include <string>
19 #include <thread>
20 #include <vector>
21 
22 #include "modules/drivers/lidar/proto/config.pb.h"
23 #include "modules/drivers/lidar/proto/robosense.pb.h"
24 #include "modules/drivers/lidar/proto/robosense_config.pb.h"
25 #include "modules/drivers/proto/pointcloud.pb.h"
26 
27 #include "cyber/cyber.h"
29 #include "modules/drivers/lidar/robosense/decoder/decoder_16.hpp"
30 #include "modules/drivers/lidar/robosense/decoder/decoder_factory.hpp"
33 #define PKT_DATA_LENGTH 1248
34 
35 namespace apollo {
36 namespace drivers {
37 namespace robosense {
38 struct alignas(16) LidarPacketMsg {
39  double timestamp = 0.0;
40  std::string frame_id = "";
41  std::array<uint8_t, PKT_DATA_LENGTH> packet{};
42 };
43 
45  public:
46  RobosenseDriver(const std::shared_ptr<cyber::Node> &node,
47  const ::apollo::drivers::lidar::config &config)
48  : node_(node), conf_(config.robosense()) {}
49  RobosenseDriver(const std::shared_ptr<cyber::Node> &node, const Config &conf)
50  : node_(node), conf_(conf) {}
51  ~RobosenseDriver() { stop(); }
52  bool Init() override;
53 
54  private:
55  void getPackets();
56  void processMsopPackets();
57  void processDifopPackets();
58 
59  private:
60  std::shared_ptr<cyber::Node> node_ = nullptr;
61  Config conf_;
62  std::shared_ptr<cyber::Writer<RobosenseScan>> scan_writer_ = nullptr;
63  std::shared_ptr<cyber::Writer<PointCloud>> pointcloud_writer_ = nullptr;
64 
65  private:
66  void prepareLidarScanMsg(std::shared_ptr<RobosenseScan> msg);
67  void preparePointsMsg(std::shared_ptr<PointCloud> msg);
68  void stop() {
69  msop_pkt_queue_.clear();
70  difop_pkt_queue_.clear();
71  if (thread_flag_ == true) {
72  thread_flag_ = false;
73  lidar_thread_ptr_->join();
74  }
75  }
76 
77  private:
78  Queue<LidarPacketMsg> msop_pkt_queue_;
79  Queue<LidarPacketMsg> difop_pkt_queue_;
80  bool thread_flag_;
81  std::shared_ptr<std::thread> lidar_thread_ptr_;
82  std::shared_ptr<DecoderBase<PointXYZIT>> lidar_decoder_ptr_;
83  std::shared_ptr<Input> lidar_input_ptr_;
84  uint32_t scan_seq_;
85  uint32_t points_seq_;
86  std::shared_ptr<PointCloud> point_cloud_ptr_;
87  std::shared_ptr<RobosenseScan> scan_ptr_;
88 };
89 } // namespace robosense
90 } // namespace drivers
91 } // namespace apollo
Definition: utility.h:34
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::string frame_id
Definition: driver.h:40
std::array< uint8_t, PKT_DATA_LENGTH > packet
lidar single packet
Definition: driver.h:41
double timestamp
Definition: driver.h:39
RobosenseDriver(const std::shared_ptr< cyber::Node > &node, const ::apollo::drivers::lidar::config &config)
Definition: driver.h:46
The class which defines the lidar driver .
Definition: driver_base.h:45
Defines the CanFrame struct and CanClient interface.
RobosenseDriver(const std::shared_ptr< cyber::Node > &node, const Config &conf)
Definition: driver.h:49
bool Init(const char *binary_name)
~RobosenseDriver()
Definition: driver.h:51