Exemplo n.º 1
0
    def retrieve_animation(self, name):
        """ Function to locate and extract animation-data

        First tries locate the file,
        then extracts and returns the data if possible

        :param name: name of the animation
        :return: The retrieved data, empty list if nothing could be retrieved.
        """
        try:
            search = "/home/darwin/%s.json" % name
            filename = find(search)
        except IOError:
            self.log.debug('animation not found in %s ' % search)
            try:
                search = os.path.join(os.path.expanduser('~'), name + ".json")
                filename = find(search)
            except IOError:
                self.log.debug('animation not found in %s ' % search)
                try:
                    filename = find_animation(name)
                except IOError:
                    self.log.warn(
                        "Animation %s konnte nirgendwo gefunden werden!" % name)
                    return False
        self.log.info("Animation unter %s gefunden" % filename)

        data = []
        with open(filename) as fp:
            try:
                data = json.load(fp)
            except ValueError as e:
                self.log.error("Animation %s ist fehlerhaft:\n %s" %
                               (filename, e.message.partition('\n')[0]))
        return data
Exemplo n.º 2
0
    def play_animation(self, ipc, name):
        """ Spiel die Animation *name* ab. Stopt den Roboter vorher, falls nötig"""
        self.log.info("Spiele Animation '%s'" % name)

        filename = find_animation(name)
        with open(filename) as fp:
            info = json.load(fp)

        anim = animation.parse(info)
        try:
            animation.Animator(anim, ipc.get_pose()).play(ipc, recordflag=True)
        except NotControlableError:
            self.log.warn("Motion meldete keine Kontrolle!")
            return False
        self.log.info("Beende Animation '%s'" % name)
        return True