Go to the documentation of this file.00001
00002
00003
00004 import rospy
00005
00006 import actionlib
00007
00008 import behavior_tree_core.msg
00009
00010
00011
00012
00013 class BTAction(object):
00014
00015 _feedback = behavior_tree_core.msg.BTFeedback()
00016 _result = behavior_tree_core.msg.BTResult()
00017
00018 def __init__(self, name):
00019 self._action_name = name
00020 self._as = actionlib.SimpleActionServer(self._action_name, behavior_tree_core.msg.BTAction, execute_cb=self.execute_cb, auto_start = False)
00021 self._as.start()
00022
00023 def execute_cb(self, goal):
00024
00025
00026 rospy.loginfo('Checking Condition')
00027
00028 self.set_status('FAILURE')
00029
00030
00031
00032 def set_status(self,status):
00033 if status == 'SUCCESS':
00034 self._feedback.status = 1
00035 self._result.status = self._feedback.status
00036 rospy.loginfo('Action %s: Succeeded' % self._action_name)
00037 self._as.set_succeeded(self._result)
00038 elif status == 'FAILURE':
00039 self._feedback.status = 2
00040 self._result.status = self._feedback.status
00041 rospy.loginfo('Action %s: Failed' % self._action_name)
00042 self._as.set_succeeded(self._result)
00043 else:
00044 rospy.logerr('Action %s: has a wrong return status' % self._action_name)
00045
00046
00047
00048 if __name__ == '__main__':
00049 rospy.init_node('condition')
00050 BTAction(rospy.get_name())
00051 rospy.spin()