table_clickable.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import numpy as np
00004 
00005 import roslib; roslib.load_manifest('hrl_clickable_behaviors')
00006 import rospy
00007 import std_srvs.srv
00008 import actionlib
00009 
00010 from hrl_clickable_world.srv import PerceiveButtons, ButtonAction, DisplayButtons
00011 from hrl_clickable_world.srv import PerceiveButtonsResponse, ButtonActionResponse
00012 from geometry_msgs.msg import Point
00013 from visualization_msgs.msg import Marker
00014 
00015 from hrl_table_detect.srv import SegmentSurfaces, GetTableApproaches
00016 from hrl_table_detect.srv import GetTableApproachesRequest
00017 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00018 from pr2_approach_table.srv import ApproachSrv
00019 
00020 class TableClickable:
00021     def __init__(self):
00022         self.perception_srv = rospy.Service("/clickable_world/table_perception",
00023                                             PerceiveButtons,
00024                                             self.do_perception)
00025         self.percept_pub = rospy.Publisher("/clickable_world/table_button_vis",
00026                                            Marker)
00027         self.action_srv = rospy.Service("/clickable_world/table_approach_action",
00028                                         ButtonAction,
00029                                         self.do_action)
00030         self.pc_capture_srv = rospy.ServiceProxy("/table_detection/surf_seg_capture_pc",
00031                                                  std_srvs.srv.Empty)
00032         self.table_seg_srv = rospy.ServiceProxy("/table_detection/segment_surfaces",
00033                                                 SegmentSurfaces)
00034         self.table_approach_detect_srv = rospy.ServiceProxy(
00035                                          "/table_detection/detect_table_approaches",
00036                                          GetTableApproaches)
00037         self.table_move_client = actionlib.SimpleActionClient("move_base", MoveBaseAction)
00038         self.approach_table_srv = rospy.ServiceProxy("/approach_table/move_forward_srv",
00039                                                      ApproachSrv)
00040 
00041     def do_perception(self, req):
00042         # capture a few clouds
00043         rate = rospy.Rate(5)
00044         for i in range(5):
00045             self.pc_capture_srv()
00046             rate.sleep()
00047             
00048         # segment surfaces
00049         self.surfaces = self.table_seg_srv().surfaces
00050         for i in range(len(self.surfaces)):
00051             self.surfaces[i].color.r = 0
00052             self.surfaces[i].color.g = 256
00053             self.surfaces[i].color.b = 0
00054             self.surfaces[i].color.a = 256
00055         self.percept_pub.publish(self.surfaces[0])
00056 
00057         resp = PerceiveButtonsResponse()
00058         resp.buttons = self.surfaces
00059         return resp
00060 
00061     def do_action(self, req):
00062         rospy.loginfo("Table clicked!")
00063         approach_req = GetTableApproachesRequest()
00064         approach_req.table = self.surfaces[0]
00065         approach_req.approach_pt = req.pixel3d
00066         approach_poses = self.table_approach_detect_srv(approach_req).approach_poses
00067         #return ButtonActionResponse()
00068 
00069         table_move_goal = MoveBaseGoal()
00070         for approach_pose in approach_poses.poses:
00071             table_move_goal.target_pose.pose = approach_pose
00072             table_move_goal.target_pose.header.frame_id = approach_poses.header.frame_id
00073             table_move_goal.target_pose.header.stamp = rospy.Time.now()
00074             try:
00075                 self.table_move_client.send_goal(table_move_goal)
00076                 self.table_move_client.wait_for_result()
00077                 cur_pose = self.table_move_client.get_result()
00078                 try:
00079                     self.approach_table_srv()
00080                     return ButtonActionResponse()
00081                 except rospy.ROSInterruptException:
00082                     print "Table approach failed"
00083             except rospy.ROSInterruptException:
00084                 print "Table move failed"
00085         return ButtonActionResponse()
00086 
00087 def main():
00088     rospy.init_node('table_clickable')
00089     tc = TableClickable()
00090     rospy.spin()
00091 
00092 if __name__ == "__main__":
00093     main()


hrl_clickable_behaviors
Author(s): Author: Kelsey Hawkins, Advisor: Prof. Charlie Kemp (Healthcare Robotics Lab at Georgia Tech)
autogenerated on Wed Nov 27 2013 12:24:35