コード例 #1
0
    def gpio_config(self):
        log_and_print("Configuring GPIO...")
        pi = pigpio.pi()
        if not pi.connected:
            raise Exception("Error while configuring RaspberryPI GPIO.")
        self.pi = pi

        # Stating outputs
        pi.set_mode(self.ULTRASONIC_TRIGGER, pigpio.OUTPUT)
        pi.set_mode(self.ULTRASONIC_ECHO, pigpio.INPUT)
        pi.set_mode(self.HEATER, pigpio.OUTPUT)
        pi.set_mode(self.H_PUMP0, pigpio.OUTPUT)
        pi.set_mode(self.H_PUMP1, pigpio.OUTPUT)
        pi.set_mode(self.MIXER, pigpio.OUTPUT)
        pi.set_mode(self.LED, pigpio.OUTPUT)
        pi.set_mode(self.SERVO0, pigpio.OUTPUT)
        pi.set_mode(self.SERVO1, pigpio.OUTPUT)
        pi.set_mode(self.SERVO2, pigpio.OUTPUT)
        pi.set_mode(self.IR0, pigpio.OUTPUT)

        pi.write(self.HEATER, 0)
        pi.write(self.H_PUMP0, 0)
        pi.write(self.H_PUMP1, 0)
        pi.write(self.MIXER, 0)
        pi.write(self.LED, 1)
        pi.write(self.ULTRASONIC_TRIGGER, 0)
        pi.write(self.IR0, 1)

        pi.read(self.ULTRASONIC_ECHO)

        log_and_print("GPIO Configured.")
        return pi
コード例 #2
0
    def wait_for_mug(self):

        mug_result = pi.gpio.light_sensor_control()
        while True:
            if mug_result == 1:
                log_and_print("Your drink will be released ")
                break
            elif mug_result == 0:
                log_and_print("Please, position your mug ")
                time.sleep(3)
コード例 #3
0
    def servo2_control(self, spoons):
        servoPIN = 19
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(servoPIN, GPIO.OUT)

        s2 = GPIO.PWM(servoPIN, 50)  # GPIO 19 for PWM with 50Hz
        s2.start(4.5)  # Initialization of Servo0

        s2.ChangeDutyCycle(4.5)
        time.sleep(0.1)
        s2.ChangeDutyCycle(3.0)
        time.sleep(1 * spoons)
        s2.ChangeDutyCycle(4.5)
        time.sleep(0.1)

        s2.stop()
        GPIO.cleanup()
        log_and_print("Servo2 test complete")
コード例 #4
0
    def servo0_control(self, spoons):
        servoPIN = 12
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(servoPIN, GPIO.OUT)

        s0 = GPIO.PWM(servoPIN, 50)  # GPIO 12 for PWM with 50Hz
        s0.start(6)  # Initialization of Servo0

        s0.ChangeDutyCycle(5.3)
        time.sleep(0.1)
        s0.ChangeDutyCycle(3.8)
        time.sleep(1 * spoons)
        s0.ChangeDutyCycle(5.3)
        time.sleep(0.1)

        s0.stop()
        GPIO.cleanup()
        log_and_print("Servo0 test complete")
コード例 #5
0
def coffee(send, receive):
    log_and_print("")
    log_and_print("Starting CO-FI...")
    pi_gpio = piGPIO()
    pi_gpio.gpio_config()
    functions = state_functions()

    while True:
        order = receive.get()
        user = order['user']
        print("Received order")

        functions.get_measures(order['chocolate'], order['coffee'],
                               order['milk'])
        ingredients_ok = functions.verify_ingredients()
        if not ingredients_ok:
            functions.request_reposition()
            result = {'user': user, 'status': False}
            send.put(result)
        elif ingredients_ok:
            result = {'user': user, 'status': True}
            send.put(result)
            functions.separate_ingredients()
            functions.heat()
            functions.add_water()
            functions.mix()
            functions.wait_for_mug()
            functions.release_drink()

    log_and_print("Turning CO-FI off.")
コード例 #6
0
 def mixer_control(self):
     log_and_print("Turning the mixer on ")
     pi = self.pi
     pi.write(self.MIXER, 1)
     time.sleep(5)
     log_and_print("Turning the mixer off ")
     pi.write(self.MIXER, 0)
     time.sleep(0.5)
     log_and_print("Mixer function finished.")
コード例 #7
0
 def heater_control(self):
     log_and_print("Turning the heater on ")
     pi = self.pi
     pi.write(self.HEATER, 1)
     time.sleep(20)
     log_and_print("Turning the heater off ")
     pi.write(self.HEATER, 0)
     time.sleep(0.5)
     log_and_print("Heater function finished.")
コード例 #8
0
 def water_pump1_control(self):
     pi = self.pi
     log_and_print("Turning the water pump 1 on ")
     pi.write(self.H_PUMP1, 1)
     time.sleep(8)
     log_and_print("Turning the water pump 1 off ")
     pi.write(self.H_PUMP1, 0)
     time.sleep(0.5)
     log_and_print("Water pump 1 function finished.")
コード例 #9
0
    while True:
        order = receive.get()
        user = order['user']
        print("Received order")

        functions.get_measures(order['chocolate'], order['coffee'],
                               order['milk'])
        ingredients_ok = functions.verify_ingredients()
        if not ingredients_ok:
            functions.request_reposition()
            result = {'user': user, 'status': False}
            send.put(result)
        elif ingredients_ok:
            result = {'user': user, 'status': True}
            send.put(result)
            functions.separate_ingredients()
            functions.heat()
            functions.add_water()
            functions.mix()
            functions.wait_for_mug()
            functions.release_drink()

    log_and_print("Turning CO-FI off.")


try:
    main()
except Exception as exc:
    log_and_print("Exception: {0}".format(exc))
    exception_logger("cofi_app.py", "main",
                     getframeinfo(currentframe()).lineno, exc)
コード例 #10
0
    def request_reposition(self):

        log_and_print("Water level is low, reposition required ")