mecha10-behavior-runtime 0.7.0

Behavior tree runtime for Mecha10 - unified AI and logic composition system
Documentation
//! Built-in action nodes for behavior trees
//!
//! This module provides common action nodes that can be used in behavior tree compositions.
//! All nodes implement the `BehaviorNode` trait and can be registered in the NodeRegistry.
//!
//! The node implementations are split into cohesive submodules:
//! - [`movement`]: nodes that publish velocity commands (`WanderNode`, `MoveNode`, `StopNode`)
//! - [`flight`]: PID altitude-hold nodes for rotorcraft (`TakeoffNode`, `LandNode`)
//! - [`sensing`]: nodes that inspect sensor state (`SensorCheckNode`)
//! - [`timing`]: nodes that gate on elapsed time or do nothing (`TimerNode`, `PauseNode`, `IdleNode`)
//! - [`navigation`]: stub path-planning/following/arrival nodes (`PlanPathNode`, `FollowPathNode`,
//!   `CheckArrivalNode`)
//! - [`rl_task`]: hands control to the `rl` node and waits for its task-complete signal (`RlTaskNode`)
//! - [`instance_track_task`]: hands control to the `instance-track` node and waits for its
//!   lost/complete signal (`InstanceTrackTaskNode`)
//! - [`capture_target`]: captures a picture of a uniquely-found vision target and publishes it
//!   for the platform API to store for user review (`CaptureTargetNode`)

mod capture_target;
mod elapsed_timer;
mod flight;
mod instance_track_task;
mod movement;
mod navigation;
mod rl_task;
mod sensing;
mod set_instance_track_target;
mod set_rl_target;
mod timing;

pub use capture_target::CaptureTargetNode;
pub use flight::{LandNode, TakeoffNode};
pub use instance_track_task::InstanceTrackTaskNode;
pub use movement::{MoveNode, StopNode, WanderNode};
pub use navigation::{CheckArrivalNode, FollowPathNode, PlanPathNode};
pub use rl_task::RlTaskNode;
pub use sensing::SensorCheckNode;
pub use set_instance_track_target::SetInstanceTrackTargetNode;
pub use set_rl_target::SetRlTargetNode;
pub use timing::{IdleNode, PauseNode, TimerNode};

use crate::{BoxedBehavior, NodeRegistry};
use serde_json::Value;

macro_rules! register_action {
    ($registry:expr, $name:literal, $node_type:ty) => {
        $registry.register($name, |config: Value| -> anyhow::Result<BoxedBehavior> {
            Ok(Box::new(<$node_type>::from_json(config)?))
        });
    };
}

/// Register all built-in action nodes with a registry
///
/// This function registers the following nodes:
/// - `wander`: WanderNode
/// - `move`: MoveNode
/// - `sensor_check`: SensorCheckNode
/// - `timer`: TimerNode
/// - `idle`: IdleNode
/// - `pause`: PauseNode
/// - `stop`: StopNode
/// - `plan_path`: PlanPathNode
/// - `follow_path`: FollowPathNode
/// - `check_arrival`: CheckArrivalNode
/// - `rl_task`: RlTaskNode
/// - `set_rl_target`: SetRlTargetNode
/// - `takeoff`: TakeoffNode
/// - `land`: LandNode
/// - `instance_track_task`: InstanceTrackTaskNode
/// - `set_instance_track_target`: SetInstanceTrackTargetNode
/// - `capture_target`: CaptureTargetNode
///
/// # Example
///
/// ```rust
/// use mecha10_behavior_runtime::{NodeRegistry, actions};
///
/// let mut registry = NodeRegistry::new();
/// actions::register_builtin_actions(&mut registry);
/// ```
pub fn register_builtin_actions(registry: &mut NodeRegistry) {
    register_action!(registry, "wander", WanderNode);
    register_action!(registry, "move", MoveNode);
    register_action!(registry, "sensor_check", SensorCheckNode);
    register_action!(registry, "timer", TimerNode);
    register_action!(registry, "idle", IdleNode);
    register_action!(registry, "pause", PauseNode);
    register_action!(registry, "stop", StopNode);
    register_action!(registry, "plan_path", PlanPathNode);
    register_action!(registry, "follow_path", FollowPathNode);
    register_action!(registry, "check_arrival", CheckArrivalNode);
    register_action!(registry, "rl_task", RlTaskNode);
    register_action!(registry, "set_rl_target", SetRlTargetNode);
    register_action!(registry, "takeoff", TakeoffNode);
    register_action!(registry, "land", LandNode);
    register_action!(registry, "instance_track_task", InstanceTrackTaskNode);
    register_action!(registry, "set_instance_track_target", SetInstanceTrackTargetNode);
    register_action!(registry, "capture_target", CaptureTargetNode);
}