예제 #1
0
 def setUpClass(self):
     self.session = qi.Session()
     self.session.connect('tcp://192.168.1.101:9559')
     self.motion = self.session.service('ALMotion')
     self.posture = self.session.service("ALRobotPosture")
     self.animation_player = AnimationPlayer(self.session,
                                             motion=self.motion)
     self.motion.setCollisionProtectionEnabled('Arms', False)
     self.motion.setExternalCollisionProtectionEnabled('All', False)
     rest_position(session=self.session)
예제 #2
0
 def testAnimationPlayerLayer(self):
     loop = 10
     config = Config.load(Version.PROGRAM_UNIXSTYLE_NAME + ".ini",
                          setAsDefault=True)
     self.e = GameEngine(config)
     animPlayer = AnimationPlayer(
         framerate,
         self.path,
         self.basename, (self.e.view.geometry[2], self.e.view.geometry[3]),
         loop=loop)
     print "Rendering as a GameEngine Layer for %d loops." % loop
     self.e.view.pushLayer(animPlayer)
     startTime = pygame.time.get_ticks()
     while not animPlayer.finished:
         self.e.run()
     stopTime = pygame.time.get_ticks()
     totalTime = stopTime - startTime
     print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
           (animPlayer.nbrFrames, loop, totalTime/1000.0, \
            (float(1000.0*animPlayer.nbrFrames*(loop+1)) / float(totalTime)))
     self.e.view.popLayer(animPlayer)
     self.e.quit()
예제 #3
0
class PointMoveTest(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.session = qi.Session()
        self.session.connect('tcp://192.168.1.101:9559')
        self.motion = self.session.service('ALMotion')
        self.posture = self.session.service("ALRobotPosture")
        self.animation_player = AnimationPlayer(self.session,
                                                motion=self.motion)
        self.motion.setCollisionProtectionEnabled('Arms', False)
        self.motion.setExternalCollisionProtectionEnabled('All', False)
        rest_position(session=self.session)

    def test_reaction_won(self):
        self.animation_player.play_win_animation()

    def test_reaction_lost(self):
        self.animation_player.play_lose_animation()

    def test_reaction_draw(self):
        self.animation_player.play_draw_animation()
예제 #4
0
    def testAnimationPlayerSlave(self):
        loop = 5
        winWidth, winHeight = 800, 600
        pygame.init()
        flags = DOUBLEBUF | OPENGL | HWPALETTE | HWSURFACE
        pygame.display.set_mode((winWidth, winHeight), flags)
        animPlayer = AnimationPlayer(framerate,
                                     self.path,
                                     self.basename, (winWidth, winHeight),
                                     loop=loop)
        glViewport(0, 0, winWidth, winHeight)  # Both required as...
        glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
        glClearColor(0, 0, 0, 1.)
        print "Rendering independently and fullscreen for %d loops." % loop
        clock = pygame.time.Clock()
        startTime = pygame.time.get_ticks()
        while not animPlayer.finished:
            ticks = clock.get_time()
            animPlayer.run(ticks)
            animPlayer.render()
            pygame.display.flip()
            clock.tick()
        stopTime = pygame.time.get_ticks()
        totalTime = stopTime - startTime
        print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
              (animPlayer.nbrFrames, loop, totalTime/1000.0,
               1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))

        # Testing animation change
        # FIXME: another set of files would be more relevant (e.g. diff. resolution)
        loop = 5
        print "Let's go for another ride of %d loops." % loop
        animPlayer.loop = loop
        animPlayer.loadAnimation(self.path, self.basename)
        startTime = pygame.time.get_ticks()
        while not animPlayer.finished:
            ticks = clock.get_time()
            animPlayer.run(ticks)
            animPlayer.render()
            pygame.display.flip()
            clock.tick()
        stopTime = pygame.time.get_ticks()
        totalTime = stopTime - startTime
        print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
              (animPlayer.nbrFrames, loop, totalTime/1000.0,
               1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))
        pygame.quit()
