sample_hist_pub.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 from std_msgs.msg import Float32MultiArray
00005 from jsk_recognition_msgs.msg import HistogramWithRange, HistogramWithRangeBin
00006 import numpy as np
00007 
00008 if __name__ == "__main__":
00009     rospy.init_node("sample_hist_pub")
00010     pub = rospy.Publisher("normal_array", Float32MultiArray)
00011     pub_range = rospy.Publisher("range_array", HistogramWithRange)
00012     r = rospy.Rate(1)
00013     while not rospy.is_shutdown():
00014         data = np.random.normal(size=1000)
00015         range_msg = HistogramWithRange()
00016         hist, bins = np.histogram(data, bins=50)
00017         for v, min, max in zip(hist, bins[:-1], bins[1:]):
00018             msg_bin = HistogramWithRangeBin()
00019             msg_bin.max_value = max
00020             msg_bin.min_value = min
00021             msg_bin.count = v
00022             range_msg.bins.append(msg_bin)
00023         msg = Float32MultiArray()
00024         msg.data = hist
00025         pub.publish(msg)
00026         pub_range.publish(range_msg)
00027         r.sleep()


jsk_rqt_plugins
Author(s):
autogenerated on Sun Sep 13 2015 22:29:48