diff --git a/beams/behavior_tree/ActionNode.py b/beams/behavior_tree/ActionNode.py index 4848db0..eebe5a9 100644 --- a/beams/behavior_tree/ActionNode.py +++ b/beams/behavior_tree/ActionNode.py @@ -44,7 +44,6 @@ def setup(self, **kwargs: int) -> None: ) # Having this in setup means the workthread should always be running. - print("LAUNCHING JAWN") self.worker.start_work() atexit.register( self.worker.stop_work diff --git a/beams/behavior_tree/ActionWorker.py b/beams/behavior_tree/ActionWorker.py index 444ea33..ab73cf2 100644 --- a/beams/behavior_tree/ActionWorker.py +++ b/beams/behavior_tree/ActionWorker.py @@ -1,3 +1,6 @@ +""" +A worker specialized to execute ActionNode work functions +""" from typing import Callable, Any, Optional from epics.multiproc import CAProcess @@ -18,6 +21,5 @@ def __init__(self, work_func=work_func, proc_type=CAProcess, add_args=(comp_cond, volatile_status)) - print(f"YO SELF: {self}") self.comp_condition = comp_cond self.__volatile_status__ = volatile_status diff --git a/beams/behavior_tree/CheckAndDo.py b/beams/behavior_tree/CheckAndDo.py index c43f32e..19058de 100644 --- a/beams/behavior_tree/CheckAndDo.py +++ b/beams/behavior_tree/CheckAndDo.py @@ -5,7 +5,7 @@ class CheckAndDo(py_trees.composites.Selector): def __init__(self, name: str, check: ConditionNode, do: ActionNode) -> None: - super().__init__(name, memory=True) + super().__init__(name, memory=False) self.name = name self.check = check self.do = do diff --git a/beams/sequencer/helpers/Worker.py b/beams/sequencer/helpers/Worker.py index a17d939..dec88e3 100644 --- a/beams/sequencer/helpers/Worker.py +++ b/beams/sequencer/helpers/Worker.py @@ -37,12 +37,9 @@ def start_work(self): logging.error("Already working, not starting work") return self.do_work.value = True - print("JEEZY") print(self.work_func) - # breakpoint() self.work_proc.start() logging.debug(f"Starting work on: {self.work_proc.pid}") - print(f"Starting work on: {self.work_proc.pid}") def stop_work(self): logging.info(f"Calling stop work on: {self.work_proc.pid}") @@ -50,6 +47,9 @@ def stop_work(self): logging.error("Not working, not stopping work") return self.do_work.value = False + logging.info(f"Sending terminate signal to{self.work_proc.pid}") + # Send kill signal to work process. # TODO: the exact location of this is important. Reflect + self.work_proc.terminate() if (self.stop_func is not None): self.stop_func() diff --git a/beams/tests/artifacts/eggs.json b/beams/tests/artifacts/eggs.json index 573d1c8..03d0c2c 100644 --- a/beams/tests/artifacts/eggs.json +++ b/beams/tests/artifacts/eggs.json @@ -4,7 +4,7 @@ "name": "self_test", "description": "", "check": { - "name": "", + "name": "self_test_check", "description": "", "pv": "PERC:COMP", "value": 100, @@ -12,9 +12,9 @@ }, "do": { "IncPVActionItem": { - "name": "", + "name": "self_test_do", "description": "", - "loop_period_sec": 1.0, + "loop_period_sec": 0.01, "pv": "PERC:COMP", "increment": 10, "termination_check": { diff --git a/beams/tests/artifacts/eggs2.json b/beams/tests/artifacts/eggs2.json index 1ec0fd7..2bcba87 100644 --- a/beams/tests/artifacts/eggs2.json +++ b/beams/tests/artifacts/eggs2.json @@ -10,7 +10,7 @@ "name": "ret_find", "description": "", "check": { - "name": "", + "name": "ret_find_check", "description": "", "pv": "RET:FOUND", "value": 1, @@ -18,9 +18,9 @@ }, "do": { "SetPVActionItem": { - "name": "", + "name": "ret_find_do", "description": "", - "loop_period_sec": 1.0, + "loop_period_sec": 0.01, "pv": "RET:FOUND", "value": 1, "termination_check": { diff --git a/beams/tests/test_leaf_node.py b/beams/tests/test_leaf_node.py index f4172a5..ec20a76 100644 --- a/beams/tests/test_leaf_node.py +++ b/beams/tests/test_leaf_node.py @@ -6,8 +6,6 @@ from beams.behavior_tree.ActionNode import ActionNode from beams.behavior_tree.ConditionNode import ConditionNode -import pytest - class TestTask: def test_action_node(self, capsys): diff --git a/beams/tests/test_tree_generator.py b/beams/tests/test_tree_generator.py index 06ebf65..6009f18 100644 --- a/beams/tests/test_tree_generator.py +++ b/beams/tests/test_tree_generator.py @@ -33,8 +33,9 @@ def test_tree_obj_execution(request): tree.root.status not in (py_trees.common.Status.SUCCESS, py_trees.common.Status.FAILURE) ): - tree.tick() - time.sleep(0.05) + for n in tree.root.tick(): + print(n) + time.sleep(0.05) rel_val = caget("PERC:COMP") assert rel_val >= 100 @@ -56,10 +57,11 @@ def test_father_tree_execution(request): py_trees.common.Status.FAILURE) and ct < 50 ): - ct += 1 - print((tree.root.status, tree.root.status, ct)) - tree.tick() - time.sleep(0.05) + for n in tree.root.tick(): + ct += 1 + print(n) + print((tree.root.status, tree.root.status, ct)) + time.sleep(0.05) check_insert = caget("RET:INSERT") diff --git a/beams/tree_config.py b/beams/tree_config.py index d48d128..d2a506b 100644 --- a/beams/tree_config.py +++ b/beams/tree_config.py @@ -177,7 +177,7 @@ def get_tree(self) -> ActionNode: wait_for_tick = Event() wait_for_tick_lock = Lock() - def work_func(self): + def work_func(myself, comp_condition, volatile_status): py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} " f"from node: {self.name}") wait_for_tick.wait() @@ -186,18 +186,18 @@ def work_func(self): value = 0 # While termination_check is not True - while not self.comp_condition(): # TODO check work_gate.is_set() + while not comp_condition(): # TODO check work_gate.is_set() py_trees.console.logdebug( f"CALLING CAGET FROM {os.getpid()} from node: " f"{self.name}" ) value = caget(self.termination_check.pv) - if self.comp_condition(): - self.volatile_status.set_value(py_trees.common.Status.SUCCESS) + if comp_condition(): + volatile_status.set_value(py_trees.common.Status.SUCCESS) py_trees.console.logdebug( f"{self.name}: Value is {value}, BT Status: " - f"{self.volatile_status.get_value()}" + f"{volatile_status.get_value()}" ) # specific caput logic to SetPVActionItem @@ -205,10 +205,10 @@ def work_func(self): time.sleep(self.loop_period_sec) # one last check - if self.comp_condition(): - self.volatile_status.set_value(py_trees.common.Status.SUCCESS) + if comp_condition(): + volatile_status.set_value(py_trees.common.Status.SUCCESS) else: - self.volatile_status.set_value(py_trees.common.Status.FAILURE) + volatile_status.set_value(py_trees.common.Status.FAILURE) comp_cond = self.termination_check.get_condition_function() @@ -235,7 +235,7 @@ def get_tree(self) -> ActionNode: wait_for_tick = Event() wait_for_tick_lock = Lock() - def work_func(comp_condition, volatile_status): + def work_func(myself, comp_condition, volatile_status): py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} " f"from node: {self.name}") wait_for_tick.wait()