sittner/linuxcnc-ethercat

Documentation

satiowadahc opened this issue · 4 comments

I've been compiling a little reference for myself. Figured I'd share here if its of any use to anyone:

LinuxCnc EtherCat (LCEC)

Installing

Setup

  1. Install Realtime Kernel https://gnipsel.com/linuxcnc/uspace/latency.html
  2. Install linuxcnc https://github.com/linuxcnc/linuxcnc
  3. Install igh-ethercat https://gitlab.com/etherlab.org/ethercat/

Install

  1. git clone https://github.com/sittner/linuxcnc-ethercat
  2. cd linuxcnc-ethercat
  3. make
  4. sudo make install

How to Use

lcec_conf is a user space component to configure how the ethercat system is set up. It parses your custom XML file and initializes the configuration.

lcec is the real time component that runs the ethercat procedures.

Example XML

<masters>
  <!-- Typically only one master -->
  <!--    appTimePeriod must match thread period -->
  <!--    refClockSyncCycles ??? -->
  <master idx="0" appTimePeriod="1000000" refClockSyncCycles="1">
    <!-- Recommend having a coupler such as the EK1100 Series -->
    <slave idx="0" type="EK1100"/>
    <!-- Some Cards and drivers such as a safety PLC need parameters -->
    <slave idx="1" type="EL6900">
      <modParam name="fsoeSlaveIdx" value="2"/>
      <modParam name="fsoeSlaveIdx" value="4"/>
    </slave>
    <slave idx="2" type="EL1904"/>
    <slave idx="3" type="EL1808"/>
    <!-- Space out safety components, as they generate high heat-->
    <slave idx="4" type="EL2904"/>
    
    <!-- If the driver is not created you can manually make one from the generic driver -->
    <!-- Most of the required information can be obtained by `ethercat cstruct`-->
    
    <!-- VID - Company of the device making it 2 = Beckoff -->
    <!-- PID - Device you are using -->
    <!-- configPDOs - Some devices like an EL6995 bridge allow changing there PDO's from ethercat-->
    <!-- XML Syntax </> is a closing tag, when there is more information, don't close the tag yet-->

    <!-- EP2338 -->
    <slave idx="5" type="generic" vid="0x00000002" pid="0x09224052" configPdos="true">     
      <!-- syncManager 0 is Cyclic Data output from the slave-->
      <syncManager idx="0" dir="out">
        <!-- Process Data Object's -->
	      <pdo idx="0x1600">
          <!-- The Entry is the important part                -->
          <!-- 7XXX typically outputs, 6XXX typically inputs  -->
          <!-- Ethercat Cstruct will show this as             -->
          <!-- ec_pdo_entry_info_t slave_0_pdo_entries[] = {  -->
          <!--     {0x7000, 0x01, 1}, /* Solenoid output */   -->
          <!-- In order this is {idx, subidx, bitLen}         -->
          <!-- halPin must be a unique name                   -->
          <!-- halType can be anything, if the bitLength is 8 -->
          <!-- and halType is bit, you will have 8 pins labeled -->
          <!-- out-0.[0-8]                                     -->
          <pdoEntry idx="0x7000" subIdx="01" bitLen="1" halPin="out-0" halType="bit" />
        </pdo>
        <pdo idx="0x1601">
          <pdoEntry idx="0x7010" subIdx="01" bitLen="1" halPin="out-1" halType="bit" />
        </pdo>
        <pdo idx="0x1602">
          <pdoEntry idx="0x7020" subIdx="01" bitLen="1" halPin="out-2" halType="bit" />
        </pdo>
        <pdo idx="0x1603">
          <pdoEntry idx="0x7030" subIdx="01" bitLen="1" halPin="out-3" halType="bit" />
        </pdo>
        <pdo idx="0x1604">
          <pdoEntry idx="0x7040" subIdx="01" bitLen="1" halPin="out-4" halType="bit" />
        </pdo>
        <pdo idx="0x1605">
          <pdoEntry idx="0x7050" subIdx="01" bitLen="1" halPin="out-5" halType="bit" />
        </pdo>
        <pdo idx="0x1606">
          <pdoEntry idx="0x7060" subIdx="01" bitLen="1" halPin="out-6" halType="bit" />
        </pdo>
        <pdo idx="0x1607">
          <pdoEntry idx="0x7070" subIdx="01" bitLen="1" halPin="out-7" halType="bit" />
        </pdo>
      </syncManager>
      <syncManager idx="1" dir="in">
        <pdo idx="0x1a00">
          <pdoEntry idx="0x6000" subIdx="01" bitLen="1" halPin="in-0" halType="bit" />
        </pdo>
        <pdo idx="0x1a01">
          <pdoEntry idx="0x6010" subIdx="01" bitLen="1" halPin="in-1" halType="bit" />
        </pdo>
        <pdo idx="0x1a02">
          <pdoEntry idx="0x6020" subIdx="01" bitLen="1" halPin="in-2" halType="bit" />
        </pdo>
        <pdo idx="0x1a03">
          <pdoEntry idx="0x6030" subIdx="01" bitLen="1" halPin="in-3" halType="bit" />
        </pdo>
        <pdo idx="0x1a04">
          <pdoEntry idx="0x6040" subIdx="01" bitLen="1" halPin="in-4" halType="bit" />
        </pdo>
        <pdo idx="0x1a05">
          <pdoEntry idx="0x6050" subIdx="01" bitLen="1" halPin="in-5" halType="bit" />
        </pdo>
        <pdo idx="0x1a06">
          <pdoEntry idx="0x6060" subIdx="01" bitLen="1" halPin="in-6" halType="bit" />
        </pdo>
        <pdo idx="0x1a07">
          <pdoEntry idx="0x6070" subIdx="01" bitLen="1" halPin="in-7" halType="bit" />
        </pdo>
      </syncManager>
    <!-- Don't forget to close the tag now-->
    </slave> 
  </master>
</masters>

Testing Code

halrun is a Linuxcnc testing interface that runs light weight linuxcnc to test components.

~: halrun 
halcmd: loadusr lcec_conf ~/test.xml 
halcmd: loadrt lcec
halcmd: loadrt threads name1=my-thread period1=1000000 fp1=1
halcmd: addf lcec.read-all my-thread
halcmd: addf lcec.write-all my-thread
halcmd: start
halcmd: show pins

Line by Line:

  1. In a terminal typing halrun will put you into the hal environment
  2. load the configuration file
  3. load the realtime component
  4. load a thread to run the realtime component
    A) period1 must match the appTimePeriod of the xml file
    B) fp1 is to notate that you need to use floating point numbers
  5. Add your component to the thread.
    A) Read must come before write, or you have unmatched datagrams
  6. Start actually begins the thread processing

Helpful tips:

  • In a separate terminal have dmesg -w open. This will show information from ethercat as it runs
  • ethercat debug [0,1,2] will change the debug level
    • 0 - Standard
    • 1 - Useful Debugging
    • 2 - Shows every datagram - CAUTION will send ALOT of data
  • See Examples in folders.
  • ethercat master will show if its actually online

The documentation looks great.

I'm wondering if you need to change:
<modParam name="fsoeSlaveIdx" value="3"/>
To this:
<modParam name="fsoeSlaveIdx" value="2"/>

Because the safety terminals are [ EL1904 idx="2" ] and [ EL2904 idx="4"] .

Regards

nbsh2 commented

Thanks! The documentation is useful. But I can't run well on the WAGO 750-354 coupler. It only works when attach it after the EK1100 by the cable. And I didn't know why the WAGO modules can't work independently.

I find I almost always need an EK1100 in the circuit. Have you checked for out put in dmesg?

nbsh2 commented

I find I almost always need an EK1100 in the circuit. Have you checked for out put in dmesg?

No I was't check out the dmesg. But after I remake the source code, the wago module can work independently now. Though I did'n know why it happens.