锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

几块钱的超声波也能仿真?ROS2仿真之添加超声波传感器

时间:2023-05-26 16:07:00 传感器if5505激光波传感器

大家好,我是小鱼,最近有点懒,对了,ROS第一个五年支持版发布了,动手学习ROS相关课程和文档也开始正式迁移Humble版本啦~

本节是扩展章节,主要讲解如何给它FishBot添加超声波传感器

在机器人开发的实际过程中,我们可以使用超声波传感器来实现实时避障功能。毕竟,超声波的价格比激光雷达便宜得多(便宜几元)。

让我们来谈谈如何使用这一节ROS2 Gazebo模拟超声波传感器。

1.超声传感器介绍

百科来段:

超声波传感器是将超声波信号转换为其它能量信号(通常是电信号)的传感器。超声波振动频率高于20kHz的机械波。它具有频率高、波长短、绕射现象小的特点,特别是方向性好,能成为射线和定向传播。超声波具有很大的液体和固体穿透能力,特别是在阳光不透明的固体中。超声波接触杂质或界面会产生明显的反射形成反射回波,接触活性物体会产生多普勒效应。超声传感器广泛应用于工业、国防、生物医学等领域。

接着看看长什么样子:

图片

便宜的就是这样。总共有两个头。一个头用于发送波,另一个头用于接收波。这也有点先进。带有光敏电阻可以补偿超声数据。

超声传感器的原理是什么?

距离=(发送时间-接收时间)*速度/2 

看了超声波的原理,你有没有发现和之前的激光雷达传感器一样,是的,所以超声波传感器插件和激光雷达传感器插件在Gazebo同一个插件:

libgazebo_ros_ray_sensor.so 

2.配置超声插件

直接配置,然后解释

2.1 添加超声波关节

超声波总是安装在机器人的某个位置,所以我们先添加关节和Joint,为了省事,link我们只写一个名字。如有必要,可以按照前一章添加。

                       

2.2 添加Gazebo插件

添加关节后,我们可以配置它gazebo的插件了,gazebo插件配置如下

            0 0 0 0 0 0              true              5                                                   5             1             -0.12             0.12                                              5             1             -0.01             0.01                                                 0.02           4           0.01                                      gaussian           0.0           0.01                                                      ~/out:=ultrasonic_sensor_1                           sensor_msgs/Range                  ultrasound                  ultrasonic_sensor_link                

3.编译操作测试

3.1Gazebo可视化

添加后,您可以编译和测试代码

colcon build --packages-select fishbot_description source install/setup.bash 
ros2 launch fishbot_description gazebo.launch.py 

没有物体的前面可以放个东西,因为本节是后面补充的,所有小鱼这里有个墙。

3.2话题数据

打开终端,输入以下指令

ros2 topic list  ros2 topic info /ultrasonic_sensor_1 ros2 topic echo /ultrasonic_sensor_1 

不出意外,您可以看到以下数据

header:   stamp:     sec: 4458     nanosec: 1000000   frame_id: ultrasonic_sensor_link radiation_type: 0 field_of_view: 0.23999999463558197 min_range: 0.019999999552965164 max_range: 4.0 range: 2.6798219680786133 

这里的range就是fishbot到墙之间的距离:2.67982

让我们来谈谈超声波传感器的数据类型sensor_msgs/msg/Range

# ros2 topic info /ultrasonic_sensor_1 Type: sensor_msgs/msg/Range Publisher count: 1 Subscription count: 0 

你可以使用ros2 interface show sensor_msgs/mg/Range看到详细的解释,我们翻译一下

# Single range reading from an active ranger that emits energy and reports
# one range reading that is valid along an arc at the distance measured.
# This message is  not appropriate for laser scanners. See the LaserScan
# message if you are working with a laser scanner.
#
# This message also can represent a fixed-distance (binary) ranger.  This
# sensor will have min_range===max_range===distance of detection.
# These sensors follow REP 117 and will output -Inf if the object is detected
# and +Inf if the object is outside of the detection range.

std_msgs/Header header # timestamp in the header is the time the ranger
                             # returned the distance reading

# Radiation type enums
# If you want a value added to this list, send an email to the ros-users list
uint8 ULTRASOUND=0
uint8 INFRARED=1

uint8 radiation_type    # 传感器射线类型
                        # (sound, IR, etc) [enum]

float32 field_of_view   # 距离数据对应的弧[rad]的大小,测量物体的范围介于		 
    					# -field_of_view/2 到 field_of_view/2 之间。
                        # 0 角度对应于传感器的 x 轴。

float32 min_range       # 最小范围值 [m]
float32 max_range       # 最大范围值 [m]
                        #  固定距离需要 min_range==max_range

float32 range           # 范围数据 [m]
                        # (Note: values < range_min or > range_max should be discarded)
                        # Fixed distance rangers only output -Inf or +Inf.
                        # -Inf represents a detection within fixed distance.
                        # (Detection too close to the sensor to quantify)
                        # +Inf represents no detection within the fixed distance.
                        # (Object out of range)

结论,主要关注range就可以了。

3.3 在RVIZ2中可视化超声波数据

Add ->By topic->Range

4.总结

本节主要介绍了如何对超声波传感器进行仿真,在导航的过程中我们通常把超声波放到一个代价地图中进行使用。所以学习其仿真还是很有用的。

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章