예제 #5
0
    def testAnimationPlayerSlaveShowOff(self):
        winWidth, winHeight = 500, 500
        loop = 4
        pygame.init()
        flags = DOUBLEBUF | OPENGL | HWPALETTE | HWSURFACE
        pygame.display.set_mode((winWidth, winHeight), flags)
        animPlayer = AnimationPlayer(framerate,
                                     self.path,
                                     self.basename, (winWidth, winHeight),
                                     loop=loop)
        print "Rendering ourselves, doing what we want with the texture, for %d loops." % loop
        glViewport(0, 0, winWidth, winHeight)  # Both required as...
        glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
        glClearColor(0, 0, 0, 1.)
        x, y = 0.0, 1.0
        fx, fy, ftheta = 1, 1, 1
        theta = 0.0
        time = 0.0
        clock = pygame.time.Clock()
        startTime = pygame.time.get_ticks()
        while not animPlayer.finished:
            ticks = clock.get_time()
            animPlayer.run(ticks)
            texture = animPlayer.getTexture()
            # Save and clear both transformation matrices
            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            glLoadIdentity()

            glClear(GL_COLOR_BUFFER_BIT)
            glColor3f(1., 1., 1.)
            glBindTexture(GL_TEXTURE_2D, texture)
            glTranslatef(x, y, 0)
            glRotatef(theta, 0, 0, 1.)
            glScalef(.5, .5, 1.)
            glCallList(animPlayer.animList)

            # Restore both transformation matrices
            glPopMatrix()
            glMatrixMode(GL_PROJECTION)
            glPopMatrix()

            pygame.display.flip()

            x = (x + fx * time)
            y = (y + fy * time)
            theta = theta + ftheta
            if x > 1.0 or x < -1.0:
                fx = fx * -1
            if y > 1.0 or y < -1.0:
                fy = fy * -1
            if theta > 90 or theta < -90:
                ftheta = ftheta * -1
            time = time + 0.00001
            clock.tick(60)
        stopTime = pygame.time.get_ticks()
        totalTime = stopTime - startTime
        print "nbrFrames: %d, nbrLoops %d, Total time: %.02f s, Average fps: %.02f" % \
              (animPlayer.nbrFrames, loop, totalTime/1000.0, \
               (float(1000.0*animPlayer.nbrFrames*(loop+1)) / float(totalTime)))

        pygame.quit()
예제 #6
0
  def testAnimationPlayerSlave(self):
    loop = 5
    winWidth, winHeight = 800, 600
    pygame.init()
    flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
    pygame.display.set_mode((winWidth, winHeight), flags)
    animPlayer = AnimationPlayer(framerate, self.path, self.basename,
                                 (winWidth, winHeight), loop = loop)
    glViewport(0, 0, winWidth, winHeight) # Both required as...
    glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
    glClearColor(0, 0, 0, 1.)
    print "Rendering independently and fullscreen for %d loops." % loop
    clock = pygame.time.Clock()
    startTime = pygame.time.get_ticks()
    while not animPlayer.finished:
      ticks = clock.get_time()
      animPlayer.run(ticks)
      animPlayer.render()
      pygame.display.flip()
      clock.tick()
    stopTime = pygame.time.get_ticks()
    totalTime = stopTime - startTime
    print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
          (animPlayer.nbrFrames, loop, totalTime/1000.0,
           1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))

    # Testing animation change
    # FIXME: another set of files would be more relevant (e.g. diff. resolution)
    loop = 5
    print "Let's go for another ride of %d loops." % loop
    animPlayer.loop = loop
    animPlayer.loadAnimation(self.path, self.basename)
    startTime = pygame.time.get_ticks()
    while not animPlayer.finished:
      ticks = clock.get_time()
      animPlayer.run(ticks)
      animPlayer.render()
      pygame.display.flip()
      clock.tick()
    stopTime = pygame.time.get_ticks()
    totalTime = stopTime - startTime
    print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
          (animPlayer.nbrFrames, loop, totalTime/1000.0,
           1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))
    pygame.quit()
