File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 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
+
36
40
def run (self ):
37
41
start = np .asarray (self .get_input ("start" ))
38
42
goal = np .asarray (self .get_input ("goal" ))
39
43
44
+ # Here we write an imperative-looking loop, but we place a `yield` call
45
+ # at each iteration. This causes the coroutine to yield back to the
46
+ # caller until the next iteration of the tree, rather than block the
47
+ # main thread.
40
48
t0 = time .time ()
41
- while (t := time .time () - t0 ) < 1.0 :
49
+ while (t := time .time () - t0 ) < 1.0 and not self . halted :
42
50
command = (1.0 - t ) * start + t * goal
43
51
self .set_output ("command" , command )
44
52
yield
@@ -47,7 +55,8 @@ def run(self):
47
55
return NodeStatus .SUCCESS
48
56
49
57
def on_halted (self ):
50
- print ("Aborted" )
58
+ # This will be picked up in the main iteration above.
59
+ self .halted = True
51
60
52
61
53
62
@ports (inputs = ["value" ])
You can’t perform that action at this time.
0 commit comments