【實操填坑】在樹莓派上編譯 EtherCAT IgH Master 主站程序


官網下載地址:
https://etherlab.org/download/ethercat/  (可list查看文件列表)
https://etherlab.org/download/ethercat/ethercat-1.5.2.pdf (pdf doc手冊)

===============================================
本人操作環境:樹莓派 3B+
pi@ProfinetPI:~ $ uname -a
Linux ProfinetPI 4.19.71-rt24-v8 #1 SMP PREEMPT RT Wed Jan 26 01:35:13 CST 2022 aarch64 GNU/Linux

ethercat代碼版本為: 1.5.2-master-3ee5e50a
(注意:1.5.2 release包,在內核>4.15.x時會編譯make modules出錯,因為從4.15開始內核timer使用方式更改。)

==============================================
1. 編譯ethercat master和安裝:

$ git clone https://gitlab.com/etherlab.org/ethercat.git

$ cd ethercat (進入clone的源碼主目錄)

$ ./bootstrap (若下載的是tar.bz包,其中帶有m4子目錄,則不需此步驟; git clone的才需要)

$ ./configure --prefix=/opt/etherlab --with-linux-dir=/usr/src/linux --enable-8139too=no --enable-generic=yes  (提前准備好內核源碼,已編譯)

$ make -j 4 (4個線程加快)

$ make modules (需要有Modules.symvers和 System.map文件)(分別是編譯內核,編譯內核模塊后產生)
(此命令執行的結尾會運行depmod, 注意不能skip, 否則安裝時 modprobe會有問題)

# make install
# make modules_install //注意 depmod是否執行了. 安裝到了 /lib/modules/<uname -r>/ethercat/ 目錄下

2. 開始與系統集成【二選1】
//【方案1】 如果要用 init.d腳本, 那么用下面3行:
$ sudo mkdir /etc/sysconfig
$ sudo cp /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig/ethercat //這是配置文件
$ sudo cp /opt/etherlab/etc/init.d/ethercat /etc/init.d/ethercat //這是啟動腳本,特別要注意修改其中 -c 的配置文件位置!!!
$ insserv ethercat (安裝為開機自啟動服務)
// 方案1啟停 master內核主站的命令為: # /etc/init.d/ethercat start| stop| reload (或 #service ethercat start|stop)

//【方案2】 如果是用的 systemd管理服務, 則運行如下命令:
# cp /opt/etherlab/etc/ethercat.conf /etc/ethercat.conf (配置文件的位置)
# nano /usr/lib/systemd/system/ethercat.service (如果沒有,照着pdf doc 第7.4節拷貝一個.)
         (這里特別要修改其中的命令!!!! 顯式自己手動寫上配置文件位置 -c /path/to/conf_file 再 start) (坑:不會如pdf所說默認去找/etc/ethercat.conf作為配置文件)
# systemctl enable ethercat.service (設置開機啟動服務)
// 方案2啟停 master內核主站的命令為: # systemctl start| stop| status ethercat.service

其實這兩種系統集成方案,都是用了ethercat提供的最基礎的命令來啟停 內核模塊,
也可以直接運行基礎命令來啟停【方案3】, 指令如下:
# /opt/etherlab/sbin/ethercatctl -c /path/to/conf_file start|stop 【注意配置文件路徑要正確

3.啟動EtherCAT主站內核模塊

 三種方案不管用哪種, 在啟動前都要修改自己的配置文件

啟動前一定要確保對應配置文件中加入了 網卡mac 和 內核模塊類型
$ sudo vi /etc/sysconfig/ethercat //更改配置文件:(填入MAC地址或"eth0",以及網卡類型 "generic"

正式開始啟動Master主站 (三種方法選一種即可,以方案1為例)
# /etc/init.d/ethercat start|stop //注意配置文件中路徑是否對.

啟動后,檢查是否已經載入了內核模塊:
# lsmod | grep ec_ (會輸出兩行, ec_generic 和 ec_master, 說明已裝載)

4.使用tools工具

tools工具為:/opt/etherlab/bin/ethercat, 連接符號到/usr/bin/下以方便使用:
$ sudo ln -s /opt/etherlab/bin/ethercat /usr/bin/ethercat //軟連接

tools的使用(/opt/etherlab/bin/ethercat為tools工具)參見 pdf doc 第7章,簡單命令如下:
# ethercat slave (顯示掛載在主站上的從站信息)
0 0:0 PREOP + SV660_1Axis_00913  (顯示出了掛在主站網絡上的 匯川 SV660N伺服)

pi@ProfinetPI:~ $ ethercat -h (幫助信息)
Usage: ethercat <COMMAND> [OPTIONS] [ARGUMENTS]

Commands (can be abbreviated):
alias Write alias addresses.
config Show slave configurations.
crc CRC error register diagnosis.
cstruct Generate slave PDO information in C language.
data Output binary domain process data.
debug Set the master's debug level.
domains Show configured domains.
download Write an SDO entry to a slave.
eoe Display Ethernet over EtherCAT statictics.
foe_read Read a file from a slave via FoE.
foe_write Store a file on a slave via FoE.
graph Output the bus topology as a graph.
ip Set EoE IP parameters.
master Show master and Ethernet device information.
pdos List Sync managers, PDO assignment and mapping.
reg_read Output a slave's register contents.
reg_write Write data to a slave's registers.
rescan Rescan the bus.
sdos List SDO dictionaries.
sii_read Output a slave's SII contents.
sii_write Write SII contents to a slave.
slaves   Display slaves on the bus.
soe_read Read an SoE IDN from a slave.
soe_write Write an SoE IDN to a slave.
states Request application-layer states.
upload Read an SDO entry from a slave.
version Show version information.
xml Generate slave information XML.

Global options:
--master -m <master> Comma separated list of masters
to select, ranges are allowed.
Examples: '1,3', '5-7,9', '-3'.
Default: '-' (all).
--force -f Force a command.
--quiet -q Output less information.
--verbose -v Output more information.
--help -h Show this help.

Numerical values can be specified either with decimal (no
prefix), octal (prefix '0') or hexadecimal (prefix '0x') base.

 

#安裝IgH EtherCAT主站部分完結, 之后就是如何使用主站來控制 伺服點擊轉圈圈了。#

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM