开始前准备:
硬件:
传输控制板*1 Type-B电源线*1 带wifi的路由器*1 可以连wifi的电脑*1 9~28V电源*1软件:
安装Ubuntu的系统*1 安装好ROS2 Humble以上版本ROS系统 1. micro-ROS Agent 和 消息接口下载与构建在主目录下创建,ros2_transmission_ws 目录及子目录src(其他目录也可以)
mkdir -p ~/ros2_transmission_ws/src下载源码
cd ~/ros2_transmission_ws/src git clone http://github.fishros.org/https://github.com/fishros/micro-ROS-Agent -b humble git clone http://github.fishros.org/https://github.com/fishros/robot_interfaces git clone http://github.fishros.org/https://github.com/micro-ROS/micro_ros_msgs.git -b humble构建工作空间
cd ~/ros2_transmission_ws/ colcon build --- Starting >>> micro_ros_agent Starting >>> robot_interfaces Finished <<< robot_interfaces [6.76s] [Processing: micro_ros_agent] --- stderr: micro_ros_agent 正克隆到 'xrceagent'... 切换到一个新分支 'ros2' HEAD 目前位于 c25243c Enable Domain Override on Reference and XML Participant (#351) CMake Warning (dev) at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:438 (message): The package name passed to `find_package_handle_standard_args` (tinyxml2) does not match the name of the calling package (TinyXML2). This can lead to problems in calling code that expects `find_package` result variables (e.g., `_FOUND`) to follow a certain pattern. Call Stack (most recent call first): cmake/modules/FindTinyXML2.cmake:40 (find_package_handle_standard_args) /opt/ros/humble/share/fastrtps/cmake/fastrtps-config.cmake:51 (find_package) CMakeLists.txt:153 (find_package) This warning is for project developers. Use -Wno-dev to suppress it. --- Finished <<< micro_ros_agent [56.9s] Summary: 2 packages finished [58.9s] 1 package had stderr output: micro_ros_agent看到:Summary: 2 packages finished [58.9s] 就表示构建成功了,中间的警告请忽略。
2.完成硬件连接这种连接方式的特点是,通过网线将雷达和电脑(控制卡)直连,优点是稳定。
连接方式:
电脑<----Type-B|USB线----->控制板USB口
电源---->控制板电源口
电脑连接路由器(无线和有线方式都可),使用ifconfig查看所有网卡,这里使用的是无线。
ifconfig --- wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.4 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::f975:43a1:633a:76a5 prefixlen 64 scopeid 0x20<link> ether 98:af:65:43:35:55 txqueuelen 1000 (以太网) RX packets 45221 bytes 31293576 (31.2 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 33645 bytes 19967816 (19.9 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (本地环回) RX packets 879222 bytes 758350473 (758.3 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 879222 bytes 758350473 (758.3 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0可以看到我这里有一个WIFI网卡:wlp0s20f3 分配的IP地址是 192.168.0.4
目前已经自动DHCP分配了一个IP地址: 192.168.0.4 这个就是服务器的IP地址。
4.使用配置助手修改配置打开配置助手,扫描配置(若无法扫描可以长按key到led停止闪烁松开,恢复默认设置),确认如下选项的值,若不是,请手动修改。
配置项 描述 设置值 transport_mode 传输模式 wifi_sta server_ip 服务器的IP地址 你的电脑ip(这里是192.168.0.4) wifi_ssid WIFI用户名 路由器2.4G WIFI名称 wifi_pswd WIFI密码 路由器2.4G WIFI 密码 server_port 服务器的端口号 8888传输模式我们这里采用 eth_dhcp ,动态分配IP模式,并设置micro-ROS的服务器的IP地址为你的电脑ip地址。
设置完成后请手动或者点击配置助手的重启设备进行重启。
5.运行agent,接收消息进入到工作空间,运行agent
cd ~/ros2_transmission_ws/ source install/setup.bash ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888 -v4 --- [1719817897.879859] info | UDPv4AgentLinux.cpp | init | running... | port: 8888 [1719817897.880011] info | Root.cpp | set_verbose_level | logger setup | verbose_level: 4 [1719817900.503042] info | Root.cpp | create_client | create | client_key: 0x4A718303, session_id: 0x81 [1719817900.503103] info | SessionManager.hpp | establish_session | session established | client_key: 0x4A718303, address: 192.168.0.6:47138 [1719817900.516614] info | ProxyClient.cpp | create_participant | participant created | client_key: 0x4A718303, participant_id: 0x000(1) [1719817900.529808] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4A718303, topic_id: 0x000(2), participant_id: 0x000(1) [1719817900.535428] info | ProxyClient.cpp | create_publisher | publisher created | client_key: 0x4A718303, publisher_id: 0x000(3), participant_id: 0x000(1) [1719817900.542849] info | ProxyClient.cpp | create_datawriter | datawriter created | client_key: 0x4A718303, datawriter_id: 0x000(5), publisher_id: 0x000(3) [1719817900.548450] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4A718303, topic_id: 0x001(2), participant_id: 0x000(1) [1719817900.554465] info | ProxyClient.cpp | create_subscriber | subscriber created | client_key: 0x4A718303, subscriber_id: 0x000(4), participant_id: 0x000(1) [1719817900.560084] info | ProxyClient.cpp | create_datareader | datareader created | client_key: 0x4A718303, datareader_id: 0x000(6), subscriber_id: 0x000(4) [1719817900.567017] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4A718303, topic_id: 0x002(2), participant_id: 0x000(1) [1719817900.576328] info | ProxyClient.cpp | create_publisher | publisher created | client_key: 0x4A718303, publisher_id: 0x001(3), participant_id: 0x000(1) [1719817900.581259] info | ProxyClient.cpp | create_datawriter | datawriter created | client_key: 0x4A718303, datawriter_id: 0x001(5), publisher_id: 0x001(3) [1719817900.588277] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4A718303, topic_id: 0x003(2), participant_id: 0x000(1) [1719817900.592815] info | ProxyClient.cpp | create_subscriber | subscriber created | client_key: 0x4A718303, subscriber_id: 0x001(4), participant_id: 0x000(1) [1719817900.598948] info | ProxyClient.cpp | create_datareader | datareader created | client_key: 0x4A718303, datareader_id: 0x001(6), subscriber_id: 0x001(4) [1719817900.604568] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4A718303, topic_id: 0x004(2), participant_id: 0x000(1) [1719817900.609124] info | ProxyClient.cpp | create_publisher | publisher created | client_key: 0x4A718303, publisher_id: 0x002(3), participant_id: 0x000(1) [1719817900.614269] info | ProxyClient.cpp | create_datawriter | datawriter created | client_key: 0x4A718303, datawriter_id: 0x002(5), publisher_id: 0x002(3) [1719817900.621935] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4A718303, topic_id: 0x005(2), participant_id: 0x000(1) [1719817900.627077] info | ProxyClient.cpp | create_subscriber | subscriber created | client_key: 0x4A718303, subscriber_id: 0x002(4), participant_id: 0x000(1) [1719817900.631950] info | ProxyClient.cpp | create_datareader | datareader created | client_key: 0x4A718303, datareader_id: 0x002(6), subscriber_id: 0x002(4)看到上面的日志就表示连接成功了,接着就可以尝试订阅IO状态话题,打开新的终端,输入如下命令:
cd ~/ros2_transmission_ws/ source install/setup.bash ros2 topic echo /read_io --- analog: [] digital: - 1 - 1 - 1 - 1 --- analog: [] digital: - 1 - 1 - 1 - 1 --- ...可以看到这里每帧输出了四个数据,是四个输入IO的状态,这个话题默认以10Hz进行发布,发布频率可以修改。
使用 ros2 topic list 可以查看控制器节点可以支持的话题。
话题名称 消息接口 订阅/发布 /write_485 robot_interfaces/msg/RawUInt8 订阅 /write_can robot_interfaces/msg/CanFrame 订阅 /write_io robot_interfaces/msg/WriteIO 订阅 /read_485 robot_interfaces/msg/RawUInt8 发布 /read_can robot_interfaces/msg/CanFrame 发布 /read_io robot_interfaces/msg/ReadIO 发布关于每个话题如何使用,可以参考例程篇介绍。
6. 设置固定IP地址因为控制板要将数据发送到电脑端,如果电脑的IP采用DHCP动态分配,一旦分配到其他IP都会造成通信异常。解决方法是通过在路由器后台设置IP地址和MAC地址绑定,这样就可以保证每次分配的IP一致。