예제 #1
0
class Regulation(object):


    def __init__(self, hot, mash, boil):
        self.hot  = hot
        self.mash = mash
        self.boil = boil
        self.lld  = LLD()

        self.sample_time = 5
        hot.setSampleTime(self.sample_time)
        mash.setSampleTime(self.sample_time)
        boil.setSampleTime(self.sample_time)
        thread = threading.Thread(target=self.update_pid, args=())
        thread.daemon = True                            # Daemonize thread
        thread.start()                                  # Start the execution

    def set_resistors(self, tanks, cycles):
        tanks[0].resistor_duty = cycles[0]
        tanks[1].resistor_duty = cycles[1]
        tanks[2].resistor_duty = cycles[2]
        self.lld.set_resistors_duty(cycles)

    def update_pid(self):
        hot  = self.hot
        mash = self.mash
        boil = self.boil
        tanks = (mash, boil, hot)
        
        lld = self.lld

        while True:

            hot.update_pid(lld.get_temperature(hot))
            mash.update_pid(lld.get_temperature(mash))
            boil.update_pid(lld.get_temperature(boil))

            max_duty = 1

            if (mash.output >= max_duty):
                self.set_resistors(tanks, (max_duty, 0, 0))
            elif (mash.output + boil.output >= max_duty):
                self.set_resistors(tanks, (mash.output, max_duty - mash.output, 0))
            elif (mash.output + boil.output + hot.output >= max_duty):
                self.set_resistors(tanks, (mash.output, boil.output, max_duty - mash.output - boil.output))
            else:
                self.set_resistors(tanks, (mash.output, boil.output, hot.output))

            time.sleep(self.sample_time)
예제 #2
0
    def __init__(self, hot, mash, boil):
        self.hot  = hot
        self.mash = mash
        self.boil = boil
        self.lld  = LLD()

        self.sample_time = 5
        hot.setSampleTime(self.sample_time)
        mash.setSampleTime(self.sample_time)
        boil.setSampleTime(self.sample_time)
        thread = threading.Thread(target=self.update_pid, args=())
        thread.daemon = True                            # Daemonize thread
        thread.start()                                  # Start the execution
예제 #3
0
    def setUp(self):
        self.lld = LLD()

        self.hot  = FakeTank("Hot")
        self.mash = FakeTank("Mash")
        self.boil = FakeTank("Boil")
예제 #4
0
class LLDTest(unittest.TestCase):

    def setUp(self):
        self.lld = LLD()

        self.hot  = FakeTank("Hot")
        self.mash = FakeTank("Mash")
        self.boil = FakeTank("Boil")


    def check_one_resistor(self, tank, m, b, h):
        tanks = (self.mash, self.boil, self.hot)
        
        print("Set " + tank.tank_name + " at 20%")
        self.lld.set_resistors_duty(tanks, (m, b, h))

        assert(input("Is tank " + tank.tank_name + " at 20 % ? [y/n]") == "y")

        print("Set " + tank.tank_name + " at 0%")
        self.lld.set_resistors_duty(tanks, (0, 0, 0))

        assert(input("Is tank " + tank.tank_name + " at  0 % ? [y/n]") == "y")


    def test_resistor(self):
        ''' Check resistor duty cycle '''

        self.check_one_resistor(self.hot,    0,   0, 0.2)
        #self.check_one_resistor(self.mash, 0.2,   0,   0)
        #self.check_one_resistor(self.boil,   0, 0.2,   0)


    def check_one_temperature(self, tank):

        temp = self.lld.get_temperature(tank)
        assert(input("Is tank " + tank.tank_name + " at "+ temp +"C ? [y/n]") == "y")


    def test_temperature(self):
        ''' Read temperatures '''

        t = self.lld.get_temperature(self.hot)
        assert(input("Is hot tank temp at " + str(t) + " ? [y/n]") == "y")
        t = self.lld.get_temperature(self.mash)
        assert(input("Is mash tank temp at " + str(t) + " ? [y/n]") == "y")
        t = self.lld.get_temperature(self.boil)
        assert(input("Is boil tank temp at " + str(t) + " ? [y/n]") == "y")

    def test_pump(self):
        ''' Test pump '''

        self.lld.pump_switch(True)
        assert(input("Is pump ON ? [y/n]") == "y")

        self.lld.pump_switch(False)
        assert(input("Is pump OFF ? [y/n]") == "y")

    def check_valve(self, tank):

        self.lld.valve_switch(tank, False)
        assert(input("Is valve "+ tank.tank_name +" OFF ? [y/n]") == "y")

        self.lld.valve_switch(tank, True)
        assert(input("Is valve "+tank.tank_name+" ON ? [y/n]") == "y")


    def test_valve(self):
        ''' Test valves '''

        self.check_valve(self.hot)
        self.check_valve(self.mash)
        #self.check_valve(self.boil)

    def check_one_dosage(self, tank):
        print("Start dosing 2 liters in "+ tank.tank_name)
        print("No message should appear before job is done....")

        self.lld.dose_water_blocking(tank, 2)
        assert(input("Do you have 2 liters in "+tank.tank_name+" ? [y/n]") == "y")



    def test_dosage(self):

        assert(input("This test will dose 2 liter per tank. Continue ? [y/n]") == "y")
        self.check_one_dosage(self.hot)
        self.check_one_dosage(self.mash)