Apollo 10.0
自动驾驶开放平台
point_cloud_updater.h
浏览该文件的文档.
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 <map>
24#include <memory>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29#include <google/protobuf/util/message_differencer.h>
30#include <pcl/common/transforms.h>
31#include <Eigen/Dense>
32#include <boost/thread/locks.hpp>
33#include <boost/thread/shared_mutex.hpp>
34
35#include "pcl/point_cloud.h"
36#include "pcl/point_types.h"
37
38#include "modules/common_msgs/localization_msgs/localization.pb.h"
39#include "modules/common_msgs/sensor_msgs/pointcloud.pb.h"
40#include "modules/common_msgs/transform_msgs/transform.pb.h"
41#include "modules/dreamview_plus/proto/data_handler.pb.h"
42#include "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
43
44#include "cyber/common/log.h"
45#include "cyber/cyber.h"
50
55namespace apollo {
56namespace dreamview {
57
59 std::string cur_channel_name_;
60 std::shared_ptr<cyber::Reader<drivers::PointCloud>> point_cloud_reader_;
61 std::shared_ptr<cyber::Reader<apollo::perception::PerceptionEdgeInfo>>
64 // The PointCloud to be pushed to frontend.
65 std::string point_cloud_str_;
66 std::unique_ptr<cyber::Timer> timer_;
67 std::atomic<bool> future_ready_;
68 std::future<void> async_future_;
69 explicit PointCloudChannelUpdater(std::string channel_name)
70 : cur_channel_name_(channel_name),
71 point_cloud_reader_(nullptr),
75 future_ready_(true) {}
76};
77
83class PointCloudUpdater : public UpdaterWithChannelsBase {
84 public:
91 explicit PointCloudUpdater(WebSocketHandler *websocket);
92
94 // dreamview callback function
95 // using DvCallback = std::function<bool(const std::string &string)>;
96
100 void Stop();
101 void StartStream(const double &time_interval_ms,
102 const std::string &channel_name = "",
103 nlohmann::json *subscribe_param = nullptr) override;
104 void StopStream(const std::string& channel_name = "") override;
105 void OnTimer(const std::string& channel_name = "");
106 void PublishMessage(const std::string& channel_name = "") override;
107 void GetChannelMsg(std::vector<std::string> *channels) override;
108 // The height of lidar w.r.t the ground.
109 static float lidar_height_;
110
111 // Mutex to protect concurrent access to point_cloud_str_ and lidar_height_.
112 // NOTE: Use boost until we have std version of rwlock support.
113 static boost::shared_mutex mutex_;
114
115 private:
116 void UpdatePerceptionEdge(
117 const std::shared_ptr<apollo::perception::PerceptionEdgeInfo>
118 &perception_edge,
119 const std::string &channel_name);
120 void UpdatePointCloud(const std::shared_ptr<drivers::PointCloud> &point_cloud,
121 const std::string &channel_name);
122
123 void FilterPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_ptr,
124 const std::string &channel_name);
125
126 void UpdateLocalizationTime(
127 const std::shared_ptr<apollo::localization::LocalizationEstimate>
128 &localization);
129 pcl::PointCloud<pcl::PointXYZ>::Ptr ConvertPCLPointCloud(
130 const std::shared_ptr<drivers::PointCloud> &point_cloud,
131 const std::string &channel_name);
132
133 PointCloudChannelUpdater* GetPointCloudChannelUpdater(
134 const std::string &channel_name);
135
136 void TransformPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr &point_cloud,
137 const std::string &frame_id);
138
139 constexpr static float kDefaultLidarHeight = 1.91f;
140
141 std::unique_ptr<cyber::Node> node_;
142
143 WebSocketHandler *websocket_;
144
145 bool enabled_ = false;
146
147
148 // Cyber messsage readers.
149 std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
150 localization_reader_;
151 std::map<std::string, PointCloudChannelUpdater *> channel_updaters_;
152 double last_localization_time_ = 0.0;
153 bool enable_voxel_filter_ = false;
154 // DvCallback callback_api_;
155 std::mutex channel_updater_map_mutex_;
156};
157} // namespace dreamview
158} // namespace apollo
void StopStream(const std::string &channel_name="") override
Stop data flow.
void StartStream(const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr) override
Start data flow.
void Stop()
Starts to push PointCloud to frontend.
void OnTimer(const std::string &channel_name="")
void PublishMessage(const std::string &channel_name="") override
Publish Message to dreamview frontend.
void GetChannelMsg(std::vector< std::string > *channels) override
GetChannelMsg
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles diff...
class register implement
Definition arena_queue.h:37
Some string util functions.
std::shared_ptr< cyber::Reader< apollo::perception::PerceptionEdgeInfo > > perception_edge_reader_
std::shared_ptr< cyber::Reader< drivers::PointCloud > > point_cloud_reader_