Skip to content

Commit

Permalink
adding an event so we can exit early if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Dec 5, 2024
1 parent 73bb568 commit 94d3a65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions config.dev.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use_rpm=True
duration_between_updates_seconds=23
post_delay_duration=0.25
pre_delay_duration=2.0
enable_dodging_od=False
enable_dodging_od=True


[stirring.pid]
Expand All @@ -54,7 +54,7 @@ Kd=0.0

[od_reading.config]
# how many samples should the ADC publish per second?
samples_per_second=0.2
samples_per_second=0.03

pd_reference_ema=0.4

Expand Down
10 changes: 9 additions & 1 deletion pioreactor/background_jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ def __init__(self, *args, source="app", **kwargs) -> None:
) # placeholder?
self.add_to_published_settings("enable_dodging_od", {"datatype": "boolean", "settable": True})
self.add_to_published_settings("currently_dodging_od", {"datatype": "boolean", "settable": False})
self._event_is_dodging_od = threading.Event()

def __post__init__(self):
self.set_enable_dodging_od(
Expand All @@ -1063,11 +1064,13 @@ def __post__init__(self):
def set_currently_dodging_od(self, value: bool):
self.currently_dodging_od = value
if self.currently_dodging_od:
self._event_is_dodging_od.clear()
self.initialize_dodging_operation() # user defined
self._action_to_do_before_od_reading = self.action_to_do_before_od_reading
self._action_to_do_after_od_reading = self.action_to_do_after_od_reading
self._setup_timer()
else:
self._event_is_dodging_od.set()
self.initialize_continuous_operation() # user defined
self._action_to_do_before_od_reading = _noop
self._action_to_do_after_od_reading = _noop
Expand Down Expand Up @@ -1135,7 +1138,12 @@ def sneak_in(ads_interval: float, post_delay: float, pre_delay: float) -> None:
"samples_per_second is too high, or post_delay is too high, or pre_delay is too high, or action_to_do_after_od_reading takes too long."
)

sleep(ads_interval - self.OD_READING_DURATION - (post_delay + pre_delay) - action_after_duration)
if self.state != self.READY:
return

self._event_is_dodging_od.wait(
ads_interval - self.OD_READING_DURATION - (post_delay + pre_delay) - action_after_duration
)

if self.state != self.READY:
return
Expand Down

0 comments on commit 94d3a65

Please sign in to comment.