コード例 #1
0
def go_to_waypoint(goal_x=0, goal_y=0, goal_theta=0):
    # Create an action client called "move_base" with action definition file "MoveBaseAction"
    client = actionlib.SimpleActionClient('move_base', MoveBaseAction)

    # Waits until the action server has started up and started listening for goals.
    client.wait_for_server()

    # Creates a new goal with the MoveBaseGoal constructor
    goal = MoveBaseGoal()
    goal.target_pose.header.frame_id = "map"
    goal.target_pose.header.stamp = rospy.Time.now()
    # Move 0.5 meters forward along the x axis of the "map" coordinate frame
    goal.target_pose.pose.position.x = goal_x
    goal.target_pose.pose.position.y = goal_y
    goal.target_pose.pose.position.z = 0
    # No rotation of the mobile base frame w.r.t. map frame
    angle_in_quat = quaternion_from_euler(0, 0, goal_theta)
    goal.target_pose.pose.orientation.x = angle_in_quat[0]
    goal.target_pose.pose.orientation.y = angle_in_quat[1]
    goal.target_pose.pose.orientation.z = angle_in_quat[2]
    goal.target_pose.pose.orientation.w = angle_in_quat[3]

    # Sends the goal to the action server.
    client.send_goal(goal, feedback_cb=fb_callback)
    # Waits for the server to finish performing the action.
    wait = client.wait_for_result()
    # If the result doesn't arrive, assume the Server is not available
    if not wait:
        rospy.logerr("Action server not available!")
        rospy.signal_shutdown("Action server not available!")
    else:
        # Result of executing the action
        return client.get_result()
コード例 #2
0
    def depthAction(self, depth):
        client = actionlib.SimpleActionClient(
            "go_to_depth", riptide_controllers.msg.GoToDepthAction)
        client.wait_for_server()

        # Sends the goal to the action server.
        client.send_goal(riptide_controllers.msg.GoToDepthGoal(depth))
        return client
コード例 #3
0
    def yawAction(self, angle):
        client = actionlib.SimpleActionClient(
            "go_to_yaw", riptide_controllers.msg.GoToYawAction)
        client.wait_for_server()

        # Sends the goal to the action server.
        client.send_goal(riptide_controllers.msg.GoToYawGoal(angle))
        return client
コード例 #4
0
 def _accept_path_from_topic(self, path_msg):
     """
     When receiving a path on a topic, just call our own action server!
     This ensures canceling/aborting/preemption etc behave as they should
     :return: None
     """
     rospy.loginfo("Path received on topic, calling action to execute")
     client = actionlib.SimpleActionClient("follow_path", FollowPathAction)
     client.wait_for_server()
     client.send_goal(FollowPathGoal(path=path_msg))
