Exemple #1
0
def read_devicefile(filename):
    devFile = open(filename, 'r')
    discardHeader = devFile.readline()
    Comps = {}
    i = 0
    begId = 2
    for line in devFile:
        dev = line.split(',')
        if dev[1] == "TURBINE":
            Comps[dev[0]] = turbine.Turbine(dev[0], int(dev[begId]),
                                            int(dev[begId + 1]))
        elif dev[1] == "BOILER":
            Comps[dev[0]] = boiler.Boiler(dev[0], int(dev[begId]),
                                          int(dev[begId + 1]))
        elif dev[1] == "CONDENSER":
            Comps[dev[0]] = condenser.Condenser(dev[0], int(dev[begId]),
                                                int(dev[begId + 1]))
        elif dev[1] == "PUMP":
            Comps[dev[0]] = pump.Pump(dev[0], int(dev[begId]),
                                      int(dev[begId + 1]))

        i = i + 1

    DevNum = i
    return Comps, DevNum
Exemple #2
0
def read_jsonfile(filename):
    """ rankine cycle in json file"""

    # 1 read json file to dict
    with open(filename, 'r') as f:
        rkcyc = json.loads(f.read())

    # print(rkcyc)
    name = rkcyc["name"]
    dictnodes = rkcyc["nodes"]
    dictcomps = rkcyc["comps"]

    # 2 convert dict nodes to the object nodes
    countNodes = len(dictnodes)
    nodes = [None for i in range(countNodes)]
    for curjnode in dictnodes:
        i = int(curjnode['id'])
        nodes[i] = node.Node(curjnode['name'], i)
        nodes[i].p = curjnode['p']
        nodes[i].t = curjnode['t']
        nodes[i].x = curjnode['x']

        if nodes[i].p != None and nodes[i].t != None:
            nodes[i].pt()
        elif nodes[i].p != None and nodes[i].x != None:
            nodes[i].px()
        elif nodes[i].t != None and nodes[i].x != None:
            nodes[i].tx()

    #print(nodes[1])

    # 3 convert dict Comps to the object Comps
    DevNum = len(dictcomps)
    Comps = {}
    for curdev in dictcomps:
        if curdev['type'] == "TURBINE":
            Comps[curdev['name']] = turbine.Turbine(curdev['name'],
                                                    curdev['inNode'],
                                                    curdev['exNode'])
        elif curdev['type'] == "BOILER":
            Comps[curdev['name']] = boiler.Boiler(curdev['name'],
                                                  curdev['inNode'],
                                                  curdev['exNode'])
        elif curdev['type'] == "CONDENSER":
            Comps[curdev['name']] = condenser.Condenser(
                curdev['name'], curdev['inNode'], curdev['exNode'])
        elif curdev['type'] == "PUMP":
            Comps[curdev['name']] = pump.Pump(curdev['name'], curdev['inNode'],
                                              curdev['exNode'])

    return name, nodes, countNodes, Comps, DevNum
Exemple #3
0
 def startDevices(self):
     print "Connecting to shutters"
     self.shutter = shutter.Shutter()
     self.shutter.initialize()
     print "Connecting to pump"
     self.pump = pump.Pump(self.config.pumpPort)
     self.pump.initialize()
     print "Connecting to valve"
     self.valve = valve.Valve(self.config.valvePort)
     self.valve.setLiquids(self.config.valveLiquidNameList)
     print "Connecting to stage"
     self.stage = stage.Stage(self.config.stagePort)
     print "Starting camera"
     self.camera = camera
     self.camera.start()
