Apollo 11.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
43#include "cyber/common/log.h"
44#include "cyber/cyber.h"
49
54namespace apollo {
55namespace dreamview {
56
58 std::string curr_channel_name_;
59 std::shared_ptr<cyber::Reader<drivers::PointCloud>> point_cloud_reader_;
61 // The PointCloud to be pushed to frontend.
62 std::string point_cloud_str_;
63 std::unique_ptr<cyber::Timer> timer_;
64 std::atomic<bool> future_ready_;
65 std::future<void> async_future_;
66 explicit PointCloudChannelUpdater(std::string channel_name)
67 : curr_channel_name_(channel_name),
68 point_cloud_reader_(nullptr),
71 future_ready_(true) {}
72};
73
79class PointCloudUpdater : public UpdaterWithChannelsBase {
80 public:
87 explicit PointCloudUpdater(WebSocketHandler *websocket);
88
90 // dreamview callback function
91 // using DvCallback = std::function<bool(const std::string &string)>;
92
96 void Stop();
97 void StartStream(const double &time_interval_ms,
98 const std::string &channel_name = "",
99 nlohmann::json *subscribe_param = nullptr) override;
100 void StopStream(const std::string& channel_name = "") override;
101 void OnTimer(const std::string& channel_name = "");
102 void PublishMessage(const std::string& channel_name = "") override;
103 void GetChannelMsg(std::vector<std::string> *channels) override;
104 // The height of lidar w.r.t the ground.
105 static float lidar_height_;
106
107 // Mutex to protect concurrent access to point_cloud_str_ and lidar_height_.
108 // NOTE: Use boost until we have std version of rwlock support.
109 static boost::shared_mutex mutex_;
110
111 private:
112 void UpdatePointCloud(const std::shared_ptr<drivers::PointCloud> &point_cloud,
113 const std::string &channel_name);
114
115 void FilterPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_ptr,
116 const std::string &channel_name);
117
118 void UpdateLocalizationTime(
119 const std::shared_ptr<apollo::localization::LocalizationEstimate>
120 &localization);
121 pcl::PointCloud<pcl::PointXYZ>::Ptr ConvertPCLPointCloud(
122 const std::shared_ptr<drivers::PointCloud> &point_cloud,
123 const std::string &channel_name);
124
125 PointCloudChannelUpdater* GetPointCloudChannelUpdater(
126 const std::string &channel_name);
127
128 void TransformPointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr &point_cloud,
129 const std::string &frame_id);
130
131 constexpr static float kDefaultLidarHeight = 1.91f;
132
133 std::unique_ptr<cyber::Node> node_;
134
135 WebSocketHandler *websocket_;
136
137 bool enabled_ = false;
138
139
140 // Cyber messsage readers.
141 std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
142 localization_reader_;
143 std::map<std::string, PointCloudChannelUpdater *> channel_updaters_;
144 double last_localization_time_ = 0.0;
145 bool enable_voxel_filter_ = false;
146 // DvCallback callback_api_;
147 std::mutex channel_updater_map_mutex_;
148};
149} // namespace dreamview
150} // 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< drivers::PointCloud > > point_cloud_reader_