Skip to content

Commit 92564df

Browse files
committed
removing "main_tree_to_execute" from tutorials and adding "BTCPP_format"
1 parent a851c79 commit 92564df

28 files changed

+94
-71
lines changed

examples/ex01_wrap_legacy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Point3D convertFromString(StringView key)
5151
// clang-format off
5252
static const char* xml_text = R"(
5353
54-
<root>
54+
<root BTCPP_format="4">
5555
<BehaviorTree>
5656
<MoveTo goal="-1;3;0.5" />
5757
</BehaviorTree>

examples/ex02_runtime_ports.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using namespace BT;
33

44
// clang-format off
55
static const char* xml_text = R"(
6-
<root main_tree_to_execute = "MainTree" >
6+
<root BTCPP_format="4" >
77
<BehaviorTree ID="MainTree">
88
<Sequence name="root">
99
<ThinkRuntimePort text="{the_answer}"/>
@@ -62,7 +62,8 @@ int main()
6262
PortsList say_ports = {BT::InputPort<std::string>("message")};
6363
factory.registerNodeType<SayRuntimePort>("SayRuntimePort", say_ports);
6464

65-
auto tree = factory.createTreeFromText(xml_text);
65+
factory.registerBehaviorTreeFromText(xml_text);
66+
auto tree = factory.createTree("MainTree");
6667
tree.tickWhileRunning();
6768

6869
return 0;

examples/ex03_ncurses_manual_selector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using namespace BT;
1010

1111
// clang-format off
1212
static const char* xml_text = R"(
13-
<root main_tree_to_execute = "MainTree" >
13+
<root BTCPP_format="4" >
1414
<BehaviorTree ID="MainTree">
1515
<Repeat num_cycles="3">
1616
<ManualSelector repeat_last_selection="0">

examples/ex04_waypoints.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class UseWaypoint : public ThreadedAction
126126
// clang-format off
127127

128128
static const char* xml_implicit = R"(
129-
<root main_tree_to_execute = "TreeImplicit" >
129+
<root BTCPP_format="4" >
130130
<BehaviorTree ID="TreeImplicit">
131131
<Sequence>
132132
<GenerateWaypoints waypoints="{waypoints}" />
@@ -140,7 +140,7 @@ static const char* xml_implicit = R"(
140140

141141

142142
static const char* xml_A = R"(
143-
<root main_tree_to_execute = "TreeA" >
143+
<root BTCPP_format="4" >
144144
<BehaviorTree ID="TreeA">
145145
<Sequence>
146146
<GenerateWaypoints waypoints="{waypoints}" />
@@ -157,7 +157,7 @@ static const char* xml_A = R"(
157157
)";
158158

159159
static const char* xml_B = R"(
160-
<root main_tree_to_execute = "TreeB" >
160+
<root BTCPP_format="4" >
161161
<BehaviorTree ID="TreeB">
162162
<Sequence>
163163
<GenerateWaypoints waypoints="{waypoints}" />

examples/t01_build_your_first_tree.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ using namespace BT;
2020
// clang-format off
2121
static const char* xml_text = R"(
2222
23-
<root main_tree_to_execute = "MainTree" >
23+
<root BTCPP_format="4" >
2424
2525
<BehaviorTree ID="MainTree">
2626
<Sequence name="root_sequence">
@@ -73,11 +73,13 @@ int main()
7373
// it automated the registering step.
7474
factory.registerFromPlugin("./libdummy_nodes_dyn.so");
7575
#endif
76+
// register the XML description
77+
factory.registerBehaviorTreeFromText(xml_text);
7678

7779
// Trees are created at deployment-time (i.e. at run-time, but only once at the beginning).
7880
// The currently supported format is XML.
7981
// IMPORTANT: when the object "tree" goes out of scope, all the TreeNodes are destroyed
80-
auto tree = factory.createTreeFromText(xml_text);
82+
auto tree = factory.createTree("MainTree");
8183

8284
// To "execute" a Tree you need to "tick" it.
8385
// The tick is propagated to the children based on the logic of the tree.

examples/t02_basic_ports.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace BT;
2828
// clang-format off
2929
static const char* xml_text = R"(
3030
31-
<root main_tree_to_execute = "MainTree" >
31+
<root BTCPP_format="4" >
3232
3333
<BehaviorTree ID="MainTree">
3434
<Sequence name="root">

