Ethercat HAL driver

More
23 Jan 2019 12:13 - 23 Jan 2019 12:13 #124660 by rodw
Replied by rodw on topic Ethercat HAL driver
I may be a bit off as I don't have an Ethercat but I had similar problems with a Mesa 7i76e. My solution was to write a bash script to shut down and restart the network. I' have found it very useful and used it today!

create a file called netstart.sh that contains
sudo service network-manager stop
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start

This is for Linux Mint and I found Debian might need different commands.

so when it happens, I just type "bash netstart.sh" from the command line (which is usually just a couple of up arrow presses as it gets used a bit!
Last edit: 23 Jan 2019 12:13 by rodw.

Please Log in or Create an account to join the conversation.

More
23 Jan 2019 14:48 #124669 by shameless
Replied by shameless on topic Ethercat HAL driver
Thank you , but it doesn't work for mine. I tried this method, I notice that my wlan0 down and up, and nothing happen to my eth0.
Maybe when I stop my ethercat master, it doesn't release the eth0. And I type "ifconfig" from the command line, there is no "eth0", but if I type "ifconfig -a", there's "eth0", but the mac is "00:00:00:00:00:00". It seems need to modify the driver.
Thank you again!

Please Log in or Create an account to join the conversation.

More
12 Feb 2019 18:19 #126289 by rwistort
Replied by rwistort on topic Ethercat HAL driver
I have crossed the Atlantic in a row boat, and I am drowning within sight of the docks.

I am trying to get my Estun ProNET servo drive to work, but I cannot seem to get it into OP mode.

I've installed the latest ec-debianize and linuxcnc-ethercat from source on my 4.1.42-rt50 #1 SMP PREEMPT RT machine.
The ethercat command line works normally, and I have exactly 1 slave on the bus.
I have tried the control word sequence x06, then x07, then x0F, as suggested long ago in this forum. No dice.

ethercat master # looks normal, I think
Master0
  Phase: Idle
  Active: no
  Slaves: 1
  Ethernet devices:
    Main: 68:05:ca:8a:b4:79 (attached)
      Link: UP
      Tx frames:   965040
      Tx bytes:    57905664
      Rx frames:   965039
      Rx bytes:    57905604
      Tx errors:   0
      Tx frame rate [1/s]:    244    244    244
      Tx rate [KByte/s]:     14.3   14.3   14.3
      Rx frame rate [1/s]:    244    244    244
      Rx rate [KByte/s]:     14.3   14.3   14.3
    Common:
      Tx frames:   965040
      Tx bytes:    57905664
      Rx frames:   965039
      Rx bytes:    57905604
      Lost frames: 0
      Tx frame rate [1/s]:    244    244    244
      Tx rate [KByte/s]:     14.3   14.3   14.3
      Rx frame rate [1/s]:    244    244    244
      Rx rate [KByte/s]:     14.3   14.3   14.3
      Loss rate [1/s]:          0      0      0
      Frame loss [%]:         0.0    0.0    0.0
  Distributed clocks:
    Reference clock: Slave 0
    Application time: 0
                      2000-01-01 00:00:00.000000000

ethercat slaves -v # looks normal, I think
=== Master 0, Slave 0 ===
Device: Main
State: PREOP
Flag: +
Identity:
  Vendor Id:       0x0000060a
  Product code:    0x00000001
  Revision number: 0x00000001
  Serial number:   0x00000000
DL information:
  FMMU bit operation: yes
  Distributed clocks: yes, 32 bit
  DC system time transmission delay: 0 ns
Port  Type  Link  Loop    Signal  NextSlave  RxTime [ns]  Diff [ns]   NextDc [ns]
   0  MII   up    open    yes             -   3516425216           0           0
   1  MII   down  closed  no              -            -           -           -
   2  N/A   down  closed  no              -            -           -           -
   3  N/A   down  closed  no              -            -           -           -
Mailboxes:
  Bootstrap RX: 0x0000/0, TX: 0x0000/0
  Standard  RX: 0x1000/128, TX: 0x1080/128
  Supported protocols: CoE
General:
  Group: EC100 
  Image name: 
  Order number: ESTUN ProNet
  Device name: ESTUN ProNet
  CoE details:
    Enable SDO: no
    Enable SDO Info: no
    Enable PDO Assign: yes
    Enable PDO Configuration: yes
    Enable Upload at startup: yes
    Enable SDO complete access: no
  Flags:
    Enable SafeOp: no
    Enable notLRW: no
  Current consumption: 0 mA


When I load linuxcnc, the hal pins I expect to see are there, and there are no lcec warnings except "installed driver for 1 slaves", and
dmsg shows:
[ 4580.426854] EtherCAT: Requesting master 0...
[ 4580.426859] EtherCAT: Successfully requested master 0.
[ 4580.427075] EtherCAT 0: Domain0: Logical address 0x00000000, 22 byte, expected working counter 3.
[ 4580.427078] EtherCAT 0:   Datagram domain0-0-main: Logical offset 0x00000000, 22 byte, type LRW.
[ 4580.429442] EtherCAT 0: Master thread exited.
[ 4580.429446] EtherCAT 0: Starting EtherCAT-OP thread.
and then, when I exit linuxcnc, dmsg continues:
[ 4596.339951] EtherCAT 0: Master thread exited.
[ 4596.339959] EtherCAT 0: Starting EtherCAT-IDLE thread.
[ 4596.340100] EtherCAT 0: Releasing master...
[ 4596.340102] EtherCAT 0: Released.
22 is the total number of bytes in my PDO datagram and, as I understand it, LRW is a read/write transaction, and working counter 3 means neither read nor write worked.

I tried to force it with the command line:
~/linuxcnc-ethercat/examples/c3pr> ethercat state -p0 OP
~/linuxcnc-ethercat/examples/c3pr> dmesg | tail -20
[ 6533.740591] EtherCAT ERROR 0-0: Failed to set SAFEOP state, slave refused state change (PREOP + ERROR).
[ 6533.740836] EtherCAT ERROR 0-0: AL status message 0x001E: "Invalid input configuration".
[ 6533.741343] EtherCAT 0-0: Acknowledged state PREOP.

Something ain't right.

I've set up the PDOs 3 ways, and they all result in the LRW problem, and the drive stays in PREOP.
  • I scanned the drive with twinCAT3 and then used the lcec generic driver in hal
  • I used the ethercat command line to set up the PDO's using a shell script, and then used the lcec generic driver in hal
  • I set up the PDOs with a shell script, wrote a custom 'PN4' lcec driver consistent with 'ethercat cstruct' output, and used type="PN4" in my hal xml.
Here is the hal configuration xml I used with the generic driver on a twinCAT-configured slave:
<masters>
  <master idx="0" appTimePeriod="1000000" refClockSyncCycles="1000">
    <slave idx="0" type="generic" vid="0000060A" pid="00000001" configPdos="true">
      <syncManager idx="0" dir="out">  <!-- MboxOut -->
      </syncManager>
      <syncManager idx="1" dir="in">  <!-- MboxIn -->
      </syncManager>

      <syncManager idx="2" dir="out">
        <pdo idx="1602">
          <pdoEntry idx="6040" subIdx="0" bitLen="16" halPin="pn4.control" halType="u32" />
          <pdoEntry idx="607A" subIdx="0" bitLen="32" halPin="pn4.velcmd"  halType="u32" />
          <pdoEntry idx="60FE" subIdx="1" bitLen="32" halPin="pn4.phyout"  halType="u32" />
        </pdo>
      </syncManager>

      <syncManager idx="3" dir="in">
        <pdo idx="1A02">
          <pdoEntry idx="6041" subIdx="0" bitLen="16" halPin="pn4.status" halType="u32" />
          <pdoEntry idx="6064" subIdx="0" bitLen="32" halPin="pn4.velact" halType="u32" />
          <pdoEntry idx="6077" subIdx="0" bitLen="16" halPin="pn4.toract" halType="u32" />
          <pdoEntry idx="60FD" subIdx="0" bitLen="32" halPin="pn4.diginp" halType="u32" />
        </pdo>
      </syncManager>

      <dcConf assignActivate="300" sync0Cycle="1" sync0Shift="0"/>
      <!--watchdog divider="" intervals=""/-->
    </slave>
  </master>
</masters>

I have been hacking with Linuxcnc for years, but this is my first ethercat project.
Can anyone help?
Thanks
Reid

Please Log in or Create an account to join the conversation.

More
12 Feb 2019 20:16 #126295 by Grotius
Replied by Grotius on topic Ethercat HAL driver
Hi Reid,

If you look at attached files, that's a servo drive c & h file for the beckhoff servo.
What i do if the driver is not available, i modify existing files until i get it to work.
I think there is also a delta servo file somewhere.
Attachments:

Please Log in or Create an account to join the conversation.

More
13 Feb 2019 10:20 #126332 by serdigi
Replied by serdigi on topic Ethercat HAL driver
Hi Frank please send me your Twincat 3
project file
I am understand my estun drive init command in twincat...Thank you.

Best regards.

Please Log in or Create an account to join the conversation.

More
13 Feb 2019 17:27 #126358 by sqmathlete
Replied by sqmathlete on topic Ethercat HAL driver
@ reid

If you see the amp in pre-op and you can't bring it in to the op state
my guess is that you are not setting the control word pins to switch the amp on.
Its hard to say without seeing your hal file...
For example Delta Ac Servo's require that the control word is set as
step 1) 0x06
step 2) 0x07
step 3) 0x0F
to move through the states into the final op state.
It's not obvious in the example configurations but by setting the pins in Hal in that order( or whatever order the amps you are using wants.), the amp turn on.

