bt_action.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 # Author: Anas Abou Allaban
00003 
00004 import rospy
00005 import actionlib
00006 import behavior_tree_core.msg
00007 from abc import ABCMeta, abstractmethod
00008 
00009 
00010 class BTAction:
00011     __metaclass__ = ABCMeta
00012     _feedback = behavior_tree_core.msg.BTFeedback()
00013     _result = behavior_tree_core.msg.BTResult()
00014 
00015     def __init__(self, name):
00016         # Behavior tree action server
00017         self._action_name = name
00018         self._as = actionlib.SimpleActionServer(self._action_name, behavior_tree_core.msg.BTAction,
00019                                                 execute_cb=self.execute_cb, auto_start=False)
00020         self._as.start()
00021         rospy.loginfo("{} Server Started".format(self._action_name))
00022 
00023     @abstractmethod
00024     def execute_cb(self, goal):
00025         raise NotImplementedError()
00026 
00027     def set_status(self, status):
00028         if status:
00029             self._feedback.status = 1
00030             self._result.status = self._feedback.status
00031             rospy.loginfo('Action %s: Succeeded' % self._action_name)
00032             self._as.set_succeeded(self._result)
00033         else:
00034             self._feedback.status = 2
00035             self._result.status = self._feedback.status
00036             rospy.loginfo('Action %s: Failed' % self._action_name)
00037             self._as.set_succeeded(self._result)


behavior_tree_leaves
Author(s): Michele Colledanchise
autogenerated on Thu Jun 6 2019 18:19:15