pr2_master.py
Go to the documentation of this file.
00001 import roslib
00002 roslib.load_manifest("phantom_omni")
00003 import rospy
00004 import tf
00005 import tf.transformations as tr
00006 
00007 from geometry_msgs.msg import PoseStamped
00008 from geometry_msgs.msg import Pose
00009 from geometry_msgs.msg import Wrench
00010 
00011 import math
00012 import numpy as np
00013 
00014 def tf2mat(tf_trans):
00015     (trans, rot) = tf_trans
00016     return np.matrix(tr.translation_matrix(trans)) * np.matrix(tr.quaternion_matrix(rot))
00017 
00018 def mat2pose(m):
00019     trans = tr.translation_from_matrix(m)
00020     rot   = tr.quaternion_from_matrix(m)
00021     p = Pose()
00022     p.position.x = trans[0]
00023     p.position.y = trans[1]
00024     p.position.z = trans[2]
00025     p.orientation.x = rot[0]
00026     p.orientation.y = rot[1]
00027     p.orientation.z = rot[2]
00028     p.orientation.w = rot[3]
00029     return p
00030 
00031 rospy.init_node("pr2_force_feedback")
00032 pub = rospy.Publisher('pr2_master', PoseStamped)
00033 wpub = rospy.Publisher('force_feedback', Wrench)
00034 r = rospy.Rate(60)
00035 
00036 listener = tf.TransformListener()
00037 listener.waitForTransform("/world", "/omni1_link6", rospy.Time(), rospy.Duration(4.0))
00038 print 'running.'
00039 while not rospy.is_shutdown():
00040     w_T_6 = tf2mat(listener.lookupTransform('/world', '/omni1_link6', rospy.Time(0)))
00041     qm = np.matrix(tr.quaternion_matrix(tr.quaternion_from_euler(0, math.pi, 0)))
00042     tm = np.matrix(tr.translation_matrix([-.134, 0, 0]))
00043     tip_6 = tm * qm
00044     tip_world = w_T_6 * tip_6
00045 
00046     ps = PoseStamped()
00047     ps.header.frame_id = 'world'
00048     ps.header.stamp = rospy.get_rostime()
00049     ps.pose = mat2pose(tip_world)
00050     pub.publish(ps)
00051     r.sleep()
00052 
00053     #Input force in link6's frame
00054     #Output force in omni base frame
00055     #wr = Wrench()
00056     #wr.force.x = np.random.rand()*2 - 1
00057     #wr.force.y = np.random.rand()*2 - 1
00058     #wr.force.z = np.random.rand()*2 - 1
00059     #wpub.publish(wr)
00060 
00061     wr = Wrench()
00062     wr.force.x = 0 
00063     wr.force.y = 0 
00064     wr.force.z = 0 
00065     wpub.publish(wr)
00066 
00067 
00068 


phantom_omni
Author(s): Hai Nguyen, Marc Killpack, Chi-Hung King, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:51:14