pub trait BehaviorNode:
Send
+ Sync
+ Debug {
// Required method
fn tick<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<NodeStatus, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
// Provided methods
fn name(&self) -> &str { ... }
fn children_mut(&mut self) -> Vec<&mut dyn BehaviorNode> { ... }
fn active_capability(&self) -> Option<&str> { ... }
fn reset_self(&mut self) { ... }
fn reset<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn on_init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn on_terminate<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}Required Methods§
Sourcefn tick<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<NodeStatus, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn tick<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<NodeStatus, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Execute one tick of the behavior.
This method is called repeatedly by the execution engine. It should:
- Perform one unit of work
- Return quickly (non-blocking)
- Return
NodeStatusto indicate progress
§Arguments
ctx- Execution context with access to messaging, sensors, etc.
§Returns
NodeStatus::Success- Behavior completed successfullyNodeStatus::Failure- Behavior failed (irrecoverable error)NodeStatus::Running- Behavior is still executing (call again)
§Errors
Return an error for exceptional conditions that should halt execution.
For recoverable failures, return Ok(NodeStatus::Failure) instead.
Provided Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Get the name of this behavior node.
Used for debugging, logging, and monitoring. The default implementation returns the type name.
Sourcefn children_mut(&mut self) -> Vec<&mut dyn BehaviorNode>
fn children_mut(&mut self) -> Vec<&mut dyn BehaviorNode>
Return mutable references to this node’s child behaviors, in the order they should receive lifecycle events.
Leaf nodes have no children and should not override this - the default
implementation returns an empty list. Composite nodes (e.g. SequenceNode,
SelectOrNode, ParallelNode, SubsumptionNode, EnsembleNode) override
this to expose their children, which drives the default on_init/
on_terminate/reset propagation below without each composite having to
hand-roll the same loop.
Sourcefn active_capability(&self) -> Option<&str>
fn active_capability(&self) -> Option<&str>
The capability this node implies should be published on /behavior/status while it’s
the one actively being ticked (e.g. rl_task’s hardcoded "rl", gating RlNode::is_active()
on the rl node crate’s side) - None for a node with no such gate (the default, correct
for the vast majority of leaves and for a composite with no currently-active child).
Composite nodes (SequenceNode, SelectOrNode, ParallelNode) override this to forward
whichever child is currently active/running - behavior-executor calls this on the tree
root each status tick rather than each leaf declaring anything back up on its own, since
which child is “current” is already tracked by the composite ticking it.
Sourcefn reset_self(&mut self)
fn reset_self(&mut self)
Reset this node’s own local state, ignoring children.
Called by the default reset() implementation before it propagates to children.
Composite nodes with local progress to rewind (e.g. SequenceNode’s current child
index, ParallelNode’s per-child statuses) override this instead of reset()
itself, so they don’t have to hand-roll the child-propagation loop below.
Sourcefn reset<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn reset<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Reset the behavior to its initial state.
Called when the behavior needs to be restarted (e.g., in a loop or
after a failure). The default implementation resets local state via
reset_self, then propagates the reset to every child returned by
children_mut.
Sourcefn on_init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn on_init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Called when the behavior is first initialized.
Use this for one-time setup like loading models, establishing connections, etc.
The default implementation propagates on_init to every child returned by
children_mut.
Sourcefn on_terminate<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn on_terminate<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 Context,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Called when the behavior is being terminated.
Use this for cleanup like closing connections, saving state, etc.
The default implementation propagates on_terminate to every child
returned by children_mut.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".