19 #include "nav2_rviz_plugins/utils.hpp"
20 #include "rclcpp/executors.hpp"
21 #include "rclcpp/future_return_code.hpp"
22 #include "rclcpp/logging.hpp"
23 #include "rclcpp/parameter_client.hpp"
24 #include "rclcpp/utilities.hpp"
26 namespace nav2_rviz_plugins
31 rclcpp::Node::SharedPtr node,
bool & server_failed,
const std::string & server_name,
32 const std::string & plugin_type, QComboBox * combo_box, rclcpp::Executor::SharedPtr executor)
35 if (combo_box->count() > 0) {
39 auto parameter_client = std::make_shared<rclcpp::AsyncParametersClient>(node, server_name);
42 bool server_unavailable =
false;
43 while (!parameter_client->wait_for_service(std::chrono::seconds(1))) {
45 RCLCPP_ERROR(node->get_logger(),
"Interrupted while waiting for the service. Exiting.");
48 RCLCPP_INFO(node->get_logger(),
"%s service not available", server_name.c_str());
49 server_unavailable =
true;
56 if (server_unavailable) {
59 auto parameters = parameter_client->get_parameters({plugin_type});
61 if (executor->spin_until_future_complete(parameters) != rclcpp::FutureReturnCode::SUCCESS) {
64 "Failed to get parameter '%s' from server '%s'",
65 plugin_type.c_str(), server_name.c_str());
69 if (rclcpp::spin_until_future_complete(node, parameters) != rclcpp::FutureReturnCode::SUCCESS) {
72 "Failed to get parameter '%s' from server '%s'",
73 plugin_type.c_str(), server_name.c_str());
78 auto result = parameters.get();
80 RCLCPP_ERROR(node->get_logger(),
81 "Parameter '%s' not found on server '%s'",
82 plugin_type.c_str(), server_name.c_str());
85 auto str_arr = result[0].as_string_array();
86 combo_box->addItem(
"Default");
87 for (
auto str : str_arr) {
88 combo_box->addItem(QString::fromStdString(str));
90 combo_box->setCurrentText(
"Default");
93 QString getGoalStatusLabel(std::string title, int8_t status)
95 std::string status_str;
97 case action_msgs::msg::GoalStatus::STATUS_EXECUTING:
98 status_str =
"<font color=green>active</color>";
101 case action_msgs::msg::GoalStatus::STATUS_SUCCEEDED:
102 status_str =
"<font color=green>reached</color>";
105 case action_msgs::msg::GoalStatus::STATUS_CANCELED:
106 status_str =
"<font color=orange>canceled</color>";
109 case action_msgs::msg::GoalStatus::STATUS_ABORTED:
110 status_str =
"<font color=red>aborted</color>";
113 case action_msgs::msg::GoalStatus::STATUS_UNKNOWN:
114 status_str =
"unknown";
118 status_str =
"inactive";
123 "<table><tr><td width=150><b>" + title +
":</b></td><td>" +
124 status_str +
"</td></tr></table>").c_str());