viz_taxel_array_for_proximity.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import numpy as np, math
00004 
00005 import roslib; roslib.load_manifest('hrl_common_code_darpa_m3')
00006 import hrl_lib.viz as hv
00007 import hrl_lib.util as ut
00008 import rospy
00009 
00010 from geometry_msgs.msg import Point
00011 from visualization_msgs.msg import Marker
00012 from visualization_msgs.msg import MarkerArray
00013 
00014 from hrl_haptic_manipulation_in_clutter_msgs.msg import TaxelArray
00015 from m3skin_ros.msg import TaxelArray as TaxelArray_Meka
00016 
00017 
00018 def visualize_taxel_array(ta, marker_pub):
00019     markers = MarkerArray()
00020     stamp = ta.header.stamp
00021     frame = ta.header.frame_id
00022 
00023     pts = np.column_stack((ta.centers_x, ta.centers_y, ta.centers_z))
00024     colors = np.zeros((4, pts.shape[0]))
00025     colors[0,:] = 243/255.0
00026     colors[1,:] = 132/255.0
00027     colors[2,:] = 0.
00028     colors[3,:] = 1.0
00029     scale = (0.005, 0.005, 0.005)
00030 
00031     duration = 0.
00032     m = hv.list_marker(pts.T, colors, scale, 'points',
00033                       frame, duration=duration, m_id=0)
00034     m.header.stamp = stamp
00035     markers.markers.append(m)
00036 
00037     # now draw non-zero forces as arrows.
00038     nrmls = np.column_stack((ta.normals_x, ta.normals_y, ta.normals_z))
00039     fs = np.column_stack((ta.values_x, ta.values_y, ta.values_z))
00040 
00041     fmags = ut.norm(fs.T).flatten()
00042 
00043     if hasattr(ta, 'link_name'):
00044         idxs = np.where(fmags > 0.0)[0]  #was .01
00045     else:
00046         # HACK. need to calibrate the skin patch so that something
00047         # reasonable gets outputted.
00048         idxs = np.where(fmags > 0.)[0] #was 0.2
00049 
00050     #force_marker_scale = 0.04
00051     force_marker_scale = 1.0
00052     duration = 0.4
00053     for i in idxs:
00054         p = np.matrix(pts[i]).T
00055         n1 = np.matrix(nrmls[i]).T
00056         n2 = np.matrix(fs[i]).T
00057 
00058         if False:
00059             q1 = hv.arrow_direction_to_quat(n1)
00060             l1 = (n2.T * n1)[0,0] * force_marker_scale
00061 
00062 
00063             if 'electric' not in roslib.__path__[0]:
00064                 scale = (l1, 0.2, 0.2)
00065             else:
00066                 scale = (0.2, 0.2, 0.2)  #something weird here, was (0.2, 0.2, l1)
00067 
00068             scale = (0.4, 0.4, l1)
00069 
00070             m = hv.single_marker(p, q1, 'arrow', frame, duration=duration,
00071                                  scale=scale, m_id=3*i+1)
00072             m.header.stamp = stamp
00073             #markers.markers.append(m)
00074 
00075         if True:
00076             if np.linalg.norm(n2) < 0.30:
00077                 q2 = hv.arrow_direction_to_quat(n2)
00078                 l2 = np.linalg.norm(n2) * force_marker_scale
00079 
00080                 m = Marker()
00081                 m.points.append(Point(p[0,0], p[1,0], p[2,0]))
00082                 m.points.append(Point(p[0,0]+n2[0,0], p[1,0]+n2[1,0], p[2,0]+n2[2,0]))
00083                 m.scale = Point(0.02, 0.04, 0.0)
00084                 m.header.frame_id = frame
00085                 m.id = 3*i+2
00086                 m.type = Marker.ARROW
00087                 m.action = Marker.ADD
00088                 m.color.r = 0.
00089                 m.color.g = 0.8
00090                 m.color.b = 0.
00091                 m.color.a = 1.
00092                 m.lifetime = rospy.Duration(duration)
00093                 m.header.stamp = stamp
00094                 markers.markers.append(m)
00095 
00096                 m = hv.single_marker(p + n2/np.linalg.norm(n2) * l2 * 1.2, q2, 'text_view_facing', frame,
00097                                      (0.07, 0.07, 0.07), m_id = 3*i+3,
00098                                      duration = duration, color=(0.5,0.5,0.5,1.))
00099                 m.text = '%.2fm'%(np.linalg.norm(n2))
00100                 m.header.stamp = stamp
00101                 markers.markers.append(m)
00102 
00103     marker_pub.publish(markers)
00104 
00105 if __name__ == '__main__':
00106     rospy.init_node('taxel_array_viz_publisher')
00107     _ = rospy.Publisher('/skin/viz/taxel_array', Marker)
00108     marker_forearm_pub = rospy.Publisher('/skin/viz/bosch/forearm_taxel_array_array', MarkerArray)
00109     marker_upperarm_pub = rospy.Publisher('/skin/viz/bosch/upperarm_taxel_array_array', MarkerArray)
00110     marker_pub = rospy.Publisher('/skin/viz/taxel_array_array', MarkerArray)
00111     simulation_pub = rospy.Publisher('/simulation/viz/taxel_array_array', MarkerArray)
00112 
00113     rospy.Subscriber('/skin/bosch/forearm_taxel_array', TaxelArray,
00114                      visualize_taxel_array,
00115                      callback_args = marker_forearm_pub)
00116 
00117     rospy.Subscriber('/skin/bosch/upperarm_taxel_array', TaxelArray,
00118                      visualize_taxel_array,
00119                      callback_args = marker_upperarm_pub)
00120 
00121     rospy.Subscriber('/haptic_mpc/simulation/proximity/taxel_array', TaxelArray,
00122                      visualize_taxel_array,
00123                      callback_args = simulation_pub)
00124 
00125     rospy.Subscriber('/skin/taxel_array', TaxelArray,
00126                      visualize_taxel_array,
00127                      callback_args = marker_pub)
00128     rospy.Subscriber('/skin/taxel_array_meka', TaxelArray_Meka,
00129                      visualize_taxel_array,
00130                      callback_args = marker_pub)
00131     rospy.loginfo('Started visulizing taxel array!')
00132 
00133     rospy.spin()
00134 
00135 


hrl_common_code_darpa_m3
Author(s): Advait Jain, Marc Killpack. Advisor: Prof. Charlie Kemp. Healthcare Robotics Lab, Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:42