如何建立 Jetson 与 EtherCAT 设备之间的通信
EtherCAT(用于控制自动化技术的以太网)是一种基于 IEEE 802.3 以太网标准的开源、高性能实时工业以太网现场总线协议。它采用主从架构,以其在工业自动化环境中的卓越速度、精度和灵活性而闻名
本文档使用 recomputer robotics J401 作为 EtherCAT 主站,使用 MyActuator X4 作为从站,演示如何建立 Jetson 与 EtherCAT 设备之间的通信。


1. 硬件连接
作为 EtherCAT 主站,Jetson 通常使用其以太网接口连接到 EtherCAT 从设备。

由于许多从设备不提供标准以太网端口,通常需要适配器将以太网连接转换为 4 针接口(Tx+、Tx–、Rx+、Rx–)。

建立物理 EtherCAT 连接后,大多数从设备仍需要额外的外部电源。
2. 安装 EtherCAT 驱动程序
本节以 L4T 36.4.3(对应 JetPack 6.2 BSP)为例,展示如何在 Jetson 中安装 EtherCAT 驱动程序。
安装构建 EtherCAT 驱动程序所需的依赖项:
sudo apt update
sudo apt install build-essential cmake libtool autoconf automake
拉取 EtherCAT 驱动程序源代码,然后编译并安装:
git clone https://gitlab.com/etherlab.org/ethercat.git
cd ethercat
./bootstrap # to create the configure script, if downloaded from the repo
./configure --sysconfdir=/etc
make all modules
sudo make modules_install install
sudo depmod -a
要验证驱动程序是否已成功安装,请运行以下命令。
您应该看到两个内核模块 ec_master 和 ec_generic:
sudo lsmod | grep "ec_"

3. EtherCAT 配置
安装 EtherCAT 驱动程序后,需要进行几项配置以激活主站和从设备之间的通信。
首先,编辑 /etc/ethercat.conf 的配置文件:
sudo vim /etc/ethercat.conf
根据连接到 Jetson 的以太网接口名称修改 /etc/ethercat.conf 中的两个参数:
MASTER0_DEVICE="eno1" # Replace eno1 with the Ethernet interface used for EtherCAT
DEVICE_MODULES="generic"
将 eno1 替换为用于 EtherCAT 的以太网接口。您可以使用 ifconfig 命令检查接口名称。
重启 EtherCAT 服务后,您应该在 /dev 目录中看到 EtherCAT 主设备:
sudo systemctl restart ethercat
ls /de/EtherCAT*

(可选)如果未找到 /dev/EtherCAT,请尝试手动加载内核模块:
sudo modprobe ec_master devices="eno1" # Replace eno1 with the Ethernet interface used for EtherCAT
sudo modprobe ec_generic
sudo systemctl restart ethercat
将 eno1 替换为用于 EtherCAT 的以太网接口。
(可选)有时用于 EtherCAT 的以太网接口可能被 NetworkManager 占用。您可以使用以下命令释放它:
sudo nmcli dev set eno1 managed no # Replace eno1 with the Ethernet interface used for EtherCAT
sudo nmcli dev set eno1 managed on # Replace eno1 with the Ethernet interface used for EtherCAT
将 eno1 替换为用于 EtherCAT 的以太网接口。
4. 测试 Jetson 与 EtherCAT 从站之间的通信
确认 EtherCAT 主节点在 Jetson 上正确初始化且硬件连接正确建立后,您可以在终端中测试 Jetson 与 EtherCAT 设备之间的通信。
扫描 EtherCAT 设备并测试数据传输,检查丢包率是否在正常范围内:
sudo ethercat rescan
sudo ethercat master

列出总线上的所有 EtherCAT 设备:
sudo ethercat rescan
sudo ethercat slaves -v

查看索引为 0 的 EtherCAT 设备的问题:
sudo ethercat rescan
sudo ethercat pdos -p 0 #0 to n
-p 后的参数可以是从 0 到 n 的任何值。

资源
技术支持与产品讨论
感谢您选择我们的产品!我们在这里为您提供不同的支持,以确保您使用我们产品的体验尽可能顺畅。我们提供多种沟通渠道,以满足不同的偏好和需求。