ft_pointmass.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import roslib; roslib.load_manifest('hrl_pr2_lib')
00004 import rospy
00005 import math
00006 from geometry_msgs.msg import WrenchStamped, PoseStamped, Point, PointStamped
00007 from tf import TransformListener, transformations
00008 from visualization_msgs.msg import Marker
00009 
00010 class Pointmass_Adjust:
00011    
00012     pub_marker = True #Set to (True) or to not(False) publish rviz marker showing force vector
00013 
00014     mass = 1.0463 #kg 1.0213
00015     pos_x = 0.0853 #m, in 'l_wrist_roll_link'
00016     pos_y = 0.0
00017     pos_z = 0.0
00018     x_force_offset = 5.62 #5.70 -- These values determined from experiment, used values are adjusted for better qualitative results using rviz
00019     y_force_offset = -13.56 #14.10
00020     z_force_offset = 4.30 #-3.88
00021     x_torque_offset = -0.4025 #0.3899
00022     y_torque_offset = -0.4175 #0.3804
00023     z_torque_offset = -0.21875
00024     adjustment = WrenchStamped()
00025 
00026     def __init__(self):
00027         rospy.init_node("ft_pointmass_adjustment")
00028         rospy.Subscriber("netft_data", WrenchStamped, self.adjust)
00029         self.ft_out = rospy.Publisher('ft_data_pm_adjusted', WrenchStamped)
00030         self.force_vec_out = rospy.Publisher('ft_force_vector_marker', Marker)
00031         self.tfl = TransformListener()
00032 
00033     def adjust(self, ft_in):
00034         ft_out = WrenchStamped()
00035         ft_out.header.stamp = rospy.Time.now()
00036         ft_out.header.frame_id = ft_in.header.frame_id
00037         ft_out.wrench.force.x = ft_in.wrench.force.x  - self.x_force_offset + self.adjustment.wrench.force.x
00038         ft_out.wrench.force.y = ft_in.wrench.force.y  - self.y_force_offset + self.adjustment.wrench.force.y
00039         ft_out.wrench.force.z = ft_in.wrench.force.z  - self.z_force_offset + self.adjustment.wrench.force.z
00040         ft_out.wrench.torque.x = ft_in.wrench.torque.x - self.x_torque_offset  - self.adjustment.wrench.torque.x
00041         ft_out.wrench.torque.y = ft_in.wrench.torque.y  - self.y_torque_offset - self.adjustment.wrench.torque.y
00042         ft_out.wrench.torque.z = ft_in.wrench.torque.z  - self.z_torque_offset - self.adjustment.wrench.torque.z
00043 
00044         self.ft_out.publish(ft_out)
00045         if self.pub_marker:
00046             marker = self.form_marker(ft_out)
00047             self.force_vec_out.publish(marker) 
00048 
00049     def form_marker(self, ws):
00050         origin = Point()
00051         force_point = Point()
00052         force_point.x = 0.1*ws.wrench.force.x
00053         force_point.y = 0.1*ws.wrench.force.y
00054         force_point.z = 0.1*ws.wrench.force.z
00055         force_vec = Marker()
00056         force_vec.header.stamp = rospy.Time.now()
00057         force_vec.header.frame_id = '/l_netft_frame'
00058         force_vec.ns = "ft_sensor"
00059         force_vec.action = 0
00060         force_vec.type = 0
00061         force_vec.scale.x = 0.1
00062         force_vec.scale.y = 0.2
00063         force_vec.scale.z = 1
00064         force_vec.color.a = 0.75
00065         force_vec.color.r = 0.0
00066         force_vec.color.g = 1.0
00067         force_vec.color.b = 0.1
00068 
00069         force_vec.lifetime = rospy.Duration(1)
00070         force_vec.points.append(origin)
00071         force_vec.points.append(force_point)
00072         return force_vec
00073 
00074     def calc_adjustment(self):
00075         try:
00076             (pos, quat) = self.tfl.lookupTransform('/base_link', '/l_netft_frame', rospy.Time(0))
00077         except:
00078             return
00079         rot = transformations.euler_from_quaternion(quat) 
00080         self.adjustment.wrench.torque.x = self.mass*9.80665*self.pos_x*math.sin(rot[0])
00081         self.adjustment.wrench.torque.y = self.mass*9.80665*self.pos_x*math.sin(rot[1])
00082         self.adjustment.wrench.torque.z = 0
00083       
00084         grav = PointStamped() # Generate a 'vector' of the force due to gravity at the ft sensor 
00085         grav.header.stamp = rospy.Time(0) #Used to tell tf to grab latest available transform in transformVector3
00086         grav.header.frame_id = '/base_link'
00087         grav.point.x = pos[0]
00088         grav.point.y = pos[1]
00089         grav.point.z = pos[2] - 9.80665*self.mass 
00090 
00091         netft_grav = self.tfl.transformPoint('/l_netft_frame', grav) #Returns components of the 'gravity force' in each axis of the 'l_netft_frame'
00092         self.adjustment.wrench.force.x = netft_grav.point.x
00093         self.adjustment.wrench.force.y = netft_grav.point.y
00094         self.adjustment.wrench.force.z = netft_grav.point.z
00095 
00096         self.adjustment.header.stamp=rospy.Time.now()
00097         #self.form_marker(self.adjustment)
00098 
00099 if __name__ == "__main__":
00100     PMC = Pointmass_Adjust()
00101     r=rospy.Rate(1000)
00102     while not rospy.is_shutdown():
00103         PMC.calc_adjustment()
00104         r.sleep()


hrl_pr2_lib
Author(s): haidai
autogenerated on Wed Nov 27 2013 11:40:34