Exemple #4
0
def RankineCycle():
    condenserOverCool = 0.1
    condenserPressure = 0.006
    desiredQuality = 0.9

    table = []

    for boilerPressure in [1, 1.5, 2]:
        nodes = []
        for i in range(4):
            nodes.append(Node.Node())

        nodes[0].p = boilerPressure

        nodes[1].p = condenserPressure
        nodes[1].x = desiredQuality

        nodes[2].p = condenserPressure
        nodes[2].x = 0

        nodes[3].p = boilerPressure

        #  simulate
        nodes[1].px()
        t = turbine.Turbine(nodes[0], nodes[1])
        t.simulate()
        nodes[0] = t.inletNode

        nodes[2].px()
        c = condenser.Condenser(nodes[1], nodes[2])
        c.simulate(condenserOverCool)
        nodes[2] = c.exitNode

        p = pump.Pump(nodes[2], nodes[3])
        p.simulate()
        nodes[3] = p.exitNode

        b = boiler.Boiler(nodes[3], nodes[0])
        b.simulate()

        efficiency = (t.workExtracted - p.workRequired) / (b.heatAdded)

        table.append([boilerPressure, efficiency])

    print(tabulate(table, headers=["Boiler Pressure", "Efficiency"]))
Exemple #5
0
def main():
    condenserOverCool = 0.1
    condenserPressure = 0.006

    desiredQuality = 0.9

    table = []

    for boilerPressure in [1, 1.5, 2]:
        turbineEntropy = iapws.IAPWS97(P=condenserPressure, x=desiredQuality).s

        turbineInletTemperature = iapws.IAPWS97(P=boilerPressure,
                                                s=turbineEntropy).T

        condenserExitState = iapws.IAPWS97(x=0, P=condenserPressure)
        condenserExitState = iapws.IAPWS97(h=condenserExitState.h -
                                           condenserOverCool,
                                           P=condenserPressure)

        p = pump.Pump(condenserExitState)
        p.simulate(boilerPressure)

        b = boiler.Boiler(p.exitState)
        b.simulate(turbineInletTemperature)

        boilerSaturationTemp = iapws.IAPWS97(P=boilerPressure, x=0.5).T
        degreeOfSuperheat = turbineInletTemperature - boilerSaturationTemp

        t = turbine.Turbine(b.exitState)
        t.simulate(condenserPressure)

        c = condenser.Condenser(t.exitState)
        c.simulate(condenserExitState.T)

        efficiency = (t.workExtracted - p.workRequired) / (b.heatAdded)

        table.append([boilerPressure, degreeOfSuperheat, efficiency])

    print tabulate(
        table,
        headers=["Boiler Pressure", "Degree of Superheat", "Efficiency"])
def make_pump_manager(moisture_threshold, sleep_windows, raspberry_pi_io,
                      wiring_config, pump_amount, db_connection, pump_interval,
                      water_level_sensor):
    """Creates a pump manager instance.

    Args:
        moisture_threshold: The minimum moisture level below which the pump
            turns on.
        sleep_windows: Sleep windows during which pump will not turn on.
        raspberry_pi_io: pi_io instance for the GreenPiThumb.
        wiring_config: Wiring configuration for the GreenPiThumb.
        pump_amount: Amount (in mL) to pump on each run of the pump.
        db_connection: Database connection to use to retrieve pump history.
        pump_interval: Maximum amount of hours between pump runs.
        water_level_sensor: Interface to the water level sensor.

    Returns:
        A PumpManager instance with the given settings.
    """
    water_pump = pump.Pump(raspberry_pi_io, clock.Clock(),
                           wiring_config.gpio_pins.pump)
    pump_scheduler = pump.PumpScheduler(clock.LocalClock(), sleep_windows)
    pump_timer = clock.Timer(clock.Clock(), pump_interval)
    last_pump_time = pump_history.last_pump_time(
        db_store.WateringEventStore(db_connection))
    if last_pump_time:
        logger.info('last watering was at %s', last_pump_time)
        time_remaining = max(datetime.timedelta(seconds=0),
                             (last_pump_time + pump_interval) -
                             clock.Clock().now())
    else:
        logger.info('no previous watering found')
        #~ time_remaining = datetime.timedelta(seconds=0)   # !!!WARNING!!! Immediately water plants if no previous watering event was found !!!WARNING!!!
        time_remaining = pump_interval  # Schedule the first mandatory plant watering event in pump_interval hours
    logger.info('time until until next watering: %s', time_remaining)
    pump_timer.set_remaining(time_remaining)
    return pump.PumpManager(water_pump, pump_scheduler, moisture_threshold,
                            pump_amount, pump_timer, water_level_sensor)
