Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Feb 20, 2025
1 parent 8529a1d commit 0f3f85a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- experiment profiles don't overwrite each other in mqtt, but at a cost!
- `led_intensity` is now registered in our database, so `pio kill --all-jobs` (and related `pio kill` commands) now disables LEDs too.
- Fix API not providing the correct web response for huey-related tasks (like adding a new pioreactor, syncing configs, updating, etc.)
- there was a scaling error in the `od_reading.config`'s `smoothing_penalizer`. This has been fixed, and your config.ini has been updated (it will look much smaller). This is in support of our new firmware, too.

### 25.2.11

Expand Down
7 changes: 6 additions & 1 deletion pioreactor/actions/led_intensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ def led_intensity(
retain=True,
)

# this is a hack to deal with there _not_ being a process that controls LEDs when run from the command line with `pio run` (tip: maybe that changes...)
# If `pio run led_intensity` is run, it's given a unique pid. This pid won't exist in the DB, so
# we register it with the job manager. Later, when we run `pio kill x`, we run `pio run led_intensity --A 0..` in LEDKill(), which trips the second condition, so we don't
# end up re-adding it.
# if something like OD reading starts led_intesity, it's pid exists, so we don't register it.
with JobManager() as jm:
if jm.does_pid_exist(os.getpid()) or new_state == {"A": 0, "B": 0, "C": 0, "D": 0}:
# part of a larger job, or turning off LEDs.
# part of a larger job, or turning off LEDs as part of LEDKill()
pass
else:
jm.register_and_set_running(
Expand Down
8 changes: 4 additions & 4 deletions pioreactor/background_jobs/od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
fake_data: bool = False,
dynamic_gain: bool = True,
penalizer: float = 0.0, # smoothing parameter between samples
oversampling_count: int = 42,
oversampling_count: int = 40,
) -> None:
super().__init__()
self.fake_data = fake_data
Expand Down Expand Up @@ -454,7 +454,7 @@ def take_reading(self) -> PdChannelToVoltage:
prior_C=(self.adc.from_voltage_to_raw_precise(self.batched_readings[channel]))
if (channel in self.batched_readings)
else None,
penalizer_C=(self.penalizer / self.oversampling_count),
penalizer_C=(self.penalizer * oversampling_count),
)

# convert to voltage
Expand Down Expand Up @@ -695,13 +695,13 @@ def calibration(observed_voltage: pt.Voltage) -> pt.OD:
raise exc.NoSolutionsFoundError
except exc.SolutionBelowDomainError:
self.logger.warning(
f"Signal outside suggested calibration range. Trimming signal. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V."
f"Signal below suggested calibration range. Trimming signal. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V."
)
self.has_logged_warning = True
return min_OD
except exc.SolutionAboveDomainError:
self.logger.warning(
f"Signal outside suggested calibration range. Trimming signal. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V."
f"Signal above suggested calibration range. Trimming signal. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V."
)
self.has_logged_warning = True
return max_OD
Expand Down
18 changes: 18 additions & 0 deletions update_scripts/upcoming/huey.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Huey service for PioreactorUI
After=network.target firstboot.service
Before=lighttpd.service


[Service]
EnvironmentFile=/etc/environment
User=pioreactor
WorkingDirectory=/var/www/pioreactorui
ExecStart=huey_consumer pioreactorui.tasks.huey -n -b 1.001 -w 10 -f -C -d 0.05
ExecStartPost=pio log -m "%n successful" -n systemd --local-only
StandardOutput=null
StandardError=null
Restart=always

[Install]
WantedBy=multi-user.target
15 changes: 14 additions & 1 deletion update_scripts/upcoming/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -xeu

export LC_ALL=C

calc(){ awk "BEGIN { print $*}"; }

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LEADER_HOSTNAME=$(crudini --get /home/pioreactor/.pioreactor/config.ini cluster.topology leader_hostname)

Expand All @@ -13,9 +15,20 @@ if [ "$HOSTNAME" = "$LEADER_HOSTNAME" ]; then

crudini --set /home/pioreactor/.pioreactor/config.ini ui.overview.cards profiles 1

OLD_SP=$(crudini --get /home/pioreactor/.pioreactor/config.ini od_reading.config smoothing_penalizer)
crudini --set /home/pioreactor/.pioreactor/config.ini od_reading.config smoothing_penalizer $(calc $OLD_SP/32/40)
pios sync-configs --shared

fi

# update firmware to 0.4
sudo cp "$SCRIPT_DIR"/main.elf /usr/local/bin/main.elf
MAIN_ELF="/usr/local/bin/main.elf"
sudo cp "$SCRIPT_DIR"/main.elf $MAIN_ELF
sudo systemctl restart load_rp2040.service || :
echo "Added new main.elf firmware."


# new huey
HUEY_SERVICE_FILE="/etc/systemd/system/huey.service"
sudo cp "$SCRIPT_DIR"/huey.service $HUEY_SERVICE_FILE
echo "Added new huey.service."

0 comments on commit 0f3f85a

Please sign in to comment.