This article describes the format of the Laserscan message and the meaning of each parameter, and at the end of the article wrote a subscriber to read the laser data.
Laserscan is a Ros-defined laser data format, and the message is defined in the Sensor_msgs/laserscan.msg file with the path:/opt/ros/indigo/share/sensor_msgs/msg.
An example of the Laserscan message is as follows:
header:seq:101732 stamp:secs:1487324446 nsecs:379890600 frame_id:laser angle_min: -3.12413907051 ang
le_max:3.14159274101 angle_increment:0.0174532923847 time_increment:1.55012827463e-07 scan_time:5.56496015633e-05 range_min:0.15000000596 range_max:8.0 ranges: [INF, INF, 5.64900016784668, 2.875999927520752, INF, 5.743000030517578, I NF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, 5.946000099182129, INF, INF, INF, 5.938000202178955, 5.84999990 4632568, INF, 5.8470001220703125, INF, INF, INF, INF, INF, INF, 6.646999835968018, INF, INF, INF, INF, INF, INF, 0.2150000 035762787, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, 5.465000152587891, INF, 3.89700 00743865967, INF, 0.16300000250339508, INF, INF, INF, INF, INF, INF, INF, INF, 0.8199999928474426, INF, 0.7910000085830688 , 0.7450000047683716, INF, 0.7210000157356262, 0.7120000123977661, INF, 0.7160000205039978, INF, 0.7260000109672546, 0.7480000257492065, INF, 0.7749999761581421, INF, 0.7950000166893005, INF, 0.8240000009536743, 0.8500000238418579, INF, 0.8830000162124634, INF, 0.8759999871253967, 0.8539999723434448, INF, 0.8349999785423279, 0.8199999928474426, INF, 0.8059999942779541, INF, 0.7940000295639038, 0.781000018119812, INF, 0.7699999809265137, 0.7599999904632568, INF, 0.7519999742507935, INF, 0.7419999837875366, 0.7360000014305115, INF, 0.7300000190734863, 0.7239999771118164, INF, 0.7179999947547913, INF, 0.7149999737739563, 0.7120000123977661, INF, 0.7099999785423279, INF, 0.7110000252723694, 0.7120000123977661, INF, 0.7120000123977661, 0.7149999737739563, INF, INF, 0.9509999752044678, 0.9440000057220459, INF, 0.9459999799728394, 0.9459999799728394, INF, 0.9490000009536743, INF, 0.953000009059906, 0.9589999914169312, INF, 0.9639999866485596, INF, 0.968999981880188, 0.9769999980926514, INF, 0.9850000143051147, INF, 0.9940000176429749, 1.0049999952316284, INF, 1.0149999856948853, INF, 1.0269999504089355, 1.0410000085830688, INF, 1.4049999713897705, INF, 1.3600000143051147, INF, 1.468000054359436, 1.402999997138977, INF, 1.343999981880188, 1.2929999828338623 , INF, 1.246000051498413, INF, 1.2039999961853027, 1.1670000553131104, INF, 1.1299999952316284, 1.100000023841858, INF, 1.0720000267028809, 1.0429999828338623, INF, 1.0190000534057617, INF, 0.996999979019165, 0.9729999899864197, INF, 0.9520000219345093, INF, 0.9340000152587891, 0.9240000247955322, INF, 0.9160000085830688, INF, INF, 0.859000027179718, INF, 0.8600000143051147, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, in F, INF, INF, INF, 0.7789999842643738, INF, 0.7879999876022339, INF, INF, INF, INF, 0.17100000381469727, INF, 0.17100000381 469727, 0.1720000058412552, INF, 0.17299999296665192, INF, 0.17399999499320984, INF, INF, INF, INF, INF, INF, 0.8230000138 282776, INF, 0.8320000171661377, INF, 0.8410000205039978, 0.8519999980926514, INF, INF, INF, INF, INF, INF, 0.911000013351 4404, INF, 0.9240000247955322, 0.9419999718666077, INF, 0.9620000123977661, 0.9810000061988831, INF, 1.0069999694824219, INF, 1.0299999713897705, INF, 1.0579999685287476, 1.0850000381469727, INF, 1.1180000305175781, INF, 1.149999976158142, 1.187999963760376, INF, 1.225000023841858, INF, 1.2710000276565552, 1.3279999494552612, INF, 0.6050000190734863, INF, 0.5920000076293945, 0.5960000157356262, INF, INF, INF, 0.6000000238418579, 0.5929999947547913, INF, 0.5910000205039978, INF, 0.597000002861023, INF, 1.2589999437332153, INF, 1.2430000305175781, INF, 1.25, INF, INF, 1.184000015258789, INF, 1.20599 99704360962, 0.1679999977350235, INF, 0.16599999368190765, INF, 1.597000002861023, INF, INF, INF, INF, INF, INF, INF, INF, INF, 0.5709999799728394, INF, INF, 0.21699999272823334, INF, INF, INF, INF, INF, INF, INF, 1.777999997138977, INF, INF, I NF, 5.8379998207092285, INF, 5.841000080108643, 5.8470001220703125, INF, 6.051000118255615, INF, 6.051000118255615, 6.1570000648498535, INF, INF, INF, 7.072000026702881, 6.934999942779541, INF, INF, 7.072000026702881, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, INF, 2.7119998931 884766, INF] intensities: [0.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 47 .0, 0.0, 0.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 47.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 47.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 47.0, 0.0, 47.0, 0.0, 47.0, 0.0, 0.0, 0.0, 0.0, 0. 0, 0.0, 0.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47. 0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0 .0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 47.0, 0.0, 0.0, 47.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 47.0, 0.0, 47.0, 47.0, 0.0, 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0.0, 47.0, 0.0]
The above example shows the format of the Laserscan as follows:
Std_msgs/header Header
float32 angle_min
float32 angle_max
float32 angle_increment
float32 time_ Increment
float32 scan_time
float32 range_min
float32 range_max
float32[] ranges
float32[] Intensities
The following parameters are explained individually:
Header Header # header is also a struct that contains the seq,stamp,frame_id, where SEQ refers to the increase in the scan order Id,stamp contains the time to start scanning and the difference from the start of the scan, frame_ The ID is the name of the scanned reference system. Note that the scan starts counterclockwise from the front.
float32 angle_min # Start scanning angle (angle)
float32 angle_max # End Scan Angle (angle)
float32 angle_increment # Each scan increases the angle (angle)
float32 time_increment # measured time interval (s)
float32 scan_time # scan interval (s)
float32 Range_min # Distance minimum (m)
float32 range_max # Distance maximum (m)
float32[] ranges # Distance Array (length)
Float32[] Intensities # device-related, strength array (length 360)
Knowing the Laserscan data format, a Subscriber is written to receive Laserscan messages (assuming both roscore and laser have been started):
#!/usr/bin/env python
import rospy from
sensor_msgs.msg import laserscan
# #代码存放路径 your/workspace/src/ packagename/scripts/listener.py
def callback (scan):
#LaserScan的数据结构
#std_msgs/header Header
# float32 angle_min
#float32 angle_max
#float32 angle_increment
#float32 time_increment
#float32 Scan_time
#float32 range_min
#float32 range_max
#float32 [] ranges
#float32 [] intensities
Rospy.loginfo (' header: {0} '. Format (scan))
def Listener ():
rospy.init_node (' Lasr_listener ', anonymous= False)
Rospy. Subscriber (' Scan ', laserscan,callback)
rospy.spin ()
if __name__ = = ' __main__ ':
Listener ()
After compiling the run Rosrun yourpackagename listener.py you can see the same data as the Laserscan example at the beginning of this article.