ROS常用命令(激光雷达消息包 LaserScan.msg)

本文详细介绍了如何在ROS(RobotOperatingSystem)环境中创建一个处理激光雷达数据的节点,包括定义参数、订阅LaserScan消息、编写C++代码以及编译和运行。步骤涉及创建目录、添加依赖、编写节点程序和在Gazebo环境中测试。
摘要由CSDN通过智能技术生成

参数定义

# Single scan from a planar laser range-finder
#
# If you have another ranging device with different behavior (e.g. a sonar
# array), please find or create a different message, since applications
# will make fairly laser-specific assumptions about this data

Header header            # timestamp in the header is the acquisition time of 
                         # the first ray in the scan.
                         #
                         # in frame frame_id, angles are measured around 
                         # the positive Z axis (counterclockwise, if Z is up)
                         # with zero angle being forward along the x axis
                         
float32 angle_min        # start angle of the scan [rad] 扫描起始角度
float32 angle_max        # end angle of the scan [rad] 扫描终止角度
float32 angle_increment  # angular distance between measurements [rad] 两次测距的弧度增量

float32 time_increment   # time between measurements [seconds] - if your scanner
                         # is moving, this will be used in interpolating position
                         # of 3d points 两次测距的时间增量
float32 scan_time        # time between scans [seconds] 单次扫描时长

float32 range_min        # minimum range value [m] 最小有效扫描距离
float32 range_max        # maximum range value [m] 最大有效扫描距离

float32[] ranges         # range data [m] (Note: values < range_min or > range_max 
                         # should be discarded) 测量距离集
float32[] intensities    # intensity data [device-specific units].  If your
                         # device does not provide intensities, please leave
                         # the array empty. 测量强度集

创建激光雷达消息包节点

# Step1:创建工作目录,添加依赖项

cd catkin_ws/src

catkin_create_pkg lidar_pkg roscpp rospy sensor_msgs

# Step2:创建lidar_node.cpp

#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

void LidarCallBack(const sensor_msgs::LaserScan msg)
{
    float fMidDist = msg.ranges[180];
    ROS_INFO("Distance is %f", fMidDist);
}

int main(int argc, char *argv[])
{
    ros::init(argc, argv, "lidar_node");

    ros::NodeHandle n;
    ros::Subscriber lidar_sub = n.subscribe("/scan", 10, &LidarCallBack);

    ros::spin();
    return 0;
}

# Step3:在CMakeLists.txt文件中,添加如下

add_executable(lidar_node src/lidar_node.cpp)
target_link_libraries(lidar_node
    ${catkin_LIBRARIES}
)

# Step4:在catkin_ws文件下,编译运行

catkin_make

# Step5:运行Gazebo

roslaunch wpr_simulation wpb_simple.launch

# Step6:运行lidar_node节点

rosrun lidar_pkg lidar_node

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值