Skip to content

Commit

Permalink
if stirring is paused, measure rpm should be 0
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 29, 2024
1 parent 351adfd commit 587e3d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pioreactor/background_jobs/stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def __init__(
)

def action_to_do_before_od_reading(self):
self.set_duty_cycle(0)
self.stop_stirring()

def action_to_do_after_od_reading(self):
self.start_stirring()
Expand Down Expand Up @@ -359,6 +359,12 @@ def start_stirring(self) -> None:
if self.rpm_calculator is not None:
self.rpm_check_repeated_thread.start() # .start is idempotent

def stop_stirring(self) -> None:
self.set_duty_cycle(0) # get momentum to start
if self.rpm_calculator is not None:
self.measured_rpm = structs.MeasuredRPM(timestamp=current_utc_datetime(), measured_rpm=0)
self.rpm_check_repeated_thread.pause() # .start is idempotent

def kick_stirring(self) -> None:
self.logger.debug("Kicking stirring")
self.set_duty_cycle(0)
Expand Down Expand Up @@ -433,8 +439,7 @@ def poll_and_update_dc(self, poll_for_seconds: Optional[float] = None) -> None:
self.set_duty_cycle(self._estimate_duty_cycle)

def on_ready_to_sleeping(self) -> None:
self.rpm_check_repeated_thread.pause()
self.set_duty_cycle(0.0)
self.stop_stirring()

def on_sleeping_to_ready(self) -> None:
super().on_sleeping_to_ready()
Expand Down
11 changes: 11 additions & 0 deletions pioreactor/tests/test_stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def test_publish_measured_rpm() -> None:
assert message is not None
assert json.loads(message.payload)["measured_rpm"] == 0

publish(f"pioreactor/{unit}/{exp}/stirring/$state/set", "sleeping")
pause()
pause()
pause()
assert st.state == st.SLEEPING
assert st.duty_cycle == 0
assert st.measured_rpm.measured_rpm == 0
message = subscribe(f"pioreactor/{unit}/{exp}/stirring/measured_rpm", timeout=3)
assert message is not None
assert json.loads(message.payload)["measured_rpm"] == 0


def test_rpm_isnt_updated_if_there_is_no_rpm_measurement() -> None:
exp = "test_publish_measured_rpm"
Expand Down

0 comments on commit 587e3d7

Please sign in to comment.