Skip to content

Commit 78ddad0

Browse files
committed
update: added simple action feedback from navigator plugin
Signed-off-by: d.kotov <moveton40@gmail.com>
1 parent 42913dd commit 78ddad0

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

tutorials/docs/integrating_new_task_server_and_navigator_plugin.rst

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ Create three action definitions in ``nav2_operations_msgs/action/``.
108108
---
109109
uint16 error_code
110110
---
111-
# no feedback
111+
builtin_interfaces/Duration navigation_time
112+
uint32 path_poses_count
113+
114+
- ``navigation_time`` — elapsed wall-clock time since the goal was accepted.
115+
- ``path_poses_count`` — number of poses in the path currently on the blackboard. Demonstrates how to read a BT blackboard value and surface it as feedback.
112116

113117
For more details refer to the ``nav2_operations_msgs`` package in the tutorial code. You can find more examples of this in ``nav2_msgs`` for ``NavigateToPose``, ``NavigateThroughPoses`` navigator APIs as well as other task servers like ``FollowPath`` and ``ComputePathToPose``.
114118

@@ -386,14 +390,14 @@ Virtual method summary:
386390
+--------------------+--------------------------------------------------------------+
387391
| ``goalReceived()`` | Load BT, write ``path`` to blackboard |
388392
+--------------------+--------------------------------------------------------------+
389-
| ``onLoop()`` | Publish empty feedback |
393+
| ``onLoop()`` | Compute elapsed time, read blackboard, publish feedback |
390394
+--------------------+--------------------------------------------------------------+
391395
| ``onPreempt()`` | Accept or reject pending goal based on BT file |
392396
+--------------------+--------------------------------------------------------------+
393397
| ``goalCompleted()``| Write ``error_code`` (0/1/2), clear blackboard |
394398
+--------------------+--------------------------------------------------------------+
395399

396-
**goalReceived** — loads the BT file and writes the path to the blackboard so BT nodes can read it immediately on the first tick.
400+
**goalReceived** — loads the BT file and writes the path to the blackboard so BT nodes can read it immediately on the first tick. It also snapshots the start time so ``onLoop()`` can compute elapsed navigation time.
397401

398402
.. code-block:: cpp
399403
@@ -407,16 +411,32 @@ Virtual method summary:
407411
auto blackboard = bt_action_server_->getBlackboard();
408412
blackboard->set<nav_msgs::msg::Path>(path_blackboard_id_, goal->path);
409413
active_goal_ = true;
414+
goal_start_time_ = clock_->now();
410415
return true;
411416
}
412417
413-
**onLoop** — called on every tick of the BT executor loop. This is where the navigator publishes action feedback to the client. For this navigator the feedback is empty, but a richer implementation could read progress from the blackboard here.
418+
**onLoop** — called on every tick of the BT executor loop. This is where the navigator publishes action feedback to the client. It computes elapsed wall-clock time since the goal was accepted and reads the path size from the blackboard to surface it as a progress signal.
414419

415420
.. code-block:: cpp
416421
417422
void NavigateWithOperations::onLoop()
418423
{
419-
bt_action_server_->publishFeedback(std::make_shared<ActionT::Feedback>());
424+
auto feedback = std::make_shared<ActionT::Feedback>();
425+
426+
feedback->navigation_time = clock_->now() - goal_start_time_;
427+
428+
// Read a value from the BT blackboard and publish it as feedback.
429+
// The path is written once by goalReceived(); a BT action node
430+
// could write a separate progress key that gets read here instead,
431+
// or you could try to calculate remaining poses with
432+
// nav2_util::getCurrentPose for example.
433+
auto blackboard = bt_action_server_->getBlackboard();
434+
nav_msgs::msg::Path current_path;
435+
if (blackboard->get<nav_msgs::msg::Path>(path_blackboard_id_, current_path)) {
436+
feedback->path_poses_count = static_cast<uint32_t>(current_path.poses.size());
437+
}
438+
439+
bt_action_server_->publishFeedback(feedback);
420440
}
421441
422442
**goalCompleted** — called once when the tree finishes. Maps the BT outcome to an error code in the action result and clears the blackboard so a subsequent goal that reuses the same BT file does not find stale data.

0 commit comments

Comments
 (0)