potential_well.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 import hrl_lib.tf_utils as tfu
00007 
00008 from geometry_msgs.msg import PoseStamped
00009 from geometry_msgs.msg import Pose
00010 from geometry_msgs.msg import Wrench
00011 
00012 import math
00013 import numpy as np
00014 
00015 rospy.init_node("omni_potential_well")
00016 wpub = rospy.Publisher('omni1_force_feedback', Wrench)
00017 
00018 def pose_cb(ps):
00019     m_f, frame = tfu.posestamped_as_matrix(ps)
00020     m_o1 = tfu.transform('/omni1', frame, listener) * m_f
00021     ee_point = np.matrix(tr.translation_from_matrix(m_o1)).T
00022     center = np.matrix([-.10, 0, .30]).T
00023     dif = 30*(center - ee_point)
00024     #force_dir = dif / np.linalg.norm(dif)
00025     force_o1 = dif #force_dir * np.sum(np.power(dif, 2))
00026 
00027     force_s = tfu.transform('/omni1_sensable', '/omni1', listener) * np.row_stack((force_o1, np.matrix([1.])))
00028     print np.linalg.norm(center - ee_point)
00029 
00030     wr = Wrench()
00031     wr.force.x = force_s[0]
00032     wr.force.y = force_s[1]
00033     wr.force.z = force_s[2]
00034     wpub.publish(wr)
00035 
00036 rospy.Subscriber('/omni1_pose', PoseStamped, pose_cb)
00037 r = rospy.Rate(1)
00038 
00039 listener = tf.TransformListener()
00040 listener.waitForTransform("/omni1", "/omni1_sensable", rospy.Time(), rospy.Duration(4.0))
00041 listener.waitForTransform("/omni1", "/omni1_link6", rospy.Time(), rospy.Duration(4.0))
00042 print 'running.'
00043 
00044 
00045 well_center = None
00046 while not rospy.is_shutdown():
00047     r.sleep()
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077     #get current pose of the tip, subtract it from a center, rotate this into the sensable frame
00078     #tip_omni1 = w_T_6 * tip_6
00079 
00080     #force_omni1 = (w_T_6[0:3,0:3] * np.matrix([-2., 0, 0]).T)
00081     #force_sensable = transform('/omni1_sensable', '/omni1', listener) * force_omni1
00082 
00083     #wr = Wrench()
00084     #wr.force.x = force_sensable[0]
00085     #wr.force.y = force_sensable[1]
00086     #wr.force.z = force_sensable[2]
00087     #print wr.force.z
00088     #wpub.publish(wr)
00089     #qm = tfu.quaternion_from_matrix(tr.quaternion_from_euler(0, math.pi, 0))
00090     #tm = tfu.translation_matrix([-.134, 0, 0])
00091     #tip_6 = tm * qm
00092     #tip_omni1 = w_T_6 * tip_6
00093 #trans, rot = listener.lookupTransform('/omni1_sensable', '/omni1', rospy.Time(0))
00094 #quat_mat = np.matrix(tr.quaternion_matrix(rot))
00095 #force_sensable = quat_mat[0:3, 0:3] * force_omni1
00096 #def tf2mat(tf_trans):
00097 #    (trans, rot) = tf_trans
00098 #    return np.matrix(tr.translation_matrix(trans)) * np.matrix(tr.quaternion_matrix(rot))
00099 
00100 #def mat2pose(m):
00101 #    trans = tr.translation_from_matrix(m)
00102 #    rot   = tr.quaternion_from_matrix(m)
00103 #    p = Pose()
00104 #    p.position.x = trans[0]
00105 #    p.position.y = trans[1]
00106 #    p.position.z = trans[2]
00107 #    p.orientation.x = rot[0]
00108 #    p.orientation.y = rot[1]
00109 #    p.orientation.z = rot[2]
00110 #    p.orientation.w = rot[3]
00111 #    return p


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