def _action_receiver(msg): global action_ids actions = _list_actions() rospy.loginfo("[RPpt][AIF] a message is received: '%d', '%s'" % (msg.action_id, msg.name)) rospy.loginfo(actions) if msg.name in actions: action_name = msg.name rospy.loginfo("[RPpt][AIF] start '%s' action" % action_name) try: action = actions[action_name](msg.action_id, msg.dispatch_time, feedback, keyval_to_dict(msg.parameters)) action_ids[msg.action_id] = action if issubclass(action.__class__, ActionSink): action.execute(action_name, **keyval_to_dict(msg.parameters)) else: action.execute(**keyval_to_dict(msg.parameters)) except Exception as e: rospy.logwarn("[RPpt][AIF] action '%s' failed." % msg.name, exc_info=1) feedback.publish( ActionFeedback(msg.action_id, "action failed", dict_to_keyval(None))) elif msg.action_id in action_ids: operation = msg.name rospy.loginfo("[RPpt][AIF] update action '%d', doing '%s'" % (msg.action_id, operation)) if operation == "cancel_action": action_ids[msg.action_id].cancel() elif operation == "pause_action": action_ids[msg.action_id].pause() elif operation == "resume_action": action_ids[msg.action_id].resume() else: rospy.loginfo("[RPpt][AR] no operation")
def _generate_predicate(type_name, **kwargs): new_type_name, is_negative = _is_predicate_negative(type_name) return KnowledgeItem(KB_ITEM_FACT, "", "", new_type_name, dict_to_keyval(kwargs), 0.0, is_negative)
def send_action(name, **kwargs): msg = ActionDispatch() msg.name = name msg.parameters = dict_to_keyval(kwargs) _action_dispatch_publisher.publish(msg)
def _feedback(self, status, info=None): self.feedback_pub.publish( ActionFeedback(self.action_id, status, dict_to_keyval(info)))