18 #include "nav2_rviz_plugins/utils.hpp"
20 namespace nav2_rviz_plugins
25 rclcpp::Node::SharedPtr node,
bool & server_failed,
const std::string & server_name,
26 const std::string & plugin_type, QComboBox * combo_box, rclcpp::Executor::SharedPtr executor)
29 if (combo_box->count() > 0) {
33 auto parameter_client = std::make_shared<rclcpp::AsyncParametersClient>(node, server_name);
36 bool server_unavailable =
false;
37 while (!parameter_client->wait_for_service(std::chrono::seconds(1))) {
39 RCLCPP_ERROR(node->get_logger(),
"Interrupted while waiting for the service. Exiting.");
42 RCLCPP_INFO(node->get_logger(),
"%s service not available", server_name.c_str());
43 server_unavailable =
true;
50 if (server_unavailable) {
53 auto parameters = parameter_client->get_parameters({plugin_type});
55 if (executor->spin_until_future_complete(parameters) != rclcpp::FutureReturnCode::SUCCESS) {
58 "Failed to get parameter '%s' from server '%s'",
59 plugin_type.c_str(), server_name.c_str());
63 if (rclcpp::spin_until_future_complete(node, parameters) != rclcpp::FutureReturnCode::SUCCESS) {
66 "Failed to get parameter '%s' from server '%s'",
67 plugin_type.c_str(), server_name.c_str());
72 auto result = parameters.get();
74 RCLCPP_ERROR(node->get_logger(),
75 "Parameter '%s' not found on server '%s'",
76 plugin_type.c_str(), server_name.c_str());
79 auto str_arr = result[0].as_string_array();
80 combo_box->addItem(
"Default");
81 for (
auto str : str_arr) {
82 combo_box->addItem(QString::fromStdString(str));
84 combo_box->setCurrentText(
"Default");
87 QString getGoalStatusLabel(std::string title, int8_t status)
89 std::string status_str;
91 case action_msgs::msg::GoalStatus::STATUS_EXECUTING:
92 status_str =
"<font color=green>active</color>";
95 case action_msgs::msg::GoalStatus::STATUS_SUCCEEDED:
96 status_str =
"<font color=green>reached</color>";
99 case action_msgs::msg::GoalStatus::STATUS_CANCELED:
100 status_str =
"<font color=orange>canceled</color>";
103 case action_msgs::msg::GoalStatus::STATUS_ABORTED:
104 status_str =
"<font color=red>aborted</color>";
107 case action_msgs::msg::GoalStatus::STATUS_UNKNOWN:
108 status_str =
"unknown";
112 status_str =
"inactive";
117 "<table><tr><td width=150><b>" + title +
":</b></td><td>" +
118 status_str +
"</td></tr></table>").c_str());