diff --git a/CHANGELOG.md b/CHANGELOG.md index d1ffd4dd..56287ea0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - fix `pio workers update-active` using the wrong HTTP verb. - When the local access point would start on a fresh boot, the SSID would start as `pioreactor`, and then change to `pioreactor-` after the next reboot. Now, this will now always be `pioreactor-`. - Fix using ethernet cable to connect Pioreactor to a router: a new simple ethernet nmconnection has been added, and has higher connection priority than the PioreactorLocalLink nmconnection. + - Fix race conditions between stirring and growth-rate. ### 24.5.13 diff --git a/pioreactor/actions/self_test.py b/pioreactor/actions/self_test.py index f22c6ccb..df237227 100644 --- a/pioreactor/actions/self_test.py +++ b/pioreactor/actions/self_test.py @@ -136,7 +136,7 @@ def test_all_positive_correlations_between_pds_and_leds( adc_reader = ADCReader( channels=ALL_PD_CHANNELS, dynamic_gain=False, fake_data=is_testing_env(), penalizer=0.0 ) - adc_reader.setup_adc() + adc_reader.tune_adc() ir_led_channel = cast(LedChannel, config["leds_reverse"][IR_keyword]) @@ -240,7 +240,7 @@ def test_ambient_light_interference(client: Client, logger: CustomLogger, unit: fake_data=is_testing_env(), ) - adc_reader.setup_adc() + adc_reader.tune_adc() led_intensity( {channel: 0 for channel in ALL_LED_CHANNELS}, unit=unit, @@ -273,7 +273,7 @@ def test_REF_is_lower_than_0_dot_256_volts( adc_reader = ADCReader( channels=[reference_channel], dynamic_gain=False, fake_data=is_testing_env(), penalizer=0.0 ) - adc_reader.setup_adc() + adc_reader.tune_adc() with change_leds_intensities_temporarily( {ir_channel: ir_intensity}, diff --git a/pioreactor/background_jobs/growth_rate_calculating.py b/pioreactor/background_jobs/growth_rate_calculating.py index 3757295b..262dd2bc 100644 --- a/pioreactor/background_jobs/growth_rate_calculating.py +++ b/pioreactor/background_jobs/growth_rate_calculating.py @@ -40,6 +40,7 @@ from datetime import datetime from json import dumps from json import loads +from time import sleep from typing import Generator import click @@ -243,6 +244,8 @@ def create_obs_noise_covariance(self, obs_std): # type: ignore def _compute_and_cache_od_statistics( self, ) -> tuple[dict[pt.PdChannel, float], dict[pt.PdChannel, float]]: + # why sleep? Users sometimes spam jobs, and if stirring and gr start closely there can be a race to secure HALL_SENSOR. This gives stirring priority. + sleep(5) means, variances = od_statistics( self._yield_od_readings_from_mqtt(), action_name="od_normalization", diff --git a/pioreactor/background_jobs/od_reading.py b/pioreactor/background_jobs/od_reading.py index 42862ab9..cd67a43b 100644 --- a/pioreactor/background_jobs/od_reading.py +++ b/pioreactor/background_jobs/od_reading.py @@ -145,7 +145,7 @@ class ADCReader(LoggerMixin): from pioreactor.background_jobs.od_reading import ADCReader adc = ADCReader(["1", "2"], fake_data=False) - adc.setup_adc() + adc.tune_adc() while True: print(adc.take_reading()) @@ -179,7 +179,7 @@ def __init__( else: self.most_appropriate_AC_hz = None - def setup_adc(self) -> PdChannelToVoltage: + def tune_adc(self) -> PdChannelToVoltage: """ This configures the ADC for reading, performs an initial read, and sets variables based on that reading. @@ -425,7 +425,7 @@ def take_reading(self) -> PdChannelToVoltage: """ if not self._setup_complete: - raise ValueError("Must call setup_adc() first.") + raise ValueError("Must call tune_adc() first.") max_signal = -1.0 oversampling_count = self.oversampling_count @@ -906,7 +906,7 @@ def __init__( self.start_ir_led() sleep(0.10) - on_reading = self.adc_reader.setup_adc() # determine best gain, max-signal, etc. + on_reading = self.adc_reader.tune_adc() # determine best gain, max-signal, etc. # IR led is off so we can set blanks self.stop_ir_led()