00001
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 visualization_msgs.msg import Marker
00011 from visualization_msgs.msg import MarkerArray
00012
00013 from hrl_haptic_manipulation_in_clutter_msgs.msg import TaxelArray
00014 from m3skin_ros.msg import TaxelArray as TaxelArray_Meka
00015
00016
00017 def visualize_taxel_array(ta, marker_pub):
00018 markers = MarkerArray()
00019 stamp = ta.header.stamp
00020 frame = ta.header.frame_id
00021
00022 pts = np.column_stack((ta.centers_x, ta.centers_y, ta.centers_z))
00023 colors = np.zeros((4, pts.shape[0]))
00024 colors[0,:] = 243/255.0
00025 colors[1,:] = 132/255.0
00026 colors[2,:] = 0.
00027 colors[3,:] = 1.0
00028 scale = (0.005, 0.005, 0.005)
00029
00030 duration = 0.
00031 m = hv.list_marker(pts.T, colors, scale, 'points',
00032 frame, duration=duration, m_id=0)
00033 m.header.stamp = stamp
00034 markers.markers.append(m)
00035
00036
00037 nrmls = np.column_stack((ta.normals_x, ta.normals_y, ta.normals_z))
00038 fs = np.column_stack((ta.values_x, ta.values_y, ta.values_z))
00039
00040 fmags = ut.norm(fs.T).flatten()
00041
00042 if hasattr(ta, 'link_name'):
00043 idxs = np.where(fmags > 0.01)[0]
00044 else:
00045
00046
00047 idxs = np.where(fmags > 0.2)[0]
00048
00049 force_marker_scale = 0.04
00050 duration = 0.02
00051 for i in idxs:
00052 p = np.matrix(pts[i]).T
00053 n1 = np.matrix(nrmls[i]).T
00054 n2 = np.matrix(fs[i]).T
00055
00056 q1 = hv.arrow_direction_to_quat(n1)
00057 l1 = (n2.T * n1)[0,0] * force_marker_scale
00058
00059
00060
00061
00062
00063 scale = (0.2, 0.2, l1)
00064
00065 m = hv.single_marker(p, q1, 'arrow', frame, duration=duration,
00066 scale=scale, m_id=3*i+1)
00067 m.header.stamp = stamp
00068 markers.markers.append(m)
00069
00070 q2 = hv.arrow_direction_to_quat(n2)
00071 l2 = np.linalg.norm(n2) * force_marker_scale
00072
00073
00074
00075
00076 scale = (0.2, 0.2, l2)
00077
00078 m = hv.single_marker(p, q2, 'arrow', frame, duration=duration,
00079 scale=scale, color=(0.,0.5,0.,1.0),
00080 m_id=3*i+2)
00081 m.header.stamp = stamp
00082 markers.markers.append(m)
00083
00084 m = hv.single_marker(p + n2/np.linalg.norm(n2) * l2 * 1.6, q2, 'text_view_facing', frame,
00085 (0.07, 0.07, 0.07), m_id = 3*i+3,
00086 duration = duration, color=(0.,0.5,0.,1.))
00087 m.text = '%.1fN'%(np.linalg.norm(n2))
00088 m.header.stamp = stamp
00089 markers.markers.append(m)
00090
00091 marker_pub.publish(markers)
00092
00093 if __name__ == '__main__':
00094 rospy.init_node('taxel_array_viz_publisher')
00095 _ = rospy.Publisher('/skin/viz/taxel_array', Marker)
00096 marker_pub = rospy.Publisher('/skin/viz/taxel_array_array', MarkerArray)
00097
00098 rospy.Subscriber('/skin/taxel_array', TaxelArray,
00099 visualize_taxel_array,
00100 callback_args = marker_pub)
00101 rospy.Subscriber('/skin/taxel_array_meka', TaxelArray_Meka,
00102 visualize_taxel_array,
00103 callback_args = marker_pub)
00104 rospy.loginfo('Started visulizing taxel array!')
00105
00106 rospy.spin()
00107
00108