EtherCAT - HowardWhile/2023_note GitHub Wiki

EtherCAT

Acontis

SOEM

OpenEtherCATsociety/SOEM

https://blog.csdn.net/hejzh123456/article/details/127357775

https://gitee.com/jeasonb/soem_-imx6ull

https://openethercatsociety.github.io/doc/soem/

安裝

1 下載

cd Downloads
git clone https://github.com/OpenEtherCATsociety/SOEM.git
cd SOEM
git checkout v1.4.0

2 編譯

mkdir build
cd build
#cmake -DCMAKE_BUILD_TYPE=Debug .. #如果要跑單步debug
cmake ..
make

3 運行

cd ~/Downloads/SOEM/test/linux/slaveinfo/
sudo ./slaveinfo eth0

tips

我會在CMakeLists.txt新增這行代碼 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

讓執行檔輸出到 bin 資料夾

set(SOURCES slaveinfo.c)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
add_executable(slaveinfo ${SOURCES})
target_link_libraries(slaveinfo soem)
install(TARGETS slaveinfo DESTINATION bin)
cd ~/Downloads/SOEM/bin
sudo ./slaveinfo eth0

ROS2 使用 SOEM

https://github.com/HowardWhile/SOEM/tree/ros2-humble

複製原版SOEM

git clone https://github.com/OpenEtherCATsociety/SOEM.git

加入ROS package需要的package.xml

description 參考 https://github.com/OpenEtherCATsociety/SOEM 裡的描述

maintainer 參考 SOEM/SOES CONTRIBUTOR LICENSE AGREEMENT裡定義的訊息

license 參考 https://github.com/OpenEtherCATsociety/SOEM/blob/master/LICENSE

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>soem</name>
  <version>1.4.0</version>
  <description>Simple Open Source EtherCAT Master</description>
  <maintainer email="[email protected]">rt-labs</maintainer>
  <license>GPLv2 with linking exception</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

**修改CMakeLists.txt **

project(soem # SOEM -> soem 為了符合ros定義的命名規則
    DESCRIPTION "Simple Open EtherCAT Master"
    VERSION 1.4.0
    LANGUAGES C)
# ....
# ....
# 最後新增
find_package(ament_cmake REQUIRED)
ament_export_include_directories(include)
ament_package()

Etherlab

https://gitlab.com/etherlab.org/ethercat.git https://gitlab.com/etherlab.org/ethercat/-/jobs/artifacts/stable-1.5/raw/pdf/ethercat_doc.pdf?job=pdf https://zhuanlan.zhihu.com/p/376021989 https://icube-robotics.github.io/ethercat_driver_ros2/quickstart/installation.html

安裝

ref:

https://gitlab.com/etherlab.org/ethercat#building-and-installing

https://gitlab.com/etherlab.org/ethercat/-/jobs/artifacts/stable-1.5/raw/pdf/ethercat_doc.pdf?job=pdf > p.91, 9 Installation

https://zhuanlan.zhihu.com/p/573099682

0 環境

硬體是 Intel NUC8i7

作業系統是 ubuntu 22.04

核心訊息

uname
5.19.10-rt10 #1 SMP PREEMPT_RT Fri Dec 2 10:36:15 CST 2022 x86_64 x86_64 x86_64 GNU/Linux

這個核心是我編譯出來的realtime kernel方法可參考

https://github.com/HowardWhile/2022_note/wiki/Linux#preempt_rt

cyclictest的性能如圖

image-20230203094757687

安裝etherlab需要用到的東西

sudo apt install git autoconf libtool pkgconf

autoconf: 執行.\bootstrap需要用到

libtool: 執行.\bootstrap需要用到

pkgconf: 執行.\bootstrap需要用到包含編譯的工具make g++ ...

1 下載

cd Downloads
git clone https://gitlab.com/etherlab.org/ethercat.git

image-20230202114516217

cd ethercat
git checkout stable-1.5

看起來蠻新的不知道穩定度怎樣2023-02-02

2 配置與編譯

先創建configure腳本

./bootstrap

使用configure腳本產生make

./configure --disable-8139too --prefix=/opt/etherlab
#./configure --disable-8139too 

./configure --disable-8139too --enable-e1000e --prefix=/opt/etherlab --with-linux-dir=/usr/src/linux-headers-5.10.130-0510130/

