Apollo 11.0
自动驾驶开放平台
apollo::dreamview::PointCloudUpdater类 参考

A wrapper around WebSocketHandler to keep pushing PointCloud to frontend via websocket while handling the response from frontend. 更多...

#include <point_cloud_updater.h>

类 apollo::dreamview::PointCloudUpdater 继承关系图:
apollo::dreamview::PointCloudUpdater 的协作图:

Public 类型

using DvCallback = std::function< bool(const std::string &string)>
 

Public 成员函数

 PointCloudUpdater (WebSocketHandler *websocket, SimulationWorldUpdater *sim_world_updater)
 Constructor with the websocket handler.
 
 ~PointCloudUpdater ()
 
void Start (DvCallback callback_api)
 Starts to push PointCloud to frontend.
 
void Stop ()
 
 PointCloudUpdater (WebSocketHandler *websocket)
 Constructor with the websocket handler.
 
 ~PointCloudUpdater ()
 
void Stop ()
 Starts to push PointCloud to frontend.
 
void StartStream (const double &time_interval_ms, const std::string &channel_name="", nlohmann::json *subscribe_param=nullptr) override
 Start data flow.
 
void StopStream (const std::string &channel_name="") override
 Stop data flow.
 
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
 
- Public 成员函数 继承自 apollo::dreamview::UpdaterWithChannelsBase
void GetChannelMsgWithFilter (std::vector< std::string > *channels, const std::string &filter_message_type, const std::string &filter_channel, bool reverse_filter_channel=false)
 GetChannelMsgWithFilter:by msg type and channel filter field to filter channels for DataUpdater
 
- Public 成员函数 继承自 apollo::dreamview::UpdaterBase
 UpdaterBase ()
 Updaterbase
 
virtual ~UpdaterBase ()
 

静态 Public 成员函数

static void LoadLidarHeight (const std::string &file_path)
 

静态 Public 属性

static float lidar_height_ = kDefaultLidarHeight
 
static boost::shared_mutex mutex_
 

额外继承的成员函数

- Public 属性 继承自 apollo::dreamview::UpdaterWithChannelsBase
std::vector< std::string > channels_
 

详细描述

A wrapper around WebSocketHandler to keep pushing PointCloud to frontend via websocket while handling the response from frontend.

在文件 point_cloud_updater.h 第 53 行定义.

成员类型定义说明

◆ DvCallback

using apollo::dreamview::PointCloudUpdater::DvCallback = std::function<bool(const std::string &string)>

在文件 point_cloud_updater.h 第 66 行定义.

构造及析构函数说明

◆ PointCloudUpdater() [1/2]

apollo::dreamview::PointCloudUpdater::PointCloudUpdater ( WebSocketHandler *  websocket,
SimulationWorldUpdater *  sim_world_updater 
)

Constructor with the websocket handler.

参数
websocketPointer of the websocket handler that has been attached to the server.
simulationworldupdaterpointer

在文件 point_cloud_updater.cc 第 42 行定义.

44 : node_(cyber::CreateNode("point_cloud")),
45 websocket_(websocket),
46 point_cloud_str_(""),
47 future_ready_(true),
48 simworld_updater_(simworld_updater) {
49 RegisterMessageHandlers();
50}
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

◆ ~PointCloudUpdater() [1/2]

apollo::dreamview::PointCloudUpdater::~PointCloudUpdater ( )

◆ PointCloudUpdater() [2/2]

apollo::dreamview::PointCloudUpdater::PointCloudUpdater ( WebSocketHandler *  websocket)
explicit

Constructor with the websocket handler.

参数
websocketPointer of the websocket handler that has been attached to the server.
simulationworldupdaterpointer

在文件 point_cloud_updater.cc 第 42 行定义.

43 : node_(cyber::CreateNode("point_cloud")),
44 websocket_(websocket) {
45 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
46 FLAGS_localization_topic,
47 [this](const std::shared_ptr<LocalizationEstimate> &msg) {
48 UpdateLocalizationTime(msg);
49 });
50}

◆ ~PointCloudUpdater() [2/2]

apollo::dreamview::PointCloudUpdater::~PointCloudUpdater ( )

成员函数说明

◆ GetChannelMsg()

void apollo::dreamview::PointCloudUpdater::GetChannelMsg ( std::vector< std::string > *  channels)
overridevirtual

◆ LoadLidarHeight()

void apollo::dreamview::PointCloudUpdater::LoadLidarHeight ( const std::string &  file_path)
static

在文件 point_cloud_updater.cc 第 54 行定义.

54 {
55 if (!cyber::common::PathExists(file_path)) {
56 AWARN << "No such file: " << FLAGS_lidar_height_yaml
57 << ". Using default lidar height:" << kDefaultLidarHeight;
58 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
59 lidar_height_ = kDefaultLidarHeight;
60 return;
61 }
62
63 YAML::Node config = YAML::LoadFile(file_path);
64 if (config["vehicle"] && config["vehicle"]["parameters"]) {
65 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
66 lidar_height_ = config["vehicle"]["parameters"]["height"].as<float>();
67 AINFO << "Lidar height is updated to " << lidar_height_;
68 return;
69 }
70
71 AWARN << "Fail to load the lidar height yaml file: "
72 << FLAGS_lidar_height_yaml
73 << ". Using default lidar height:" << kDefaultLidarHeight;
74 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
75 lidar_height_ = kDefaultLidarHeight;
76}
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
bool PathExists(const std::string &path)
Check if the path exists.
Definition file.cc:195

◆ OnTimer()

