7 #include <QApplication>
8 #include <QProgressDialog>
9 #include "rclcpp/generic_subscription.hpp"
14 const std::string & topic_name,
const std::vector<rclcpp::TopicEndpointInfo> & endpoints)
16 rclcpp::QoS request_qos(rmw_qos_profile_default.depth);
18 if (endpoints.empty()) {
21 size_t num_endpoints = endpoints.size();
22 size_t reliability_reliable_endpoints_count = 0;
23 size_t durability_transient_local_endpoints_count = 0;
24 for (
const auto & endpoint : endpoints) {
25 const auto & profile = endpoint.qos_profile().get_rmw_qos_profile();
26 if (profile.reliability == RMW_QOS_POLICY_RELIABILITY_RELIABLE) {
27 reliability_reliable_endpoints_count++;
29 if (profile.durability == RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL) {
30 durability_transient_local_endpoints_count++;
35 if (reliability_reliable_endpoints_count == num_endpoints) {
36 request_qos.reliable();
38 request_qos.best_effort();
43 if (durability_transient_local_endpoints_count == num_endpoints) {
44 request_qos.transient_local();
46 request_qos.durability_volatile();
60 _context = std::make_shared<rclcpp::Context>();
63 auto exec_args = rclcpp::ExecutorOptions();
65 _executor = std::make_unique<rclcpp::executors::MultiThreadedExecutor>(exec_args, 2);
71 using namespace std::chrono;
72 milliseconds wait_time_ms(1000);
74 QProgressDialog progress_dialog;
75 progress_dialog.setLabelText(
"Collecting ROS topic samples to understand data layout.");
76 progress_dialog.setRange(0, wait_time_ms.count());
77 progress_dialog.setAutoClose(
true);
78 progress_dialog.setAutoReset(
true);
79 progress_dialog.show();
81 auto start_time = system_clock::now();
83 while (system_clock::now() - start_time < (wait_time_ms))
85 int msec = duration_cast<milliseconds>(system_clock::now() - start_time).count();
86 progress_dialog.setValue(msec);
87 QApplication::processEvents();
88 if (progress_dialog.wasCanceled())
94 if (progress_dialog.wasCanceled() ==
false)
96 progress_dialog.cancel();
104 auto node_opts = rclcpp::NodeOptions();
106 _node = std::make_shared<rclcpp::Node>(
"plotjuggler", node_opts);
111 std::lock_guard<std::mutex> lock(
mutex());
120 std::vector<std::pair<QString, QString>> dialog_topics;
123 QTimer update_list_timer;
124 update_list_timer.setSingleShot(
false);
125 update_list_timer.setInterval(1000);
126 update_list_timer.start();
128 auto getTopicsFromNode = [&]() {
129 dialog_topics.clear();
130 auto topic_list =
_node->get_topic_names_and_types();
131 for (
const auto&
topic : topic_list)
134 auto topic_name = QString::fromStdString(
topic.first);
135 auto type_name = QString::fromStdString(
topic.second[0]);
136 dialog_topics.push_back({ topic_name, type_name });
143 connect(&update_list_timer, &QTimer::timeout, getTopicsFromNode);
145 int res = dialog.exec();
147 update_list_timer.stop();
159 for (
const auto&
topic : dialog_topics)
177 _executor->spin_once(std::chrono::milliseconds(5));
215 static std::vector<QAction*> empty;
232 auto bound_callback = [=](std::shared_ptr<rclcpp::SerializedMessage>
msg) {
messageCallback(topic_name,
msg); };
234 auto publisher_info =
_node->get_publishers_info_by_topic(topic_name);
238 auto subscription =
_node->create_generic_subscription(topic_name,
243 _node->get_node_topics_interface()->add_subscription(subscription,
nullptr);
251 std::unique_lock<std::mutex> lock(
mutex());
253 auto msg_ptr =
msg.get()->get_rcl_serialized_message();
258 catch (std::runtime_error& ex)
262 QMessageBox::warning(
nullptr, tr(
"Error"),
263 QString(
"rosbag::open thrown an exception:\n") +
264 QString(ex.what()) +
"\nThis message will be shown only once.");
290 QDomElement& parent_element)
const