[转]ROS Q&A | How to read LaserScan data
http://www.theconstructsim.com/read-laserscan-data/
Step 1. Open a project on ROS Development Studio(RDS)
We can reproduce the question easily using RDS. If you haven’t had an account yet, you can register one for free here. After registration, you can log in and open the project from Public(click on my projects to switch to public simulations) -> Kobuki. In the project, click simulations -> Turtlebot 2 to launch the simulation.
Step 2. Read LaserScan data
The simulation is up and running now. You can check all the topic available with the command
|
1
|
$ rostopic list
|
The LaserScan topic is called /kobuki/laser/scan. You can type the following command into the terminal to check the topic.
|
1
|
$ rostopic echo /kobuki/lase/scan -n1
|
The -n1 flag prints the topic exactly once. You’ll get something like this.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
header:
seq: 5
stamp:
secs: 2829
nsecs: 69000000
frame_id: "laser_sensor_link"
angle_min: -1.57079994678
angle_max: 1.57079994678
angle_increment: 0.00436940183863
time_increment: 0.0
scan_time: 0.0
range_min: 0.10000000149
range_max: 30.0
ranges: [inf, inf, inf, inf, inf, ....]
|
The following command will give you the information for the topic
|
1
|
rostopic info /kobuki/laser/scan
|
You’ll see that the topic is using the message type called sensor_msgs/LaserScan. You can further check it with the command
|
1
|
rosmsg show sensor_msgs/LaserScan
|
The command gives you the message’s structure.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
std_msgs/Header header
uint32 seq
time stamp
string frame_id
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 angle_min and angle_max indicate the angle range(from -90 to 90 degree in this case) that the LaserScan is measuring and the ranges is an array which gives you the distance measured for each angle bin.
To explore the range value, let’s create a package.
|
1
2
3
4
|
$ cd ~/catkin_ws/src
$ catkin_create_pkg laser_values rospy
$ cd laser_values
$ mkdir launch
|
Add a python script under src with the following code
|
1
2
3
4
5
6
7
8
9
10
11
|
#! /usr/bin/env python
import rospy
from sensor_msgs.msg import LaserScan
def callback(msg):
print len(msg.ranges)
rospy.init_node('scan_values')
sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, callback)
rospy.spin()
|
Normally, you’ll need to give the script permission to execute with
|
1
|
$ chmod +x src/scan.py
|
Then we create a launch file under lunch directory to launch the script
|
1
2
3
4
5
|
<launch>
<node pkg="laser_values" type="scan.py" name="scan_values" output="screen">
</node>
</launch>
|
Now you can type
|
1
|
roslaunch laser_values laser.launch
|
to launch the script. You should also see that the length of the ranges array is 720 in the 180-degree range. So if we want to read the LaserScan data on the left, in front and on the right of the robot, we can change our script a bit.
|
1
2
3
4
5
6
7
8
9
|
...
def callback(msg):
# values at 0 degree
print msg.ranges[]
# values at 90 degree
print msg.ranges[360]
# values at 180 degree
print msg.ranges[719]
...
|
That’s all now you get the value. You can play with it to navigate the robot. If you want to learn more about this topic, you can go to Robot Ignite Academy. We have tons of courses which teach you how to navigate the robot in a more advanced way.
[转]ROS Q&A | How to read LaserScan data的更多相关文章
- [转]ROS 传感器消息及RVIZ可视化Laserscan和PointCloud
https://blog.csdn.net/yangziluomu/article/details/79576508 https://answers.ros.org/question/60239/ho ...
- ros使用RPLIDAR激光雷达
1.首先下载RPLIDAR的驱动功能包 https://github.com/robopeak/rplidar_ros 2.然后解压放到~/catkin_ws/src目录下 3.执行catkin_ma ...
- 在ros中使用rplidar Laser发布scan数据--25
原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 由于市面上买的激光雷达价格太贵了.所以在学习时会造成很大的经济压力.但是最近好多做机器人核心组件的公司都 ...
- Rplidar学习(四)—— ROS下进行rplidar雷达数据采集源码分析
一.子函数分析 1.发布数据子函数 (1)雷达数据数据类型 Header header # timestamp in the header is the acquisition time of # t ...
- ROS中发布激光扫描消息
激光雷达工作时会先在当前位置发出激光并接收反射光束,解析得到距离信息,而后激光发射器会转过一个角度分辨率对应的角度再次重复这个过程.限于物理及机械方面的限制,激光雷达通常会有一部分“盲区”.使用激光雷 ...
- 第十一课,ROS与传感器
1.Kinect 1)安装 sudo apt-get install ros-indigo-openni-camera sudo apt-get install ros-indigo-openni-l ...
- 在学习ROS过程中碰到的一些问题--1
好了,这是接触ROS的第三周了,初步了解了一下ROS,很多问题自己还是无法解决,但是想着很久没有在blog上记录自己的学习过程,就先胡乱写一下吧.^-^ 1.关于ROS各种基本概念的理解 这方面知识建 ...
- [转]ROS订阅激光数据
https://github.com/robopeak/rplidar_ros/blob/master/src/client.cpp /* * Copyright (c) 2014, RoboPe ...
- Q promise API简单翻译
详细API:https://github.com/kriskowal/q/wiki/API-Reference Q提供了promise的一种实现方式,现在在node中用的已经比较多了.因为没有中文的a ...
随机推荐
- python模块----sys模块 (系统相关的参数和函数)
pprint 模块:它给我们提供了一个方法 pprint() 该方法可以用来对打印的数据做简单的格式化 sys模块+pprint模块 标准库网址(sys):https://docs.python.or ...
- shell(shell变量、条件表达式、流程控制)
本章内容: 变量 运算 if语句 for语句 while语句 break.continue 实例 shell变量 1.shell变量简介 变量是任何一种编程语言都必不可少的组成部分,变量用来存放各种数 ...
- 关于base64编码Encode和Decode编码的几种方式--Java
Base64是一种能将任意Binary资料用64种字元组合成字串的方法,而这个Binary资料和字串资料彼此之间是可以互相转换的,十分方便.在实际应用上,Base64除了能将Binary资料可视化之外 ...
- Eureka详解系列(三)--探索Eureka强大的配置体系
简介 通过前面的两篇博客,我们知道了:什么是 Eureka?为什么使用 Eureka?如何适用 Eureka?今天,我们开始来研究 Eureka 的源码,先从配置部分的源码开始看,其他部分后面再补充. ...
- 一统江湖的大前端(10)——inversify.js控制反转
<大史住在大前端>前端技术博文集可在下列地址访问: [github总基地][博客园][华为云社区][掘金] 字节跳动幸福里大前端团队邀请各路高手前来玩耍,团队和谐有爱,技术硬核,字节范儿正 ...
- 2019牛客暑期多校训练营(第十场)E-Hilbert Sort(分形)
>传送门< 题意 现给出你 $n $个坐标和 $k$,让你根据$ k$阶 希尔伯特曲线的走向排列给出的 $n $个坐标 希尔伯特曲线如下: $k=1$ $k=2$ $k=3$可以将边长为 ...
- Codeforces Global Round 7 C. Permutation Partitions(组合数学)
题意: 给你 n 长全排列的一种情况,将其分为 k 份,取每份中的最大值相加,输出和的最大值和有多少种分法等于最大值. 思路: 取前 k 大值,储存下标,每两个 k 大值间有 vi+1 - vi 种分 ...
- hdu1313 Round and Round We Go (大数乘法)
Problem Description A cyclic number is an integer n digits in length which, when multiplied by any i ...
- AtCoder Beginner Contest 179 D - Leaping Tak (DP)
题意:给你一个数字\(n\)和\(k\)个区间,\(S\)表示所有区间的并的集合,你目前在\(1\),每次可以从集合中选择一个数字向右移动,问有多少种方法从\(1\)走到\(n\). 题解:我们从1开 ...
- Codeforces Round #669 (Div. 2) C. Chocolate Bunny (交互,构造)
题意:有一个长度为\(n\)的隐藏序列,你最多可以询问\(2n\)次,每次可以询问\(i\)和\(j\)位置上\(p[i]\ mod\ p[j]\)的结果,询问的格式是\(?\ x\ y\),如果已经 ...