Skip to content

Commit 04f435d

Browse files
committed
Add halt_tree binding and use in demo
1 parent 535ea88 commit 04f435d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: python_examples/ex06_async_nodes.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333

3434
@ports(inputs=["start", "goal"], outputs=["command"])
3535
class MyAsyncNode(AsyncActionNode):
36-
def __init__(self, name, config):
37-
super().__init__(name, config)
38-
self.halted = False
39-
4036
def run(self):
4137
start = np.asarray(self.get_input("start"))
4238
goal = np.asarray(self.get_input("goal"))
@@ -46,7 +42,7 @@ def run(self):
4642
# caller until the next iteration of the tree, rather than block the
4743
# main thread.
4844
t0 = time.time()
49-
while (t := time.time() - t0) < 1.0 and not self.halted:
45+
while (t := time.time() - t0) < 1.0:
5046
command = (1.0 - t) * start + t * goal
5147
self.set_output("command", command)
5248
yield
@@ -55,8 +51,7 @@ def run(self):
5551
return NodeStatus.SUCCESS
5652

5753
def on_halted(self):
58-
# This will be picked up in the main iteration above.
59-
self.halted = True
54+
print("Trajectory halted!")
6055

6156

6257
@ports(inputs=["value"])
@@ -73,4 +68,8 @@ def tick(self):
7368
factory.register(Print)
7469

7570
tree = factory.create_tree_from_text(xml_text)
76-
tree.tick_while_running()
71+
72+
# Run for a bit, then halt early.
73+
for i in range(0, 10):
74+
tree.tick_once()
75+
tree.halt_tree()

Diff for: src/python/bindings.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ PYBIND11_MODULE(btpy_cpp, m)
169169
.def("tick_once", &Tree::tickOnce)
170170
.def("tick_exactly_once", &Tree::tickExactlyOnce)
171171
.def("tick_while_running", &Tree::tickWhileRunning,
172-
py::arg("sleep_time") = std::chrono::milliseconds(10));
172+
py::arg("sleep_time") = std::chrono::milliseconds(10))
173+
.def("halt_tree", &Tree::haltTree);
173174

174175
py::enum_<NodeStatus>(m, "NodeStatus")
175176
.value("IDLE", NodeStatus::IDLE)

0 commit comments

Comments
 (0)