Skip to content

Commit e9f92f2

Browse files
committed
Objectathon Example Vector and String Handling
1 parent 515bc0f commit e9f92f2

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<root BTCPP_format="4" main_tree_to_execute="ErrorCheckVectorSize">
3+
<!--//////////-->
4+
<BehaviorTree
5+
ID="ErrorCheckVectorSize"
6+
_description="Assert that the input vector is the expected length, and if not show a UI error and return FAILURE"
7+
>
8+
<Control ID="Sequence">
9+
<Action
10+
ID="GetSizeOfVector"
11+
vector_in="{vector}"
12+
vector_size="{vector_size}"
13+
/>
14+
<Decorator
15+
ID="Precondition"
16+
else="SUCCESS"
17+
if="vector_size!=expected_vector_size"
18+
name="Error Check "
19+
>
20+
<Control ID="Sequence">
21+
<Action
22+
ID="LogMessage"
23+
log_level="error"
24+
message="'Vector size is wrong'"
25+
/>
26+
<Action ID="AlwaysFailure" />
27+
</Control>
28+
</Decorator>
29+
</Control>
30+
</BehaviorTree>
31+
<TreeNodesModel>
32+
<SubTree ID="ErrorCheckVectorSize">
33+
<MetadataFields>
34+
<Metadata runnable="false" />
35+
<Metadata subcategory="Vector Handling" />
36+
</MetadataFields>
37+
<inout_port name="expected_vector_size" default="1" type="int">
38+
The size the vector should be
39+
</inout_port>
40+
<inout_port name="vector" default="{vector}">
41+
The input vector that is to be checked for size.
42+
</inout_port>
43+
</SubTree>
44+
</TreeNodesModel>
45+
</root>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1) A robot may not injure a human being or, through inaction, allow a human being to come to harm;
2+
2) A robot must obey orders from a human, except when they conflict with the First Law; and
3+
3) A robot must protect its own existence, provided it doesn't conflict with the First or Second Law.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<root BTCPP_format="4" main_tree_to_execute="Vector and String Example">
3+
<BehaviorTree
4+
ID="Vector and String Example"
5+
_description="Showcases creating, inserting, replacing, and removing strings from a vector, as well as reading strings from file and publishing them to ROS."
6+
_favorite="false"
7+
>
8+
<Control ID="Sequence" name="TopLevelSequence">
9+
<Action ID="ResetVector" vector="{my_vector}" name="Create the Vector" />
10+
<Control ID="Sequence" name="Test Some Vector Operations">
11+
<Action
12+
ID="ReadTextFileAsString"
13+
string_file_contents="{string1}"
14+
text_filename="example_file.txt"
15+
/>
16+
<Action
17+
ID="PublishString"
18+
queue_size="1"
19+
use_best_effort="false"
20+
message="{string1}"
21+
topic="/ai_safety_announcement"
22+
/>
23+
<Action ID="LogMessage" message="{string1}" log_level="warn" />
24+
<Action
25+
ID="InsertInVector"
26+
element="{json:{&quot;__type&quot;:&quot;string&quot;,&quot;value&quot;:&quot;{string1}&quot;}"
27+
index="0"
28+
input_vector="{my_vector}"
29+
output_vector="{my_vector}"
30+
/>
31+
<SubTree
32+
ID="ErrorCheckVectorSize"
33+
_collapsed="true"
34+
expected_vector_size="1"
35+
vector="{my_vector}"
36+
/>
37+
</Control>
38+
<Control ID="Sequence" name="Test Some Vector Operations">
39+
<Action
40+
ID="RemoveFromVector"
41+
index="0"
42+
input_vector="{my_vector}"
43+
output_vector="{my_vector}"
44+
/>
45+
<SubTree
46+
ID="ErrorCheckVectorSize"
47+
_collapsed="true"
48+
expected_vector_size="0"
49+
vector="{my_vector}"
50+
/>
51+
</Control>
52+
<Control ID="Sequence" name="Test Some Vector Operations">
53+
<Action ID="Script" code="string2 := 'Do not be evil'" />
54+
<Action
55+
ID="InsertInVector"
56+
element="{json:{&quot;__type&quot;:&quot;string&quot;,&quot;value&quot;:&quot;{string2}&quot;}"
57+
index="0"
58+
input_vector="{my_vector}"
59+
output_vector="{my_vector}"
60+
/>
61+
<SubTree
62+
ID="ErrorCheckVectorSize"
63+
_collapsed="true"
64+
expected_vector_size="1"
65+
vector="{my_vector}"
66+
/>
67+
<Action ID="LogMessage" message="{string2}" log_level="warn" />
68+
</Control>
69+
<Control ID="Sequence" name="Test Some Vector Operations">
70+
<Action
71+
ID="Script"
72+
code="string3 := 'Comply with the laws of physics, unless you are in simulation.'"
73+
/>
74+
<Action
75+
ID="ReplaceInVector"
76+
element="{json:{&quot;__type&quot;:&quot;string&quot;,&quot;value&quot;:&quot;{string3}&quot;}"
77+
index="0"
78+
input_vector="{my_vector}"
79+
output_vector="{my_vector}"
80+
/>
81+
<SubTree
82+
ID="ErrorCheckVectorSize"
83+
_collapsed="true"
84+
expected_vector_size="1"
85+
vector="{my_vector}"
86+
/>
87+
<Action ID="LogMessage" message="{string3}" log_level="warn" />
88+
</Control>
89+
</Control>
90+
</BehaviorTree>
91+
<TreeNodesModel>
92+
<SubTree ID="Vector and String Example">
93+
<MetadataFields>
94+
<Metadata runnable="true" />
95+
<Metadata subcategory="Vector Handling" />
96+
</MetadataFields>
97+
</SubTree>
98+
</TreeNodesModel>
99+
</root>

0 commit comments

Comments
 (0)