Skip to content

Commit

Permalink
FIX: SlowPwmDevice.cycle no longer depends in input
Browse files Browse the repository at this point in the history
... within sensible limits:
*Input.interval should be less than SlowPwmDevice.cycle, otherwise the
PWM will react unproportionally (non linear).
Too short cycle time may wear your relay contacts. I'd recommend
semiconductor switches for short cycle times. After all its named
SLOWPwmDevice!
  • Loading branch information
schwabix-1311 committed Nov 22, 2024
1 parent 6207021 commit 06b8f70
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion aquaPi/machineroom/out_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def toggle_and_wait(state: bool, end: float) -> bool:
>>>>>>> 9037c8a (FIX: SlowPwmDevice 100% showed as 50% in History)
def listen(self, msg):
if isinstance(msg, MsgData):
log.brief('SlowPwmDevice %s: got %f %%', self.name, msg.data)
self.set(float(msg.data))
return super().listen(msg)

<<<<<<< HEAD
def _pulse(self, dur: float):
log.brief(' PID pulse: %s -> %f s', self.name, round(dur, 1))
if dur > 0.1:
Expand All @@ -269,12 +269,41 @@ def _pulse(self, dur: float):
self.post(MsgData(self.id, 0))
log.brief(' PID pulse: done')
>>>>>>> 5f2158d (Fixes and tuning of PidCtrl on real HW)
=======
def _pulse(self, hi_sec: float):
def toggle_and_wait(state: bool, end: float) -> bool:
start = time.time()
self._driver.write(state if not self._inverted else not state)
self.post(MsgData(self.id, 100 if state else 0))
# avoid error accumulation by exact final sleep()
while time.time() < end - .1:
if self._thread_stop:
self._thread_stop = False
return False
time.sleep(.1)
time.sleep(end - time.time())
log.debug(' _pulse needed %f instead of %f',
time.time() - start, end - start)
return True

while True:
lead_edge = time.time()
if hi_sec > 0.1:
if not toggle_and_wait(True, lead_edge + hi_sec):
return
if hi_sec < self.cycle:
if not toggle_and_wait(False, lead_edge + self.cycle):
return
>>>>>>> 0ee1ae1 (FIX: SlowPwmDevice.cycle no longer depends in input)
return

def set(self, perc: float) -> None:
self.data: float = perc

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 0ee1ae1 (FIX: SlowPwmDevice.cycle no longer depends in input)
log.info('SlowPwmDevice %s: sets %.1f %% (%.3f of %f s)',
self.id, self.data, self.cycle * perc/100, self.cycle)
if self._thread:
Expand All @@ -283,6 +312,7 @@ def set(self, perc: float) -> None:
self._thread = Thread(name='PIDpulse', target=self._pulse,
args=[self.data / 100 * self.cycle], daemon=True)
self._thread.start()
<<<<<<< HEAD
=======
log.error('SlowPwmDevice %s: sets %.1f', self.id, self.data)
#if self._thread:
Expand All @@ -293,6 +323,8 @@ def set(self, perc: float) -> None:
self._thread = Thread(name='PIDpulse', target=self._pulse, args=[self.data / 100. * self.cycle], daemon=True).start()
>>>>>>> 5f2158d (Fixes and tuning of PidCtrl on real HW)

=======
>>>>>>> 0ee1ae1 (FIX: SlowPwmDevice.cycle no longer depends in input)

def get_settings(self):
settings = super().get_settings()
Expand Down

0 comments on commit 06b8f70

Please sign in to comment.