Skip to content

Commit

Permalink
clean up config, try install lgpio elsehwer
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 7, 2024
1 parent 05193d3 commit 683077a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:

- name: Install
run: |
apt-get install python3-lgpio
pip install -e .
pip install -r requirements/requirements_dev.txt
pip install pyyaml
Expand Down
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
### Upcoming
- fixed a bug where stirring DC would jump up too high when RPM measured 0.

#### Enhancements
- Support for RPi5! To use an RPi5, we recommend not upgrading the software, but using a fresh install. Under the hood: we are using a new route to load the firmware on the HATs RP2040, which was the blocker previously.
- new ENV variable, `HAT_PRESENT=1`, can be set to skip `is_HAT_present` checks.
- added the RPis unique MAC addresses to the `Manage -> System` tab on the Pioreactors page.
- added table `ir_led_intensities` to be able to be exported on the Exports page.
- added a new `smoothing_penalizer` config option to `[od_config]`. This parameter, which has default value 700, controls how much smoothing to apply to optical density measurements. This smoothing has always been applied, but now it's a config option.
- Cleaned up some UI interactions

#### Bug fixes
- Ack! I reintroduced a UI export bug. Fix is present going forward. For existing users, try the following: https://forum.pioreactor.com/t/new-pioreactor-release-23-11-18/179/2
- fixed a bug where stirring DC would jump up too high when RPM measured 0.


### 23.12.11

#### Enhancements

- Improvements to OD calibration and pump calibrations. Both now have a `-f` option to provide a json file with calibration data, to skip rerunning data-gathering routines. For example: `pio run pump_calibration -f pump_data.json`.
- Ability to update via our release_archives (available on the [Github release page](https://github.com/Pioreactor/pioreactor/releases)) via the UI. To turn this feature off (which is a recommended practice when you expose your UI publically), add an empty file called `DISALLOW_UI_UPLOADS` to the `~/.pioreactor` directory.
- A new config option to change the max volume to dose when a larger dose volume is split. For example, if your chemostat asks to dose 1.6ml, our internal algorithm will dose 0.75, 0.75 and 0.1 (this is to avoid overflow). The 0.75 was previously hardcoded, but is now a config `max_subdose` under section `[dosing_automation.config]` (default is still 0.75ml).
- Ability to update via our release_archives (available on the [Github release page](https://github.com/Pioreactor/pioreactor/releases)) via the UI. To turn this feature off (which is a recommended practice when you expose your UI publicly), add an empty file called `DISALLOW_UI_UPLOADS` to the `~/.pioreactor` directory.
- A new config option to change the max volume to dose when a larger dose volume is split. For example, if your chemostat asks to dose 1.6 ml, our internal algorithm will dose 0.75, 0.75 and 0.1 (this is to avoid overflow). The 0.75 was previously hardcoded, but is now a config `max_subdose` under section `[dosing_automation.config]` (default is still 0.75 ml).

#### Breaking changes

Expand Down
20 changes: 10 additions & 10 deletions config.dev.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ ir_led_intensity=90
# use the most recent calibration file, if available
use_calibration=1

# apply a smoothing penalizer
smoothing_penalizer=700.0

[storage]
database=pioreactor.sqlite

Expand Down Expand Up @@ -87,18 +90,11 @@ log_display_count=65
time_display_mode=hours


[dosing_automation]
pause_between_subdoses_seconds=0.1

[dosing_automation.pid_morbidostat]
Kp=5
Ki=0
Kd=0

[dosing_automation.pid_turbidostat]
Kp=0.05
Ki=0.01
Kd=0.01

[temperature_automation.thermostat]
Kp=.01
Expand All @@ -122,6 +118,10 @@ obs_std=3.0
od_std=0.005
rate_std=0.20

[motor_driver]
initial_duty_cycle=10
hz=20

[dosing_automation.config]
pause_between_subdoses_seconds=5
waste_removal_multiplier=2
max_volume_to_warn=17.0
max_volume_to_stop=18.0
max_subdose=0.75
28 changes: 15 additions & 13 deletions pioreactor/utils/pwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@

class HardwarePWMOutputDevice(HardwarePWM):
HARDWARE_PWM_CHANNELS: dict[GpioPin, int] = {12: 0, 13: 1}
_started = False

def __init__(
self, pin: GpioPin, initial_dc: pt.FloatBetween0and100 = 0.0, frequency: float = 100
) -> None:
if (
pin not in self.HARDWARE_PWM_CHANNELS
): # Only GPIO pins 18 and 19 are supported for hardware PWM
raise ValueError(
"Only GPIO pins 12 (PWM channel 0) and 13 (PWM channel 1) are supported."
)
if pin not in self.HARDWARE_PWM_CHANNELS: # Only GPIO pins 18 and 19 are supported for hardware PWM
raise ValueError("Only GPIO pins 12 (PWM channel 0) and 13 (PWM channel 1) are supported.")

pwm_channel = self.HARDWARE_PWM_CHANNELS[pin]
super().__init__(pwm_channel, hz=frequency)
self._dc = initial_dc

def start(self) -> None:
super().start(self.dc)
self._started = True

def off(self) -> None:
self.dc = 0.0
Expand All @@ -63,20 +61,24 @@ def dc(self) -> pt.FloatBetween0and100:

@dc.setter
def dc(self, dc: pt.FloatBetween0and100) -> None:
dc = clamp(0.0, dc, 100.0)
self.change_duty_cycle(dc)
self._dc = dc
if self._started:
dc = clamp(0.0, dc, 100.0)
self.change_duty_cycle(dc)
self._dc = dc
else:
raise ValueError("must call .start() first!")

def close(self) -> None:
pass


class SoftwarePWMOutputDevice:
_started = False

def __init__(self, pin: GpioPin, initial_dc: pt.FloatBetween0and100 = 0.0, frequency=100):
self.pin = pin
self._dc = initial_dc
self.frequency = frequency
self._started = False
self._handle = lgpio.gpiochip_open(0)

lgpio.gpio_claim_output(self._handle, self.pin)
Expand All @@ -103,6 +105,8 @@ def dc(self, dc: pt.FloatBetween0and100) -> None:
self._dc = dc
if self._started:
lgpio.tx_pwm(self._handle, self.pin, self.frequency, self.dc)
else:
raise ValueError("must call .start() first!")

def close(self):
lgpio.gpiochip_close(self._handle)
Expand Down Expand Up @@ -173,9 +177,7 @@ def __init__(
self.pubsub_client = pubsub_client

if logger is None:
self.logger = create_logger(
f"PWM@GPIO-{pin}", experiment=self.experiment, unit=self.unit
)
self.logger = create_logger(f"PWM@GPIO-{pin}", experiment=self.experiment, unit=self.unit)
else:
self.logger = logger

Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ msgspec==0.18.4
diskcache==5.6.3
wheel==0.41.2
crudini==0.9.5
lgpio; platform_machine!='armv7l' and platform_machine!='armv6l'
# lgpio; platform_machine!='armv7l' and platform_machine!='armv6l'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"diskcache==5.6.3",
"wheel==0.41.2",
"crudini==0.9.5",
"lgpio; platform_machine!='armv7l' and platform_machine!='armv6l'",
# "lgpio; platform_machine!='armv7l' and platform_machine!='armv6l'", # primarily available via apt-get install python3-lgpio
]


Expand Down

0 comments on commit 683077a

Please sign in to comment.