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, queue_size=1)
00011     pub_range = rospy.Publisher(
00012         "range_array", HistogramWithRange, queue_size=1)
00013     r = rospy.Rate(1)
00014     while not rospy.is_shutdown():
00015         data = np.random.normal(size=1000)
00016         range_msg = HistogramWithRange()
00017         hist, bins = np.histogram(data, bins=50)
00018         for v, min, max in zip(hist, bins[:-1], bins[1:]):
00019             msg_bin = HistogramWithRangeBin()
00020             msg_bin.max_value = max
00021             msg_bin.min_value = min
00022             msg_bin.count = v
00023             range_msg.bins.append(msg_bin)
00024         msg = Float32MultiArray()
00025         msg.data = hist
00026         pub.publish(msg)
00027         pub_range.publish(range_msg)
00028         r.sleep()


jsk_rqt_plugins
Author(s):
autogenerated on Wed May 1 2019 02:40:16