Table of contents
Installing EtherCAT
ethercat-rs
uses thelibclang
andprotobuf
libraries. To install them on ubuntu run:sudo apt-get install libclang-dev sudo apt-get install -y protobuf-compiler libprotobuf-dev
Installing the EtherCAT master
- Install the dependencies (on ubuntu):
sudo apt install autoconf libtool pkg-config
- Install the ethercat master
git clone https://gitlab.com/etherlab.org/ethercat.git
cd ethercat
- use the
stable-1.6
branchgit checkout stable-1.6
- if needed
stable-1.5
will work too
- if needed
./bootstrap
./configure --enable-generic --disable-8139too
make all modules
sudo make modules_install install
sudo depmod
Rust stack will need to know where the
ethercat
binary is located. So add the path to theethercat
binary to theETHERCAT_PATH
variable
- either by:
export ETHERCAT_PATH=$HOME/ethercat
- or add it to the
.bashrc
file
Configure EtherCAT master
In order configure the ethercat
we need to give the master the MAC address of the PC/ehternet port.
-
run
ip a
to find the mac address of the ethernet port:2: enp8s0f2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether d0:63:b4:05:47:37 brd ff:ff:ff:ff:ff:ff
- Modify the file
/usr/local/etc/ethercat.conf
MASTER0_DEVICE
- set the mac address (ex.d0:63:b4:05:47:37
) or the name of the port (ex.enp8s0f2
)DEVICE_MODULES
set to”generic”
- Then condifure the udev rules for
/dev/EtherCAT0
(go to the mode0666
)- create the ethercat rule:
sudo nano /etc/udev/rules.d/99-EtherCAT.rules
- add the following line:
KERNEL == "EtherCAT[0-9]*" , MODE ="0666", GROUP ="users"
- reload the rules:
sudo udevadm control --reload-rules && sudo udevadm trigger
- create the ethercat rule:
There are some helpful notion pages with a bit more info on the ethercat setup:
- Setup EtherCAT
- Integration to Bedrock (a bit more recent)
- Also the ethercat docs are very helpful
Start the EtherCAT master
Start the ethercat
master:
sudo ethercatctl start
Verify that /dev/EtherCAT0
exists
ls /dev/EtherCAT0
The output should be something like:
$ ls -l /dev/EtherCAT
crw-rw-rw- 1 root users 509, 0 Jun 4 07:01 /dev/EtherCAT0
- Use
ethercat
(installed withmake install
after the compilation) to veviry is the master is working- ex.
ethercat graph
(list of nodes connected) - ex.
ethercat slaves
(list of slaves connected)
- ex.
The output should be something like:
$ ethercat graph
/* EtherCAT bus graph. Generated by 'ethercat graph'. */
strict graph bus {
rankdir="LR"
ranksep=0.8
nodesep=0.8
node [fontname="Helvetica"]
edge [fontname="Helvetica",fontsize="10"]
master [label="EtherCAT\nMaster"]
}