You also have to make sure that the mode is set e.g. CSP, CSV, homing etc. By adding the mode word to your pdo entry, you can set the bits in Hal or you can set the mode via an sdo entry directly.

Kind regards,
Dan

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 05:30 #126434 by rwistort
Replied by rwistort on topic Ethercat HAL driver
grotius:
thanks for the nice code. I'm not sure why you used IDNs instead of SDOs, though. (I'm not sure about much!)

sqmathelete:
I'd tried the mode-set and x06->x07->x0f trick, but it didn't seem to work.
I tried it some more, and found that if I set the mode before setting up the PDOs and the control sequence, my servo becomes enabled and I can control it with sdo downloads. It stayed in PREOP mode, though, and dmesg gave the same error about LRW and working counter.
I tried to enter OP manually:
ethercat -p0 states OP
stdout was silent, it stayed in PREOP, and dmesg showed:
[132995.296949] EtherCAT ERROR 0-0: Failed to set SAFEOP state, slave refused state change (PREOP + ERROR).
[132995.297197] EtherCAT ERROR 0-0: AL status message 0x001E: "Invalid input configuration".
I need to think about this...
Thanks,
Reid

Please Log in or Create an account to join the conversation.

More
14 Feb 2019 19:33 - 14 Feb 2019 19:36 #126487 by chimeno
Replied by chimeno on topic Ethercat HAL driver
Hello Reid,
the servos of the series beckhoff AX5000 need every time they connect to load all the configuration of the servo drive and servo motor through the IDN parameters.
I do not have this type of servodriver, but if it stays in PREOP it is because some parameter is incorrect, I do not know if you can look at the error in the servo driver to see where the problem is, I recommend that you go from parameter to parameter until you des is wrong, another thing you can look at is if you have loaded all the configuration of the servo drive with SDO parameters? I attached a file that uses PRONET servos and see what differences there are, I hope I have helped a little, regards
Chimeno