examples/t03_generic_ports.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PrintTarget : public SyncActionNode
9393
* 2) Call PrintTarget. The input "target" will be read from the Blackboard
9494
* entry "GoalPosition".
9595
*
96-
* 3) Use the built-in action SetBlackboard to write the key "OtherGoal".
96+
* 3) Use the built-in action Script to write the key "OtherGoal".
9797
* A conversion from string to Position2D will be done under the hood.
9898
*
9999
* 4) Call PrintTarget. The input "goal" will be read from the Blackboard
@@ -103,7 +103,7 @@ class PrintTarget : public SyncActionNode
103103
// clang-format off
104104
static const char* xml_text = R"(
105105
106-
<root main_tree_to_execute = "MainTree" >
106+
<root BTCPP_format="4" >
107107
<BehaviorTree ID="MainTree">
108108
<Sequence name="root">
109109
<CalculateGoal goal="{GoalPosition}" />
@@ -126,6 +126,7 @@ int main()
126126
factory.registerNodeType<PrintTarget>("PrintTarget");
127127

128128
auto tree = factory.createTreeFromText(xml_text);
129+
129130
tree.tickWhileRunning();
130131

131132
/* Expected output:

examples/t04_reactive_sequence.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using namespace BT;
1616

1717
static const char* xml_text_sequence = R"(
1818
19-
<root main_tree_to_execute = "MainTree" >
19+
<root BTCPP_format="4" >
2020
2121
<BehaviorTree ID="MainTree">
2222
<Sequence name="root">
@@ -32,7 +32,7 @@ static const char* xml_text_sequence = R"(
3232

3333
static const char* xml_text_reactive = R"(
3434
35-
<root main_tree_to_execute = "MainTree" >
35+
<root BTCPP_format="4" >
3636
3737
<BehaviorTree ID="MainTree">
3838
<ReactiveSequence name="root">
@@ -55,6 +55,7 @@ using namespace DummyNodes;
5555
int main()
5656
{
5757
BehaviorTreeFactory factory;
58+
5859
factory.registerSimpleCondition("BatteryOK", std::bind(CheckBattery));
5960
factory.registerNodeType<MoveBaseAction>("MoveBase");
6061
factory.registerNodeType<SaySomething>("SaySomething");

examples/t05_crossdoor.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// clang-format off
1111

1212
static const char* xml_text = R"(
13-
<root main_tree_to_execute = "MainTree">
13+
<root BTCPP_format="4">
1414
1515
<BehaviorTree ID="MainTree">
1616
<Sequence>
@@ -46,8 +46,12 @@ int main()
4646
CrossDoor cross_door;
4747
cross_door.registerNodes(factory);
4848

49-
// Load from text or file...
50-
auto tree = factory.createTreeFromText(xml_text);
49+
// In this example a single XML contains multiple tags <BehaviorTree>
50+
// To determine which one is the "main one", we should first register
51+
// the XML and then allocate a specific tree, using its ID
52+
53+
factory.registerBehaviorTreeFromText(xml_text);
54+
auto tree = factory.createTree("MainTree");
5155

5256
// helper function to print the tree
5357
BT::printTreeRecursively(tree.rootNode());

examples/t06_subtree_port_remapping.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
// clang-format off
2222

2323
static const char* xml_text = R"(
24-
<root main_tree_to_execute = "MainTree">
24+
<root BTCPP_format="4">
2525
2626
<BehaviorTree ID="MainTree">
2727
<Sequence>
28-
<Script script=" move_goal='1;2;3' " />
28+
<Script code=" move_goal='1;2;3' " />
2929
<SubTree ID="MoveRobot" target="{move_goal}" result="{move_result}" />
3030
<SaySomething message="{move_result}"/>
3131
</Sequence>
@@ -35,10 +35,10 @@ static const char* xml_text = R"(
3535
<Fallback>
3636
<Sequence>
3737
<MoveBase goal="{target}"/>
38-
<Script script=" result:='goal reached' " />
38+
<Script code=" result:='goal reached' " />
3939
</Sequence>
4040
<ForceFailure>
41-
<Script script=" result:='error' " />
41+
<Script code=" result:='error' " />
4242
</ForceFailure>
4343
</Fallback>
4444
</BehaviorTree>
@@ -58,7 +58,8 @@ int main()
5858
factory.registerNodeType<SaySomething>("SaySomething");
5959
factory.registerNodeType<MoveBaseAction>("MoveBase");
6060

61-
auto tree = factory.createTreeFromText(xml_text);
61+
factory.registerBehaviorTreeFromText(xml_text);
62+
auto tree = factory.createTree("MainTree");
6263

6364
tree.tickWhileRunning();
6465

0 commit comments

Comments
 (0)