Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Aug 8, 2022
1 parent 0173869 commit 37492aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions pioreactor_air_bubbler/additional_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
[air_bubbler]
# this should be tuned to produce modest bubbles
duty_cycle=10
hertz=200
22 changes: 12 additions & 10 deletions pioreactor_air_bubbler/air_bubbler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import time
from time import sleep, time
import click
from pioreactor.background_jobs.base import BackgroundJobContrib
from pioreactor.whoami import get_latest_experiment_name, get_unit_name
Expand All @@ -17,7 +17,7 @@ class AirBubbler(BackgroundJobContrib):
"duty_cycle": {"settable": True, "unit": "%", "datatype": "float"}
}

def __init__(self, duty_cycle, hertz=60, unit=None, experiment=None):
def __init__(self, duty_cycle: float, hertz: float=60, unit:str=None, experiment:str=None):
super(AirBubbler, self).__init__(
job_name="air_bubbler",
plugin_name="pioreactor_air_bubbler",
Expand Down Expand Up @@ -90,14 +90,14 @@ def turn_off_pump_between_readings(self, msg):
# pre_duration: duration between stopping the action and the next ADS reading
# we have a pretty large pre_duration, since the air pump can introduce microbubbles
# that we want to see dissipate.
post_duration, pre_duration = 0.6, 1.25
post_duration, pre_duration = 0.25, 2.0

def sneak_in():
if self.state != self.READY:
return

self.set_duty_cycle(config.getint("air_bubbler", "duty_cycle"))
time.sleep(ads_interval - (post_duration + pre_duration))
sleep(ads_interval - (post_duration + pre_duration))
self.set_duty_cycle(0)

# this could fail in the following way:
Expand All @@ -119,15 +119,15 @@ def sneak_in():
if ads_interval <= (post_duration + pre_duration):
# TODO: this should error out better. The thread errors, but the main program doesn't.
self.logger.error("Your samples_per_second is too high to add in a pump.")
self.set_state(self.DISCONNECTED)
self.clean_up()

self.sneak_in_timer = RepeatedTimer(ads_interval, sneak_in, run_immediately=False)

time_to_next_ads_reading = ads_interval - (
(time.time() - ads_start_time) % ads_interval
(time() - ads_start_time) % ads_interval
)

time.sleep(time_to_next_ads_reading + post_duration)
sleep(time_to_next_ads_reading + post_duration)
self.sneak_in_timer.start()


Expand All @@ -137,12 +137,14 @@ def click_air_bubbler():
turn on air bubbler
"""
if is_pio_job_running("od_reading"):
dc = 0
dc = 0.0
else:
dc = config.getint("air_bubbler", "duty_cycle")
dc = config.getfloat("air_bubbler", "duty_cycle")

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

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

ab.block_until_disconnected()
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ editable_settings:
- key: duty_cycle
unit: "%"
label: Bubbler intensity
description: Modify the intensity of the air bubbler. Value between 0 (off) and 100 (too high).
description: Modify the intensity of the air bubbler. Value between 0 (off) and 100 (high).
type: numeric
default: null
display: true

0 comments on commit 37492aa

Please sign in to comment.