Skip to content

Commit ff15e23

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

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
@@ -117,7 +117,7 @@ Nav2Panel::Nav2Panel(QWidget * parent)
117117
// State entered when navigate_to_pose action is not active
118118
accumulating_ = new QState();
119119
accumulating_->setObjectName("accumulating");
120-
accumulating_->assignProperty(start_reset_button_, "text", "Reset");
120+
accumulating_->assignProperty(start_reset_button_, "text", "Cancel Waypoint Mode");
121121
accumulating_->assignProperty(start_reset_button_, "toolTip", cancel_waypoint_msg);
122122
accumulating_->assignProperty(start_reset_button_, "enabled", true);
123123

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

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

134146
// State entered to cancel the navigate_to_pose action
135147
canceled_ = new QState();
@@ -185,12 +197,12 @@ Nav2Panel::Nav2Panel(QWidget * parent)
185197
idle_->addTransition(navigation_mode_button_, SIGNAL(clicked()), accumulating_);
186198
accumulating_->addTransition(navigation_mode_button_, SIGNAL(clicked()), accumulated_);
187199
accumulating_->addTransition(start_reset_button_, SIGNAL(clicked()), idle_);
200+
accumulated_->addTransition(start_reset_button_, SIGNAL(clicked()), canceled_);
188201

189202
// Internal state transitions
190203
canceled_->addTransition(canceled_, SIGNAL(entered()), idle_);
191204
reset_->addTransition(reset_, SIGNAL(entered()), initial_);
192205
resumed_->addTransition(resumed_, SIGNAL(entered()), idle_);
193-
accumulated_->addTransition(accumulated_, SIGNAL(entered()), idle_);
194206

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

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

@@ -407,7 +428,7 @@ Nav2Panel::onNewGoal(double x, double y, double theta, QString frame)
407428
void
408429
Nav2Panel::onCancelButtonPressed()
409430
{
410-
if (state_machine_.configuration().contains(accumulating_)) {
431+
if (waypoint_follower_goal_handle_) {
411432
auto future_cancel =
412433
waypoint_follower_action_client_->async_cancel_goal(waypoint_follower_goal_handle_);
413434

@@ -417,7 +438,9 @@ Nav2Panel::onCancelButtonPressed()
417438
RCLCPP_ERROR(client_node_->get_logger(), "Failed to cancel waypoint follower");
418439
return;
419440
}
420-
} else {
441+
}
442+
443+
if (navigation_goal_handle_) {
421444
auto future_cancel = navigation_action_client_->async_cancel_goal(navigation_goal_handle_);
422445

423446
if (rclcpp::spin_until_future_complete(client_node_, future_cancel, server_timeout_) !=
@@ -448,7 +471,7 @@ Nav2Panel::onAccumulating()
448471
void
449472
Nav2Panel::timerEvent(QTimerEvent * event)
450473
{
451-
if (state_machine_.configuration().contains(accumulating_)) {
474+
if (state_machine_.configuration().contains(accumulated_)) {
452475
if (event->timerId() == timer_.timerId()) {
453476
if (!waypoint_follower_goal_handle_) {
454477
RCLCPP_DEBUG(client_node_->get_logger(), "Waiting for Goal");

0 commit comments

Comments
 (0)