async def execute_callback(self, goal_handle):
        """Executes a goal."""
        self._node.get_logger().info('Executing goal...')

        # Append the seeds for the Fibonacci sequence
        feedback_msg = Fibonacci.Feedback()
        feedback_msg.sequence = [0, 1]

        # Start executing the action
        for i in range(1, goal_handle.request.order):
            if goal_handle.is_cancel_requested:
                goal_handle.canceled()
                self._node.get_logger().info('Goal canceled')
                return Fibonacci.Result()

            # Update Fibonacci sequence
            feedback_msg.sequence.append(feedback_msg.sequence[i] + feedback_msg.sequence[i-1])

            self._node.get_logger().info('Publishing feedback: {0}'.format(feedback_msg.sequence))

            # Publish the feedback
            goal_handle.publish_feedback(feedback_msg)

            # Sleep for demonstration purposes
            #time.sleep(0.5)

        goal_handle.succeed()

        # Populate result message
        result = Fibonacci.Result()
        result.sequence = feedback_msg.sequence

        self._node.get_logger().info('Returning result: {0}'.format(result.sequence))

        return result
Exemplo n.º 2
0
    async def execute_callback(self, goal_handle):
        # アクションの実行
        self.get_logger().info('executing...')
        # フィボナッチ数列の初期値0, 1を設定
        msg = Fibonacci.Feedback()
        msg.sequence = [0, 1]

        # フィボナッチ数列を一つずつ追加
        for i in range(1, goal_handle.request.order):
            if goal_handle.is_cancel_requested:
                # アクションのキャンセル
                goal_handle.set_canceled()
                self.get_logger().info('goal canceled')
                return Fibonacci.Result()

            # フィボナッチ数列の更新
            msg.sequence.append(msg.sequence[i] + msg.sequence[i - 1])
            self.get_logger().info('feedback: {0}'.format(msg.sequence))
            # アクションのフィードバックの送信
            goal_handle.publish_feedback(msg)
            # 1秒待機(重たい処理の代わり)
            time.sleep(1)

        # アクションの実行結果の送信
        goal_handle.set_succeeded()
        result = Fibonacci.Result()
        result.sequence = msg.sequence
        self.get_logger().info('result: {0}'.format(result.sequence))
        return result
Exemplo n.º 3
0
    async def execute_callback(self, goal_handle):
        # this is where the actual virtual rail execution code goes

        # Start executing the action
        while True:
            start_time = current_time()

            # check if the goal has been cancelled
            if goal_handle.is_cancel_requested:
                goal_handle.canceled()
                result = Fibonacci.Result()
                result.success = False
                return Fibonacci.Result()

            if path_complete():
                goal_handle.succeed()
                result = Fibonacci.Result()
                result.success = True
                return Fibonacci.Result()

            # Publish a pose to the position controller
            msg=Pose()
            pose.data = calc_position_setpoint(time, percent_complete)
            self.abs_pose_publisher.publish(msg)


            # Publish the feedback, could be current setpoint, percent complete, whatever we need to display in the GUI
            goal_handle.publish_feedback(feedback_msg)

            # Sleep for loop time
            while (current_time() - start_time < loop_time):
                ros.spin_once() # this is te asynchronous bit, allows other call backs to run sunch as cancelling the goal, rejecting incoming goals, basically Python asyncio
Exemplo n.º 4
0
    def execute_callback(self, goal_handle):
        """Executes a goal."""
        try:
            self.get_logger().info('Executing goal...')

            # Append the seeds for the Fibonacci sequence
            feedback_msg = Fibonacci.Feedback()
            feedback_msg.sequence = [0, 1]

            # Start executing the action
            for i in range(1, goal_handle.request.order):
                if goal_handle.is_cancel_requested:
                    goal_handle.canceled()
                    self.get_logger().info('Goal canceled')
                    return Fibonacci.Result()

                # Update Fibonacci sequence
                feedback_msg.sequence.append(feedback_msg.sequence[i] +
                                             feedback_msg.sequence[i - 1])

                self.get_logger().info('Publishing feedback: {0}'.format(
                    feedback_msg.sequence))

                # Publish the feedback
                goal_handle.publish_feedback(feedback_msg)

                # Sleep for demonstration purposes
                time.sleep(1)

            goal_handle.succeed()

            # Populate result message
            result = Fibonacci.Result()
            result.sequence = feedback_msg.sequence

            self.get_logger().info('Returning result: {0}'.format(
                result.sequence))

            return result
        finally:
            with self._goal_queue_lock:
                try:
                    # Start execution of the next goal in the queue.
                    self._current_goal = self._goal_queue.popleft()
                    self.get_logger().info('Next goal pulled from the queue')
                    self._current_goal.execute()
                except IndexError:
                    # No goal in the queue.
                    self._current_goal = None
Exemplo n.º 5
0
    def execute_callback(self, goal_handle):
        """Execute the goal."""
        self.get_logger().info('Executing goal...')

        # Append the seeds for the Fibonacci sequence
        feedback_msg = Fibonacci.Feedback()
        feedback_msg.sequence = [0, 1]

        # Start executing the action
        for i in range(1, goal_handle.request.order):
            # If goal is flagged as no longer active (ie. another goal was accepted),
            # then stop executing
            if not goal_handle.is_active:
                self.get_logger().info('Goal aborted')
                return Fibonacci.Result()

            if goal_handle.is_cancel_requested:
                goal_handle.canceled()
                self.get_logger().info('Goal canceled')
                return Fibonacci.Result()

            # Update Fibonacci sequence
            feedback_msg.sequence.append(feedback_msg.sequence[i] +
                                         feedback_msg.sequence[i - 1])

            self.get_logger().info('Publishing feedback: {0}'.format(
                feedback_msg.sequence))

            # Publish the feedback
            goal_handle.publish_feedback(feedback_msg)

            # Sleep for demonstration purposes
            time.sleep(1)

        goal_handle.succeed()

        # Populate result message
        result = Fibonacci.Result()
        result.sequence = feedback_msg.sequence

        self.get_logger().info('Returning result: {0}'.format(result.sequence))

        return result
Exemplo n.º 6
0
    async def execute_callback(self, goal_handle):
        self.get_logger().info('executing...')
        msg = Fibonacci.Feedback()
        msg.sequence = [0, 1]

        for i in range(1, goal_handle.request.order):
            if goal_handle.is_cancel_requested:
                goal_handle.canceled()
                self.get_logger().info('goal_canceled')
                return Fibonacci.Result()

            msg.sequence.append(msg.sequence[i] + msg.sequence[i - 1])
            self.get_logger().info('feedback:{}'.format(msg.sequence))
            goal_handle.publish_feedback(msg)
            time.sleep(1)  # dummy job

        goal_handle.set_succeeded()

        result = Fibonacci.Result()
        result.sequence = msg.sequence
        self.get_logger().info('result:{}'.format(result.sequence))
        return result