小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
《ROS 2多协议传输控制器》使用 micro-ROS 协议+以太网DHCP方式接入 ROS 系统
-
《ROS 2多协议传输控制器》使用 micro-ROS 协议+以太网DHCP方式接入 ROS 系统
开始前准备:
硬件:
- 传输控制板*1
- Type-B电源线*1
- 网线*1
- 带网口的电脑或者USB网卡*1
- 9~28V电源
软件:
- 安装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口
电脑<----网线----->路由器<----网线----->控制板网口
电源---->控制板电源口3.查看电脑IP地址
使用ifconfig查看所有网卡
ifconfig --- enx4ce173422378: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::915b:c170:f24c:844c prefixlen 64 scopeid 0x20<link> ether 4c:e1:73:42:23:78 txqueuelen 1000 (以太网) RX packets 38 bytes 3850 (3.8 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 81 bytes 12357 (12.3 KB) 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
可以看到我这里有一个USB网卡:enx4ce173422378 是以太网(你的可能不是这个名字,请仔细辨别)
目前已经自动DHCP分配了一个IP地址:192.168.0.2 这个就是服务器的IP地址。
4.使用配置助手修改配置
打开配置助手,扫描配置,确认如下选项的值,若不是,请手动修改。
配置项 描述 设置值 transport_mode 传输模式(例如以太网静态IP配置协议) eth_dhcp server_ip 服务器的IP地址 你的电脑ip(这里是192.168.0.2) 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 --- [1719815438.222600] info | UDPv4AgentLinux.cpp | init | running... | port: 8888 [1719815438.222750] info | Root.cpp | set_verbose_level | logger setup | verbose_level: 4 [1719815496.167443] info | Root.cpp | create_client | create | client_key: 0x4786978B, session_id: 0x81 [1719815496.167490] info | SessionManager.hpp | establish_session | session established | client_key: 0x4786978B, address: 192.168.0.5:47138 [1719815496.183027] info | ProxyClient.cpp | create_participant | participant created | client_key: 0x4786978B, participant_id: 0x000(1) [1719815496.185031] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4786978B, topic_id: 0x000(2), participant_id: 0x000(1) [1719815496.186523] info | ProxyClient.cpp | create_publisher | publisher created | client_key: 0x4786978B, publisher_id: 0x000(3), participant_id: 0x000(1) [1719815496.188218] info | ProxyClient.cpp | create_datawriter | datawriter created | client_key: 0x4786978B, datawriter_id: 0x000(5), publisher_id: 0x000(3) [1719815496.190136] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4786978B, topic_id: 0x001(2), participant_id: 0x000(1) [1719815496.191351] info | ProxyClient.cpp | create_subscriber | subscriber created | client_key: 0x4786978B, subscriber_id: 0x000(4), participant_id: 0x000(1) [1719815496.192840] info | ProxyClient.cpp | create_datareader | datareader created | client_key: 0x4786978B, datareader_id: 0x000(6), subscriber_id: 0x000(4) [1719815496.194586] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4786978B, topic_id: 0x002(2), participant_id: 0x000(1) [1719815496.195990] info | ProxyClient.cpp | create_publisher | publisher created | client_key: 0x4786978B, publisher_id: 0x001(3), participant_id: 0x000(1) [1719815496.197459] info | ProxyClient.cpp | create_datawriter | datawriter created | client_key: 0x4786978B, datawriter_id: 0x001(5), publisher_id: 0x001(3) [1719815496.199148] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4786978B, topic_id: 0x003(2), participant_id: 0x000(1) [1719815496.200651] info | ProxyClient.cpp | create_subscriber | subscriber created | client_key: 0x4786978B, subscriber_id: 0x001(4), participant_id: 0x000(1) [1719815496.202154] info | ProxyClient.cpp | create_datareader | datareader created | client_key: 0x4786978B, datareader_id: 0x001(6), subscriber_id: 0x001(4) [1719815496.203922] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4786978B, topic_id: 0x004(2), participant_id: 0x000(1) [1719815496.205361] info | ProxyClient.cpp | create_publisher | publisher created | client_key: 0x4786978B, publisher_id: 0x002(3), participant_id: 0x000(1) [1719815496.206800] info | ProxyClient.cpp | create_datawriter | datawriter created | client_key: 0x4786978B, datawriter_id: 0x002(5), publisher_id: 0x002(3) [1719815496.208490] info | ProxyClient.cpp | create_topic | topic created | client_key: 0x4786978B, topic_id: 0x005(2), participant_id: 0x000(1) [1719815496.209961] info | ProxyClient.cpp | create_subscriber | subscriber created | client_key: 0x4786978B, subscriber_id: 0x002(4), participant_id: 0x000(1) [1719815496.211445] info | ProxyClient.cpp | create_datareader | datareader created | client_key: 0x4786978B, 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一致。
-