15 #include "nav2_rviz_plugins/selector.hpp"
16 #include "nav2_rviz_plugins/utils.hpp"
17 #include "rviz_common/display_context.hpp"
19 using namespace std::chrono_literals;
21 namespace nav2_rviz_plugins
23 Selector::Selector(QWidget * parent)
26 client_node_ = std::make_shared<rclcpp::Node>(
"nav2_rviz_selector_node");
27 rclcpp::QoS qos(rclcpp::KeepLast(1));
28 qos.transient_local().reliable();
31 client_node_->create_publisher<std_msgs::msg::String>(
"controller_selector", qos);
32 pub_planner_ = client_node_->create_publisher<std_msgs::msg::String>(
"planner_selector", qos);
34 client_node_->create_publisher<std_msgs::msg::String>(
"goal_checker_selector", qos);
35 pub_smoother_ = client_node_->create_publisher<std_msgs::msg::String>(
"smoother_selector", qos);
36 pub_progress_checker_ =
37 client_node_->create_publisher<std_msgs::msg::String>(
"progress_checker_selector", qos);
39 main_layout_ =
new QVBoxLayout;
40 row_1_label_layout_ =
new QHBoxLayout;
41 row_2_label_layout_ =
new QHBoxLayout;
42 row_3_label_layout_ =
new QHBoxLayout;
43 row_1_layout_ =
new QHBoxLayout;
44 row_2_layout_ =
new QHBoxLayout;
45 row_3_layout_ =
new QHBoxLayout;
46 controller_ =
new QComboBox;
47 planner_ =
new QComboBox;
48 goal_checker_ =
new QComboBox;
49 smoother_ =
new QComboBox;
50 progress_checker_ =
new QComboBox;
52 main_layout_->setContentsMargins(10, 10, 10, 10);
54 row_1_label_layout_->addWidget(
new QLabel(
"Controller"));
55 row_1_layout_->addWidget(controller_);
56 row_1_label_layout_->addWidget(
new QLabel(
"Planner"));
57 row_1_layout_->addWidget(planner_);
58 row_2_label_layout_->addWidget(
new QLabel(
"Goal Checker"));
59 row_2_layout_->addWidget(goal_checker_);
60 row_2_label_layout_->addWidget(
new QLabel(
"Smoother"));
61 row_2_layout_->addWidget(smoother_);
62 row_3_label_layout_->addWidget(
new QLabel(
"Progress Checker"));
63 row_3_layout_->addWidget(progress_checker_);
65 main_layout_->addLayout(row_1_label_layout_);
66 main_layout_->addLayout(row_1_layout_);
67 main_layout_->addLayout(row_2_label_layout_);
68 main_layout_->addLayout(row_2_layout_);
69 main_layout_->addLayout(row_3_label_layout_);
70 main_layout_->addLayout(row_3_layout_);
72 setLayout(main_layout_);
76 controller_, QOverload<int>::of(&QComboBox::activated),
this,
77 &Selector::setController);
80 planner_, QOverload<int>::of(&QComboBox::activated),
this,
81 &Selector::setPlanner);
84 goal_checker_, QOverload<int>::of(&QComboBox::activated),
this,
85 &Selector::setGoalChecker);
88 smoother_, QOverload<int>::of(&QComboBox::activated),
this,
89 &Selector::setSmoother);
92 progress_checker_, QOverload<int>::of(&QComboBox::activated),
this,
93 &Selector::setProgressChecker);
101 void Selector::setSelection(
102 QComboBox * combo_box, rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher)
105 if (combo_box->findText(
"Default") != -1) {
106 combo_box->removeItem(0);
110 if (combo_box->count() == 0) {
114 std_msgs::msg::String msg;
115 msg.data = combo_box->currentText().toStdString();
117 publisher->publish(msg);
121 void Selector::setController()
123 setSelection(controller_, pub_controller_);
127 void Selector::setPlanner()
129 setSelection(planner_, pub_planner_);
133 void Selector::setGoalChecker()
135 setSelection(goal_checker_, pub_goal_checker_);
139 void Selector::setSmoother()
141 setSelection(smoother_, pub_smoother_);
144 void Selector::setProgressChecker()
146 setSelection(progress_checker_, pub_progress_checker_);
150 Selector::loadPlugins()
152 load_plugins_thread_ = std::thread(
154 rclcpp::Rate rate(0.2);
155 while (rclcpp::ok() && !plugins_loaded_) {
156 RCLCPP_INFO(client_node_->get_logger(),
"Trying to load plugins...");
157 nav2_rviz_plugins::pluginLoader(
158 client_node_, server_failed_,
"controller_server",
"controller_plugins", controller_);
159 nav2_rviz_plugins::pluginLoader(
160 client_node_, server_failed_,
"planner_server",
"planner_plugins", planner_);
161 nav2_rviz_plugins::pluginLoader(
162 client_node_, server_failed_,
"controller_server",
"goal_checker_plugins",
164 nav2_rviz_plugins::pluginLoader(
165 client_node_, server_failed_,
"smoother_server",
"smoother_plugins", smoother_);
166 nav2_rviz_plugins::pluginLoader(
167 client_node_, server_failed_,
"controller_server",
"progress_checker_plugins",
169 if (controller_->count() > 0 &&
170 planner_->count() > 0 &&
171 goal_checker_->count() > 0 &&
172 smoother_->count() > 0 &&
173 progress_checker_->count() > 0)
175 plugins_loaded_ =
true;
177 RCLCPP_INFO(client_node_->get_logger(),
"Failed to load plugins. Retrying...");
185 #include "pluginlib/class_list_macros.hpp"