Ejemplo n.º 1
0
 def senseSelectAct(self):
     data = Space.read(self.name, [])
     if len(data) > 0:
         try:
             line = str(data)
             self.putline(line)
         except Exception as e:
             print('disconnected')
             self.stop()
Ejemplo n.º 2
0
 def senseSelectAct(self):
     forward = Space.read(self.nameForward,0)
     turn = Space.read(self.nameTurn,0)
     if turn < 0: # to left
         self.left_motor.run(HAT.BACKWARD)
         self.right_motor.run(HAT.FORWARD)
     elif turn > 0: # to right
         self.left_motor.run(HAT.FORWARD)
         self.right_motor.run(HAT.BACKWARD)
     elif forward > 0: # forward
         self.left_motor.run(HAT.FORWARD)
         self.right_motor.run(HAT.FORWARD)
     elif forward < 0: # backward
         self.left_motor.run(HAT.BACKWARD)
         self.right_motor.run(HAT.BACKWARD)
     else:
         self.left_motor.run(HAT.RELEASE)
         self.right_motor.run(HAT.RELEASE)
Ejemplo n.º 3
0
 def senseSelectAct(self):
     speaking = Space.read(self.name, False)
     if speaking:
         if random.random() < 0.7:
             self.emotions.set('neu')
         else:
             self.emotions.set('sur')
             self.openmouth = True
     else:
         if self.openmouth:
             self.emotions.set('neu')
             self.openmouth = False
Ejemplo n.º 4
0
 def senseSelectAct(self):
     data = Space.read(self.nameJoystick, [[], [0, 0, 0], []])
     if data[1][0] < -5000:  # to left
         Space.write(self.nameForward, 0, validity=0.2, priority=2.0)
         Space.write(self.nameTurn, -1, validity=0.2, priority=2.0)
     elif data[1][0] > 5000:  # to right
         Space.write(self.nameForward, 0, validity=0.2, priority=2.0)
         Space.write(self.nameTurn, 1, validity=0.2, priority=2.0)
     elif data[1][1] < -5000:  # forward
         Space.write(self.nameForward, 1, validity=0.2, priority=2.0)
         Space.write(self.nameTurn, 0, validity=0.2, priority=2.0)
     elif data[1][1] > 5000:  # backward
         Space.write(self.nameForward, -1, validity=0.2, priority=2.0)
         Space.write(self.nameTurn, 0, validity=0.2, priority=2.0)
Ejemplo n.º 5
0
 def senseSelectAct(self):
     data = Space.read(self.nameJoystick, [])
     if data[1][0] < -5000:  # to left
         Space.write(self.nameForward, 0, 0.2)
         Space.write(self.nameTurn, -1, 0.2)
     elif data[1][0] > 5000:  # to right
         Space.write(self.nameForward, 0, 0.2)
         Space.write(self.nameTurn, 1, 0.2)
     elif data[1][1] < -5000:  # forward
         Space.write(self.nameForward, 1, 0.2)
         Space.write(self.nameTurn, 0, 0.2)
     elif data[1][1] > 5000:  # backward
         Space.write(self.nameForward, -1, 0.2)
         Space.write(self.nameTurn, 0, 0.2)
     else:
         Space.write(self.nameForward, 0, 0.2)
         Space.write(self.nameTurn, 0, 0.2)
Ejemplo n.º 6
0
    def senseSelectAct(self):
        global threshold
        frame = Space.read(self.nameImage, None)
        if frame is None:
            cv2.imshow("hough circle", frame)
            return

        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        frame = cv2.blur(frame, (3, 3))
        circles = cv2.HoughCircles(frame,
                                   cv2.HOUGH_GRADIENT,
                                   2,
                                   100,
                                   param1=threshold,
                                   param2=threshold // 2,
                                   minRadius=10,
                                   maxRadius=90)
        found = False
        frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
        if circles is not None:
            for circle in circles[0, :]:
                x = int(circle[0])
                y = int(circle[1])
                r = int(circle[2])
                if r > 0:
                    cv2.circle(frame, (x, y), r, (0, 0, 255), 2)
                    cv2.circle(frame, (x, y), 2, (0, 0, 255), cv2.FILLED)
                    found = True
                    found_x = x
                    found_y = y
                    found_radius = r
                    break

        if found:
            #print('found',found_x,found_y,found_radius)
            Space.write(self.nameBall, [found_x, found_y, found_radius], 0.5)
        else:
            #print('ball not recognized, threshold:',threshold)
            pass

        cv2.imshow("hough circle", frame)
        key = cv2.waitKey(1)
        if key == ord('s'):
            cv2.imwrite('houghCircle.png', frame)
Ejemplo n.º 7
0
 def senseSelectAct(self):
     text = Space.read(self.name, '')
     text = text.lower()
     text = str(
         unicodedata.normalize('NFKD', text).encode('ASCII', 'ignore'))
     if len(text) <= 0 or text == "b'connect'":
         return
     print(text[2:-1])
     responses = self.chatbot_agent.handle_text(text)
     if responses:
         speak(responses[0]["text"])
         print("\n")
         if (responses[0]["text"]
                 == "Dobre, daj mi prosím chvíľu aby som sa to naučil"
                 or responses[0]["text"] ==
                 "Malý moment, naučím sa to a nanovo načítam svoju neurónovú sieť"
             ):
             time.sleep(12)
             self.chatbot_agent = self.loadChatbot()
Ejemplo n.º 8
0
 def command(self):
     text = Space.read(self.name, '')
     Space.write(self.name, '')
     text = text.lower().strip()
     return text
Ejemplo n.º 9
0
 def senseSelectAct(self):
     data = Space.read(self.name, [])
     print(data)
Ejemplo n.º 10
0
 def command(self):
     self.text = Space.read(self.name, '')
     Space.write(self.name, '')
     self.text = self.text.lower().strip()
     return self.text