拓展: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%E6%95%99%E7%A8%8B-5-%E9%9B%B7%E8%BE%BE%E5%9B%BA%E4%BB%B6%E7%83%A7%E5%BD%95%E5%8F%8A%E9%85%8D%E7%BD%AE/1?lang=zh-CN
  • https://fishros.org.cn/forum/topic/954/fishbot%E6%95%99%E7%A8%8B-6-%E9%9B%B7%E8%BE%BE%E9%A9%B1%E5%8A%A8%E5%8F%8A%E5%BB%BA%E5%9B%BE%E6%B5%8B%E8%AF%95

如果想通过源码的方式也可以,雷达板的主要作用是将雷达 数据生成一个虚拟的串口,在电脑上直接运行下面这段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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值