Exemple #7
0
def RankineCycle():
    boilerPressure = 8.0
    condenserPressure = 0.008
    Wcycledot = 100.00

    # 1 init nodes
    nodes = []
    for i in range(4):
        nodes.append(node.Node())

    nodes[0].p = boilerPressure
    nodes[0].x = 1

    nodes[1].p = condenserPressure

    nodes[2].p = condenserPressure
    nodes[2].x = 0

    nodes[3].p = boilerPressure

    nodes[0].px()
    nodes[2].px()

    # 2 connect device
    t = turbine.Turbine(0, 1)
    p = pump.Pump(2, 3)
    b = boiler.Boiler(3, 0)

    # 3 simulate
    t.simulate(nodes)
    p.simulate(nodes)

    bwr = p.workRequired / t.workExtracted
    mdot = Wcycledot * 1000.0* 3600.0 / (t.workExtracted - p.workRequired)

    b.simulate(nodes, mdot)                  # in MW
    efficiency = (t.workExtracted - p.workRequired) / \
        (b.heatAdded)                # in MW

   # 4 condenser
    nodew = []
    for i in range(2):
        nodew.append(node.Node())

    nodew[0].t = 15
    nodew[0].x = 0
    nodew[1].t = 35
    nodew[1].x = 0
    nodew[0].tx()
    nodew[1].tx()

    c = condenser.Condenser(1, 2, 0, 1)
    c.simulate(nodes, nodew, mdot)

    print("Boiler Pressure: ", boilerPressure, "MPa")
    print("Condenser Pressure: ", condenserPressure, "MPa")
    print("The net power output of the cycle: ", Wcycledot, "MW")
    print("Cooling water enters the condenser T", nodew[0].t, "°C")
    print("Cooling water exits  the condenser T", nodew[1].t, "°C")
    print(" \n --------------------------------------------------")
    print("Efficiency: ", '%.2f' % (efficiency * 100), "%")
    print("The back work ratio: ", '%.2f' % (bwr * 100), "%")
    print("The mass flow rate: ",  '%.2f' % mdot, "%")
    print('The rate of heat transfer as the fluid passes the boiler: ',
          '%.2f' % b.Qindot, 'MW')
    print('The rate of heat transfer from the condensing steam: ',
          '%.2f' % c.Qoutdot, 'MW')
    print('The mass flow rate of the condenser cooling water: ', '%.2f' %
          c.mcwdot, 'kg/h')
Exemple #8
0
# coding: utf-8
import pump
from time import sleep
import subprocess as s
import sqlite3

from pump_db import PUMPDB

if __name__ == '__main__':

    db_conn = sqlite3.connect('pumpdata.db')

    pump_db_conn = PUMPDB(db_conn)

    pump = pump.Pump()

    while True:

        if not pump.is_loggedin():
            pump.login()

        if (available_classes := pump.get_classes_available()) is not None:
            for available_class in available_classes:

                if pump_db_conn.check_class_notification_last_10_minutes(
                        available_class):
                    pump_db_conn.insert_class(available_class, notified=False)
                else:
                    s.call([
                        'notify-send',
                        available_class.hour + ' ' + available_class.name,
Exemple #9
0
'''
Sean Tasaki
11/25/2018
Lesson06
'''

import decider
import sensor
import controller
import pump

if __name__ == '__main__':

    DECIDER = decider.Decider(5, 1)
    SENSOR = sensor.Sensor('127.0.0.1', 8000)
    PUMP = pump.Pump('100.9.9.0', 9000)
    CONTROLLER = controller.Controller(SENSOR, PUMP, DECIDER)
Exemple #10
0
    "b": 494,
    "C": 523,
    "D": 587,
    "E": 659,
    "F": 698,
    "G": 784,
    "A": 880,
    "B": 988
}

# initialise direction and step counter
direction = "P"
total_steps = 0

# instantiate and initialise pump
p = pump.Pump(pump_port)
p.open()
p.initialise(pump_adress)
p.is_ready(pump_adress)
time.sleep(1)

with open(sheet_music_file) as f:
    for line in f:
        # parse notes
        content = line.split("-")
        note = content[0]
        length = content[1]

        # calculate frequencies
        frequency = frequencies[note]
        steps = int((frequency * 120) / (bpm * int(length)))