navi_relay.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_demo/rocon_navi_relay/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 import threading
00011 import roslib
00012 roslib.load_manifest('rocon_navi_relay')
00013 import rospy
00014 import actionlib
00015 #import tf
00016 #from geometry_msgs.msg import Twist
00017 #from std_msgs.msg import String
00018 import geometry_msgs.msg as geometry_msgs
00019 import demo_msgs.msg as demo_msgs
00020 import move_base_msgs.msg as move_base_msgs
00021 
00022 ##############################################################################
00023 # NaviRelay
00024 ##############################################################################
00025 
00026 
00027 class Job(threading.Thread):
00028 
00029     def __init__(self, action_client, result_publisher, task_id, pose, current_task_id):
00030         threading.Thread.__init__(self)
00031         self._current_task_id = task_id
00032         self._result_publisher = result_publisher
00033         self._action_client = action_client
00034         self._response = demo_msgs.ResponseMoveRobot()
00035         self._response.task_id = task_id
00036         self._response.status = False
00037         rospy.loginfo("Sending robot to [%s,%s]" % (pose.position.x, pose.position.y))
00038         goal = move_base_msgs.MoveBaseGoal()
00039         goal.target_pose.header.frame_id = '/map'
00040         goal.target_pose.header.stamp = rospy.Time.now()
00041         goal.target_pose.pose = pose
00042         self._action_client.send_goal(goal)
00043 
00044     def run(self):
00045         self._action_client.wait_for_result()
00046         unused_result = self._action_client.get_result()  # use this result
00047         self._response.status = True
00048         self._result_publisher.publish(self._response)
00049         self._current_task_id = None
00050 
00051 
00052 class NaviRelay(object):
00053     def __init__(self):
00054         self._current_task_id = None
00055         self.subscribers = {}
00056         self.subscribers['command'] = rospy.Subscriber('command', demo_msgs.RequestMoveRobot, self._process_command)
00057         self.publishers = {}
00058         self.publishers['result'] = rospy.Publisher('result', demo_msgs.ResponseMoveRobot)
00059         self.actionclient = {}
00060         self.actionclient['move_base'] = actionlib.SimpleActionClient('move_base', move_base_msgs.MoveBaseAction)
00061         self.actionclient['move_base'].wait_for_server()
00062         self._initialise_navigation
00063 
00064     def _initialise_navigation(self):
00065         initial_x = rospy.get_param('~initial_x', 0.0)
00066         initial_y = rospy.get_param('~initial_y', 0.0)
00067         initial_a = rospy.get_param('~initial_a', 0.0)
00068         pwcs = geometry_msgs.PoseWithCovarianceStamped()
00069         pwcs.pose.pose.position.x = initial_x
00070         pwcs.pose.pose.position.y = initial_y
00071         #pwcs.pose.pose.quaternion = tf.transformations
00072         #initialpose_publisher = rospy.Publisher('/initialpose', demo_msgs.ResponseMoveRobot)
00073         #while initialpose_publisher.get_num_connections() == 0:
00074         #    rospy.sleep(1.0)
00075         #initialpose_publisher.publish(pwcs)
00076 
00077     def spin(self):
00078         rospy.spin()
00079 
00080     def _process_command(self, msg):
00081         if self._current_task_id is not None:
00082             result = demo_msgs.ResponseMoveRobot()
00083             result.task_id = msg.task_id
00084             result.status = False
00085             self.publishers['result'].publish(result)
00086         else:
00087             job = Job(self.actionclient['move_base'], self.publishers['result'], msg.task_id, msg.pose, self._current_task_id)
00088             job.start()
00089 
00090     def log(self, msg):
00091         #self.pub['status'].publish(msg)
00092         rospy.loginfo("NaviRelay : " + str(msg))
 All Classes Namespaces Files Functions Variables Typedefs Enumerations


rocon_navi_relay
Author(s): Jihoon
autogenerated on Thu Jan 24 2013 13:33:39