38 import roslib; roslib.load_manifest(
'rcprg_gazebo_utils')
46 from std_msgs.msg
import ColorRGBA
52 import tf_conversions.posemath
as pm
62 rospy.wait_for_service(
'/gazebo/set_link_state', 4.0)
63 self.
set_link_state = rospy.ServiceProxy(
'/gazebo/set_link_state', SetLinkState)
65 rospy.wait_for_service(
'/gazebo/get_link_state', 4.0)
66 get_link_state = rospy.ServiceProxy(
'/gazebo/get_link_state', GetLinkState)
68 req = GetLinkStateRequest()
70 req.reference_frame =
"torso_base" 71 resp = get_link_state(req)
72 if resp.success ==
False:
73 print "success:", resp.success,
", status:", resp.status_message
74 raise Exception(
"/gazebo/get_link_state")
76 print "IntMarkers6D init ok" 79 self.
server = InteractiveMarkerServer(
'gazebo_move_object_' + self.
link_name.replace(
":",
"_"))
81 self.
T_B_M = PyKDL.Frame(PyKDL.Vector(1,1,1))
85 self.
server.applyChanges();
88 req = SetLinkStateRequest()
90 req.link_state.pose.position.x = T_B_M.p.x()
91 req.link_state.pose.position.y = T_B_M.p.y()
92 req.link_state.pose.position.z = T_B_M.p.z()
93 qx, qy, qz, qw = T_B_M.M.GetQuaternion()
94 req.link_state.pose.orientation.x = qx
95 req.link_state.pose.orientation.y = qy
96 req.link_state.pose.orientation.z = qz
97 req.link_state.pose.orientation.w = qw
98 req.link_state.twist.linear.x = 0
99 req.link_state.twist.linear.y = 0
100 req.link_state.twist.linear.z = 0
101 req.link_state.twist.angular.x = 0
102 req.link_state.twist.angular.y = 0
103 req.link_state.twist.angular.z = 0
104 req.link_state.reference_frame =
"torso_base" 106 if resp.success ==
False:
107 print "success:", resp.success,
", status:", resp.status_message
111 self.
server.applyChanges();
114 int_position_marker = InteractiveMarker()
115 int_position_marker.header.frame_id =
'torso_base' 116 int_position_marker.name = self.
link_name+
'_position_marker' 117 int_position_marker.scale = 0.2
118 int_position_marker.pose = pm.toMsg(T_B_M)
128 box.interaction_mode = InteractiveMarkerControl.BUTTON
130 int_position_marker.controls.append( box )
132 self.
server.applyChanges();
135 if ( feedback.marker_name == self.
link_name+
'_position_marker' ):
136 T_B_M = pm.fromMsg(feedback.pose)
138 print "pose:", T_B_M.p.x(), T_B_M.p.y(), T_B_M.p.z()
142 markerX.type = Marker.ARROW
143 markerX.scale = scale
144 markerX.pose.position = position
145 ori = quaternion_about_axis(0, [0, 1 ,0])
146 markerX.pose.orientation = Quaternion(ori[0], ori[1], ori[2], ori[3])
147 markerX.color = ColorRGBA(1,0,0,1)
149 markerY.type = Marker.ARROW
150 markerY.scale = scale
151 markerY.pose.position = position
152 ori = quaternion_about_axis(math.pi/2.0, [0, 0 ,1])
153 markerY.pose.orientation = Quaternion(ori[0], ori[1], ori[2], ori[3])
154 markerY.color = ColorRGBA(0,1,0,1)
156 markerZ.type = Marker.ARROW
157 markerZ.scale = scale
158 markerZ.pose.position = position
159 ori = quaternion_about_axis(-math.pi/2.0, [0, 1 ,0])
160 markerZ.pose.orientation = Quaternion(ori[0], ori[1], ori[2], ori[3])
161 markerZ.color = ColorRGBA(0,0,1,1)
162 control = InteractiveMarkerControl()
163 control.always_visible =
True;
164 control.markers.append( markerX );
165 control.markers.append( markerY );
166 control.markers.append( markerZ );
170 control = InteractiveMarkerControl()
171 control.orientation_mode = InteractiveMarkerControl.FIXED
172 if mode == InteractiveMarkerControl.ROTATE_AXIS:
173 control.name =
'rotate_';
174 if mode == InteractiveMarkerControl.MOVE_AXIS:
175 control.name =
'move_';
177 control.orientation = Quaternion(1,0,0,1)
178 control.name = control.name+
'x';
180 control.orientation = Quaternion(0,1,0,1)
181 control.name = control.name+
'x';
183 control.orientation = Quaternion(0,0,1,1)
184 control.name = control.name+
'x';
185 control.interaction_mode = mode
189 print "usage: gazebo_move_object model_name::link_name" 191 if __name__ ==
"__main__":
193 rospy.init_node(
'gazebo_move_object', anonymous=
True)
195 if len(sys.argv) != 2:
def insert6DofGlobalMarker(self, T_B_M)
def createAxisMarkerControl(self, scale, position)
def processFeedback(self, feedback)
def erase6DofMarker(self)
def __init__(self, link_name)
def createInteractiveMarkerControl6DOF(self, mode, axis)
def setLinkState(self, T_B_M)