Go to the documentation of this file.
7 <root BTCPP_format="4">
9 <BehaviorTree ID="MainTree">
11 <SaySomething name="talk" message="hello world"/>
13 <SubTree ID="MySub" name="mysub"/>
15 <Script name="set_message" code="msg:= 'the original message' "/>
16 <SaySomething message="{msg}"/>
18 <Sequence name="counting">
19 <SaySomething message="1"/>
20 <SaySomething message="2"/>
21 <SaySomething message="3"/>
26 <BehaviorTree ID="MySub">
28 <AlwaysSuccess name="action_subA"/>
29 <AlwaysSuccess name="action_subB"/>
46 int main(
int argc,
char** argv)
57 std::cout <<
"----- Nodes fullPath() -------\n";
62 std::cout <<
"\n------ Output (original) ------\n";
63 tree.tickWhileRunning();
75 std::cout <<
"DummyAction substituting node with fullPath(): " <<
self.fullPath()
81 auto msg =
self.getInput<std::string>(
"message");
82 std::cout <<
"DummySaySomething: " << msg.value() << std::endl;
94 test_config.
async_delay = std::chrono::milliseconds(2000);
96 test_config.
post_script =
"msg := 'message SUBSTITUTED' ";
105 bool const USE_JSON =
true;
131 "return_status": "SUCCESS",
132 "post_script": "msg ='message SUBSTITUTED'"
135 "return_status": "SUCCESS"
139 "SubstitutionRules": {
140 "mysub/action_*": "DummyAction",
141 "talk": "DummySaySomething",
142 "set_message": "NewMessage",
143 "counting": "NoCounting"
155 std::cout <<
"\n------ Output (substituted) ------\n";
std::chrono::milliseconds async_delay
if async_delay > 0, this action become asynchronous and wait this amount of time
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
void loadSubstitutionRuleFromJSON(const std::string &json_text)
loadSubstitutionRuleFromJSON will parse a JSON file to create a set of substitution rules....
Abstract base class for Behavior Tree Nodes.
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
static const char * json_text
void registerNodeType(const std::string &ID, const PortsList &ports, ExtraArgs... args)
int main(int argc, char **argv)
In this example we will see how we can substitute some nodes in the Tree above with.
NodeStatus return_status
status to return when the action is completed.
static const char * xml_text
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
void registerBehaviorTreeFromText(const std::string &xml_text)
const std::string & fullPath() const
std::string post_script
script to execute when actions is completed
void addSubstitutionRule(StringView filter, SubstitutionRule rule)
addSubstitutionRule replace a node with another one when the tree is created. If the rule ia a string...
void applyVisitor(const std::function< void(const TreeNode *)> &visitor)
void registerSimpleAction(const std::string &ID, const SimpleActionNode::TickFunctor &tick_functor, PortsList ports={})
registerSimpleAction help you register nodes of type SimpleActionNode.