7 import roslib; roslib.load_manifest(
'velma_common')
12 import xml.dom.minidom
as minidom
14 from std_msgs.msg
import ColorRGBA
20 import tf_conversions.posemath
as pm
24 from velma_common
import VelmaInterface
25 from rcprg_ros_utils
import exitError, marker_publisher
29 def __init__(self, name, parent_link, orig, ax, limit_lo, limit_up, rot):
52 robot_description = rospy.get_param(
"/robot_description")
55 self.
pub = marker_publisher.MarkerPublisher(
'/joints_vis')
58 dom = minidom.parseString(robot_description)
59 robot = dom.getElementsByTagName(
"robot")
61 print "robot_description does not contain 'robot' node" 66 for j
in robot[0].childNodes:
67 if j.localName !=
"joint":
69 name = j.getAttribute(
"name")
70 joint_type = j.getAttribute(
"type")
71 if joint_type ==
"fixed":
73 origin = j.getElementsByTagName(
"origin")
75 print "joint '" + name +
"' does contain wrong number of 'origin' nodes: " + str(len(origin))
77 axis = j.getElementsByTagName(
"axis")
79 print "joint '" + name +
"' contain wrong number of 'axis' nodes: " + str(len(axis))
81 limit = j.getElementsByTagName(
"limit")
83 print "joint '" + name +
"' contain wrong number of 'limit' nodes: " + str(len(limit))
85 parent = j.getElementsByTagName(
"parent")
87 print "joint '" + name +
"' contain wrong number of 'parent' nodes: " + str(len(parent))
90 xyz = origin[0].getAttribute(
"xyz")
91 rpy = origin[0].getAttribute(
"rpy")
94 orig = PyKDL.Frame(PyKDL.Rotation.RPY(float(rpy[0]), float(rpy[1]), float(rpy[2])), PyKDL.Vector(float(xyz[0]), float(xyz[1]), float(xyz[2])))
96 axis_xyz = axis[0].getAttribute(
"xyz")
97 axis_xyz = axis_xyz.split()
98 ax = PyKDL.Vector(float(axis_xyz[0]), float(axis_xyz[1]), float(axis_xyz[2]))
100 limit_lo = float(limit[0].getAttribute(
"lower"))
101 limit_up = float(limit[0].getAttribute(
"upper"))
102 print name +
": " + str(limit_lo) +
" " + str(limit_up) +
" axis: " + str(ax.x()) +
" " + str(ax.y()) +
" " + str(ax.z()) +
" " 104 parent_link = parent[0].getAttribute(
"link")
107 if abs(axis_z.z()) > 0.7:
108 axis_x = PyKDL.Vector(1,0,0)
110 axis_x = PyKDL.Vector(0,0,1)
111 axis_y = axis_z * axis_x
112 axis_x = axis_y * axis_z
116 rot = PyKDL.Frame(PyKDL.Rotation(axis_z,axis_x,axis_y))
119 limit_lo, limit_up, rot) )
127 angle = joint.limit_lo
128 while angle < joint.limit_up-0.15:
131 pl.append(PyKDL.Vector())
132 pl.append(rot*PyKDL.Vector(0, math.cos(angle_prev), math.sin(angle_prev))*scale)
133 pl.append(rot*PyKDL.Vector(0, math.cos(angle), math.sin(angle))*scale)
134 pl.append(PyKDL.Vector())
135 pl.append(rot*PyKDL.Vector(0, math.cos(angle), math.sin(angle))*scale)
136 pl.append(rot*PyKDL.Vector(0, math.cos(joint.limit_up), math.sin(joint.limit_up))*scale)
140 self.
server = InteractiveMarkerServer(
'int_markers_jimp')
142 self.
server.applyChanges();
145 imp_joints = self.
velma.getJointGroup(
'impedance_joints')
146 head_joints = self.
velma.getJointGroup(
'head')
147 js = self.
velma.getLastJointState()[1]
153 if (
not joint.name
in imp_joints)
and (
not joint.name
in head_joints):
155 self.
initial_q[joint.name] = js[joint.name]
156 self.
prev_q[joint.name] = js[joint.name]
157 self.
desired_q[joint.name] = js[joint.name]
159 int_position_marker = InteractiveMarker()
160 int_position_marker.header.frame_id = joint.parent_link
161 int_position_marker.name = joint.name
163 int_position_marker.pose = pm.toMsg(joint.orig)
169 box.interaction_mode = InteractiveMarkerControl.BUTTON
171 int_position_marker.controls.append( box )
174 self.
server.applyChanges();
177 joint_names = self.
velma.getJointGroup(
'impedance_joints')
180 for joint_name
in joint_names:
183 result[joint_name] = self.
desired_q[joint_name]
189 joint_names = self.
velma.getJointGroup(
'head')
192 for joint_name
in joint_names:
195 result[joint_name] = self.
desired_q[joint_name]
201 joint_name = feedback.marker_name
203 T_B_Td = pm.fromMsg(feedback.pose)
204 rot_diff = PyKDL.diff(PyKDL.Frame(), T_B_Td).rot
207 if joint_name == joint.name:
210 diff_q = PyKDL.dot(axis, rot_diff)
213 if ( feedback.control_name ==
'button' )
and\
214 ( feedback.event_type == InteractiveMarkerFeedback.BUTTON_CLICK ):
217 if not imp_cmd
is None:
218 self.
velma.moveJoint(imp_cmd, 3.0, start_time=0.5, position_tol=15.0/180.0*math.pi)
219 if not head_cmd
is None:
220 head_dst_q = [head_cmd[
"head_pan_joint"], head_cmd[
"head_tilt_joint"]]
221 self.
velma.moveHead(head_dst_q, 3.0, start_time=0.5, position_tol=15.0/180.0*math.pi)
227 marker.type = Marker.ARROW
228 marker.scale = Point(width, width*2, width*2)
229 marker.color = ColorRGBA(0,1,0,1)
230 marker.points.append( Point(0,0,0) )
231 v = rot*PyKDL.Vector(0, math.cos(init_q), math.sin(init_q))*length
232 marker.points.append( Point(v.x(), v.y(), v.z()) )
234 control = InteractiveMarkerControl()
235 control.always_visible =
True;
236 control.markers.append( marker );
242 control = InteractiveMarkerControl()
243 control.orientation_mode = InteractiveMarkerControl.FIXED
244 control.name =
'control' 245 control.orientation = pose.orientation
246 control.interaction_mode = InteractiveMarkerControl.ROTATE_AXIS
251 imp_joints = self.
velma.getJointGroup(
'impedance_joints')
252 head_joints = self.
velma.getJointGroup(
'head')
254 while not rospy.is_shutdown():
255 js = self.
velma.getLastJointState()[1]
258 if (
not joint.name
in imp_joints)
and (
not joint.name
in head_joints):
261 m_id = self.
pub.publishTriangleListMarker(self.
points_list[joint.name], m_id,
262 r=0, g=1, b=0, a=0.5, namespace=
"limits",
263 frame_id=joint.parent_link, T=joint.orig)
266 vec = joint.rot*PyKDL.Vector(0, math.cos(q), math.sin(q))
267 m_id = self.
pub.publishVectorMarker(joint.orig*PyKDL.Vector(),
269 1, 0, 0, a=1.0, namespace=
"limits", frame=joint.parent_link, scale=0.01)
275 if __name__ ==
"__main__":
276 rospy.init_node(
'int_markers_jimp', anonymous=
False)
280 velma = VelmaInterface()
281 print "waiting for init..." 286 print "Switch to jnt_imp mode (no trajectory)..." 287 if not velma.moveJointImpToCurrentPos(start_time=0.2):
289 if velma.waitForJoint() != 0:
292 print "Switched to jnt_imp mode."
def __init__(self, name, parent_link, orig, ax, limit_lo, limit_up, rot)
def createAxisMarkerControl(self, width, length, rot, init_q)
def processFeedback(self, feedback)
def createInteractiveMarkerControl1DOF(self, T)
def __init__(self, velma_interface)
def getMarkerSize(self, joint_name)