3333
3434@ports (inputs = ["start" , "goal" ], outputs = ["command" ])
3535class 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):
7368factory .register (Print )
7469
7570tree = 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