コード例 #5
0
    def execute(self, userdata):
        rospy.loginfo('{}: Executing state: {}'.format(
            rospy.get_name(), self.__class__.__name__))

        pose = userdata.current_pose.parameters['pose']

        theta, beta, alpha = euler_from_quaternion(
            (pose.orientation.w, pose.orientation.x, pose.orientation.y,
             pose.orientation.z))
        print 'TurnAround current theta: {} {} {}'.format(alpha, beta, theta)
        if theta < 0:
            new_pose = makePose(pose.position.x, pose.position.y,
                                theta + math.pi)
        else:
            new_pose = makePose(pose.position.x, pose.position.y,
                                theta - math.pi)

        answer_id = self.conversation_interface.setAutomaticAnswer(
            'q_current_task', u'niekorzystne warunki pogodowe odwracam się')

        if self.sim_mode == 'sim':
            for i in range(50):
                if self.preempt_requested():
                    self.conversation_interface.removeAutomaticAnswer(
                        answer_id)
                    self.service_preempt()
                    return 'preemption'

                rospy.sleep(0.1)
            self.conversation_interface.removeAutomaticAnswer(answer_id)
            return 'ok'
        else:
            goal = MoveBaseGoal()
            goal.target_pose.pose = new_pose
            goal.target_pose.header.frame_id = 'map'
            goal.target_pose.header.stamp = rospy.Time.now()

            client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
            client.wait_for_server()

            # start moving
            client.send_goal(goal, self.move_base_done_cb,
                             self.move_base_active_cb,
                             self.move_base_feedback_cb)

            # action_feedback = GoActionFeedback()
            # action_result = GoActionResult()
            # action_result.result.is_goal_accomplished = False
            # userdata.nav_result = action_result.result

            start_time = rospy.Time.now()

            self.is_goal_achieved = False
            while self.is_goal_achieved == False:
                # action_feedback.feedback.current_pose = self.current_pose

                # userdata.nav_feedback = action_feedback.feedback
                # userdata.nav_actual_pose = self.current_pose

                end_time = rospy.Time.now()
                loop_time = end_time - start_time
                loop_time_s = loop_time.secs

                if self.__shutdown__:
                    client.cancel_all_goals()
                    self.conversation_interface.removeAutomaticAnswer(
                        answer_id)
                    self.service_preempt()
                    return 'shutdown'

                if loop_time_s > NAVIGATION_MAX_TIME_S:
                    # break the loop, end with error state
                    self.conversation_interface.removeAutomaticAnswer(
                        answer_id)
                    rospy.logwarn(
                        'State: Navigation took too much time, returning error'
                    )
                    client.cancel_all_goals()
                    return 'stall'

                if self.preempt_requested():
                    self.conversation_interface.removeAutomaticAnswer(
                        answer_id)
                    client.cancel_all_goals()
                    self.service_preempt()
                    return 'preemption'

                rospy.sleep(0.1)

            # Manage state of the move_base action server
            self.conversation_interface.removeAutomaticAnswer(answer_id)

            # Here check move_base DONE status
            if self.move_base_status == GoalStatus.PENDING:
                # The goal has yet to be processed by the action server
                raise Exception('Wrong move_base action status: "PENDING"')
            elif self.move_base_status == GoalStatus.ACTIVE:
                # The goal is currently being processed by the action server
                raise Exception('Wrong move_base action status: "ACTIVE"')
            elif self.move_base_status == GoalStatus.PREEMPTED:
                # The goal received a cancel request after it started executing
                #   and has since completed its execution (Terminal State)
                return 'preemption'
            elif self.move_base_status == GoalStatus.SUCCEEDED:
                # The goal was achieved successfully by the action server (Terminal State)
                return 'ok'
            elif self.move_base_status == GoalStatus.ABORTED:
                # The goal was aborted during execution by the action server due
                #    to some failure (Terminal State)
                return 'stall'
            elif self.move_base_status == GoalStatus.REJECTED:
                # The goal was rejected by the action server without being processed,
                #    because the goal was unattainable or invalid (Terminal State)
                return 'error'
            elif self.move_base_status == GoalStatus.PREEMPTING:
                # The goal received a cancel request after it started executing
                #    and has not yet completed execution
                raise Exception('Wrong move_base action status: "PREEMPTING"')
            elif self.move_base_status == GoalStatus.RECALLING:
                # The goal received a cancel request before it started executing,
                #    but the action server has not yet confirmed that the goal is canceled
                raise Exception('Wrong move_base action status: "RECALLING"')
            elif self.move_base_status == GoalStatus.RECALLED:
                # The goal received a cancel request before it started executing
                #    and was successfully cancelled (Terminal State)
                return 'preemption'
            elif self.move_base_status == GoalStatus.LOST:
                # An action client can determine that a goal is LOST. This should not be
                #    sent over the wire by an action server
                raise Exception('Wrong move_base action status: "LOST"')
            else:
                raise Exception('Wrong move_base action status value: "' +
                                str(self.move_base_status) + '"')
コード例 #6
0
                print_info()

        goal = KickGoal()
        goal.header.stamp = self.get_clock().now()
        goal.header.frame_id = "base_footprint"
        goal.ball_position.x = 0.2
        goal.ball_position.y = -0.09
        goal.ball_position.z = 0
        goal.kick_direction = Quaternion(*quaternion_from_euler(0, 0, 0))
        goal.kick_speed = 1

        client = actionlib.SimpleActionClient('dynamic_kick', KickAction)
        client.done_cb = done_cb
        client.feedback_cb = feedback_cb
        client.active_cb = active_cb
        client.send_goal(goal)
        client.wait_for_result()

    if not (had_diag_stale or had_diag_warn or had_diag_error):
        print_info("Diagnostic status were okay during motions.")
    else:
        print_warn(
            "Diagnostics report problem. Please use rqt_monitor to investigate."
        )
        if had_diag_error:
            print_warn("  There were errors.")
        if had_diag_warn:
            print_warn("  There were warnings.")
        if had_diag_stale:
            print_warn("  There were stales.")
コード例 #7
0
orig_config = None

def config_callback(config):
  global orig_config
  if orig_config is None:
    orig_config = config
  rospy.loginfo("Config is {volume}, {pitch}, {rate}, {pitch_range}, {announce_punctuation}, {wordgap}".format(**config))

rospy.init_node('speech_client')
client = actionlib.SimpleActionClient('speak', SpeakAction)
client.wait_for_server()

while not rospy.is_shutdown():
  goal = SpeakGoal()
  goal.text = "Witaj świecie raz dwa"
  client.send_goal(goal, feedback_cb=feedback_cb, done_cb=done_cb, active_cb=active_cb)
  
  #interrupt immediately
  goal = SpeakGoal()
  goal.text = "Witaj świecie raz dwa trzy cztery"
  client.send_goal(goal, feedback_cb=feedback_cb, done_cb=done_cb, active_cb=active_cb)
  rospy.sleep(1)
  
  #interrupt aftet a second
  goal = SpeakGoal()
  goal.text = "Witaj ponownie świecie, raz dwa trzy cztery"
  client.send_goal(goal, feedback_cb=feedback_cb, done_cb=done_cb, active_cb=active_cb)
  
  # no interruption
  client.wait_for_result()