15 #ifndef NAV2_RVIZ_PLUGINS__DOCKING_PANEL_HPP_
16 #define NAV2_RVIZ_PLUGINS__DOCKING_PANEL_HPP_
20 #include <QBasicTimer>
21 #include <QStateMachine>
23 #include <QSignalTransition>
29 #include "nav2_lifecycle_manager/lifecycle_manager_client.hpp"
30 #include "rclcpp/rclcpp.hpp"
31 #include "rclcpp_action/rclcpp_action.hpp"
32 #include "rviz_common/panel.hpp"
33 #include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
34 #include "sensor_msgs/msg/battery_state.hpp"
35 #include "nav2_msgs/action/dock_robot.hpp"
36 #include "nav2_msgs/action/undock_robot.hpp"
41 namespace nav2_rviz_plugins
44 class InitialDockThread;
55 void onInitialize()
override;
58 void load(
const rviz_common::Config & config)
override;
59 void save(rviz_common::Config config)
const override;
63 void onDockingButtonPressed();
64 void onUndockingButtonPressed();
65 void onCancelDocking();
66 void onCancelUndocking();
67 void dockIdCheckbox();
70 using Dock = nav2_msgs::action::DockRobot;
71 using Undock = nav2_msgs::action::UndockRobot;
72 using DockGoalHandle = rclcpp_action::ClientGoalHandle<Dock>;
73 using UndockGoalHandle = rclcpp_action::ClientGoalHandle<Undock>;
76 void timerEvent(QTimerEvent * event)
override;
79 static inline QString getDockFeedbackLabel(Dock::Feedback msg = Dock::Feedback());
83 static inline std::string toLabel(T & msg);
86 static inline std::string toString(
double val,
int precision = 0);
89 static inline std::string dockStateToString(int16_t state);
90 static inline std::string dockErrorToString(int16_t error_code);
93 rclcpp::Node::SharedPtr client_node_;
94 rclcpp::executors::SingleThreadedExecutor::SharedPtr executor_;
97 std::shared_ptr<rviz_common::ros_integration::RosNodeAbstractionIface> node_ptr_;
100 std::chrono::milliseconds server_timeout_;
103 QBasicTimer action_timer_;
106 nav2::ActionClient<Dock>::SharedPtr dock_client_;
107 nav2::ActionClient<Undock>::SharedPtr undock_client_;
110 nav2::Subscription<Dock::Impl::FeedbackMessage>::SharedPtr docking_feedback_sub_;
111 nav2::Subscription<Undock::Impl::FeedbackMessage>::SharedPtr undocking_feedback_sub_;
112 nav2::Subscription<Dock::Impl::GoalStatusMessage>::SharedPtr docking_goal_status_sub_;
113 nav2::Subscription<Undock::Impl::GoalStatusMessage>::SharedPtr undocking_goal_status_sub_;
116 DockGoalHandle::SharedPtr dock_goal_handle_;
117 UndockGoalHandle::SharedPtr undock_goal_handle_;
120 bool plugins_loaded_ =
false;
121 bool server_failed_ =
false;
123 QVBoxLayout * main_layout_{
nullptr};
124 QHBoxLayout * info_layout_{
nullptr};
125 QVBoxLayout * feedback_layout_{
nullptr};
126 QHBoxLayout * dock_id_layout_{
nullptr};
127 QHBoxLayout * dock_type_layout_{
nullptr};
128 QHBoxLayout * dock_pose_layout_{
nullptr};
129 QHBoxLayout * nav_stage_layout_{
nullptr};
131 QComboBox * dock_type_{
nullptr};
132 QPushButton * docking_button_{
nullptr};
133 QPushButton * undocking_button_{
nullptr};
134 QCheckBox * use_dock_id_checkbox_{
nullptr};
135 QCheckBox * nav_to_staging_checkbox_{
nullptr};
137 QLabel * docking_goal_status_indicator_{
nullptr};
138 QLabel * docking_feedback_indicator_{
nullptr};
139 QLabel * docking_result_indicator_{
nullptr};
141 QLineEdit * dock_id_{
nullptr};
142 QLineEdit * dock_pose_x_{
nullptr};
143 QLineEdit * dock_pose_y_{
nullptr};
144 QLineEdit * dock_pose_yaw_{
nullptr};
147 bool docking_in_progress_ =
false;
148 bool undocking_in_progress_ =
false;
149 bool use_dock_id_ =
false;
151 QStateMachine state_machine_;
154 QState * pre_initial_{
nullptr};
155 QState * idle_{
nullptr};
156 QState * docking_{
nullptr};
157 QState * undocking_{
nullptr};
158 QState * canceled_docking_{
nullptr};
159 QState * canceled_undocking_{
nullptr};
168 nav2::ActionClient<nav2_msgs::action::DockRobot>::SharedPtr & dock_client,
169 nav2::ActionClient<nav2_msgs::action::UndockRobot>::SharedPtr & undock_client)
170 : dock_client_(dock_client), undock_client_(undock_client)
175 while (!dock_active_) {
176 dock_active_ = dock_client_->wait_for_action_server(std::chrono::seconds(1));
179 while (!undock_active_) {
180 undock_active_ = undock_client_->wait_for_action_server(std::chrono::seconds(1));
184 emit dockingActive();
186 emit dockingInactive();
189 if (undock_active_) {
190 emit undockingActive();
192 emit undockingInactive();
197 void dockingActive();
198 void dockingInactive();
199 void undockingActive();
200 void undockingInactive();
203 nav2::ActionClient<nav2_msgs::action::DockRobot>::SharedPtr dock_client_;
204 nav2::ActionClient<nav2_msgs::action::UndockRobot>::SharedPtr undock_client_;
205 bool dock_active_ =
false;
206 bool undock_active_ =
false;
Panel to interface to the docking server.
void load(const rviz_common::Config &config) override
Load and save configuration data.