Beispiel #1
0
def valve_loop(breathing, peeping, oxp, start, start_time, top, top_time, down,
               down_time, bottom, bottom_time, peep_steps, peep_step_time,
               peep_wait, count):

    i2c = rpi2c.rpi_i2c(1)
    kit = MotorKit(i2c=i2c)

    breather = Breather(kit.motor1, kit.motor2)
    breather.set_cycle(start, start_time, top.value, top_time, down, down_time,
                       bottom)

    for i in range(0, count):
        # breath
        breather.breath(breathing, top, oxp)
        # peep
        peep_cycle(breathing, peeping, peep_steps, peep_step_time, peep_wait)
        # wait
        sleep_time = 0.1
        sleep_count = (int)(bottom_time / sleep_time)
        for i in range(0, sleep_count):
            if breathing.value == constants.INSPIRING:
                break
            time.sleep(sleep_time)

    # cleanup
    logging.warn("cleaning up please wait")
    breather.cleanup(breathing, oxp)
    peep.peep_cleanup()
    logging.warn("done")
Beispiel #2
0
def flow_calibrate(bus, percent, count):
    print("runing calibration on bus %d" % (bus,))

    # setup pressure sensors and zero pressure them
    in_p1 = PressureSensorLPS(rpi2c.rpi_i2c(1), address=0x5d)
    in_p2 = PressureSensorLPS(rpi2c.rpi_i2c(1), address=0x5c)
    ex_p1 = PressureSensorLPS(rpi2c.rpi_i2c(3), address=0x5d)
    ex_p2 = PressureSensorLPS(rpi2c.rpi_i2c(3), address=0x5c)
    sensor.pressure_zero(in_p1, in_p2, ex_p1, ex_p2)
    
    flow = FlowSensorD6F(rpi2c.rpi_i2c(1))
    kit = MotorKit(i2c=rpi2c.rpi_i2c(1))
    breather = Breather(kit.motor1, kit.motor2)
    ox = Value('i', 0)

    if bus == 1:
        p1 = in_p1
        p2 = in_p2
    else:
        p1 = ex_p1
        p2 = ex_p2
        
    # open valve
    breather.throttle(percent, ox)
    total = 0
    samples = 0
    vmin = 100
    vmax = 0
    THRESH = 50

    logging.warning("Start calibration")
    for i in range(0,count):
        p1.read()
        p2.read()
        flow.read()
        r = flow.data.rate
        hp = p2.data.pressure
        lp = p1.data.pressure
        if hp > (lp + THRESH):
            vco = r / ((hp-lp)**0.5)
            total += vco
            samples += 1
            vmin = min(vco, vmin)
            vmax = max(vco, vmax)
            logging.warning("%f %f %f %f" % (r, vco, hp, lp))
        
        time.sleep(0.1)

    # close valve
    logging.warning("VCO: %f min %f max %f" % (total/samples, vmin, vmax))
    breather.throttle(0, ox)
Beispiel #3
0
        sleep_time = 0.1
        sleep_count = (int)(bottom_time / sleep_time)
        for i in range(0, sleep_count):
            if breathing.value == constants.INSPIRING:
                break
            time.sleep(sleep_time)

    # cleanup
    logging.warn("cleaning up please wait")
    breather.cleanup(breathing, oxp)
    peep.peep_cleanup()
    logging.warn("done")


if __name__ == '__main__':
    breathing = Value('i', 0)
    i2c = rpi2c.rpi_i2c(1)
    kit = MotorKit(i2c=i2c)
    breather = Breather(kit.motor1, kit.motor2)

    print('Hit <ENTER> to disconnect')
    while True:
        duty = user_int('Enter Breath duty (0 to exit)')
        breather.set_cycle(80, 0.1, duty, 1.0, 0, 0, 0)
        for i in range(0, 5):
            breather.breath(breathing, 500)
            time.sleep(2.0)
        breather.throttle(0)

    print('Bye')
Beispiel #4
0
class OxygenADS:
    def __init__(self, i2c):
        self.i2c = i2c
        
        self.ads = ADS.ADS1015(i2c)
        self.chan = AnalogIn(self.ads, ADS.P0)
        self.calibration = 0
        self.percent = 0
        
    def calibrate(self):
        sample_sum = 0
        num_samples = 50
        for i in range(0,num_samples):
            sample_sum += self.chan.voltage
            time.sleep(0.05)
        self.calibration = sample_sum / num_samples

    def read(self):
        # datasheet : https://cdn.shopify.com/s/files/1/1275/4659/files/SS-26.pdf?867825592994555160
        self.percent = self.chan.voltage * 2000
        return self.percent
        
if __name__ == '__main__':
    i2c = rpi2c.rpi_i2c(3)
    sensor = OxygenADS(i2c)
    sensor.calibrate()
    while True:
        print(sensor.read())
        time.sleep(0.5)

Beispiel #5
0
import time
from datetime import datetime
from multiprocessing import Process, Queue, Array, Value
import logging

import board
import busio

import rpi2c
import constants

from sensor import oxygen

from sensor.sensor_lps import PressureSensorLPS

i2c_in = rpi2c.rpi_i2c(1)
i2c_ex = rpi2c.rpi_i2c(3)
"""
venturi coefficient - https://www.efunda.com/formulae/fluids/venturi_flowmeter.cfm

60000 * 0.975 * (pi/4) * D2^2 * ( (2 * dP) / (1.204 * (1 - (D2/D1)^4))^0.5

where:
  60000 is conversion from m^3/s to L/min
  0.975 is the discharge coefficient 
         usually lies between 0.90 and 0.98 for smoothly tapering venturis
  1.204 air density at sea level

assumptions:
  
and: