Esempio n. 1
0
    def run(self):
        control = gcc()
        contLoop = 0

        while True and not self.killMyself:
            with self.lock:
                self.alive = True
                if self.newAngle != self.angle:
                    self.angle = self.newAngle
                    self.initAngle = self.actualAngle

                if self.actualAngle == self.initAngle:
                    control.moveRightEyelid(self.angle)

                # If we already are where we wanted, done
                if round(self.actualAngle) == self.angle:
                    break

                # Sometimes it never ends this loop, this is a security loop breaker
                if contLoop == 50:
                    break
                contLoop += 1

            sleep(0.1)

        self.alive = False
        self.killMyself = False
Esempio n. 2
0
    def run(self):
        control = gcc()
        securityLoop = 200
        contLoop = 0  # sometimes we get an infinite loop, sometimes. Still need to be solved

        while True and not self.killMyself:
            with self.lock:
                self.alive = True
                if self.newAngle != self.angle:
                    self.angle = self.newAngle
                    self.initAngle = self.actualAngle

                if self.actualAngle == self.initAngle:
                    control.movePairEyelid(self.angle)

                contLoop += 1
                if contLoop > securityLoop:
                    break

                if round(self.actualAngle) == self.angle:
                    break
            sleep(0.1)

        self.alive = False
        self.killMyself = False
Esempio n. 3
0
    def run(self):
        control = gcc()
        securityLoop = 200
        contLoop = 0  #sometimes we get an infinite loop, sometimes. Still need to be solved

        while True and not self.killMyself:
            with self.lock:
                self.alive = True
                if self.newAngle != self.angle:
                    self.angle = self.newAngle
                    self.initAngle = self.actualAngle

                if self.actualAngle == self.initAngle:
                    control.movePairEyelid(self.angle)

                contLoop += 1
                if contLoop > securityLoop:
                    break

                if round(self.actualAngle) == self.angle:
                    break
            sleep(0.1)

        self.alive = False
        self.killMyself = False
Esempio n. 4
0
    def run(self):
        control = gcc()
        contLoop = 0

        while True and not self.killMyself:
            with self.lock:
                self.alive = True
                if self.newAngle != self.angle:
                    self.angle = self.newAngle
                    self.initAngle = self.actualAngle

                if self.actualAngle == self.initAngle:
                    control.moveRightEyelid(self.angle)

            #If we already are where we wanted, done
                if round(self.actualAngle) == self.angle:
                    break

#Sometimes it never ends this loop, this is a security loop breaker
                if contLoop == 50:
                    break
                contLoop += 1

            sleep(0.1)

        self.alive = False
        self.killMyself = False
Esempio n. 5
0
    def run(self):
        control = gcc()

        with self.lock:
            initPosX = self.actualPosX
            initPosY = self.actualPosY

        lastPosX = -1000
        lastPosY = -1000

        cont = 0
        contLoop = 0

        while True and not self.killMyself:
            with self.lock:
                if self.pan_pos == -1000:
                    self.alive = False
                    self.killMyself = True
                else:

                    self.alive = True

                    # We check whether the movement have been finished or not, so if the last five movements
                    # are the same, is because it reached the end point.
                    if lastPosX == self.actualPosX and lastPosY == self.actualPosY:
                        cont += 1
                        if cont >= 5:
                            self.pan_pos = -1000
                            contLoop = 0
                            cont = 0

                    if not self.ordenEjecutada:

                        self.ordenEjecutada = True

                        move = {}
                        move["pan_position"] = self.pan_pos
                        move["pan_speed"] = self.pan_speed
                        move["tilt_position"] = self.tilt_pos
                        move["tilt_speed"] = self.tilt_speed

                        control.headServosPut(move)

                    lastPosX = self.actualPosX
                    lastPosY = self.actualPosY

            sleep(0.1)

        self.alive = False
        self.killMyself = False
