拓展2:FishBot配套雷达驱动教程(源码版)
-
目前FishBot主要配套雷达型号为EAI-X2,后续可能会引入其他雷达。
一、EAI-X2 雷达
针对EAI-X2,采用的驱动为小鱼修改后的ROS2驱动:
- 代码仓库为:https://github.com/fishros/ydlidar_ros2
- 代码分支为:v1.0.0/fishbot
1.1 有线驱动-树莓派工控机直连都可以通过这种方式
将配套的雷达转接板模式调整到UART模式,拔掉EN跳线帽(可以关闭ESP8266,节省能源), 找一根USB线,将 雷达板接入到你要驱动的电脑或者各种PI上。
下载源码到任意一个目录:
git clone http://github.fishros.org/https://github.com/fishros/ydlidar_ros2 -b v1.0.0/fishbot
进入到源码,修改串口编号ydlidar_ros2/params/ydlidar.yaml,一般是/dev/ttyUSB0
ydlidar_node: ros__parameters: port: /dev/ttyUSB0 frame_id: laser_frame ignore_array: ""
接着编译 :
cd ydlidar_ros2 colcon build
接着修改串口权限,然后运行驱动
sudo chmod 666 /dev/ttyUSB0 source install/setup.bash ros2 launch ydlidar ydlidar_launch.py --- [INFO] [launch]: All log files can be found below /home/pi/.ros/log/2023-07-21-23-13-28-893425-raspberrypi-4518 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [ydlidar_node-1]: process started with pid [4539] [INFO] [static_transform_publisher-2]: process started with pid [4541] [static_transform_publisher-2] [WARN] [1689952409.891692804] []: Old-style arguments are deprecated; see --help for new-style arguments [static_transform_publisher-2] [INFO] [1689952409.975433434] [static_tf_pub_laser]: Spinning until stopped - publishing transform [static_transform_publisher-2] translation: ('0.020000', '0.000000', '0.000000') [static_transform_publisher-2] rotation: ('0.000000', '0.000000', '0.000000', '1.000000') [static_transform_publisher-2] from 'base_link' to 'laser_frame' [ydlidar_node-1] [YDLIDAR INFO] Current ROS Driver Version: 1.4.5 [ydlidar_node-1] [YDLIDAR]:SDK Version: 1.4.5 [ydlidar_node-1] [YDLIDAR]:Lidar running correctly ! The health status: good [ydlidar_node-1] [YDLIDAR] Connection established in [/dev/ttyUSB0][115200]: [ydlidar_node-1] Firmware version: 1.5 [ydlidar_node-1] Hardware version: 1 [ydlidar_node-1] Model: S4 [ydlidar_node-1] Serial: 2020112400007024 [ydlidar_node-1] [YDLIDAR]:Fixed Size: 370 [ydlidar_node-1] [YDLIDAR]:Sample Rate: 3K [ydlidar_node-1] [YDLIDAR INFO] Current Sampling Rate : 3K [ydlidar_node-1] [YDLIDAR INFO] Now YDLIDAR is scanning ......
最后使用ros2 topic list 就可以看到话题list了,scan就是雷达话题
os2 topic list /parameter_events /rosout /scan /tf_static /ydlidar_node/transition_event
1.2 无线驱动-对于台式机很合适
直接用Docker,最方便:
- https://www.fishros.org.cn/forum/topic/940/fishbot教程-5-雷达固件烧录及配置/1?lang=zh-CN
- https://fishros.org.cn/forum/topic/954/fishbot教程-6-雷达驱动及建图测试
如果想通过源码的方式也可以,雷达板的主要作用是将雷达 数据生成一个虚拟的串口,在电脑上直接运行下面这段Python代码,当连接建立后,就会直接生成 一个虚拟串口,然后按照 1.1 的方式就可以直接驱动了。
#!/usr/bin/env python3 import subprocess import os import pty import socket import select import argparse import subprocess import time class LaserScanRos2(): def __init__(self) -> None: self.laser_pro = None class SocketServer(): def __init__(self,lport=8888,uart_name="/tmp/fishbot_laser") -> None: self.lport = lport self.uart_name = uart_name self.laser_ros2 = LaserScanRos2() self.main() def main(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(('0.0.0.0', self.lport)) s.listen(5) master, slave = pty.openpty() if os.path.exists(self.uart_name): os.remove(self.uart_name) os.symlink(os.ttyname(slave), self.uart_name) print(f"UART2SOCKET:{self.lport}->{self.uart_name}") mypoll = select.poll() mypoll.register(master, select.POLLIN) try: while True: print("Prepare to Accept connect!") client, client_address = s.accept() mypoll.register(client.fileno(), select.POLLIN) print(s.fileno(), client, master) print('PTY: Opened {} for {}:{}'.format( os.ttyname(slave), '0.0.0.0', self.lport)) is_connect = True try: while is_connect: fdlist = mypoll.poll(256) for fd, event in fdlist: data = os.read(fd, 256) write_fd = client.fileno() if fd == master else master if len(data) == 0: is_connect = False break os.write(write_fd, data) # print(fd, event, data) except ConnectionResetError: is_connect = False print("远程被迫断开链接") finally: mypoll.unregister(client.fileno()) finally: s.close() os.close(master) os.close(slave) os.remove(self.uart_name) def main(): SocketServer() if __name__ == "__main__": main()
-
小 小鱼 在 中 引用了 这个主题
-
小 小鱼 在 中 引用了 这个主题
-
@小鱼 我感觉这段python代码也许可以修改一下:
https://fishros.org.cn/forum/topic/1477/fishbot雷达板docker驱动断连后不能自动恢复
-
@d4nk3n 收到,感谢指正
-
@小鱼 在 拓展2:FishBot配套雷达驱动教程(源码版) 中说:
fishbot_laser
无线驱动这段没看懂呢,有线的跑通了
这个python运行后,是谁来连接它呢?
我运行后处于 Prepare to Accept connect!状态
然后我把ydlidar_ros2/params/ydlidar.yaml 改为 port: /tmp/fishbot_laser
编译后,运行会time out,解决:作者这段py的端口号要改为8889,因为雷达板默认配的是8889
希望可以给后来者 -
@154453683 可以先看快速上手教程,搞定链接
-
鱼哥,用树莓派通过串口连接转接板后运行雷达出现雷达停止运行了
-
@2524167316 确认下端口号是否正确,串口权限是否正确,可以使用cutecom打开指定端口看看数据。
-
-
雷达启动后会发布/map话题么,我在nav2启动的时候遇到如下报错
需要对雷达驱动进行更改么? -
@1141682555 雷达启动只发布sca话题,map需要slam算法发布
-
@小鱼 我现在建图时候一直发生漂移,/map坐标轴是移动的,/odom坐标轴固定不动
<?xml version="1.0"?>
<robot name="pigbot"><!-- Robot Footprint -->
<link name="base_footprint"/>
<joint name="base_joint" type="fixed">
<parent link="base_footprint"/>
<child link="base_link"/>
<origin xyz="0.0 0.0 0.166" rpy="0 0 0"/>
</joint><!-- base link -->
<link name="base_link">
<visual>
<origin xyz="0 0 0.0" rpy="0 0 0"/>
<geometry>
<box size="0.57 0.45 0.17"/>
</geometry>
<material name="blue">
<color rgba="0.1 0.1 1.0 0.5" />
</material>
</visual>
</link><!-- laser link -->
<link name="laser_frame">
<visual>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<cylinder length="0.02" radius="0.02"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.5" />
</material>
</visual>
</link><!-- laser joint -->
<joint name="laser_joint" type="fixed">
<parent link="base_link" />
<child link="laser_frame" />
<origin xyz="0 0 0.075" />
</joint><!-- wheel link -->
<link name="left_front_wheel_link">
<visual>
<origin xyz="0 0 0" rpy="1.57079 0 0"/>
<geometry>
<cylinder length="0.07" radius="0.166"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.5" />
</material>
</visual>
</link><joint name="left_front_wheel_joint" type="continuous">
<parent link="base_link" />
<child link="left_front_wheel_link" />
<origin xyz="0.175 0.225 -0.085" />
<axis xyz="0 1 0" />
</joint><link name="left_back_wheel_link">
<visual>
<origin xyz="0 0 0" rpy="1.57079 0 0"/>
<geometry>
<cylinder length="0.07" radius="0.166"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.5" />
</material>
</visual>
</link><joint name="left_back_wheel_joint" type="continuous">
<parent link="base_link" />
<child link="left_back_wheel_link" />
<origin xyz="-0.175 0.225 -0.085" />
<axis xyz="0 1 0" />
</joint><link name="right_front_wheel_link">
<visual>
<origin xyz="0 0 0" rpy="1.57079 0 0"/>
<geometry>
<cylinder length="0.07" radius="0.166"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.5" />
</material>
</visual>
</link><joint name="right_front_wheel_joint" type="continuous">
<parent link="base_link" />
<child link="right_front_wheel_link" />
<origin xyz="0.175 -0.225 -0.085" />
<axis xyz="0 1 0" />
</joint><link name="right_back_wheel_link">
<visual>
<origin xyz="0 0 0" rpy="1.57079 0 0"/>
<geometry>
<cylinder length="0.07" radius="0.166"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.5" />
</material>
</visual>
</link><joint name="right_back_wheel_joint" type="continuous">
<parent link="base_link" />
<child link="right_back_wheel_link" />
<origin xyz="-0.175 -0.225 -0.085" />
<axis xyz="0 1 0" />
</joint></robot>
这是我的URDF,里程计话题发布和教程是一样的,请问中间有什么问题需要更改 -
按照教程编译的时候会报错,我的pi上位机版本是:
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=foxy -
你好,usb一连接到虚拟机,就断开是怎么回事啊。
,谢谢!
-
@distinctyz 看看驱动占用问题是否解决
-
@dong5515 驱动时humble版本导致的,建议更换到humble