Пример #1
0
    def run(self):
        p = float(self.P)
        i = float(self.I)
        d = float(self.D)
        pmax = int(self.Pmax)
        ts = 5

        print((p, i, d, pmax))
        pid = PID(ts, p, i, d, pmax)

        while self.is_running():
            heat_percent = pid.calc(self.get_sensor_value(), self.get_target_temp())
            if heat_percent == 0:
                self.actor_power(heat_percent)
                self.heater_off()
                cbpi.log_action("PIDHendi OFF {}")
            else:
                self.actor_power(heat_percent)
                self.heater_on(power=heat_percent)

                cbpi.log_action("PIDHendi calling heater_on(power={})".format(heat_percent))

            self.sleep(ts)

        self.heater_off()
Пример #2
0
 def on(self, power=None):
     HendiControl.stopped = False
     if HendiControl.pwm is None:
         if HendiControl.freq is None:
             HendiControl.freq = 100
         HendiControl.pwm = GPIO.PWM(int(self.power_pin), int(self.freq))
         HendiControl.pwm.start(int(HendiControl.power))
     if(0 == HendiControl.power):
         GPIO.output(int(self.onoff_pin), 0)
     else:
         GPIO.output(int(self.onoff_pin), 1)
         HendiControl.pwm.start(1)
         HendiControl.pwm.ChangeDutyCycle(int(HendiControl.power))
         cbpi.log_action("ON, Set power {}".format(HendiControl.power))
Пример #3
0
    def init_step(self, step):
        cbpi.log_action("Start Step %s" % step.name)
        type_cfg = cbpi.cache.get("step_types").get(step.type)
        if type_cfg is None:
            # if type not found
            return

        # copy config to stepstate
        # init step
        cfg = step.config.copy()
        cfg.update(dict(name=step.name, api=cbpi, id=step.id, timer_end=None, managed_fields=get_manged_fields_as_array(type_cfg)))
        instance = type_cfg.get("class")(**cfg)
        instance.init()
        # set step instance to ache
        cbpi.cache["active_step"] = instance
Пример #4
0
    def start(self):
        active = Step.get_by_state("A")
        inactive = Step.get_by_state('I')

        if (active is not None):
            active.state = 'D'
            active.end = int(time.time())
            self.stop_step()
            Step.update(**active.__dict__)

        if (inactive is not None):
            self.init_step(inactive)
            inactive.state = 'A'
            inactive.stepstate = inactive.config
            inactive.start = int(time.time())
            Step.update(**inactive.__dict__)
        else:
            cbpi.log_action("Brewing Finished")
            cbpi.notify("Brewing Finished", "You are done!", timeout=None)

        cbpi.emit("UPDATE_ALL_STEPS", Step.get_all())
        return ('', 204)
Пример #5
0
 def off(self):
     cbpi.log_action("off")
     self.stopped = True
     self.pwm.ChangeDutyCycle(0)
     self.pwm.stop()
     GPIO.output(int(self.onoff_pin), 0)
Пример #6
0
 def set_power(self, power):
     HendiControl.power = min(int(power), int(self.Pmax))
     cbpi.log_action("Set power {}".format(HendiControl.power))
     self.pwm.ChangeDutyCycle(HendiControl.power)