EtherCAT - HowardWhile/2023_note GitHub Wiki
https://blog.csdn.net/hejzh123456/article/details/127357775
https://gitee.com/jeasonb/soem_-imx6ull
https://openethercatsociety.github.io/doc/soem/
cd Downloads
git clone https://github.com/OpenEtherCATsociety/SOEM.gitcd SOEM
git checkout v1.4.0mkdir build
cd build
#cmake -DCMAKE_BUILD_TYPE=Debug .. #如果要跑單步debug
cmake ..
makecd ~/Downloads/SOEM/test/linux/slaveinfo/
sudo ./slaveinfo eth0tips
我會在
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 eth0https://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()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
硬體是 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的性能如圖
安裝etherlab需要用到的東西
sudo apt install git autoconf libtool pkgconfautoconf: 執行.\bootstrap需要用到
libtool: 執行.\bootstrap需要用到
pkgconf: 執行.\bootstrap需要用到包含編譯的工具make g++ ...
cd Downloads
git clone https://gitlab.com/etherlab.org/ethercat.git
cd ethercat
git checkout stable-1.5看起來蠻新的不知道穩定度怎樣2023-02-02
先創建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裡面去了,只好自己打一遍
- 編譯
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- 配置網卡訊息
先查看網卡配置

# 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.confMASTER0_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"For init.d based distro
sudo /etc/init.d/ethercat start
#sudo /etc/init.d/ethercat stopFor systemd based distro
sudo systemctl start ethercat
#sudo systemctl stop ethercat
#sudo systemctl enable ethercat #開機啟動
#sudo systemctl disenable ethercat #取消開機啟動執行後可以看到/dev/目錄出現EtherCAT0

使用者手冊第7章
https://zhuanlan.zhihu.com/p/376021989
我拿 AMAX-4833 (研華的IO模組 32路DI) 來測試
ethercat version
ethercat slave
ethercat slave -v
ethercat graph
ethercat graph | dot -Tpng > bus.png #輸出成圖片

列出設備的SDO字典
ethercat sdos
訪問從站讀出Device name
ethercat upload 0x1008 00
假如要讀DI0的狀態

ethercat upload 0x6000 01假如要改變DO10的輸出

sudo ethercat download 0x7001 03 1 # 開
# sudo ethercat download 0x7001 03 0 # 關顯示PDO任務訊息
ethercat pdos
以上各字段的含义:
-
同步管理器信息 SM3:同步管理器3; PhysAddr:物理地址开始地址; DefaultSize:默认数据大小; ControlRegister:控制寄存器; Enable:使能字
-
显示PDO方向,索引值,PDO名字 TxPDO:代表从站发送数据的方向(从站發送数据); 0x1600:PDO的索引值;
"TxPDO":PDO的名字; -
顯示PDO条目的索引和子索引(都是以16进制的形式现实的),显示位宽和描述 0x6000:01 : 表示索引和子索引;
1 bit:表示该条目的位宽;
"DIO0":表示该位的描述;
切到OP mode?
不用特別設定甚麼就切換過去了...
sudo ethercat state SAFEOP
sudo ethercat state OP
sudo dmesg
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
