Skip to content

Commit

Permalink
refactor to expose duty_cycle as the ON duty_cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Aug 26, 2022
1 parent c55fbae commit 3bcc2fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pioreactor_air_bubbler/additional_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
duty_cycle=10 # this should be tuned to produce modest bubbles
hertz=200
pre_delay_duration=1.5
post_delay_duration=0.1
post_delay_duration=0.75
enable_dodging_od=1
18 changes: 6 additions & 12 deletions pioreactor_air_bubbler/air_bubbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class AirBubbler(BackgroundJobWithDodgingContrib):
published_settings = {
"duty_cycle": {"settable": False, "unit": "%", "datatype": "float"}
}
_previous_duty_cycle = 0.0

def __init__(self, duty_cycle: float, hertz: float=60, unit:str=None, experiment:str=None):
super(AirBubbler, self).__init__(
Expand All @@ -32,11 +31,11 @@ def __init__(self, duty_cycle: float, hertz: float=60, unit:str=None, experiment
"Unable to find `air_bubbler` under PWM section in the config.ini"
)


self.duty_cycle = duty_cycle
self.pwm = PWM(self.pin, self.hertz)
self.pwm.start(0)

self.set_duty_cycle(duty_cycle)

def on_disconnected(self):
self.stop_pumping()
self.pwm.stop()
Expand All @@ -45,17 +44,15 @@ def on_disconnected(self):
def stop_pumping(self):
if hasattr(self, "pwm"):
# if the user unpauses, we want to go back to their previous value, and not the default.
self._previous_duty_cycle = self.duty_cycle
self.set_duty_cycle(0)
self.pwm.change_duty_cycle(0)

def start_pumping(self):
self.set_duty_cycle(self._previous_duty_cycle)
self.pwm.change_duty_cycle(self.duty_cycle)

def on_sleeping(self):
self.stop_pumping()

def on_sleeping_to_ready(self) -> None:
self.duty_cycle = self._previous_duty_cycle
self.start_pumping()

def set_duty_cycle(self, value):
Expand All @@ -74,15 +71,12 @@ def click_air_bubbler():
"""
turn on air bubbler
"""
if is_pio_job_running("od_reading"):
dc = 0.0
else:
dc = config.getfloat("air_bubbler", "duty_cycle")

dc = config.getfloat("air_bubbler", "duty_cycle")
hertz = config.getfloat("air_bubbler", "hertz")

ab = AirBubbler(
duty_cycle=dc, hertz=hertz, unit=get_unit_name(), experiment=get_latest_experiment_name()
)

ab.start_pumping()
ab.block_until_disconnected()

0 comments on commit 3bcc2fd

Please sign in to comment.