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

Related content:  [ROS Q&A] 069 - RQT Custom Plugin: undefined symbol
 
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

Related content:  [ROS Q&A] 081 - Making Aibo robot walk with ROS - #Part 1
 
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的更多相关文章

  1. [转]ROS 传感器消息及RVIZ可视化Laserscan和PointCloud

    https://blog.csdn.net/yangziluomu/article/details/79576508 https://answers.ros.org/question/60239/ho ...

  2. ros使用RPLIDAR激光雷达

    1.首先下载RPLIDAR的驱动功能包 https://github.com/robopeak/rplidar_ros 2.然后解压放到~/catkin_ws/src目录下 3.执行catkin_ma ...

  3. 在ros中使用rplidar Laser发布scan数据--25

    原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 由于市面上买的激光雷达价格太贵了.所以在学习时会造成很大的经济压力.但是最近好多做机器人核心组件的公司都 ...

  4. Rplidar学习(四)—— ROS下进行rplidar雷达数据采集源码分析

    一.子函数分析 1.发布数据子函数 (1)雷达数据数据类型 Header header # timestamp in the header is the acquisition time of # t ...

  5. ROS中发布激光扫描消息

    激光雷达工作时会先在当前位置发出激光并接收反射光束,解析得到距离信息,而后激光发射器会转过一个角度分辨率对应的角度再次重复这个过程.限于物理及机械方面的限制,激光雷达通常会有一部分“盲区”.使用激光雷 ...

  6. 第十一课,ROS与传感器

    1.Kinect 1)安装 sudo apt-get install ros-indigo-openni-camera sudo apt-get install ros-indigo-openni-l ...

  7. 在学习ROS过程中碰到的一些问题--1

    好了,这是接触ROS的第三周了,初步了解了一下ROS,很多问题自己还是无法解决,但是想着很久没有在blog上记录自己的学习过程,就先胡乱写一下吧.^-^ 1.关于ROS各种基本概念的理解 这方面知识建 ...

  8. [转]ROS订阅激光数据

    https://github.com/robopeak/rplidar_ros/blob/master/src/client.cpp /*   * Copyright (c) 2014, RoboPe ...

  9. Q promise API简单翻译

    详细API:https://github.com/kriskowal/q/wiki/API-Reference Q提供了promise的一种实现方式,现在在node中用的已经比较多了.因为没有中文的a ...

随机推荐

  1. csv的读写操作

    cvs简介: CSV 全称 Comma-Separated Values,中文叫逗号分隔值或字符分隔值,它以纯文本形式存储表格数据(数字和文本),其本质就是一个字符序列,可以由任意数目的记录组成,记录 ...

  2. RabbitMQ (基础知识)

    AMQP简介 AMQP(Advanced Message Queue )即:高级消息队列协议:,是应用层协议的一个开放标准,为面向消息的中间件设计:高级消息队列协议使得遵从该规范的客户端应用和消息中间 ...

  3. 文本处理三剑客简介(grep、awk、sed)

    本章内容: 命令 描述 awk 支持所有的正则表达式 sed 默认不支持扩展表达式,加-r 选项开启 ERE,如果不加-r 使用花括号要加转义符\{\} grep 默认不支持扩展表达式,加-E 选项开 ...

  4. Flink-v1.12官方网站翻译-P027-State Schema Evolution

    状态方案的演变 Apache Flink流媒体应用通常被设计为无限期或长时间运行.与所有长期运行的服务一样,应用程序需要更新以适应不断变化的需求.这对于应用程序所针对的数据模式也是一样的,它们会随着应 ...

  5. 2019牛客暑期多校训练营(第三场)G.Removing Stones(ST+分治)

    题意:给你n堆石子 每堆有ai个 现在问你有多少个连续的区间保证最大值小于等于该区间和的两倍 思路:我们可以考虑每个区间的分割点 总是该区间的最大值 所以我们只要ST找到该区间的最大值 然后每次都枚举 ...

  6. AtCoder Beginner Contest 170

    比赛链接:https://atcoder.jp/contests/abc170 A - Five Variables 题意 $5$ 个数中有 $1$ 个 $0$,判断是第几个. 代码 #include ...

  7. Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value(鸽巢原理)

    题目链接:https://codeforces.com/problemset/problem/1365/E 题意 有 $n$ 个元素,定义大小为 $k$ 的集合值为 $\sum2^i$,其中,若集合内 ...

  8. hdu4339 Query

    Problem Description You are given two strings s1[0..l1], s2[0..l2] and Q - number of queries. Your t ...

  9. 解决M1 MacBook无法使用pip安装Numpy

    问题描述 Python官方已发布支持M1 Apple Silicon的版本,但是在使用pip包管理工具安装一些依赖时发生了错误,这里面就包括在科学计算领域常用的numpy.pandas等.目前可以通过 ...

  10. OpenStack Train版-15.创建并挂载存储卷

    1.创建并挂载存储卷 创建一个1GB的卷 source ~/demo-openrc openstack volume create --size 1 volume1 很短的时间后,卷状态应该从crea ...