Skip to content

Commit ac66de2

Browse files
Rviz state machine waypoint follower updates (#2227)
* working on canceling state machine for waypoint mode * fixing cancelation logic * fix linting isue
1 parent c054cdd commit ac66de2

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

nav2_rviz_plugins/src/nav2_panel.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Nav2Panel::Nav2Panel(QWidget * parent)
118118
// State entered when navigate_to_pose action is not active
119119
accumulating_ = new QState();
120120
accumulating_->setObjectName("accumulating");
121-
accumulating_->assignProperty(start_reset_button_, "text", "Reset");
121+
accumulating_->assignProperty(start_reset_button_, "text", "Cancel Waypoint Mode");
122122
accumulating_->assignProperty(start_reset_button_, "toolTip", cancel_waypoint_msg);
123123
accumulating_->assignProperty(start_reset_button_, "enabled", true);
124124

@@ -131,6 +131,18 @@ Nav2Panel::Nav2Panel(QWidget * parent)
131131
accumulating_->assignProperty(navigation_mode_button_, "toolTip", waypoint_goal_msg);
132132

133133
accumulated_ = new QState();
134+
accumulated_->setObjectName("accumulated");
135+
accumulated_->assignProperty(start_reset_button_, "text", "Cancel");
136+
accumulated_->assignProperty(start_reset_button_, "toolTip", cancel_msg);
137+
accumulated_->assignProperty(start_reset_button_, "enabled", true);
138+
139+
accumulated_->assignProperty(pause_resume_button_, "text", "Pause");
140+
accumulated_->assignProperty(pause_resume_button_, "enabled", false);
141+
accumulated_->assignProperty(pause_resume_button_, "toolTip", pause_msg);
142+
143+
accumulated_->assignProperty(navigation_mode_button_, "text", "Start Navigation");
144+
accumulated_->assignProperty(navigation_mode_button_, "enabled", false);
145+
accumulated_->assignProperty(navigation_mode_button_, "toolTip", waypoint_goal_msg);
134146

135147
// State entered to cancel the navigate_to_pose action
136148
canceled_ = new QState();
@@ -186,12 +198,12 @@ Nav2Panel::Nav2Panel(QWidget * parent)
186198
idle_->addTransition(navigation_mode_button_, SIGNAL(clicked()), accumulating_);
187199
accumulating_->addTransition(navigation_mode_button_, SIGNAL(clicked()), accumulated_);
188200
accumulating_->addTransition(start_reset_button_, SIGNAL(clicked()), idle_);
201+
accumulated_->addTransition(start_reset_button_, SIGNAL(clicked()), canceled_);
189202

190203
// Internal state transitions
191204
canceled_->addTransition(canceled_, SIGNAL(entered()), idle_);
192205
reset_->addTransition(reset_, SIGNAL(entered()), initial_);
193206
resumed_->addTransition(resumed_, SIGNAL(entered()), idle_);
194-
accumulated_->addTransition(accumulated_, SIGNAL(entered()), idle_);
195207

196208
// Pause/Resume button click transitions
197209
idle_->addTransition(pause_resume_button_, SIGNAL(clicked()), paused_);
@@ -206,6 +218,15 @@ Nav2Panel::Nav2Panel(QWidget * parent)
206218
runningTransition->setTargetState(idle_);
207219
running_->addTransition(runningTransition);
208220

221+
ROSActionQTransition * idleAccumulatedTransition =
222+
new ROSActionQTransition(QActionState::INACTIVE);
223+
idleAccumulatedTransition->setTargetState(accumulated_);
224+
idle_->addTransition(idleAccumulatedTransition);
225+
226+
ROSActionQTransition * accumulatedTransition = new ROSActionQTransition(QActionState::ACTIVE);
227+
accumulatedTransition->setTargetState(idle_);
228+
accumulated_->addTransition(accumulatedTransition);
229+
209230
initial_thread_ = new InitialThread(client_nav_, client_loc_);
210231
connect(initial_thread_, &InitialThread::finished, initial_thread_, &QObject::deleteLater);
211232

@@ -408,7 +429,7 @@ Nav2Panel::onNewGoal(double x, double y, double theta, QString frame)
408429
void
409430
Nav2Panel::onCancelButtonPressed()
410431
{
411-
if (state_machine_.configuration().contains(accumulating_)) {
432+
if (waypoint_follower_goal_handle_) {
412433
auto future_cancel =
413434
waypoint_follower_action_client_->async_cancel_goal(waypoint_follower_goal_handle_);
414435

@@ -418,7 +439,9 @@ Nav2Panel::onCancelButtonPressed()
418439
RCLCPP_ERROR(client_node_->get_logger(), "Failed to cancel waypoint follower");
419440
return;
420441
}
421-
} else {
442+
}
443+
444+
if (navigation_goal_handle_) {
422445
auto future_cancel = navigation_action_client_->async_cancel_goal(navigation_goal_handle_);
423446

424447
if (rclcpp::spin_until_future_complete(client_node_, future_cancel, server_timeout_) !=
@@ -449,7 +472,7 @@ Nav2Panel::onAccumulating()
449472
void
450473
Nav2Panel::timerEvent(QTimerEvent * event)
451474
{
452-
if (state_machine_.configuration().contains(accumulating_)) {
475+
if (state_machine_.configuration().contains(accumulated_)) {
453476
if (event->timerId() == timer_.timerId()) {
454477
if (!waypoint_follower_goal_handle_) {
455478
RCLCPP_DEBUG(client_node_->get_logger(), "Waiting for Goal");

0 commit comments

Comments
 (0)