Refactor NavigateToPose action client into rviz Nav2 panel and expose Cancel/Shutdown#944
Conversation
| { | ||
|
|
||
| /// Custom Event to track state of ROS Action | ||
| struct ROSActionEvent : public QEvent |
There was a problem hiding this comment.
Minor nit: I would've split this into its own header/implementation files - ros_action_event.[cpp,h]
nav2_rviz_plugins/src/nav2_panel.cpp
Outdated
| completedTransition->setTargetState(running_); | ||
| completed_->addTransition(completedTransition); | ||
|
|
||
| machine_.addState(initial_); |
There was a problem hiding this comment.
Probably should have called this "state_machine_" instead of "machine_". I haven't looked at this code in a while and was a bit confused for a sec.
| // State entered while the NavigateToPose action is active | ||
| running_ = new QState(); | ||
| running_->setObjectName("running"); | ||
| running_->assignProperty(start_stop_button_, "text", "Cancel"); |
There was a problem hiding this comment.
The start_stop_button is not longer just start and stop, but now also cancel. Perhaps rename the variable?
There was a problem hiding this comment.
Any name suggestions? You can argue cancel is semantically a stop as well, if you don't mind the term overloading.
There was a problem hiding this comment.
Yeah, that's true. Never mind on the original comment. I think it's clear enough as is.
| rclcpp::Node::SharedPtr goal_node_; | ||
|
|
||
| // Executor needed to spin node in thread | ||
| std::unique_ptr<rclcpp::executors::SingleThreadedExecutor> executor_; |
There was a problem hiding this comment.
Similar question: why does this need to be a ptr?
1152b58 to
b9e2b23
Compare
|
Addressed feedback. I decided to remove the |
|
@bpwilcox Please change the topic name or something to prevent both the panel and bt_navigator from responding to the topic. |
de8cfce to
a247cbf
Compare
|
I've updated this PR to address feedback from our meeting to not use a subscriber in the nav2 panel to listen for the goal pose. Per @crdelsey's suggestion, I defined a custom global object to allow access between the panel and tool plugins in rviz. This custom |
a247cbf to
cbb04be
Compare
|
@mjeronimo @crdelsey Can you re-review since the changes I made? |
ghost
left a comment
There was a problem hiding this comment.
This could really use some design documentation to go along with it.
nav2_rviz_plugins/CMakeLists.txt
Outdated
| find_package(tf2_geometry_msgs REQUIRED) | ||
|
|
||
| set(nav2_rviz_plugins_headers_to_moc | ||
| include/nav2_rviz_plugins/goal_pose_updater; |
There was a problem hiding this comment.
It doesn't seem that these lines should be terminated by a semicolon
|
|
||
| auto options = rclcpp::NodeOptions().arguments( | ||
| {"__node:=navigation_dialog_action_client"}); | ||
| client_node_ = std::make_shared<rclcpp::Node>("_", options); |
There was a problem hiding this comment.
What are you doing here? Why create the node by the name of "_" but then use a argument to rename it?
There was a problem hiding this comment.
This wasn't my code but moved from the navigation_dialog.cpp before my refactor. Seemingly, this is done several places in the code (see bt_navigator.cpp). If I recall, this was done to support remapping?
nav2_rviz_plugins/src/nav2_panel.cpp
Outdated
| if (status == action_msgs::msg::GoalStatus::STATUS_ACCEPTED || | ||
| status == action_msgs::msg::GoalStatus::STATUS_EXECUTING) | ||
| { | ||
| state_machine_.postEvent(new ROSActionQEvent(true)); |
There was a problem hiding this comment.
If I understand this correctly, you are posting a bool as an event. Is that correct? That conveys little information. The events should be an enum at a minimum. That way you could post something like "NAV_ACTIVATED" or "NAV_DEACTIVATED"
There was a problem hiding this comment.
Same functionality but I suppose an enum indicates it is more specific to actions being active/inactive.
| // Send the goal pose | ||
| goal_.pose = pose; | ||
|
|
||
| // Enable result awareness by providing an empty lambda function |
There was a problem hiding this comment.
What's "result awareness"? Can you elaborate on this comment
There was a problem hiding this comment.
I'm not entirely sure as this wasn't my code/comment, just part of refactor, perhaps @mjeronimo could explain better.
There was a problem hiding this comment.
"Result awareness" was introduced into the ROS2 action client. There were some relatively recent changes (a couple months ago or so), where one now provides callbacks in the SendGoalOptions for the goal response, feedback, and result. The SendGoalOptions are then passed to the client's async_send_goal method. In the navigation stack we already had code written to the old style of explicitly sending the goal request, etc. This SendGoalOptions change broke our code. One way I found to work around it was to provide an empty callback for the result_callback. Providing this callback causes the ROS2 to set the result aware flag (whatever that means) and allows us to call the existing functions. Alternatively, we could update our client code to conform to the new callback model. See the ROS2 code in rclcpp_action for more about "result awareness." I haven't found any docs.
cbb04be to
1540ec5
Compare
Codecov Report
@@ Coverage Diff @@
## master #944 +/- ##
==========================================
- Coverage 33.71% 28.43% -5.29%
==========================================
Files 197 196 -1
Lines 10241 10006 -235
Branches 4038 3226 -812
==========================================
- Hits 3453 2845 -608
- Misses 4466 5397 +931
+ Partials 2322 1764 -558
Continue to review full report at Codecov.
|
1540ec5 to
42d18cc
Compare
42d18cc to
e4e73e4
Compare
mjeronimo
left a comment
There was a problem hiding this comment.
I'm fine with the code pending the few minor changes I mentioned in the latest review.
nav2_rviz_plugins/src/nav2_panel.cpp
Outdated
| #include <QPushButton> | ||
| #include <QtConcurrent/QtConcurrent> | ||
| #include <QVBoxLayout> | ||
| #include <QEventTransition> |
There was a problem hiding this comment.
Some of these headers are no longer needed and can be removed (dirent, QHBoxLayout, QLabel, QEventTransition).
nav2_rviz_plugins/src/nav2_panel.cpp
Outdated
| this, SLOT(onNewGoal(double,double,double,QString))); // NOLINT | ||
|
|
||
| // Launch a thread to run the node | ||
| thread_ = std::make_unique<std::thread>( |
There was a problem hiding this comment.
You could use a QBasicTimer (see the old code) instead of creating a node just to create a timer.
nav2_rviz_plugins/src/nav2_panel.cpp
Outdated
| executor_.remove_node(node->get_node_base_interface()); | ||
| }, timer_node_); | ||
|
|
||
| timer_ = timer_node_->create_wall_timer(1s, std::bind(&Nav2Panel::timerActionEvent, this)); |
There was a problem hiding this comment.
You could check more frequently than once per second. This would make it more responsive to detecting the completed navigation at little expense. For example, running the callback at 5Hz should be negligible.
| // Send the goal pose | ||
| goal_.pose = pose; | ||
|
|
||
| // Enable result awareness by providing an empty lambda function |
There was a problem hiding this comment.
"Result awareness" was introduced into the ROS2 action client. There were some relatively recent changes (a couple months ago or so), where one now provides callbacks in the SendGoalOptions for the goal response, feedback, and result. The SendGoalOptions are then passed to the client's async_send_goal method. In the navigation stack we already had code written to the old style of explicitly sending the goal request, etc. This SendGoalOptions change broke our code. One way I found to work around it was to provide an empty callback for the result_callback. Providing this callback causes the ROS2 to set the result aware flag (whatever that means) and allows us to call the existing functions. Alternatively, we could update our client code to conform to the new callback model. See the ROS2 code in rclcpp_action for more about "result awareness." I haven't found any docs.
clean up remove extra log info
minor clean up
fix compile issues remove extra semicolons fix uncrustify
cleanup timer
e4e73e4 to
c36e90b
Compare



Description of contribution
GoalPoseUpdaterQObject to emit signal for goal poses. Creates a global object to be accessed in both the nav2 panel and nav2 goal toolnav2_rviz_plugin::GoalToolto send goal poses via Qt signal using `GoalPoseUpdater' QObjectNav2PanelROSActionEventandROSActionTransitionto handle Qt button state transitions