예제 #7
0
  def testAnimationPlayerSlaveShowOff(self):
    winWidth, winHeight = 500, 500
    loop = 4
    pygame.init()
    flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
    pygame.display.set_mode((winWidth, winHeight), flags)
    animPlayer = AnimationPlayer(framerate, self.path, self.basename,
                                 (winWidth, winHeight), loop = loop)
    print "Rendering ourselves, doing what we want with the texture, for %d loops." % loop
    glViewport(0, 0, winWidth, winHeight) # Both required as...
    glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
    glClearColor(0, 0, 0, 1.)
    x, y = 0.0, 1.0
    fx, fy, ftheta = 1, 1, 1
    theta = 0.0
    time = 0.0
    clock = pygame.time.Clock()
    startTime = pygame.time.get_ticks()
    while not animPlayer.finished:
      ticks = clock.get_time()
      animPlayer.run(ticks)
      texture = animPlayer.getTexture()
      # Save and clear both transformation matrices
      glMatrixMode(GL_PROJECTION)
      glPushMatrix()
      glLoadIdentity()
      glMatrixMode(GL_MODELVIEW)
      glPushMatrix()
      glLoadIdentity()

      glClear(GL_COLOR_BUFFER_BIT)
      glColor3f(1., 1., 1.)
      glBindTexture(GL_TEXTURE_2D, texture)
      glTranslatef(x, y, 0)
      glRotatef(theta, 0, 0, 1.)
      glScalef(.5, .5, 1.)
      glCallList(animPlayer.animList)

      # Restore both transformation matrices
      glPopMatrix()
      glMatrixMode(GL_PROJECTION)
      glPopMatrix()

      pygame.display.flip()

      x = (x + fx*time)
      y = (y + fy*time)
      theta = theta + ftheta
      if x > 1.0 or x < -1.0:
        fx = fx * -1
      if y > 1.0 or y < -1.0:
        fy = fy * -1
      if theta > 90 or theta < -90:
        ftheta = ftheta * -1
      time = time + 0.00001
      clock.tick(60)
    stopTime = pygame.time.get_ticks()
    totalTime = stopTime - startTime
    print "nbrFrames: %d, nbrLoops %d, Total time: %.02f s, Average fps: %.02f" % \
          (animPlayer.nbrFrames, loop, totalTime/1000.0, \
           (float(1000.0*animPlayer.nbrFrames*(loop+1)) / float(totalTime)))
    
    pygame.quit()
예제 #8
0
    def __init__(self, session, ip, motion, leds):
        self.__session = session
        self.__speech = Speech(self.__session)
        self.__showScreen = ShowScreen(self.__session, ip)
        self.__showScreen.show_screen("")
        self.__game = TicTacToe(self.__session, self.__speech,
                                self.__showScreen)
        self.__moveReader = MoveReader(self.__session, self.__game)
        self.__speechDetection = SpeechDetection(self.__session,
                                                 ["Let's Play", "Stop"],
                                                 self.speech_callback)
        self.__animationPlayer = AnimationPlayer(self.__session, motion)
        self.__waiting_game_start = 1
        self.__playing = 1
        self.__program_running = 1
        self.__motion = motion
        self.__leds = leds
        while self.__program_running:
            while self.__waiting_game_start:
                # Add the following for starting on Enter
                #input = raw_input('Say ´lets play´ or press enter to start a game.')
                #if input == "":
                #    self.__speechDetection.unsubscribe()
                #    self.look_at_player_and_say("Okay, Let's do this!", False)
                #    self.__waiting_game_start = 0
                #    self.__showScreen.show_screen("")
                #    self.__game.restart()
                #    self.__playing = 1
                pass
            while self.__playing:
                delta = 0
                self.__speech.say("Now make your move")
                while delta != 1:
                    time.sleep(0.5)
                    delta = self.__moveReader.read_move()
                    if delta > 1:
                        self.look_at_player_and_say(
                            "Too many moves detected! Restore my image board",
                            True)
                        time.sleep(1)

                self.__showScreen.show_screen(self.__game.get_url_params())
                print self.__game.get_url_params()

                delta2 = 1
                while delta2 != 0:
                    delta2 = self.__moveReader.check_correct_board()
                    if delta2 > 0:
                        self.look_at_player_and_say("Wrong move.", True)
                        self.__game.say_move(self.__game.move_player2)
                    time.sleep(1)

                self.__playing = self.__game.player_won() == 0
            winner = self.__game.player_won()
            if winner == 3:
                self.__animationPlayer.play_draw_animation()
            if winner == 2:
                self.__animationPlayer.play_win_animation()
            if winner == 1:
                self.__animationPlayer.play_lose_animation()
            print "End of Game"
            self.__waiting_game_start = 1
            self.__playing = 1
            self.__speechDetection = SpeechDetection(self.__session,
                                                     ["Let's Play", "Stop"],
                                                     self.speech_callback)
        self.__speechDetection.unsubscribe()
