15 #ifndef NAV2_RVIZ_PLUGINS__NAV2_PANEL_HPP_
16 #define NAV2_RVIZ_PLUGINS__NAV2_PANEL_HPP_
19 #include <QBasicTimer>
20 #include <QStateMachine>
21 #include <QSignalTransition>
28 #include "nav2_lifecycle_manager/lifecycle_manager_client.hpp"
29 #include "nav2_msgs/action/navigate_to_pose.hpp"
30 #include "nav2_msgs/action/navigate_through_poses.hpp"
31 #include "nav2_msgs/action/follow_waypoints.hpp"
32 #include "nav2_rviz_plugins/ros_action_qevent.hpp"
33 #include "rclcpp/rclcpp.hpp"
34 #include "rclcpp_action/rclcpp_action.hpp"
35 #include "rviz_common/panel.hpp"
36 #include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
37 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
38 #include "visualization_msgs/msg/marker_array.hpp"
39 #include "nav2_util/geometry_utils.hpp"
40 #include "tf2_ros/transform_listener.hpp"
41 #include "tf2_ros/create_timer_ros.hpp"
42 #include "tf2_ros/buffer.hpp"
46 namespace nav2_rviz_plugins
60 void onInitialize()
override;
63 void load(
const rviz_common::Config & config)
override;
64 void save(rviz_common::Config config)
const override;
74 void onAccumulatedWp();
75 void onAccumulatedNTP();
76 void onAccumulating();
77 void onNewGoal(
double x,
double y,
double theta, QString frame);
78 void handleGoalSaver();
79 void handleGoalLoader();
81 void initialStateHandler();
85 void onCancelButtonPressed();
86 void timerEvent(QTimerEvent * event)
override;
87 bool isLoopValueValid(std::string & loop);
92 bool store_initial_pose_ =
false;
93 bool initial_pose_stored_ =
false;
94 bool loop_counter_stop_ =
true;
95 std::string loop_no_ =
"0";
96 std::string base_frame_;
99 std::shared_ptr<rviz_common::ros_integration::RosNodeAbstractionIface> node_ptr_;
102 geometry_msgs::msg::PoseStamped convert_to_msg(
103 std::vector<double> pose,
104 std::vector<double> orientation);
105 void startWaypointFollowing(std::vector<geometry_msgs::msg::PoseStamped> poses);
106 void startNavigation(geometry_msgs::msg::PoseStamped);
107 void startNavThroughPoses(nav_msgs::msg::Goals poses);
108 using NavigationGoalHandle =
109 rclcpp_action::ClientGoalHandle<nav2_msgs::action::NavigateToPose>;
110 using WaypointFollowerGoalHandle =
111 rclcpp_action::ClientGoalHandle<nav2_msgs::action::FollowWaypoints>;
112 using NavThroughPosesGoalHandle =
113 rclcpp_action::ClientGoalHandle<nav2_msgs::action::NavigateThroughPoses>;
116 rclcpp::Node::SharedPtr client_node_;
117 rclcpp::executors::SingleThreadedExecutor::SharedPtr executor_;
119 std::chrono::milliseconds server_timeout_;
125 nav2::ActionClient<nav2_msgs::action::NavigateToPose>::SharedPtr navigation_action_client_;
126 nav2::ActionClient<nav2_msgs::action::FollowWaypoints>::SharedPtr
127 waypoint_follower_action_client_;
128 nav2::ActionClient<nav2_msgs::action::NavigateThroughPoses>::SharedPtr
129 nav_through_poses_action_client_;
132 nav2::Subscription<nav2_msgs::action::NavigateToPose::Impl::FeedbackMessage>::SharedPtr
133 navigation_feedback_sub_;
134 nav2::Subscription<nav2_msgs::action::NavigateThroughPoses::Impl::FeedbackMessage>::SharedPtr
135 nav_through_poses_feedback_sub_;
136 nav2::Subscription<nav2_msgs::action::NavigateToPose::Impl::GoalStatusMessage>::SharedPtr
137 navigation_goal_status_sub_;
138 nav2::Subscription<nav2_msgs::action::NavigateThroughPoses::Impl::GoalStatusMessage>::SharedPtr
139 nav_through_poses_goal_status_sub_;
142 std::shared_ptr<tf2_ros::Buffer> tf2_buffer_;
143 std::shared_ptr<tf2_ros::TransformListener> transform_listener_;
146 nav2_msgs::action::NavigateToPose::Goal navigation_goal_;
147 nav2_msgs::action::FollowWaypoints::Goal waypoint_follower_goal_;
148 nav2_msgs::action::NavigateThroughPoses::Goal nav_through_poses_goal_;
149 NavigationGoalHandle::SharedPtr navigation_goal_handle_;
150 WaypointFollowerGoalHandle::SharedPtr waypoint_follower_goal_handle_;
151 NavThroughPosesGoalHandle::SharedPtr nav_through_poses_goal_handle_;
154 std::shared_ptr<nav2_lifecycle_manager::LifecycleManagerClient> client_nav_;
155 std::shared_ptr<nav2_lifecycle_manager::LifecycleManagerClient> client_loc_;
157 QCheckBox * store_initial_pose_checkbox_{
nullptr};
159 QPushButton * start_reset_button_{
nullptr};
160 QPushButton * pause_resume_button_{
nullptr};
161 QPushButton * navigation_mode_button_{
nullptr};
162 QPushButton * save_waypoints_button_{
nullptr};
163 QPushButton * load_waypoints_button_{
nullptr};
164 QPushButton * pause_waypoint_button_{
nullptr};
166 QLabel * navigation_status_indicator_{
nullptr};
167 QLabel * localization_status_indicator_{
nullptr};
168 QLabel * navigation_goal_status_indicator_{
nullptr};
169 QLabel * navigation_feedback_indicator_{
nullptr};
170 QLabel * waypoint_status_indicator_{
nullptr};
171 QLabel * number_of_loops_{
nullptr};
173 QLineEdit * nr_of_loops_{
nullptr};
175 QStateMachine state_machine_;
178 QState * pre_initial_{
nullptr};
179 QState * initial_{
nullptr};
180 QState * idle_{
nullptr};
181 QState * reset_{
nullptr};
182 QState * paused_{
nullptr};
183 QState * resumed_{
nullptr};
184 QState * paused_wp_{
nullptr};
185 QState * resumed_wp_{
nullptr};
187 QLabel * imgDisplayLabel_{
nullptr};
193 QState * running_{
nullptr};
194 QState * canceled_{
nullptr};
197 QState * accumulating_{
nullptr};
198 QState * accumulated_wp_{
nullptr};
199 QState * accumulated_nav_through_poses_{
nullptr};
201 nav_msgs::msg::Goals acummulated_poses_;
202 nav_msgs::msg::Goals store_poses_;
205 void updateWpNavigationMarkers();
210 void resetUniqueId();
213 static inline QString getNavToPoseFeedbackLabel(
214 nav2_msgs::action::NavigateToPose::Feedback msg =
215 nav2_msgs::action::NavigateToPose::Feedback());
216 static inline QString getNavThroughPosesFeedbackLabel(
217 nav2_msgs::action::NavigateThroughPoses::Feedback =
218 nav2_msgs::action::NavigateThroughPoses::Feedback());
220 static inline std::string toLabel(T & msg);
223 static inline std::string toString(
double val,
int precision = 0);
226 rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr wp_navigation_markers_pub_;
234 using SystemStatus = nav2_lifecycle_manager::SystemStatus;
237 std::shared_ptr<nav2_lifecycle_manager::LifecycleManagerClient> & client_nav,
238 std::shared_ptr<nav2_lifecycle_manager::LifecycleManagerClient> & client_loc)
239 : client_nav_(client_nav), client_loc_(client_loc)
244 SystemStatus status_nav = SystemStatus::TIMEOUT;
245 SystemStatus status_loc = SystemStatus::TIMEOUT;
247 while (status_nav == SystemStatus::TIMEOUT) {
248 if (status_nav == SystemStatus::TIMEOUT) {
249 status_nav = client_nav_->is_active(std::chrono::seconds(1));
254 bool tried_loc_bringup_once =
false;
255 while (status_loc == SystemStatus::TIMEOUT) {
256 status_loc = client_loc_->is_active(std::chrono::seconds(1));
257 if (tried_loc_bringup_once) {
260 tried_loc_bringup_once =
true;
263 if (status_nav == SystemStatus::ACTIVE) {
264 emit navigationActive();
266 emit navigationInactive();
269 if (status_loc == SystemStatus::ACTIVE) {
270 emit localizationActive();
272 emit localizationInactive();
277 void navigationActive();
278 void navigationInactive();
279 void localizationActive();
280 void localizationInactive();
283 std::shared_ptr<nav2_lifecycle_manager::LifecycleManagerClient> client_nav_;
284 std::shared_ptr<nav2_lifecycle_manager::LifecycleManagerClient> client_loc_;
Panel to interface to the nav2 stack.
void load(const rviz_common::Config &config) override
Load and save configuration data.