33
33
34
34
@ports (inputs = ["start" , "goal" ], outputs = ["command" ])
35
35
class MyAsyncNode (AsyncActionNode ):
36
- def __init__ (self , name , config ):
37
- super ().__init__ (name , config )
38
- self .halted = False
39
-
40
36
def run (self ):
41
37
start = np .asarray (self .get_input ("start" ))
42
38
goal = np .asarray (self .get_input ("goal" ))
@@ -46,7 +42,7 @@ def run(self):
46
42
# caller until the next iteration of the tree, rather than block the
47
43
# main thread.
48
44
t0 = time .time ()
49
- while (t := time .time () - t0 ) < 1.0 and not self . halted :
45
+ while (t := time .time () - t0 ) < 1.0 :
50
46
command = (1.0 - t ) * start + t * goal
51
47
self .set_output ("command" , command )
52
48
yield
@@ -55,8 +51,7 @@ def run(self):
55
51
return NodeStatus .SUCCESS
56
52
57
53
def on_halted (self ):
58
- # This will be picked up in the main iteration above.
59
- self .halted = True
54
+ print ("Trajectory halted!" )
60
55
61
56
62
57
@ports (inputs = ["value" ])
@@ -73,4 +68,8 @@ def tick(self):
73
68
factory .register (Print )
74
69
75
70
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 ()
0 commit comments