def preempt(self):
     rospy.loginfo("Executer Server: got preempt")
     if self.sm:
         self.sm.request_preempt()
     result = ExecuteResult()
     result.retval = result.RETVAL_SUCCESS
     result.outcome = 'preempted'
     self.actionlib_server.set_preempted(result)
 def preempt(self):
      rospy.loginfo("Executer Server: got preempt")
      if self.sm:
          self.sm.request_preempt()
      result = ExecuteResult()
      result.retval = result.RETVAL_SUCCESS
      result.outcome = 'preempted'
      self.actionlib_server.set_preempted(result)
    def execute(self, goal):
        rospy.loginfo('Got goal:\n %s' % str(goal))

        # parse the json string
        try:
            action_dict = json.loads(goal.action)
        except KeyError as e:
            rospy.logerr('Unable to parse json string (%s)' % str(e))
            result = ExecuteResult()
            result.retval = result.RETVAL_PARSE_ERROR
            result.error_string = str(e)
            self.actionlib_server.set_succeeded(result)
            return

        # execute the action
        try:
            (outcome, outputs) = self.execute_action(action_dict)
        except ValueError as e:
            rospy.logerr('Runtime error while executing state machine: %s' %
                         str(e))
            traceback.print_exc()
            result = ExecuteResult()
            result.retval = result.RETVAL_RUNTIME_ERROR
            result.error_string = str(e)
            self.actionlib_server.set_succeeded(result)
            return
        except Exception as e:
            rospy.logerr('General error while executing state machine: %s' %
                         str(e))
            traceback.print_exc()
            result = ExecuteResult()
            result.retval = result.RETVAL_RUNTIME_ERROR
            result.error_string = str(e)
            self.actionlib_server.set_aborted(result)
            return

        # set_preempted is done in the preempted callback function
        if self.actionlib_server.is_preempt_requested():
            return

        # finished successfully (even though the action itself may have failed)
        result = ExecuteResult()
        result.retval = result.RETVAL_SUCCESS
        if outputs:
            try:
                result.outputs = json.dumps(outputs)
            except Exception as e:
                rospy.logerr("Unable to dump outputs to json string: %s" %
                             str(e))
        result.outcome = outcome
        self.actionlib_server.set_succeeded(result)
        return
    def execute(self, goal):
        rospy.loginfo('Got goal:\n %s' % str(goal))

        # parse the json string
        try:
            action_dict = json.loads(goal.action)
        except KeyError as e:
            rospy.logerr('Unable to parse json string (%s)' % str(e))
            result = ExecuteResult()
            result.retval = result.RETVAL_PARSE_ERROR
            result.error_string = str(e)
            self.actionlib_server.set_succeeded(result)
            return

        # execute the action
        try:
            (outcome, outputs) = self.execute_action(action_dict)
        except ValueError as e:
            rospy.logerr('Runtime error while executing state machine: %s' % str(e))
            traceback.print_exc()
            result = ExecuteResult()
            result.retval = result.RETVAL_RUNTIME_ERROR
            result.error_string = str(e)
            self.actionlib_server.set_succeeded(result)
            return
	except Exception as e:
            rospy.logerr('General error while executing state machine: %s' % str(e))
            traceback.print_exc()
            result = ExecuteResult()
            result.retval = result.RETVAL_RUNTIME_ERROR
            result.error_string = str(e)
            self.actionlib_server.set_aborted(result)
            return

        # set_preempted is done in the preempted callback function
        if self.actionlib_server.is_preempt_requested():
            return

        # finished successfully (even though the action itself may have failed)
        result = ExecuteResult()
        result.retval = result.RETVAL_SUCCESS
        if outputs:
            try:
                result.outputs = json.dumps(outputs)
            except Exception as e:
                rospy.logerr("Unable to dump outputs to json string: %s"%str(e))
        result.outcome = outcome
        self.actionlib_server.set_succeeded(result)
        return