<This page is currently under active progress. Please contact Alisha Babbitt (ababbitt@slac.stanford.edu) for more information or questions.>
This page covers how to setup a new EtherCAT device and integrate into the EPICS Control System. The following topics are included:
- EtherCAT Resources & Reference Material
- linuxRT PC Set-up
- Configuring the $IOC/vioc-<>-<> Directory
- EtherCAT linuxRT Configuration
- EtherCAT Template for Creating Epics Application
- Configuring EtherCAT Epics Application
- Debugging Tips
EtherCAT Resources & Reference Material
The following resources and reference material provide an introduction to the EtherCAT technology:
linuxRT PC Set-up
In the SLAC environment, we are currently running EtherCAT on industrial PC's running linux with a pre-emptive real-time patch (linuxRT). Before configuring for EtherCAT, the very first step is to set-up a new linuxRT host.
Verification checks on linuxRT machines:
- Please see $IOC/cpu-<bld>-<name>/README on instructions on how to power cycle machines remotely through the use of ipmi commands
- Once you set-up your linuxRT machine and boot up, log in as laci to your linuxRT system. ( ssh laci@cpu-<bld>-<name>)
- Test if your machine is running real-time linux using uname -a
$ uname -a Linux cpu-b34-mc23 3.18.11-rt7 #5 SMP PREEMPT RT Wed Mar 16 19:03:38 PDT 2016 x86_64 GNU/Linux $ /lib/libc.so.6 GNU C Library (Buildroot) stable release version 2.20, by Roland McGrath et al. Copyright (C) 2014 Free Software Foundation, Inc. |
---|
EtherCAT linuxRT Configuration
We are currently using Etherlab's EtherCAT Master module, which can be found under the package area. The kernel-modules.cmd file needs to be updated to include the following:
- Location of EtherCAT kernel drivers
- Install kernel drivers
- Network configuration
- EtherCAT system configuration & set-up
- Start scanner process
Update the following lines of code in your $IOC/cpu-<>-<>/kernel-modules.cmd. The following code excerpts are from $IOC/cpu-b084-hp03/kernel-modules.cmd
This current code stanza defines the location for the EtherCAT kernel drivers.
# =============================================================== # Define kernel module driver location # =============================================================== PACKAGE_TOP=/afs/slac/g/lcls/package KERNEL_DRIVER_HOME=$PACKAGE_TOP/linuxKernel_Modules ETHERCAT_DRIVER=$KERNEL_DRIVER_HOME/ethercat/buildroot-2015.02-x86_64 |
---|
The following stanza provides the network configuration, installs kernel drivers, and performs some EtherCAT system configuration & set-up
# ========================================= # Install EtherCat kernel drivers + Set-up # ========================================= # Need to configure another ethernet port on cpu-b084-hp03 for ethercat # MUST configure another ethernet port for ethercat # ifconfig eth1 192.168.1.10 netmask 255.255.252.0 # Recommend using the following logic to configure based on the port’s MAC Address EthCat_MAC_ADDR=00:0B:AB:39:3F:CB eth_cat=$(ifconfig -a | grep "HWaddr ${EthCat_MAC_ADDR}" | awk '{print $1}') ifconfig ${eth_cat} netmask 255.255.255.0
# insert MAC address for eth1 after main_devices # the ethercat slaves/devices are connected at eth1 (for this specific configuration)
insmod $ETHERCAT_DRIVER/master/ec_master.ko main_devices=${EthCat_MAC_ADDR} insmod $ETHERCAT_DRIVER/devices/ec_generic.ko
/sbin/ifconfig eth1 up
ln -s $ETHERCAT_DRIVER/tool/ethercat /sbin/ethercat
sleep 5 chmod o+rw /dev/EtherCAT* # =========================================================== |
---|
Next, need to add the following lines to start the scanner process up automatically.
# =================================================================== # Now we start the ethercat scanner process under the linux screen program: # This will allow us to attach/detach to our Ethercat scanner process # ============================================== cd $EPICS_IOCS/cpu-b084-hp03 su laci -c $EPICS_IOCS/vioc-b084-tmp1/scannerStartup.sh # =================================================
|
---|
Verification checks on linuxRT machines:
- Test if your machine has the Etherlab EtherCAT driver module loaded.
$ ethercat version IgH EtherCAT master 1.5.2 2eff7c993a63 $ lsmod | grep ec ec_generic 3453 1 ec_master 240382 3 ec_generic |
---|
- If the slaves are connected with the setup, the ethercat command line tool can help visualize it.
$ ethercat slaves 0 0:0 OP + E1250-EC-UC V1.7b1 |
---|
- Another helpful ethercat command line took is ethercat master
Configuring the $IOC/vioc-<>-<> Directory
EtherCAT Template for Creating Epics Application
When starting a new EtherCAT application, it is highly recommended to start a new epics application and vioc using the slac_ethercat template.
The following command creates a new epics command using the slac_ethercat template.
Generate a vioc for your application. We are using the following format for linuxRT IOC's: vioc-<area>-<subsystem>
Choose your target architecture:
The following target architectures are available in base: linux-x86 vxWorks-ppc604_long vxWorks-mpc8540 vxWorks-ppc604_altivec linux-x86_64 linuxRT_glibc-x86_64 linuxRT_glibc-i686 RTEMS-beatnik RTEMS-mvme3100 RTEMS-uC5282 What architecture do you want to use? linuxRT_glibc-x86_64 |
---|
Choose the application that you want your new vioc to boot:
The following applications are available: <insert_your_application_name> What application should the IOC(s) boot? >> <insert_your_application_name>
|
---|
You have now created a baseline EtherCAT application.
(For more reference material on getting started with EPICS: CH. 2 Getting Started)
Configuring EtherCAT Epics Application
The EtherCAT application has two parts.
- The scanner process which scans the bus
- The EPICS IOC application
Before being able to successfully run the application, some clean-up and configuration are necessary in the following areas:
- <top>/etc/
- <top>/<app_name>/Db/Makefile
- <top>/iocBoot/vioc-<>-<>/st.cmd
The first step specific to an EtherCAT application, is creating a chain.xml file for the scanner process. The scanner process will open up a unix socket for communication with the IOC. If using the slac_ethercat template, you should already have a directory named /etc under <top>. Otherwise, you will been to create a directory called /etc. This directory will consist of a Makefile, chain.xml, and a scanner.xml. The scanner.xml will be automatically generated upon building the application.
The Makefile should consist of the following lines:
TOP=..
include $(TOP)/configure/CONFIG
install: /usr/bin/python $(ECASYN)/etc/scripts/expandChain.py chain.xml > scanner.xml
clean: rm -f scanner.xml rm -f EK1101-EtherCAT.template distclean: clean realclean: clean uninstall: |
---|
However, the chain.xml needs to be manually created based off the devices in your EtherCAT chain.
This is an example of a chain with just one motion control device (ref: $APP/users/namrata/EtherCATest/etc):
<chain> <device type_name="E1250-EC-UC" revision="0x00010007" position="0" name="LINMOTOR0" /> </chain> |
---|
Here is another example with two slave devices for an EtherCAT coupler and an analog output device for reading temperature from RTD's (ref: $APP/users/ababbitt/LCLS-II/TEMPERATURE/etc):
<chain> <device type_name="EK1101" revision="0x00120000" position="0" name="C <device type_name="EL3202" revision="0x00100000" position="1" name="A </chain> |
---|
To obtain the revision number for the device use the slaves ethercat command line tool.
$ ethercat slaves -v -p0 === Master 0, Slave 0 === Device: Main State: OP Flag: + Identity: Vendor Id: 0x4c4e5449 Product code: 0x009606e3 Revision number: 0x00010007 Serial number: 0x1bd200e7 |
---|
NOTE: If you are using a brand new module, it may not currently exist in the EtherCAT module. You can check whether you device is supported by looking in the following areas in the EtherCAT module area.
XML
Templates
For the long-term, any new devices should be integrated into the EtherCAT module. Please contact the EtherCAT module owners:
- Who wants to be the EtherCAT module owner?
- Add the scanner.xml file in a bin folder along with the scanner binary in $IOC/vioc-b34-mc23 folder.
Add the script to start the scanner as a linux screen process. (ref: $IOC/cpu-b34-mc23)
Start the scanner at 100Hz frequency.
Verification checks on development machines (lcls-dev3):
- Check that your python version is correct:
Python version: Python 2.7.9
export the correct version to the path
$ python --version Python 2.7.4 $ export PATH=/afs/slac/g/lcls/package/python/python2.7.9/linux-x86_64/bin/:$PATH $ python --version Python 2.7.9 |
---|
Debugging Tips