Skip to content

Commit 42913dd

Browse files
committed
update: success section
Signed-off-by: d.kotov <moveton40@gmail.com>
1 parent bf74e3e commit 42913dd

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tutorials/docs/integrating_new_task_server_and_navigator_plugin.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ Header (``include/nav2_operations_bt_nodes/action/set_blade_state.hpp``):
297297
});
298298
}
299299
void on_tick() override;
300+
BT::NodeStatus on_success() override;
300301
};
301302
302303
Implementation (``src/action/set_blade_state.cpp``):
@@ -310,13 +311,18 @@ Implementation (``src/action/set_blade_state.cpp``):
310311
goal_.enable = enable;
311312
}
312313
313-
``on_success()``, ``on_aborted()``, and ``on_cancelled()`` are not overridden here — the ``BtActionNode`` base class defaults apply. If they were explicitly written out, they would look like this:
314+
``on_aborted()`` and ``on_cancelled()`` are not overridden here — the ``BtActionNode`` base class defaults apply (``FAILURE`` and ``SUCCESS`` respectively). ``on_success()`` checks the action result's ``success`` field so that the BT node reports the real outcome rather than assuming success unconditionally:
314315

315316
.. code-block:: cpp
316317
317-
BT::NodeStatus SetBladeState::on_success() { return BT::NodeStatus::SUCCESS; }
318-
BT::NodeStatus SetBladeState::on_aborted() { return BT::NodeStatus::FAILURE; }
319-
BT::NodeStatus SetBladeState::on_cancelled() { return BT::NodeStatus::SUCCESS; }
318+
// Use the action result to decide the BT node status
319+
BT::NodeStatus SetBladeState::on_success()
320+
{
321+
return result_.result->success ? BT::NodeStatus::SUCCESS : BT::NodeStatus::FAILURE;
322+
}
323+
// Base-class defaults for reference:
324+
// BT::NodeStatus SetBladeState::on_aborted() { return BT::NodeStatus::FAILURE; }
325+
// BT::NodeStatus SetBladeState::on_cancelled() { return BT::NodeStatus::SUCCESS; }
320326
321327
Override these in your own node when you need to extract result fields, publish feedback, or return a non-default status.
322328

0 commit comments

Comments
 (0)