[转]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 ...
随机推荐
- CSS定位走一波(定位学习续)
又是新的一周过去了,时间到了,春天绿了,关于HTML5的学习进步了,今天博客更新一些CSS定位的内容,小的一些细节也要牢记,方便做一个更完美的项目. 如何让垂直方向居中,解决方式:在父元素添加over ...
- SonarQube+jenkins-自动化持续代码扫描
SonarQube+jenkins-自动化持续代码扫描 1.SonarQube 1.1 SonarQube介绍 1.1.1 SonarQube 工作流程 1. 2 Docker方式安装SonarQub ...
- Spring Cloud与Docker——微服务架构概述
Spring Cloud与Docker--微服务架构概述 单体应用架构概述 微服务概述 微服务的特性 微服务架构的优点 微服务面临的挑战 微服务的设计原则 单体应用架构概述 传统的服务发布都是采用单体 ...
- BGP总结(二)
BGP属性 路由器发送关于目标网络的BGP更新消息,更新的度量值被称为路径属性.属性可以是公认的或可选的.强制的或自由决定的.传递的或非传递的.属性也可以是部分的.并非组织的和有组合都是合法的,路径属 ...
- NodeMCU学习笔记
NodeMCU学习笔记 引脚连通 引脚 连通 D3 FLASH按键 D0 模组上的LED D4 芯片的LED FLASH按键 D3引脚已经与开发板上的FLASH按键开关连接 我们可以通过NodeMCU ...
- hdu3341Lost's revenge (AC自动机+变进制dp)
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submissio ...
- JavaScript——六
magin和padding的区别:https://www.cnblogs.com/zxnn/p/8186225.html magin:兄弟之间的 padding:父子关系 body和网页边框左右距离上 ...
- Detect the Virus ZOJ - 3430 AC自动机
One day, Nobita found that his computer is extremely slow. After several hours' work, he finally fou ...
- QQ空间自动点赞js代码
1.jQuery().each(): each() 方法为每个匹配元素规定要运行的函数. 提示:返回 false 可用于及早停止循环. 函数原型: function(index,element) 为每 ...
- Drone构建失败,一次drone依赖下载超时导致构建失败的爬坑记录
Once upon a time, birds were singing in the forest, and people were dancing under the trees, It's so ...