File Attachment:

File Name: Pronet.xml
File Size:4 KB
Attachments:
Last edit: 14 Feb 2019 19:36 by chimeno.

Please Log in or Create an account to join the conversation.

More
17 Feb 2019 23:27 #126696 by rwistort
Replied by rwistort on topic Ethercat HAL driver
Hello again.
I've been trying hard to follow up all your tips, and I am here to tell you that trying didn't used to be this hard.

I have, you'll recall, a problem getting my ProNET servo online, and I've come to you for help.
Before I tick off some of the things I've tried, let me ask 2 simple questions:

Is it normal that, while lcec is running, the ethercat commands for up- and download 'hang' until lcec is terminated, while "ethercat master, slave, cstruct, and pdos" run immediately? I was a little surprised.

Also, it would appear that, as long as the slave is powered up -- both while lcec is running, and while it's not -- the frame count from "ethercat masters" is increasing at about 1000/sec. I thought cyclic frames were only produced while a master is active. Is this normal?

With that out of the way, let me guide you through some of the things that didn't solve my problem:

Dead end #1: do it the way they tell you to do it.
I adapted the pronet xml from chimeno and used it to load the generic driver with a freshly-powered-up slave. See the attachment pronet_2.xml.
I started up lcec with this hal fragment:
loadusr -W lcec_conf /home/reid/linuxcnc-ethercat/examples/c3pr/pronet_2.xml
loadrt lcec
# apply 6-7-F control sequence to activate the motor.
net shouldercontrol lcec.0.shoulder.control
sets shouldercontrol  0x00000006
sets shouldercontrol  0x00000007
sets shouldercontrol  0x0000000f
The slave stayed in PREOP.
Plenty of hal pins were created. All the pins sourced from the slave are false or zero.
I did 'ethercat -p0 states OP' and it ran silently, but the slave stayed in PREOP.
I did 'ethercat -p0 pdos' and it listed an empty configuration:
~/linuxcnc-ethercat> ethercat -p0 pdos
SM0: PhysAddr 0x1000, DefaultSize  128, ControlRegister 0x36, Enable 1
SM1: PhysAddr 0x1080, DefaultSize  128, ControlRegister 0x32, Enable 1
SM2: PhysAddr 0x1100, DefaultSize    6, ControlRegister 0x74, Enable 1
SM3: PhysAddr 0x1d00, DefaultSize    6, ControlRegister 0x30, Enable 1
dmesg reports:
[450869.654923] EtherCAT WARNING 0: 65 datagrams TIMED OUT!
[450869.654929] EtherCAT WARNING 0: 1 datagram UNMATCHED!
[450871.028537] e1000: eth1 NIC Link is Up 100 Mbps Full Duplex, Flow Control: RX
[450871.030143] EtherCAT 0: Link state of ecm0 changed to UP.
[450871.034230] EtherCAT 0: 1 slave(s) responding on main device.
[450871.034237] EtherCAT 0: Slave states on main device: INIT.
[450871.034549] EtherCAT 0: Scanning bus.
[450871.089776] EtherCAT ERROR 0-0: SDO upload 0x0000:00 aborted.
[450871.089782] EtherCAT ERROR 0-0: SDO abort message 0x06020000: "This object does not exist in the object directory".
[450871.089784] EtherCAT ERROR 0-0: Failed to read number of mapped PDO entries.
[450871.089786] EtherCAT ERROR 0-0: Failed to read mapped PDO entries for PDO 0x0000.
[450871.108530] EtherCAT ERROR 0-0: SDO upload 0x0000:00 aborted.
[450871.108535] EtherCAT ERROR 0-0: SDO abort message 0x06020000: "This object does not exist in the object directory".
[450871.108537] EtherCAT ERROR 0-0: Failed to read number of mapped PDO entries.
[450871.108539] EtherCAT ERROR 0-0: Failed to read mapped PDO entries for PDO 0x0000.
[450871.108543] EtherCAT 0: Bus scanning completed in 76 ms.
[450871.108545] EtherCAT 0: Using slave 0 as DC reference clock.
[450871.112636] EtherCAT 0: Slave states on main device: PREOP.

