diff --git a/beams/tree_config.py b/beams/tree_config.py index 7d371cd..427dbe4 100644 --- a/beams/tree_config.py +++ b/beams/tree_config.py @@ -171,36 +171,37 @@ def work_func(myself, comp_condition: Callable[[Any], bool], volatile_status: VolatileStatus, wait_for_tick: Event()): - py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} " - f"from node: {self.name}") - wait_for_tick.wait() - - # Set to running - value = 0 - - # While termination_check is not True - 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) - + while myself.do_work.value: + py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} " + f"from node: {self.name}") + wait_for_tick.wait() + + # Set to running + value = 0 + + # While termination_check is not True + 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 comp_condition(): + volatile_status.set_value(py_trees.common.Status.SUCCESS) + py_trees.console.logdebug( + f"{self.name}: Value is {value}, BT Status: " + f"{volatile_status.get_value()}" + ) + + # specific caput logic to SetPVActionItem + caput(self.pv, self.value) + time.sleep(self.loop_period_sec) + + # one last check 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"{volatile_status.get_value()}" - ) - - # specific caput logic to SetPVActionItem - caput(self.pv, self.value) - time.sleep(self.loop_period_sec) - - # one last check - if comp_condition(): - volatile_status.set_value(py_trees.common.Status.SUCCESS) - else: - volatile_status.set_value(py_trees.common.Status.FAILURE) + else: + volatile_status.set_value(py_trees.common.Status.FAILURE) comp_cond = self.termination_check.get_condition_function() @@ -226,36 +227,37 @@ def work_func(myself, comp_condition: Callable[[Any], bool], volatile_status: VolatileStatus, wait_for_tick: Event()): - py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} " - f"from node: {self.name}") - wait_for_tick.wait() - - # Set to running - value = 0 - - # While termination_check is not True - 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.pv) - + while myself.do_work.value: + py_trees.console.logdebug(f"WAITING FOR INIT {os.getpid()} " + f"from node: {self.name}") + wait_for_tick.wait() + + # Set to running + value = 0 + + # While termination_check is not True + 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.pv) + + 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"{volatile_status.get_value()}" + ) + + # specific caput logic to IncPVActionItem + caput(self.pv, value + self.increment) + time.sleep(self.loop_period_sec) + + # one last check 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"{volatile_status.get_value()}" - ) - - # specific caput logic to IncPVActionItem - caput(self.pv, value + self.increment) - time.sleep(self.loop_period_sec) - - # one last check - if comp_condition(): - volatile_status.set_value(py_trees.common.Status.SUCCESS) - else: - volatile_status.set_value(py_trees.common.Status.FAILURE) + else: + volatile_status.set_value(py_trees.common.Status.FAILURE) comp_cond = self.termination_check.get_condition_function()