Go to the documentation of this file.00001
00002
00003 import numpy as np
00004
00005 import roslib; roslib.load_manifest('hrl_clickable_world')
00006 import rospy
00007 import std_srvs
00008
00009 from hrl_clickable_world.srv import PerceiveButtons, ButtonAction, DisplayButtons
00010 from hrl_clickable_world.srv import PerceiveButtonsResponse, ButtonActionResponse
00011 from geometry_msgs.msg import Point
00012 from visualization_msgs.msg import Marker
00013
00014 class TestButton:
00015 def __init__(self):
00016 self.perception_srv = rospy.Service("/clickable_world/test_button_perception",
00017 PerceiveButtons,
00018 self.do_perception)
00019 self.percept_pub = rospy.Publisher("/clickable_world/test_button_vis",
00020 Marker)
00021 self.action_srv = rospy.Service("/clickable_world/test_button_action",
00022 ButtonAction,
00023 self.do_action)
00024
00025 def do_perception(self, req):
00026 button = Marker()
00027 button.header.frame_id = "/base_link"
00028 button.header.stamp = rospy.Time.now()
00029 button.type = Marker.LINE_STRIP
00030 button.ns = "buttons"
00031 button.color.r = 1; button.color.a = 1
00032 button.scale.x = 0.01; button.scale.y = 0.01; button.scale.z = 0.01;
00033 button.pose.orientation.w = 1
00034 polygon = [(1.5, 0.5), (2.5, 0.5), (2.5, -0.5), (1.5, -0.5), (1.5, 0.5)]
00035 for pt in polygon:
00036 point = Point()
00037 point.x = pt[0]; point.y = pt[1]; point.z = 0.5
00038 button.points.append(point)
00039 self.percept_pub.publish(button)
00040
00041 resp = PerceiveButtonsResponse()
00042 resp.buttons.append(button)
00043 return resp
00044
00045 def do_action(self, req):
00046 rospy.loginfo("TestButton clicked!")
00047 rospy.sleep(10)
00048 rospy.loginfo("TestButton done!")
00049 return ButtonActionResponse()
00050
00051 def main():
00052 rospy.init_node('test_button')
00053 tb = TestButton()
00054 rospy.spin()
00055
00056 if __name__ == "__main__":
00057 main()