|
AutoAPMS
Streamlining behaviors in ROS 2
|
PX4 mode executor that runs an AutoAPMS behavior in-process when put in charge by the FMU. More...
#include <auto_apms_px4/behavior_mode_executor.hpp>
Public Types | |
| enum class | CompletionReaction { HOLD , RTL , LAND , DISARM , COMPLETE , NONE } |
| Reaction performed when a behavior terminates or fails, using the in-charge executor API. More... | |
Public Member Functions | |
| BehaviorModeExecutor (BehaviorOwnedMode &owned_mode, const px4_ros2::ModeExecutorBase::Settings &settings, std::function< Config()> config_provider, auto_apms_behavior_tree::GenericTreeExecutorNode &engine) | |
| Constructor. | |
| void | prepareTree () |
| Build the configured behavior tree and keep it detached, ready to be executed on the next activation. | |
| void | onExecutionResult (ExecutionResult result) |
| Handle the termination of the behavior running on the in-process executor. | |
Static Public Member Functions | |
| static CompletionReaction | reactionFromString (const std::string &str) |
| Parse a string into a CompletionReaction. | |
PX4 mode executor that runs an AutoAPMS behavior in-process when put in charge by the FMU.
The behavior tree is built ahead of time and kept detached (see prepareTree): the potentially expensive tree construction (which instantiates the ROS 2 waitables of the behavior tree nodes) happens once when the node is constructed and again after every run, off the activation path. When the owned mode is selected (RC switch, GCS or ActivateImmediately), PX4 puts this executor in charge and onActivate() hands the pre-built tree to the in-process executor (engine) via startExecution, so activation only recreates the lightweight execution timer and starts ticking. A pilot override or failsafe triggers onDeactivate(), which terminates the behavior. When the behavior finishes, a configurable in-charge reaction (hold/RTL/land/disarm/complete/none) is performed and a fresh tree is prepared for the next activation.
The behavior itself is built from standard AutoAPMS nodes and drives the vehicle through the regular PX4 skills. Before starting, the executor publishes its VehicleCommand source component on the global blackboard (under the key configured via the AUTO_APMS_PX4_SOURCE_COMPONENT_GLOBAL_KEY compile definition) so that ownership-aware nodes (e.g. SendCmdSetNavState) can attribute their commands to the executor.
Definition at line 94 of file behavior_mode_executor.hpp.
|
strong |
Reaction performed when a behavior terminates or fails, using the in-charge executor API.
Definition at line 100 of file behavior_mode_executor.hpp.
| BehaviorModeExecutor | ( | BehaviorOwnedMode & | owned_mode, |
| const px4_ros2::ModeExecutorBase::Settings & | settings, | ||
| std::function< Config()> | config_provider, | ||
| auto_apms_behavior_tree::GenericTreeExecutorNode & | engine ) |
Constructor.
| owned_mode | Placeholder mode owned by this executor. |
| settings | PX4 mode executor settings (activation policy). |
| config_provider | Callable returning the current Config. It is invoked whenever a tree is prepared (once at construction and again after each run, see prepareTree) and at the start of every activation, so runtime parameter changes take effect on the next run. It must stay valid for the lifetime of this executor and is expected to keep any underlying parameter listener alive. |
| engine | In-process behavior tree executor used to run the behavior. |
Definition at line 50 of file behavior_mode_executor.cpp.
| void prepareTree | ( | ) |
Build the configured behavior tree and keep it detached, ready to be executed on the next activation.
Snapshots the current configuration, publishes the mode-executor-active flag on the global blackboard (so the behavior tree nodes pick it up as they construct) and builds the tree via the in-process executor's makeTreeConstructor. This is the expensive step (it instantiates the ROS 2 waitables of the behavior tree nodes) and is intentionally kept off the activation path: it is called once when the node is constructed (before FMU registration, so a build failure prevents the mode from being registered) and again after every run.
| std::exception | if the tree cannot be built (e.g. an empty or invalid build request). |
Definition at line 158 of file behavior_mode_executor.cpp.
|
static |
Parse a string into a CompletionReaction.
| std::invalid_argument | if the value is not a valid reaction. |
Definition at line 86 of file behavior_mode_executor.cpp.
| void onExecutionResult | ( | ExecutionResult | result | ) |
Handle the termination of the behavior running on the in-process executor.
Translates the tree execution result into a px4_ros2::Result and performs the configured completion reaction. Intended to be called from the owning node's TreeExecutorBase::onTermination override.
| result | Final result of the tree execution. |
Definition at line 62 of file behavior_mode_executor.cpp.