예제 #9
0
class GameHandler(object):
    def __init__(self, session, ip, motion, leds):
        self.__session = session
        self.__speech = Speech(self.__session)
        self.__showScreen = ShowScreen(self.__session, ip)
        self.__showScreen.show_screen("")
        self.__game = TicTacToe(self.__session, self.__speech,
                                self.__showScreen)
        self.__moveReader = MoveReader(self.__session, self.__game)
        self.__speechDetection = SpeechDetection(self.__session,
                                                 ["Let's Play", "Stop"],
                                                 self.speech_callback)
        self.__animationPlayer = AnimationPlayer(self.__session, motion)
        self.__waiting_game_start = 1
        self.__playing = 1
        self.__program_running = 1
        self.__motion = motion
        self.__leds = leds
        while self.__program_running:
            while self.__waiting_game_start:
                # Add the following for starting on Enter
                #input = raw_input('Say ´lets play´ or press enter to start a game.')
                #if input == "":
                #    self.__speechDetection.unsubscribe()
                #    self.look_at_player_and_say("Okay, Let's do this!", False)
                #    self.__waiting_game_start = 0
                #    self.__showScreen.show_screen("")
                #    self.__game.restart()
                #    self.__playing = 1
                pass
            while self.__playing:
                delta = 0
                self.__speech.say("Now make your move")
                while delta != 1:
                    time.sleep(0.5)
                    delta = self.__moveReader.read_move()
                    if delta > 1:
                        self.look_at_player_and_say(
                            "Too many moves detected! Restore my image board",
                            True)
                        time.sleep(1)

                self.__showScreen.show_screen(self.__game.get_url_params())
                print self.__game.get_url_params()

                delta2 = 1
                while delta2 != 0:
                    delta2 = self.__moveReader.check_correct_board()
                    if delta2 > 0:
                        self.look_at_player_and_say("Wrong move.", True)
                        self.__game.say_move(self.__game.move_player2)
                    time.sleep(1)

                self.__playing = self.__game.player_won() == 0
            winner = self.__game.player_won()
            if winner == 3:
                self.__animationPlayer.play_draw_animation()
            if winner == 2:
                self.__animationPlayer.play_win_animation()
            if winner == 1:
                self.__animationPlayer.play_lose_animation()
            print "End of Game"
            self.__waiting_game_start = 1
            self.__playing = 1
            self.__speechDetection = SpeechDetection(self.__session,
                                                     ["Let's Play", "Stop"],
                                                     self.speech_callback)
        self.__speechDetection.unsubscribe()

    def say_reaction(self, reaction_text):
        self.__speech.say(text=reaction_text)
        return True

    def do_animation(self, animation):
        return animation

    def speech_callback(self, value):
        print(value)
        if value[0] == "Let's Play":
            if value[1] > 0.3:
                self.__speechDetection.unsubscribe()
                self.look_at_player_and_say("Okay, Let's do this!", False)
                self.__waiting_game_start = 0
                self.__showScreen.show_screen("")
                self.__game.restart()
        if value[0] == "Stop":
            if value[1] > 0.4:
                self.__playing = 0
                self.__waiting_game_start = 0
                self.__program_running = 0

    def look_at_player_and_say(self, text, warning_led):
        self.__motion.setStiffnesses("Head", 1.0)
        names = ["HeadYaw", "HeadPitch"]
        angles = [78. * almath.TO_RAD, -30. * almath.TO_RAD]
        times = [1., 1.]
        is_absolute = True
        self.__motion.angleInterpolation(names, angles, times, is_absolute)
        if warning_led:
            qi. async (self.rotate_eyes, delay=0)
        self.__speech.say(text=text)
        angles = [0., 0.]
        times = [1., 1.]
        is_absolute = True
        self.__motion.angleInterpolation(names, angles, times, is_absolute)

    def rotate_eyes(self):
        self.__leds.setIntensity('RightFaceLedsRed', 1.0)
        self.__leds.setIntensity('LeftFaceLedsRed', 1.0)
        self.__leds.rotateEyes(16711680, 1, 6)