Apollo  6.0
Open source self driving car software
point_cloud_updater.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 
26 #include <boost/thread/locks.hpp>
27 #include <boost/thread/shared_mutex.hpp>
28 #include "pcl/point_cloud.h"
29 #include "pcl/point_types.h"
30 
31 #include "cyber/common/log.h"
32 #include "cyber/cyber.h"
36 #include "modules/drivers/proto/pointcloud.pb.h"
37 #include "modules/localization/proto/localization.pb.h"
38 
43 namespace apollo {
44 namespace dreamview {
45 
52  public:
60  SimulationWorldUpdater *sim_world_updater);
61 
63 
64  static void LoadLidarHeight(const std::string &file_path);
65 
69  void Start();
70  void Stop();
71 
72  // The height of lidar w.r.t the ground.
73  static float lidar_height_;
74 
75  // Mutex to protect concurrent access to point_cloud_str_ and lidar_height_.
76  // NOTE: Use boost until we have std version of rwlock support.
77  static boost::shared_mutex mutex_;
78 
79  private:
80  void RegisterMessageHandlers();
81 
82  void UpdatePointCloud(
83  const std::shared_ptr<drivers::PointCloud> &point_cloud);
84 
85  void FilterPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_ptr);
86 
87  void UpdateLocalizationTime(
88  const std::shared_ptr<apollo::localization::LocalizationEstimate>
89  &localization);
90  pcl::PointCloud<pcl::PointXYZ>::Ptr ConvertPCLPointCloud(
91  const std::shared_ptr<drivers::PointCloud> &point_cloud);
92 
93  constexpr static float kDefaultLidarHeight = 1.91f;
94 
95  std::unique_ptr<cyber::Node> node_;
96 
97  WebSocketHandler *websocket_;
98 
99  bool enabled_ = false;
100 
101  // The PointCloud to be pushed to frontend.
102  std::string point_cloud_str_;
103 
104  std::future<void> async_future_;
105  std::atomic<bool> future_ready_;
106 
107  // Cyber messsage readers.
108  std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
109  localization_reader_;
110  std::shared_ptr<cyber::Reader<drivers::PointCloud>> point_cloud_reader_;
111  double last_point_cloud_time_ = 0.0;
112  double last_localization_time_ = 0.0;
113  SimulationWorldUpdater *simworld_updater_;
114  bool enable_voxel_filter_ = false;
115 };
116 } // namespace dreamview
117 } // namespace apollo
PointCloudUpdater(WebSocketHandler *websocket, SimulationWorldUpdater *sim_world_updater)
Constructor with the websocket handler.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
static boost::shared_mutex mutex_
Definition: point_cloud_updater.h:77
Some string util functions.
A wrapper around SimulationWorldService and WebSocketHandler to keep pushing SimulationWorld to front...
Definition: simulation_world_updater.h:56
static void LoadLidarHeight(const std::string &file_path)
static float lidar_height_
Definition: point_cloud_updater.h:73
A wrapper around WebSocketHandler to keep pushing PointCloud to frontend via websocket while handling...
Definition: point_cloud_updater.h:51
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
Definition: websocket_handler.h:46
void Start()
Starts to push PointCloud to frontend.