In my previous post on this topic I successfully managed to get LinuxCNC with EtherCat running on a Beckhoff CX2040. That was over a year ago and since then I didn’t have the time to dig deeper into the matter. Until now, and a lot has changed in the meantime …
Last weekend I attended DDos at the Odenwilusenz Hackerspace in Beringen, Switzerland. In the days before that, I planned to reactivate my setup and bring it along.
When I started the system, everything worked exactly like when I left it. So I added a Beckhoff EL1804 and as Beckhoff EL2828 just to find out that the used version of the linuxcnc-ethercat does not sopport these two types.
An attempt to update to the latest version failed. So I looked at the LinuxCNC website to check out what’s the latest version. I ran 2.8.4 and the latest release was 2.9.3 which, to my surprise now comes from a debian repo along withthe latest version of linuxcn-ethercat. And that also includes the CCAT driver which I had to build from source the last time.
So I decided to start all over and install the 2.9.3 ISO on a new CF card.
Installation ๐
The installation was straight forward as expected. After booting the system for the first time, I got an error at the attempt to do a system update.
The reason is a missing or wrong GPG key in the sources.list
However, the recommended solution from the LinuxCNC forum didn’t work for me, but I was able to use the instructions from the Etherlab website
1export KEYRING=/usr/share/keyrings/etherlab.gpg
2curl -fsSL https://download.opensuse.org/repositories/science:/EtherLab/Debian_12/Release.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
3echo "deb [signed-by=$KEYRING] https://download.opensuse.org/repositories/science:/EtherLab/Debian_12/ ./" | sudo tee /etc/apt/sources.list.d/etherlab.list > /dev/null
This adds a new file called etherlab.list
to /etc/apt/sources.list.d/
, which requires that the original .list file is deleted.
After that I was able ti update and upgrade with
1sudo apt update
2sudo apt upgrade
I installed LinuxCNC and linuxcnc-ethercat from the repo
1sudo apt install ethercat-master libethercat-dev linuxcnc-ethercat
Then I enabled and started the EtherCat Master
1sudo systemctl enable ethercat.service
2sudo systemctl start ethercat.service
That failed because I was missing configuration in /etc/ethercat.conf
.
The config file requires two settings MASTER0_DEVICE
and DEVICE_MODULES
.
To get the MAC of eth0
which is the CCAT simply run ip a
and read the MAC address from there.
I set MASTER0_DEVICE="00:01:05:1e:6b:8e"
and DEVICE_MODULES="ccat"
Luckily the Etherlab master comes with prebuild ccat drivers.
After a reboot there was still no /dev/EtherCAT
device 🤔
So I ran sudo systemctl restart ethercat.service
and that worked.
The LinuxCNC forum recommends to add a udev rule for correct permissions, so I added /etc/udev/rules.d/99-ethercat.rules
with this content:
1KERNEL=="EtherCAT[0-9]", MODE="0777"
After another reboot /dev/EtherCAT
was gone again. sudo systemctl restart ethercat.service
brought it back.
At the time of writing this I was not able to figure out whats causing this and how to fix it other than running a sudo systemctl restart ethercat.service
after every system start.
Testing EtherCat ๐
I quickly checked if the master was running
1ethercat master
2
3Master0
4 Phase: Idle
5 Active: no
6 Slaves: 3
7 Ethernet devices:
8 Main: 00:01:05:1e:6b:8e (attached)
9 Link: UP
10 Tx frames: 18587429
11 Tx bytes: 1299386046
12 Rx frames: 18587422
13 Rx bytes: 1596784378
14 Tx errors: 0
15 Tx frame rate [1/s]: 122 121 121
16 Tx rate [KByte/s]: 7.1 7.1 7.1
17 Rx frame rate [1/s]: 122 121 121
18 Rx rate [KByte/s]: 9.1 9.0 9.0
19 Common:
20 Tx frames: 18587429
21 Tx bytes: 1299386046
22 Rx frames: 18587422
23 Rx bytes: 1596784378
24 Lost frames: 7
25 Tx frame rate [1/s]: 122 121 121
26 Tx rate [KByte/s]: 7.1 7.1 7.1
27 Rx frame rate [1/s]: 122 121 121
28 Rx rate [KByte/s]: 9.1 9.0 9.0
29 Loss rate [1/s]: 0 0 0
30 Frame loss [%]: 0.0 0.0 0.0
31 Distributed clocks:
32 Reference clock: Slave 0
33 DC reference time: 0
34 Application time: 0
35 2000-01-01 00:00:00.000000000
Nice 😎
Creating a test config ๐
I started LinuxCNC with the sim.axis config to have a template to start with.
In the [HAL]
section of axis.ini
I added a HALFILE = ethercat.hal
.
Next I created two new files in the same folder, ethercat.hal
and ethercat-config.xml
.
The first looks like this:
loadusr -W lcec_conf ethercat-conf.xml
loadrt lcec
addf lcec.read-all servo-thread
addf lcec.write-all servo-thread
The later like this
1<masters>
2 <master idx="0" appTimePeriod="1000000" refClockSyncCycles="-1" name="master0">
3 <slave idx="0" type="EL1018" name="DI1"/>
4 <slave idx="1" type="EL2008" name="DO1"/>
5 </master>
6</masters>
I switched my setup back to the old EL1018 and EL2008 terminals because I knew they were working in the old setup.
After starting LinuxCNC with this config I was able to see inputs in the Show HAL configuration menu under Pins -> lcec -> Master0
.
Overall a very easy setup compared to what I had to do last time.
Nice work from the people at LinuxCNC , Etherlab/IgH and linuxcnc-ethercat