[450893.559361] EtherCAT: Requesting master 0...
[450893.559367] EtherCAT: Successfully requested master 0.
[450893.559623] EtherCAT 0: Domain0: Logical address 0x00000000, 12 byte, expected working counter 3.
[450893.559626] EtherCAT 0:   Datagram domain0-0-main: Logical offset 0x00000000, 12 byte, type LRW.
[450893.562153] EtherCAT 0: Master thread exited.
[450893.562158] EtherCAT 0: Starting EtherCAT-OP thread.
[450893.562197] EtherCAT WARNING 0: 189 datagrams UNMATCHED!
The first group of messages happens only when the slave is powered on and is probably normal ?
The next group happens when lcec starts up.
I'd done most of this before my first post, so not much of this is new.


Dead end #2: bash it into submission.
Using a freshly-powered-up slave and a bash script (see attachment pronet_2.txt), I did ethercat downloads to configure my slave before starting up lcec. This includes setting the MODE and providing the 6-7-F startup sequence.
Before starting lcec, the pdo configuration set up by the bash commands "looked good to me" and seemed to match the values used in the hal xml in dead end #1.
~/linuxcnc-ethercat> ethercat pdos
SM0: PhysAddr 0x1000, DefaultSize  128, ControlRegister 0x36, Enable 1
SM1: PhysAddr 0x1080, DefaultSize  128, ControlRegister 0x32, Enable 1
SM2: PhysAddr 0x1100, DefaultSize    6, ControlRegister 0x74, Enable 1
  RxPDO 0x1602 ""
    PDO entry 0x6040:00, 16 bit, ""
    PDO entry 0x607a:00, 32 bit, ""