Esempio n. 6
0
    def run(self):
        control = gcc()

        with self.lock:
            initPosX = self.actualPosX
            initPosY = self.actualPosY

        lastPosX = -1000
        lastPosY = -1000

        cont = 0
        contLoop = 0

        while True and not self.killMyself:
            with self.lock:
                if self.pan_pos == -1000:
                    self.alive = False
                    self.killMyself = True
                else:

                    self.alive = True

                    #We check whether the movement have been finished or not, so if the last five movements
                    # are the same, is because it reached the end point.
                    if lastPosX == self.actualPosX and lastPosY == self.actualPosY:
                        cont += 1
                        if cont >= 5:
                            self.pan_pos = -1000
                            contLoop = 0
                            cont = 0

                    if not self.ordenEjecutada:

                        self.ordenEjecutada = True

                        move = {}
                        move["pan_position"] = self.pan_pos
                        move["pan_speed"] = self.pan_speed
                        move["tilt_position"] = self.tilt_pos
                        move["tilt_speed"] = self.tilt_speed

                        control.headServosPut(move)

                    lastPosX = self.actualPosX
                    lastPosY = self.actualPosY

            sleep(0.1)

        self.alive = False
        self.killMyself = False
Esempio n. 7
0
    def run(self):
        headThread = None
        leftEyeThread = None
        rightEyeThread = None
        relativeHeadThread = None
        EyesThread = None
        m = mouth()

        control = gcc()

        for move in self.cmdList:
            runningThreads = []

            moveList = move.split(" ")

            relativeHeadThread = None

            for i in range(0, len(moveList) - 1):
                if moveList[i] == "l":  # LEFT EYE
                    angle = self.getNumber(moveList[i + 1])

                    if leftEyeThread == None:
                        leftEyeThread = ThreadMoveLeftEye()

                    leftEyeThread.set(angle)
                    runningThreads.append(leftEyeThread)

                    if not leftEyeThread.is_alive():
                        leftEyeThread.imBack()
                        leftEyeThread.start()

                    i += 2
                elif moveList[i] == "r":  # RIGHT EYE
                    angle = self.getNumber(moveList[i + 1])

                    if rightEyeThread == None:
                        rightEyeThread = ThreadMoveRightEye()

                    rightEyeThread.set(angle)
                    runningThreads.append(rightEyeThread)

                    if not rightEyeThread.is_alive():
                        rightEyeThread.imBack()
                        rightEyeThread.start()

                    i += 2
                elif moveList[i] == "e":  # BOTH EYES
                    angle = self.getNumber(moveList[i + 1])

                    if EyesThread == None:
                        EyesThread = ThreadMoveEyes()

                    EyesThread.set(angle)
                    runningThreads.append(EyesThread)

                    if not EyesThread.is_alive():
                        EyesThread.imBack()
                        EyesThread.start()

                    i += 2

                elif moveList[i] == "h":  # HEAD
                    pan_pos = self.getNumber(moveList[i + 1])
                    tilt_pos = self.getNumber(moveList[i + 2])
                    pan_speed = self.getNumber(moveList[i + 3])
                    tilt_speed = self.getNumber(moveList[i + 4])

                    if headThread == None:
                        headThread = ThreadMoveHead()

                    headThread.set(pan_pos, pan_speed, tilt_pos, tilt_speed)
                    runningThreads.append(headThread)

                    if not headThread.is_alive():
                        headThread.imBack()
                        headThread.start()

                    i += 5
                elif moveList[i] == "v":  # RELATIVE HEAD
                    pan_pos = self.getNumber(moveList[i + 1])
                    tilt_pos = self.getNumber(moveList[i + 2])
                    pan_speed = self.getNumber(moveList[i + 3])
                    tilt_speed = self.getNumber(moveList[i + 4])

                    if relativeHeadThread == None:
                        relativeHeadThread = ThreadMoveRelativeHead()

                    relativeHeadThread.set(pan_pos, pan_speed, tilt_pos, tilt_speed)
                    runningThreads.append(relativeHeadThread)

                    if not relativeHeadThread.is_alive():
                        relativeHeadThread.imBack()
                        relativeHeadThread.start()

                    i += 5
                elif moveList[i] == "w":  # WAIT
                    time = self.getNumber(moveList[i + 1])

                    if str(time) == "-1":
                        for thread in runningThreads:
                            thread.join()

                        runningThreads = []

                    else:
                        sleep(time)

                    i += 2
                elif moveList[i] == "s":  # SPEAK
                    sentence = ""
                    i += 1

                    while True:
                        w = moveList[i]
                        if w.endswith("]"):
                            w = w.replace("]", "")
                            sentence = sentence + " " + w
                            break

                        sentence = sentence + " " + w
                        i += 1

                    say = Speak(sentence)
                    say.start()
                    runningThreads.append(say)

                    i += 2

                elif moveList[i] == "x":  # OTHER FACE
                    expression = moveList[i + 1]

                    newExp = MainThread(expression)
                    newExp.start()

                    i += 2
                elif moveList[i] == "o":  # MOUTH
                    if moveList[i + 1] == "smile":
                        a = m.changeMouth(0)
                    elif moveList[i + 1] == "none":
                        a = m.changeMouth(13)
                    elif moveList[i + 1] == "sad":
                        a = m.changeMouth(1)
                    elif moveList[i + 1] == "puckerRight":
                        a = m.changeMouth(3)
                    elif moveList[i + 1] == "puckerLeft":
                        a = m.changeMouth(4)
                    elif moveList[i + 1] == "straight":
                        a = m.changeMouth(5)
                    elif moveList[i + 1] == "smallMouth":
                        a = m.changeMouth(6)
                    elif moveList[i + 1] == "surprise":
                        a = m.changeMouth(14)
                    elif moveList[i + 1] == "regular":
                        a = m.changeMouth(15)
                    elif moveList[i + 1] == "laugh":
                        a = m.changeMouth(7)
                    elif moveList[i + 1] == "laugh2":
                        a = m.changeMouth(8)
                    elif moveList[i + 1] == "laugh3":
                        a = m.changeMouth(9)
                    elif moveList[i + 1] == "laugh4":
                        a = m.changeMouth(10)
                    elif moveList[i + 1] == "laugh5":
                        a = m.changeMouth(11)
                    elif moveList[i + 1] == "tongue":
                        a = m.changeMouth(16)
                    elif moveList[i + 1] == "laugh6":
                        a = m.changeMouth(12)

                    i += 2

            if relativeHeadThread != None:
                relativeHeadThread.die()

        if headThread != None:
            headThread.die()
        if rightEyeThread != None:
            rightEyeThread.die()
        if leftEyeThread != None:
            leftEyeThread.die()
