AutoAPMS
Resilient Robot Mission Management
Loading...
Searching...
No Matches
simple_skill_build_handler.cpp
1// Copyright 2025 Robin Müller
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
25
29
30// This also includes the node models for all standard nodes
31#include "auto_apms_behavior_tree/build_handler.hpp"
32
33// Include custom node models (under namespace auto_apms_examples::model)
34#include "auto_apms_examples/example_nodes.hpp"
35
37{
38
39class SimpleSkillBuildHandler : public auto_apms_behavior_tree::TreeBuildHandler
40{
41public:
42 using TreeBuildHandler::TreeBuildHandler;
43
44 TreeDocument::TreeElement buildTree(TreeDocument & doc, TreeBlackboard & /*bb*/) override final
45 {
46 // Create an empty tree element
47 TreeDocument::TreeElement tree = doc.newTree("SimpleSkillDemo").makeRoot();
48
49 // Alias for the standard node model namespace
50 namespace standard_model = auto_apms_behavior_tree::model;
51
52 // Insert the nodes of the tree using the generated node models
53 TreeDocument::NodeElement sequence = tree.insertNode<standard_model::Sequence>();
54 sequence.insertNode<standard_model::ForceSuccess>()
55 .insertNode<model::HasParameter>()
56 .set_parameter("bb.msg")
57 .setConditionalScript(BT::PostCond::ON_SUCCESS, "msg := @msg")
58 .setConditionalScript(BT::PostCond::ON_FAILURE, "msg := 'No blackboard parameter'");
59 sequence.insertNode<standard_model::ForceSuccess>()
60 .insertNode<model::HasParameter>()
61 .set_parameter("bb.n_times")
62 .setConditionalScript(BT::PostCond::ON_SUCCESS, "n_times := @n_times")
63 .setConditionalScript(BT::PostCond::ON_FAILURE, "n_times := 1");
64 sequence.insertNode<model::SimpleSkillActionNode>().set_n_times("{n_times}").set_msg("{msg}");
65 sequence.insertNode<model::SimpleSkillActionNode>().set_n_times(1).set_msg("Last message");
66
67 return tree;
68 }
69};
70
71} // namespace auto_apms_examples
72
73// Make the build handler discoverable for the class loader
74AUTO_APMS_BEHAVIOR_TREE_DECLARE_BUILD_HANDLER(auto_apms_examples::SimpleSkillBuildHandler)
Base class for plugins that implement patterns for creating behavior trees using a standardized inter...
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_BUILD_HANDLER(type)
Macro for registering a behavior tree build handler plugin which may be loaded at runtime to build a ...
Models for all available behavior tree nodes.