Ejemplo n.º 1
0
    def __init__(self):

        GPIO.setmode(GPIO.BOARD)
        self._last_direction = 0
        self.controller = GpioController()
        self.controller.switch_callback = None
        self.controller.rotary_callback = self.rotaryChange
        self.controller.start()
    def start_working(self, device):

        try:
            print('doing PickAndPlace')
            if device == "RPI":
                from Controller.GpioController import GpioController
                gpio = GpioController()
                gpio.initPins()
                gpio.gpioControl('elbow_f', 1.1)
                time.sleep(0.5)
                # gpio.gpioControl('grip_f', 0.3)
                # gpio.gpioControl('grip_b', 0.3)
                # time.sleep(0.5)
                gpio.gpioControl('elbow_b', 1.5)
                time.sleep(0.5)
            elif device == "LAPTOP":
                time.sleep(1)

            print('PickAndPlace finished..')
            print('Replying to WT server...')
            response = self.COMPLETED_MESSAGE
            return response

        except (ConnectionResetError, OSError) as e:
            print(e)
Ejemplo n.º 3
0
    def start_working(self, device):
        try:
            print('doing PickAndFlipAndPress')
            if device == "RPI":
                from Controller.GpioController import GpioController
                gpio = GpioController()
                gpio.initPins()
                # gpio.gpioControl('wrist_f', 1)
                # time.sleep(0.5)
                gpio.gpioControl('grip_f', 0.7)
                gpio.gpioControl('grip_b', 0.7)
                time.sleep(0.5)
                gpio.gpioControl('grip_f', 0.7)
                gpio.gpioControl('grip_b', 0.7)
                time.sleep(0.5)
                # gpio.gpioControl('wrist_b', 1.2)
            elif device == "LAPTOP":
                time.sleep()

            print('PickAndFlipAndPress finished..')
            print('Replying to WT server...')
            encoded_response = self.COMPLETED_MESSAGE
            return encoded_response
        except (ConnectionResetError, OSError) as e:
            print(e)
Ejemplo n.º 4
0
class PlayerGpioController():
    def __init__(self):

        GPIO.setmode(GPIO.BOARD)
        self._last_direction = 0
        self.controller = GpioController()
        self.controller.switch_callback = None
        self.controller.rotary_callback = self.rotaryChange
        self.controller.start()

    def readVolume(self):
        value = os.popen(
            "sudo amixer get Headphone|grep -o [0-9]*%|sed 's/%//'").read()
        return int(value)

    def rotaryChange(self, direction):
        if direction is not self._last_direction:
            self._last_direction = direction
            return
        volume_step = 5
        volume = self.readVolume()

        if direction == 1:
            os.system("sudo amixer set Headphone -- " +
                      str(min(100, max(0, volume + volume_step))) + "%")
            print("vol-up")
        else:
            os.system("sudo amixer set Headphone -- " +
                      str(min(100, max(0, volume - volume_step))) + "%")
            print("vol-down")

    def start(self):
        self.controller.start()

    def stop(self):
        self.controller.stop()
    def start_working(self, message, device):
        try:
            print('doing MoveMs to ' + str(message))
            if "left" in message:
                print(" \n \n \n move to left \n \n \n ")
                if device == "RPI":
                    from Controller.GpioController import GpioController
                    gpio = GpioController()
                    gpio.initPins()
                    gpio.gpioControl('rotate_l', 2.6)
                    time.sleep(1)
                elif device == "LAPTOP":
                    time.sleep(1)

                print('MoveMs finished..')
                print('Replying to server...')
                encoded_response = self.COMPLETED_MESSAGE_POS1
                return encoded_response
            elif "right" in message:
                print(" \n \n \n move to right \n \n \n ")
                if device == "RPI":
                    from Controller.GpioController import GpioController
                    gpio = GpioController()
                    gpio.initPins()
                    gpio.gpioControl('rotate_r', 2.4)
                    time.sleep(1)
                elif device == "LAPTOP":
                    time.sleep(1)

                print('MoveMs finished..')
                print('Replying to server...')
                encoded_response = self.COMPLETED_MESSAGE_POS2
                return encoded_response
            else:
                return "wrong message"

        except (ConnectionResetError, OSError) as e:
            print(e)