Skip to main content

mecha10_behavior_runtime/
lib.rs

1//! Mecha10 Behavior Runtime
2//!
3//! This crate provides a unified behavior composition system for robotics and AI.
4//! All behaviors implement the `BehaviorNode` trait with a simple tick-based interface.
5//!
6//! # Philosophy
7//!
8//! - **Behavior Logic** = Rust code (complex logic, high performance)
9//! - **Behavior Composition** = JSON config (simple orchestration, hot-reloadable)
10//! - **Configuration** = JSON with validation (parameters only)
11//!
12//! # Example
13//!
14//! ```rust
15//! use mecha10_behavior_runtime::{BehaviorNode, NodeStatus, Context};
16//! use async_trait::async_trait;
17//!
18//! #[derive(Debug)]
19//! struct MyBehavior;
20//!
21//! #[async_trait]
22//! impl BehaviorNode for MyBehavior {
23//!     async fn tick(&mut self, ctx: &Context) -> anyhow::Result<NodeStatus> {
24//!         // Your behavior logic here
25//!         Ok(NodeStatus::Success)
26//!     }
27//! }
28//! ```
29
30pub mod actions;
31mod behavior;
32mod composition;
33pub mod config;
34pub mod control;
35mod execution;
36mod loader;
37mod registry;
38mod status;
39#[cfg(test)]
40mod test_helpers;
41
42pub use actions::{
43    register_builtin_actions, LandNode, MoveNode, RlTaskNode, SensorCheckNode, SetRlTargetNode, TakeoffNode, TimerNode,
44    WanderNode,
45};
46pub use behavior::{boxed_children_mut, BehaviorNode, BehaviorNodeExt, BoxedBehavior};
47pub use composition::{
48    ForceFailureNode, ForceSuccessNode, InverterNode, ParallelNode, ParallelPolicy, RepeatNode, RetryNode,
49    SelectOrNode, SequenceNode, SubsumptionLayer, SubsumptionNode, TimeoutNode, WatchNode,
50};
51pub use config::{
52    detect_project_root, get_current_environment, list_available_behaviors, load_behavior_config,
53    resolve_behavior_config_path, validate_behavior_composition_json, validate_behavior_config, BehaviorConfig,
54    CompositionConfig, NodeConfig, NodeReference, ParallelPolicyConfig, SubsumptionLayerConfig, ValidationResult,
55};
56pub use control::{PidController, PidGains};
57pub use execution::{BehaviorExecutor, ExecutionContext, ExecutionStats};
58pub use loader::BehaviorLoader;
59pub use registry::NodeRegistry;
60pub use status::NodeStatus;
61
62pub mod hot_reload;
63
64pub use mecha10_core::Context;
65
66pub mod prelude {
67    pub use crate::actions::{
68        LandNode, MoveNode, RlTaskNode, SensorCheckNode, SetRlTargetNode, TakeoffNode, TimerNode, WanderNode,
69    };
70    pub use crate::behavior::{BehaviorNode, BehaviorNodeExt, BoxedBehavior};
71    pub use crate::composition::{
72        ForceFailureNode, ForceSuccessNode, InverterNode, ParallelNode, ParallelPolicy, RepeatNode, RetryNode,
73        SelectOrNode, SequenceNode, SubsumptionLayer, SubsumptionNode, TimeoutNode, WatchNode,
74    };
75    pub use crate::config::{
76        BehaviorConfig, CompositionConfig, NodeConfig, NodeReference, ParallelPolicyConfig, SubsumptionLayerConfig,
77    };
78    pub use crate::control::{PidController, PidGains};
79    pub use crate::execution::{BehaviorExecutor, ExecutionContext, ExecutionStats};
80    pub use crate::loader::BehaviorLoader;
81    pub use crate::registry::NodeRegistry;
82    pub use crate::status::NodeStatus;
83    pub use async_trait::async_trait;
84    pub use mecha10_core::Context;
85}