00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 PKG='semanticmodel'
00044 import roslib
00045 roslib.load_manifest(PKG)
00046 import rospy
00047 import time
00048 import actionlib
00049 import math
00050
00051 from move_base_msgs.msg import *
00052 from geometry_msgs.msg import *
00053 import pr2_common_action_msgs.msg as act
00054 import actionlib_msgs.msg as am
00055 import continuous_ops_msgs.msg as cont_ops
00056 import std_msgs.msg as sm
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 places = {\
00073 "whiteboard": ("green room looking towards whiteboard from across", (17.52, 18.11, 1.25)),
00074 "magazines": ("looking at magazines in green room", (18.30, 25.81, 2.82)),
00075 "bigscreen": ("looking at big screen", (17.81, 22.15, 2.74)),
00076 "cafe1": ("at entrance to cafeteria", (36.11, 21.77, 1.94)),
00077 "coffee": ("looking diagonally at coffee machine", (34.56, 16.11, 1.22)),
00078 "cafe2": ("looking out side entrance", (27.83, 10.84, 2.78)),
00079 "glass": ("looking out glass door", (26.75, 15.04, 1.86)),
00080 "whitelab": ("looking towards white lab", (33.39, 30.88, 1.20)),
00081 "frontdoor": ("looking towards front door", (41.45, 20.78, 1.15)),
00082 "pooltable": ("looking at pool table from narrow hallway", (19.90, 32.74, 1.67)),
00083 "bike": ("looking out bike exit", (17.12, 55.21, 2.69)),
00084 "research": ("looking out research exit", (05.00, 21.40, 1.75)),
00085 "fishbowl": ("fishbowl, looking at pool table", (12.18, 32.55, 0.55)),
00086 "boondocks": ("boondocks, looking at white lab", (41.23, 49.47, 0.31)),
00087 "looking-at-fridge": ("pool room, looking at fridge", (20.4, 36.32, 0.448)),
00088 }
00089
00090
00091
00092 goals = [
00093 [(20.11, 25.77, 0.0), (0.0, 0.0, -0.83, 0.55)],
00094 [(17.85, 19.21, 0.0), (0.0, 0.0, -0.19, 0.98)],
00095 [(27.06, 15.57, 0.0), (0.0, 0.0, 0.56, 0.82)],
00096 [(35.37, 20.52, 0.0), (0, 0, -0.96, -0.25)],
00097 [(31.26, 25.06, 0.0), (0, 0, -0.829, 0.55)],
00098 [(19.78, 33.32, 0.0), (0, 0, 0.6, 0.79)],
00099 [(20.76, 37,84, 0.0), (0, 0, 0.98, 0.17)],
00100 [(19.22, 24.29, 0.0), (0, 0, -0.71, 0.69)]
00101 ]
00102
00103 def convert_2d_pose(p):
00104 return [(p[0], p[1], 0), (0, 0, math.sin(p[2]/2), math.cos(p[2]/2))]
00105
00106
00107 wp = ["whiteboard", "bigscreen", "magazines", "pooltable", "looking-at-fridge", "research", "bike", "boondocks",
00108 "cafe1", "coffee", "cafe2", "glass", "frontdoor", "whitelab", "whiteboard"
00109 ]
00110
00111
00112 goals = [convert_2d_pose(places[p][1]) for p in wp]
00113 print "The goals are ", [places[p] for p in wp]
00114
00115
00116
00117 def mb_goal(goal):
00118 return MoveBaseGoal(PoseStamped(sm.Header(frame_id = 'map'),
00119 Pose(Point(goal[0][0], goal[0][1],
00120 goal[0][2]),
00121 Quaternion(goal[1][0], goal[1][1],
00122 goal[1][2], goal[1][3]))))
00123
00124
00125 ACTION_SERVER=None
00126
00127
00128
00129
00130
00131
00132 def do_the_tour(msg=None):
00133 global ACTION_SERVER
00134 tuck_client = actionlib.SimpleActionClient('tuck_arms', act.TuckArmsAction)
00135 rospy.loginfo("Waiting for tuck_arms")
00136 tuck_client.wait_for_server()
00137 while not rospy.is_shutdown():
00138 rospy.loginfo("Sending tuck goal")
00139 res = tuck_client.send_goal_and_wait(act.TuckArmsGoal(True, True),
00140 execute_timeout=rospy.Duration(20.0))
00141 rospy.loginfo("Tuck result was {0}".format(res))
00142 if res == am.GoalStatus.SUCCEEDED:
00143 break
00144
00145
00146
00147
00148 client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
00149 rospy.loginfo("Waiting for move_base")
00150 client.wait_for_server()
00151 rospy.loginfo("Sending goals")
00152
00153 for idx, goal in list(enumerate(goals))[:]:
00154 mb = mb_goal(goal)
00155 rospy.loginfo("Sending goal {1} at {0}".format(goal, wp[idx]))
00156 client.send_goal(mb)
00157 while not client.wait_for_result(rospy.Duration(1.0)):
00158 if rospy.is_shutdown():
00159 rospy.loginfo("Tour node shutting down, cancelling nav goals")
00160 client.cancel_all_goals()
00161 return
00162 if ACTION_SERVER.is_preempt_requested():
00163 rospy.loginfo("Tour has been preempted. Cancelling")
00164 client.cancel_all_goals()
00165 ACTION_SERVER.set_preempted()
00166 return
00167 rospy.sleep(3.0)
00168
00169 rospy.loginfo('Done with tour')
00170 ACTION_SERVER.set_succeeded()
00171
00172
00173
00174 if __name__ == '__main__':
00175 rospy.init_node('willow_tour_node')
00176 ACTION_SERVER = actionlib.SimpleActionServer("semantic_passive", cont_ops.TaskAction,
00177 execute_cb = do_the_tour)
00178 ACTION_SERVER.start()
00179