void apollo::dreamview::PointCloudUpdater::OnTimer ( const std::string &  channel_name = "")

在文件 point_cloud_updater.cc 第 95 行定义.

95 {
96 PublishMessage(channel_name);
97}
void PublishMessage(const std::string &channel_name="") override
Publish Message to dreamview frontend.

◆ PublishMessage()

void apollo::dreamview::PointCloudUpdater::PublishMessage ( const std::string &  channel_name = "")
overridevirtual

Publish Message to dreamview frontend.

实现了 apollo::dreamview::UpdaterBase.

在文件 point_cloud_updater.cc 第 112 行定义.

112 {
113 PointCloudChannelUpdater *updater = GetPointCloudChannelUpdater(channel_name);
114 std::string to_send;
115 // the channel has no data input, clear the sending object.
116 if (!updater->point_cloud_reader_->HasWriter()) {
117 updater->last_point_cloud_time_ = 0.0;
118 updater->point_cloud_str_ = "";
119 to_send = "";
120 } else {
121 if (updater->point_cloud_str_ != "" &&
122 std::fabs(last_localization_time_ - updater->last_point_cloud_time_) >
123 2.0) {
124 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
125 updater->point_cloud_str_ = "";
126 }
127 {
128 boost::shared_lock<boost::shared_mutex> reader_lock(mutex_);
129 to_send = updater->point_cloud_str_;
130 }
131 }
132 StreamData stream_data;
133 std::string stream_data_string;
134 stream_data.set_action("stream");
135 stream_data.set_data_name("pointcloud");
136 stream_data.set_channel_name(channel_name);
137 std::vector<uint8_t> byte_data(to_send.begin(), to_send.end());
138 stream_data.set_data(&(byte_data[0]), byte_data.size());
139 stream_data.set_type("pointcloud");
140 stream_data.SerializeToString(&stream_data_string);
141 websocket_->BroadcastBinaryData(stream_data_string);
142}
bool BroadcastBinaryData(const std::string &data, bool skippable=false)
Sends the provided binary data to all the connected clients.

◆ Start()

void apollo::dreamview::PointCloudUpdater::Start ( DvCallback  callback_api)

Starts to push PointCloud to frontend.

在文件 point_cloud_updater.cc 第 205 行定义.

205 {
206 callback_api_ = callback_api;
207 localization_reader_ = node_->CreateReader<LocalizationEstimate>(
208 FLAGS_localization_topic,
209 [this](const std::shared_ptr<LocalizationEstimate> &msg) {
210 UpdateLocalizationTime(msg);
211 });
212 LoadLidarHeight(FLAGS_lidar_height_yaml);
213}
static void LoadLidarHeight(const std::string &file_path)

◆ StartStream()

void apollo::dreamview::PointCloudUpdater::StartStream ( const double &  time_interval_ms,
const std::string &  channel_name = "",
nlohmann::json *  subscribe_param = nullptr 
)
overridevirtual

Start data flow.

参数
time_interval_msData stream sending frequency. 0 means single subscribe
subscribe_paramsubscribe some updater may need extra params

实现了 apollo::dreamview::UpdaterBase.

在文件 point_cloud_updater.cc 第 70 行定义.

72 {
73 if (channel_name.empty()) {
74 AERROR << "Failed to subscribe channel for channel is empty!";
75 return;
76 }
77 if (std::find(channels_.begin(), channels_.end(), channel_name) ==
78 channels_.end()) {
79 AERROR << "Failed to subscribe point cloud updater, for channel: "
80 << channel_name << " is invalid.";
81 return;
82 }
83 if (time_interval_ms > 0) {
84 PointCloudChannelUpdater *updater =
85 GetPointCloudChannelUpdater(channel_name);
86 updater->timer_.reset(new cyber::Timer(
87 time_interval_ms,
88 [channel_name, this]() { this->OnTimer(channel_name); }, false));
89 updater->timer_->Start();
90 } else {
91 this->OnTimer(channel_name);
92 }
93}
void OnTimer(const std::string &channel_name="")
#define AERROR
Definition log.h:44

◆ Stop() [1/2]

void apollo::dreamview::PointCloudUpdater::Stop ( )

在文件 point_cloud_updater.cc 第 215 行定义.

215 {
216 if (enabled_) {
217 async_future_.wait();
218 }
219}

◆ Stop() [2/2]

void apollo::dreamview::PointCloudUpdater::Stop ( )

Starts to push PointCloud to frontend.

◆ StopStream()

void apollo::dreamview::PointCloudUpdater::StopStream ( const std::string &  channel_name = "")
overridevirtual

Stop data flow.

实现了 apollo::dreamview::UpdaterBase.

在文件 point_cloud_updater.cc 第 98 行定义.

98 {
99 if (channel_name.empty()) {
100 AERROR << "Failed to unsubscribe channel for channel is empty!";
101 return;
102 }
103 PointCloudChannelUpdater *updater = GetPointCloudChannelUpdater(channel_name);
104 if (updater->timer_) {
105 updater->timer_->Stop();
106 }
107 // 回到初始值
108 updater->last_point_cloud_time_ = 0.0;
109 updater->point_cloud_str_ = "";
110 updater->future_ready_ = true;
111}

类成员变量说明

◆ lidar_height_

static float apollo::dreamview::PointCloudUpdater::lidar_height_ = kDefaultLidarHeight
static

在文件 point_cloud_updater.h 第 75 行定义.

◆ mutex_

static boost::shared_mutex apollo::dreamview::PointCloudUpdater::mutex_
static

在文件 point_cloud_updater.h 第 79 行定义.


该类的文档由以下文件生成: