sample_hist_pub.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from std_msgs.msg import Float32MultiArray
5 from jsk_recognition_msgs.msg import HistogramWithRange, HistogramWithRangeBin
6 import numpy as np
7 
8 if __name__ == "__main__":
9  rospy.init_node("sample_hist_pub")
10  pub = rospy.Publisher("normal_array", Float32MultiArray, queue_size=1)
11  pub_range = rospy.Publisher(
12  "range_array", HistogramWithRange, queue_size=1)
13  r = rospy.Rate(1)
14  while not rospy.is_shutdown():
15  data = np.random.normal(size=1000)
16  range_msg = HistogramWithRange()
17  hist, bins = np.histogram(data, bins=50)
18  for v, min, max in zip(hist, bins[:-1], bins[1:]):
19  msg_bin = HistogramWithRangeBin()
20  msg_bin.max_value = max
21  msg_bin.min_value = min
22  msg_bin.count = v
23  range_msg.bins.append(msg_bin)
24  msg = Float32MultiArray()
25  msg.data = hist
26  pub.publish(msg)
27  pub_range.publish(range_msg)
28  r.sleep()


jsk_rqt_plugins
Author(s):
autogenerated on Fri Feb 5 2021 04:03:20