def pose(self, frame_id): """ Take pose of a specific keyframe :param frame_id: id of the frame """ assert frame_id > 0 frame_id -= 1 try: frame = copy.deepcopy(self.current.anim[frame_id]) except IndexError: self.log.warn("Keyframe %s existiert nicht!" % (frame_id + 1)) return False frame['duration'] = 1.0 frame['pause'] = 0.0 anim = {'name': 'record-pose', 'keyframes': [frame] } self.log.info("Trying to pose Keyframe %s" % (frame_id + 1)) try: animation.Animator( animation.parse(anim), self.ipc.get_pose()).play(self.ipc, recordflag=True) except NotControlableError: self.log.warn("Motion meldete keine Kontrolle!") return False return True
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
def execute_play(self, anim_dict): """ Try to move the robot according to given data The operation might fail if it is not possible to control the Robot :param anim_dict: Animation data (as dict) :return: Success of the operation """ success = True try: animation.Animator( animation.parse(anim_dict), self.ipc.get_pose()).play(self.ipc, recordflag=True) except NotControlableError: self.log.warn("Motion meldete keine Kontrolle!") success = False return success
def __play_animation(name, ipc, callback=None): """ Spielt eine Animation ab Wenn IPC gesperrt ist wird false zurückgegeben und die Animation nicht Ausgeführt, sonst True. Animation läuft dann im hintergrund """ old_callback = None if isinstance(name, (tuple, list)) and len(name) == 2: name, old_callback = name debug.warning("Use of deprecated callback in play_animation") if not ipc.controlable: debug.log("Verweigere Animation für '%s', da ipc not controllable meldet" % name) return False elif ipc.get_state() == STATE_ANIMATION_RUNNING: debug.log("Verweigere Animation für '%s', da bereits eine animation läuft" % name) return False # Animation laden filename = find_animation(name) with open(filename) as fp: info = json.load(fp) if "hands" in info: if info["hands"] == "yes" and not CONFIG["hands"]: debug.warning("Versuche Animatione %s abzuspielen: Diese Animation \ benötigt Hände" % name) return False elif info["hands"] == "no" and CONFIG["hands"]: debug.warning("Versuche Animatione %s abzuspielen: Diese Animation \ funktioniert nicht mit Händen" % name) return False anim = animation.parse(info) def play(callback): if not ipc.controlable or ipc.get_state() == STATE_ANIMATION_RUNNING: debug.log("Führe Animations-Callback aus") callback(False) return with ipc.force: try: debug.log("Spiele Animation %s..." % name) animation.Animator(anim, ipc.get_pose()).play(ipc) debug.log("Animation %s fertig." % name) if callback: debug.log("Führe Animations-Callback aus") callback(True) except: debug.log("Animation %s wurde durch einen Fehler unterprochen" % name) if callback: debug.log("Führe Animations-Callback aus") callback(False) debug.log("Starte Animationsthread für %s" % name) thread = threading.Thread(target=play, args=(callback,)) thread.daemon = True thread.start() if old_callback: debug.log("Führe Animations-Callback aus") old_callback() return True