Esempio n. 8
0
    def run(self):
        headThread = None
        leftEyeThread = None
        rightEyeThread = None
        relativeHeadThread = None
        EyesThread = None
        m = mouth()

        control = gcc()

        for move in self.cmdList:
            runningThreads = []

            moveList = move.split(" ")

            relativeHeadThread = None

            for i in range(0, len(moveList) - 1):
                if moveList[i] == "l":  # LEFT EYE
                    angle = self.getNumber(moveList[i + 1])

                    if leftEyeThread == None:
                        leftEyeThread = ThreadMoveLeftEye()

                    leftEyeThread.set(angle)
                    runningThreads.append(leftEyeThread)

                    if not leftEyeThread.is_alive():
                        leftEyeThread.imBack()
                        leftEyeThread.start()

                    i += 2
                elif moveList[i] == "r":  # RIGHT EYE
                    angle = self.getNumber(moveList[i + 1])

                    if rightEyeThread == None:
                        rightEyeThread = ThreadMoveRightEye()

                    rightEyeThread.set(angle)
                    runningThreads.append(rightEyeThread)

                    if not rightEyeThread.is_alive():
                        rightEyeThread.imBack()
                        rightEyeThread.start()

                    i += 2
                elif moveList[i] == "e":  # BOTH EYES
                    angle = self.getNumber(moveList[i + 1])

                    if EyesThread == None:
                        EyesThread = ThreadMoveEyes()

                    EyesThread.set(angle)
                    runningThreads.append(EyesThread)

                    if not EyesThread.is_alive():
                        EyesThread.imBack()
                        EyesThread.start()

                    i += 2

                elif moveList[i] == "h":  # HEAD
                    pan_pos = self.getNumber(moveList[i + 1])
                    tilt_pos = self.getNumber(moveList[i + 2])
                    pan_speed = self.getNumber(moveList[i + 3])
                    tilt_speed = self.getNumber(moveList[i + 4])

                    if headThread == None:
                        headThread = ThreadMoveHead()

                    headThread.set(pan_pos, pan_speed, tilt_pos, tilt_speed)
                    runningThreads.append(headThread)

                    if not headThread.is_alive():
                        headThread.imBack()
                        headThread.start()

                    i += 5
                elif moveList[i] == "v":  # RELATIVE HEAD
                    pan_pos = self.getNumber(moveList[i + 1])
                    tilt_pos = self.getNumber(moveList[i + 2])
                    pan_speed = self.getNumber(moveList[i + 3])
                    tilt_speed = self.getNumber(moveList[i + 4])

                    if relativeHeadThread == None:
                        relativeHeadThread = ThreadMoveRelativeHead()

                    relativeHeadThread.set(pan_pos, pan_speed, tilt_pos,
                                           tilt_speed)
                    runningThreads.append(relativeHeadThread)

                    if not relativeHeadThread.is_alive():
                        relativeHeadThread.imBack()
                        relativeHeadThread.start()

                    i += 5
                elif moveList[i] == "w":  # WAIT
                    time = self.getNumber(moveList[i + 1])

                    if str(time) == "-1":
                        for thread in runningThreads:
                            thread.join()

                        runningThreads = []

                    else:
                        sleep(time)

                    i += 2
                elif moveList[i] == "s":  # SPEAK
                    sentence = ""
                    i += 1

                    while True:
                        w = moveList[i]
                        if w.endswith("]"):
                            w = w.replace("]", "")
                            sentence = sentence + " " + w
                            break

                        sentence = sentence + " " + w
                        i += 1

                    say = Speak(sentence)
                    say.start()
                    runningThreads.append(say)

                    i += 2

                elif moveList[i] == "x":  # OTHER FACE
                    expression = moveList[i + 1]

                    newExp = MainThread(expression)
                    newExp.start()

                    i += 2
                elif moveList[i] == "o":  # MOUTH
                    if moveList[i + 1] == 'smile':
                        a = m.changeMouth(0)
                    elif moveList[i + 1] == 'none':
                        a = m.changeMouth(13)
                    elif moveList[i + 1] == 'sad':
                        a = m.changeMouth(1)
                    elif moveList[i + 1] == 'puckerRight':
                        a = m.changeMouth(3)
                    elif moveList[i + 1] == 'puckerLeft':
                        a = m.changeMouth(4)
                    elif moveList[i + 1] == 'straight':
                        a = m.changeMouth(5)
                    elif moveList[i + 1] == 'smallMouth':
                        a = m.changeMouth(6)
                    elif moveList[i + 1] == 'surprise':
                        a = m.changeMouth(14)
                    elif moveList[i + 1] == 'regular':
                        a = m.changeMouth(15)
                    elif moveList[i + 1] == 'laugh':
                        a = m.changeMouth(7)
                    elif moveList[i + 1] == 'laugh2':
                        a = m.changeMouth(8)
                    elif moveList[i + 1] == 'laugh3':
                        a = m.changeMouth(9)
                    elif moveList[i + 1] == 'laugh4':
                        a = m.changeMouth(10)
                    elif moveList[i + 1] == 'laugh5':
                        a = m.changeMouth(11)
                    elif moveList[i + 1] == 'tongue':
                        a = m.changeMouth(16)
                    elif moveList[i + 1] == 'laugh6':
                        a = m.changeMouth(12)

                    i += 2

            if relativeHeadThread != None:
                relativeHeadThread.die()

        if headThread != None:
            headThread.die()
        if rightEyeThread != None:
            rightEyeThread.die()
        if leftEyeThread != None:
            leftEyeThread.die()