說明書說--prefix的預設值是/opt/etherlab,但是實際上卻跑到/usr/local/etc裡面去了,只好自己打一遍

image-20230202171840075

  • 編譯
make all modules
  • 安裝
sudo make modules_install install
sudo depmod

完成時執行檔與各總相關的配置就會移動到/opt/etherlab/

  • 建立鏈結

建立/opt/etherlab與系統之間的連結關係

# 鏈結配置文件
#sudo mkdir /etc/sysconfig/
sudo ln -s /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig/ 

# 鏈結啟動文件
sudo ln -s /opt/etherlab/etc/init.d/ethercat /etc/init.d/

# 鏈結ethercat指令
sudo ln -s /opt/etherlab/bin/ethercat /usr/local/bin/ethercat
  • 配置網卡訊息

先查看網卡配置

image-20230202165325749

# For init.d based distro
sudo gedit /etc/sysconfig/ethercat 
# 與 sudo gedit /opt/etherlab/etc/sysconfig/ethercat 一樣的意思
# For systemd based distro
#sudo gedit /opt/etherlab/etc/ethercat.conf
code /opt/etherlab/etc/ethercat.conf
MASTER0_DEVICE="1c:69:7a:02:7d:99"
...
DEVICE_MODULES="generic"
  • udev設定
# 
sudo gedit /etc/udev/rules.d/99-EtherCAT.rules
# 輸入這些內容
KERNEL=="EtherCAT[0-9]*", MODE="0664", GROUP="users"

3 運行

For init.d based distro

sudo /etc/init.d/ethercat start
#sudo /etc/init.d/ethercat stop

For systemd based distro

sudo systemctl start ethercat
#sudo systemctl stop ethercat
#sudo systemctl enable ethercat #開機啟動
#sudo systemctl disenable ethercat #取消開機啟動

執行後可以看到/dev/目錄出現EtherCAT0

image-20230202174353600

透過指令使用

使用者手冊第7章

https://zhuanlan.zhihu.com/p/376021989

我拿 AMAX-4833 (研華的IO模組 32路DI) 來測試

版本訊息

ethercat version

image-20230209094919974

看從站訊息

ethercat slave
ethercat slave -v

image-20230209084316097

看整體狀態

ethercat graph
ethercat graph | dot -Tpng > bus.png #輸出成圖片

image-20230209085642198

image-20230209085845560

訪問SDO

列出設備的SDO字典

ethercat sdos

image-20230209101538405

訪問從站讀出Device name

ethercat upload 0x1008 00

image-20230209103234662

假如要讀DI0的狀態

image-20230209102725938

ethercat upload 0x6000 01

假如要改變DO10的輸出

image-20230209104739837

sudo ethercat download 0x7001 03 1 #
# sudo ethercat download 0x7001 03 0 # 關

訪問PDO

顯示PDO任務訊息

ethercat pdos

image-20230209111419163

以上各字段的含义:

  1. 同步管理器信息 SM3:同步管理器3; PhysAddr:物理地址开始地址; DefaultSize:默认数据大小; ControlRegister:控制寄存器; Enable:使能字

  2. 显示PDO方向,索引值,PDO名字 TxPDO:代表从站发送数据的方向(从站發送数据); 0x1600:PDO的索引值; "TxPDO":PDO的名字;

  3. 顯示PDO条目的索引和子索引(都是以16进制的形式现实的),显示位宽和描述 0x6000:01 : 表示索引和子索引;

    1 bit:表示该条目的位宽; "DIO0":表示该位的描述;

模式切換

切到OP mode?

不用特別設定甚麼就切換過去了...

sudo ethercat state SAFEOP
sudo ethercat state OP
sudo dmesg

image-20230209094328133

方便開關ethercat服務的腳本

echo '#!/bin/bash' > ~/ec-start.sh
echo 'sudo /etc/init.d/ethercat start' >> ~/ec-start.sh
chmod +x ~/ec-start.sh

echo '#!/bin/bash' > ~/ec-stop.sh
echo 'sudo /etc/init.d/ethercat stop' >> ~/ec-stop.sh
chmod +x ~/ec-stop.sh
⚠️ **GitHub.com Fallback** ⚠️