SM3: PhysAddr 0x1d00, DefaultSize    6, ControlRegister 0x30, Enable 1
  TxPDO 0x1a02 ""
    PDO entry 0x6041:00, 16 bit, ""
    PDO entry 0x6064:00, 32 bit, ""
The motor actually turned on after the bash script, and I could control it with SDO downloads. (My wife was not impressed.)
ethercat -p0 states OP worked, but the drive reverted from 'run' to 'standby' when it went to OP.

I started up lcec while the slave was already in OP state, using the same generic xml as in dead end #1 (never mind that the xml and the ethercat commands are mostly redundant)
The slave stayed in OP mode.
The LINK light went to 'continuously on,' meaning "There is connection in link layer but there is no data exchange."
It was basically 'hung,' and 'ethercat -p0 states PREOP' failed to bring it out of OP state.

I repeated:
I powered up the slave afresh and ran the bash script to configure the PDOs, but this time I left it in PREOP when I started up lcec.
The slave stayed in PREOP mode.
The LINK light went to 'continuously on' again. It was basically 'hung' again and 'ethercat -p0 states OP'

I repeated with a twist:
I powered up the slave afresh and ran the bash script to configure the PDOs and again left it in PREOP before starting lcec.
This time, though, I changed configPdos="true" in the xml's 'slave' line to "false". I did this because, hey, the PDO's already got configured by the bash script, so why let the xml mess it up? (I also took out the sdoConfig stanza.)
Same thing: stayed in PREOP, LINK light stuck on.
No love!

Dead end #3:
"No error" from 'ethercat states' command, hmm? Perhaps, I thought, it's getting to OP just fine, but then getting chased out by ... a watchdog, maybe? I fiddled with my xml watchdog line, but nothing seemed to make a difference.

Dead end #4: do it the hard way
I built a custom lcec_pn4.c driver, but did not get better results. I found out the hard way that calls like ecrt_slave_config_sdo16() don't work in RT code. (Just like it says. Duh.)
I can believe that I screwed this up, so I won't drag you through it.
It seemed to me, though, that pretty much nothing in the xml was getting written to the slave, so I hacked the code with some rtpi_print_msg()'s so that I could watch as rtapi_app_main() and the generic driver processed the correct indices into the correct ecrt_whatever() calls, with good return codes. Everything looked good.
And yet, when the xml does something like:
<sdoConfig idx="6098" subIdx="0">
      <sdoDataRaw data="23"/>
    </sdoConfig>
and then I terminate lcec and go back to the command line, shouldn't
ethercat -p0 -t uint8 upload 0x6098 0
return 23? It returns whatever was in it before lcec ran, as though the sdoConfig never happened.
It's almost as though there were some kind of write-protect against sdo updates while lcec is running.

In all these cases, all the right hal pins are created, but all the inputs from the slave were false or zero.

It wasn't long ago that this was all greek to me, but by now, most of the code, docs, xml, concepts and samples make perfect sense, and this really ought to be straightforward.

Clearly, I'm doing something stupid, but what?

Thanks,
Reid
Attachments:

Please Log in or Create an account to join the conversation.

More
18 Feb 2019 20:29 #126723 by chimeno
Replied by chimeno on topic Ethercat HAL driver
Hello Reid,
a clue would be to look at the error report in the driver through the TWINCAT3 program to see what error it gives you, another thing is that you should load the whole servo configuration through the generic module before reaching your OP status, another thing is [450871.108535] EtherCAT ERROR 0-0: SDO cancellation message 0x06020000: "This object does not exist in the object directory". this parameter does not exist ??? another thing, does it work through TWINCAT3 ??? , otherwise the network cable is CAT5 or CAT6 ??, greetings Chimeno

Please Log in or Create an account to join the conversation.

Time to create page: 0.375 seconds
Powered by Kunena Forum