Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import rospy
00020
00021 from interactive_markers.interactive_marker_server import InteractiveMarker, InteractiveMarkerFeedback
00022 from visualization_msgs.msg import Marker, InteractiveMarkerControl
00023
00024
00025 class InteractiveConnectorSelector(object):
00026 def __init__(self, object_names, callback_fct, interactive_server):
00027
00028 self.server = interactive_server
00029
00030 self.callback_function = callback_fct
00031 self.object_names = object_names
00032
00033 self.int_markers = {}
00034 self.object_markers = {}
00035 self.object_controls = {}
00036 self.select_controls = {}
00037
00038 for object_name in self.object_names:
00039 self.create_marker( object_name )
00040
00041 def create_marker(self, object_name):
00042
00043 int_marker = InteractiveMarker()
00044 int_marker.header.frame_id = "/"+object_name
00045 int_marker.name = object_name
00046 int_marker.description = "Select this object"
00047 int_marker.pose.position.z = -0.3
00048
00049 self.int_markers[ object_name ] = int_marker
00050
00051
00052 object_marker = Marker()
00053 object_marker.type = Marker.SPHERE
00054 object_marker.pose.position.z = 0.6
00055
00056 object_marker.scale.x = 0.1
00057 object_marker.scale.y = 0.1
00058 object_marker.scale.z = 0.1
00059 object_marker.color.r = 0.6
00060 object_marker.color.g = 0.02
00061 object_marker.color.b = 1.0
00062 object_marker.color.a = 1.0
00063 self.object_markers[object_name] = object_marker
00064
00065
00066 object_control = InteractiveMarkerControl()
00067 object_control.interaction_mode = InteractiveMarkerControl.BUTTON
00068 object_control.always_visible = True
00069 object_control.markers.append( object_marker )
00070
00071 self.object_controls[object_name] = object_control
00072
00073
00074 self.int_markers[object_name].controls.append( object_control )
00075
00076
00077
00078 self.server.insert(self.int_markers[object_name], self.processFeedback)
00079
00080
00081 self.server.applyChanges()
00082
00083 def processFeedback(self, feedback):
00084
00085 if feedback.event_type != InteractiveMarkerFeedback.BUTTON_CLICK:
00086 return
00087
00088
00089
00090
00091
00092 selected_name = feedback.marker_name
00093
00094
00095 for index, name in enumerate(self.object_controls):
00096 self.object_controls[name].markers.remove( self.object_markers[name] )
00097
00098 if name == selected_name:
00099
00100
00101 self.object_markers[name].pose.position.z = 0.65
00102
00103 self.object_markers[name].scale.x = 0.15
00104 self.object_markers[name].scale.y = 0.15
00105 self.object_markers[name].scale.z = 0.15
00106 self.object_markers[name].color.r = 0.32
00107 self.object_markers[name].color.g = 0.83
00108 self.object_markers[name].color.b = 0.15
00109 else:
00110
00111
00112 self.object_markers[name].pose.position.z = 0.6
00113
00114 self.object_markers[name].scale.x = 0.1
00115 self.object_markers[name].scale.y = 0.1
00116 self.object_markers[name].scale.z = 0.1
00117 self.object_markers[name].color.r = 0.6
00118 self.object_markers[name].color.g = 0.02
00119 self.object_markers[name].color.b = 1.0
00120
00121 self.object_controls[name].markers.append( self.object_markers[name] )
00122
00123 self.server.insert(self.int_markers[name])
00124
00125
00126 self.server.applyChanges()
00127 self.callback_function( selected_name )
00128
00129
00130
00131 if __name__ == "__main__":
00132 rospy.init_node("simple_marker")
00133
00134 int_mark = InteractiveConnectorSelector(["srh/position/palm"], None)
00135 rospy.spin()