EtherCAT + RPi build log along with questions
- pseudo
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 7
23 Sep 2021 03:01 #221397
by pseudo
EtherCAT + RPi build log along with questions was created by pseudo
Hello all.
I'm building a product around LCNC and ethercat (still in prototype phase, long way to go yet) and thanks to a lot of the detailed posts of others I've made some excellent progress which I felt I should share so others can skip some of the fumbling in the dark that I did. Plus I have a few questions but I'll get to them in a sec.
Firstly, the hardware:
Finally my questions:
That's all I can think of for now, cheers guys.
I'm building a product around LCNC and ethercat (still in prototype phase, long way to go yet) and thanks to a lot of the detailed posts of others I've made some excellent progress which I felt I should share so others can skip some of the fumbling in the dark that I did. Plus I have a few questions but I'll get to them in a sec.
Firstly, the hardware:
- Raspberry Pi 4, set up folling Hakan's excellent guide, worked flawlessly. Link to that thread Thanks Hakan, your youtube vid popped up in my recommendations just as I was struggling to figure out my options for an ethercat master for the product and saved the day.
- The pi is running off an M.2 drive instead of an SD card, vital for long term use, and it's in an 'Argon ONE M.2' Case I wouldn't normally consider the case worth mentioning but I can't recommend this enough, sleek little aluminium case with all the boards etc needed to run an m.2 drive and break all the ports out in a useful way. Cheap too.
-
Leadshine ELP-EC400Z drives
and
ELM0400FM60H-HH2 MS20
motors, which are 220v AC servos and drives, 400w. So far the leadshine ELP-EC drives seem pretty good, everything appears to be exceptionally high quality for the money, these definitely appear to be a sweet spot for cost/quality. (side note, for those who struggled to find a price for these I paid (USD) $85 for the motor, $145 for same with brake, and $224 per drive, I purchased directly from leadshine.)
- One important tip for others working with these drives: Leadshine's motion studio did not want to run under windows 10, it took a bunch of sleuthing with windows event viewer to figure out that it wants a C++ redistributable from 2008 and it needs to be run as administrator. I've attached a screenshot of the redistributable version properties, it's pretty hard to find as microsoft doesn't officially want you to download one that old but some google fu found me a viable official MS download link eventually. I'd link that here but it was a while ago. If anyone's desperate PM me and I'll share the file... if you trust exe's from strangers on the internet
- Followed Hakan's guide, got a pi running ethercat in a few hours.
- Set up the cia402 element. I didn't understand what this bit was for at first until i figured out that CIA402 is an industrial standard for addressing drives, basically a standard set of instructions/responses relating to position/vel/torque etc.
- github.com/dbraun1981/hal-cia402 is the magic glue for talking CIA402.
- create it using instructions found at
- If you're not using the same drives as Hakan or similar you won't be able to address your device in the xml like they do <slave idx="0" type="EK1100"/> you'll need to create one with 'type=generic', see my xml for example
- Fumbled about for a while trying to get the drives to move. Some troubleshooting tips for those in a similar position:
- Run linuxcnc from terminal with the verbose flag in the directory of your config, 'linuxcnc -v configname.ini' This probably sounds really obvious to a lot of you but I'd mostly just launched from the desktop shortcuts sim/pncconf created in the past and yeah, from the terminal gives you a lot more info
- 'ethercat slaves -v' provided most of the info I needed to modify the example xmls to suit my drives (attached mine for ref too)
- 'ethercat xml' also provided some useful info for modifying xml examples.
- Ethercat: dmesg is your friend... I was banging my head against the wall trying to understand what the problems were until I figured out that the ethercat stack (... not sure which bit, LCEC, etherlab, etc) is sending info there. Open a separate terminal and run 'dmesg -wH' (those flags basically give you the tail and update it in real time), Now you can see what the ethercat stack has been quietly crying about in the background all this time....
- ...dmesg revealed the crucial nugget of info I'd struggled to find for a while: PDO length mismatch. I was modifying Hakan's example config etc and on his drive one of the PDOs was 32bit length where my drive was sending them as 16bit.
- Side note on PDOs: you may need to configure your drives to send them/which ones to send using the manufacturer's software before any of this will work. If you're using the same drives then open leadshine motion studio with the drive connected via usb (doesn't need power), run the setup wizard (just 'next' everything for now), then go to the ethercat section, open 'object dictionary' then the little 'PDO' button at the top.... that took forever to figure out when I didn't know what a PDO was....
- Next step was IO... the drives have 14 digital in, 6 out, some of each are differential, all optoisolated as you'd expect and conveniently you can wire them for common+ or common-, basically you can choose the IO bank for the drive to be sinking or sourcing, which is handy as my Z lims are a different flavour to the X and Y (space limitations motivating that decision). This took a while to figure out:
- On these drives you can use PDO 0x3000 for raw input states, or 0x60FD (side note, leadshine uses xxxxh to denote hex in the manual) for input states with some named (estop, home etc). You'll need to configure in the leadshine software which IO goes to which name first.
- Next you'll need to configure the drive to send that, see the leadshine pic for info
- Then you’ll need to edit your xml to have that new PDO in it.
- and the bit that took forever to figure out: how do I get this 32/16bit number to be something useful for LCNC? The answer is 'haltype=complex'... which as far as I can figure (if I'm wrong link me, I couldn't find it) does not exist in the linux docs.... only in that 130 page thread 'Ethercat Hal Driver'... Via this haltype you can treat a single 32bit PDO as 32 hal pins, or whatever mix you need. See my attached xml for example
Finally my questions:
- I think it's possible to have LCNC/ethercat stack configure a drive on connect via SDOs etc, is that correct? How would I do that?
- I note that other devices exist already defined in the lcec stack, what benefits does that bring (beyond the obvious of making their definition in your xml a single line)? Also how would I go about creating an entry for my devices?
- Leadshine provides a giant xml file for dowload (attached, leadshine400z.xml), is this useful/how do I use this? Is there some tool I can feed it to?
That's all I can think of for now, cheers guys.
The following user(s) said Thank You: PKM, tommylight, LAUSCH
Please Log in or Create an account to join the conversation.
- LAUSCH
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 3
13 Feb 2022 16:05 #234707
by LAUSCH
Replied by LAUSCH on topic EtherCAT + RPi build log along with questions
Thank you so much pseudo.
I am also building a CNC with a quite similar setup as yours.
RPi 4B 8GB + Beckhoff EK1100 (Digital Input, Digital Output, Analog Output) and Leadshine ELP-EC750Z drives and ELM0750LH80F-SS.
With your instructions I got things running very quickly.
Cheers
I am also building a CNC with a quite similar setup as yours.
RPi 4B 8GB + Beckhoff EK1100 (Digital Input, Digital Output, Analog Output) and Leadshine ELP-EC750Z drives and ELM0750LH80F-SS.
With your instructions I got things running very quickly.
Cheers
Please Log in or Create an account to join the conversation.
- db1981
- Offline
- Platinum Member
Less
More
- Posts: 790
- Thank you received: 275
13 Feb 2022 19:06 #234721
by db1981
Replied by db1981 on topic EtherCAT + RPi build log along with questions
Finally my questions:
1. I think it's possible to have LCNC/ethercat stack configure a drive on connect via SDOs etc, is that correct? How would I do that?
this can be done by startup commands as xml file or manually in the ethercat_conf file. Search for initcmds or sdoconfig in this forum, there is also an example on ehtercat github.
2. I note that other devices exist already defined in the lcec stack, what benefits does that bring (beyond the obvious of making their definition in your xml a single line)? Also how would I go about creating an entry for my devices?
the benefit is, that you can put the ethercat configuration for the device and realtime handling of the values like statusword controlword, velocity, drive config, scaling together in one component. So you can handle the drives data and translate it to common linuxcnc halpins / structure
The CIA402 Wrapper for example is the realtime part from an ethercat driver without the pdo config.....
Leadshine provides a giant xml file for dowload (attached, leadshine400z.xml), is this useful/how do I use this? Is there some tool I can feed it to?
With this file you can feed Beckhoff or other master with all information about the drive, sdo dictonary, pdo types/config etc.
For now at etherlab / lcec you can only use it to manually read out your drive pdo config.
1. I think it's possible to have LCNC/ethercat stack configure a drive on connect via SDOs etc, is that correct? How would I do that?
this can be done by startup commands as xml file or manually in the ethercat_conf file. Search for initcmds or sdoconfig in this forum, there is also an example on ehtercat github.
2. I note that other devices exist already defined in the lcec stack, what benefits does that bring (beyond the obvious of making their definition in your xml a single line)? Also how would I go about creating an entry for my devices?
the benefit is, that you can put the ethercat configuration for the device and realtime handling of the values like statusword controlword, velocity, drive config, scaling together in one component. So you can handle the drives data and translate it to common linuxcnc halpins / structure
The CIA402 Wrapper for example is the realtime part from an ethercat driver without the pdo config.....
Leadshine provides a giant xml file for dowload (attached, leadshine400z.xml), is this useful/how do I use this? Is there some tool I can feed it to?
With this file you can feed Beckhoff or other master with all information about the drive, sdo dictonary, pdo types/config etc.
For now at etherlab / lcec you can only use it to manually read out your drive pdo config.
The following user(s) said Thank You: LAUSCH
Please Log in or Create an account to join the conversation.
- LAUSCH
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 3
03 Mar 2022 15:04 #236265
by LAUSCH
Replied by LAUSCH on topic EtherCAT + RPi build log along with questions
Hi pseudo,
May I ask if you have progressed on setting up your Leadshine drives? As mentioned in my previous post I am in a very similar situtaion besides my drives are the 750W version.
I just got the bare minimum running including the Digital and Analog IOs via the Beckhoff EK1100.
My questions are right now: Do I need to configure dedicated servo Parameters (P, I, D, FF1, FF2, Deadband) within my INI file or is it also possible to simply pass the position and direction to the drive and let the drive take over?
I got things running without the definition of any servo parameters however I get joint.following errors all the times. When running the servos via the manufacturer software "Motion Control" it is possible to easily adjust acceleration parameters and the servos run very smoothly.
Cheers
Christian
May I ask if you have progressed on setting up your Leadshine drives? As mentioned in my previous post I am in a very similar situtaion besides my drives are the 750W version.
I just got the bare minimum running including the Digital and Analog IOs via the Beckhoff EK1100.
My questions are right now: Do I need to configure dedicated servo Parameters (P, I, D, FF1, FF2, Deadband) within my INI file or is it also possible to simply pass the position and direction to the drive and let the drive take over?
I got things running without the definition of any servo parameters however I get joint.following errors all the times. When running the servos via the manufacturer software "Motion Control" it is possible to easily adjust acceleration parameters and the servos run very smoothly.
Cheers
Christian
Please Log in or Create an account to join the conversation.
- pseudo
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 7
18 Jun 2022 06:00 - 19 Jun 2022 09:17 #245381
by pseudo
Replied by pseudo on topic EtherCAT + RPi build log along with questions
Hi Lausch,
apologies for the belated response, I haven't checked here in a while.
I think I ran into the same issue and I thiiiiink I found (can't remember where and I'm only 70% sure that this was the fix) that changing the base period and servo period in ECMOT to something ludicrously high resolved the issue and appeared to have no impact on accuracy (still in the prototype phase of this so I haven't fully validated that - do a bunch of tests before you trust it).
As for servo tuning: I did it with the leadshine software connected to the drive directly and saved the settings on the drive, no need for linuxcnc to be involved.
For ref here's the relevant lines of my ECMOT bit in my ini
BASE_PERIOD = 50000
SERVO_PERIOD = 1000000
apologies for the belated response, I haven't checked here in a while.
I think I ran into the same issue and I thiiiiink I found (can't remember where and I'm only 70% sure that this was the fix) that changing the base period and servo period in ECMOT to something ludicrously high resolved the issue and appeared to have no impact on accuracy (still in the prototype phase of this so I haven't fully validated that - do a bunch of tests before you trust it).
As for servo tuning: I did it with the leadshine software connected to the drive directly and saved the settings on the drive, no need for linuxcnc to be involved.
For ref here's the relevant lines of my ECMOT bit in my ini
BASE_PERIOD = 50000
SERVO_PERIOD = 1000000
Last edit: 19 Jun 2022 09:17 by pseudo. Reason: lol ethercat and step and direction? brain fart
The following user(s) said Thank You: LAUSCH
Please Log in or Create an account to join the conversation.
- LAUSCH
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 3
09 Aug 2022 16:27 #249409
by LAUSCH
Replied by LAUSCH on topic EtherCAT + RPi build log along with questions
Hi pseudo,
No worries about the late answer. In the meantime I have made some progress as well.
After performing the latency test with the Raspberry Pi 4, I have realised that the response is too low in order to run my CNC.
For that reason I have purchased a used Lenovo M710q (intel i3 7100T 16GB Ram) for about 180$ as replacement for the RPi4. This solved many of my issues with the Leadshine drives and is a system with much quicker response time in general.
I am using the follwowing settings for the Leadshine drivers:
Pr0.0 Mode Following Control = 1 (automatically sets bandwidth)
Pr0.1 Control Mode = 9 Ethercat
Pr0.2 Real-time auto-gain tuning = 2 (position mode)
Pr0.3 Stiffness = 60-65 (depending on the axis) tuned to minimize following error when using Leadshine's Motion Studio
Pr0.4 Inertia Ratio = 100-250 (determined by Motion Studio
Afterwards I have tried several settings in LinuxCNC.
With and without PID in place as well as CSP mode = 1 (position mode) 0 (velocity mode).
My preliminary conclusion is that CSP = 0 in conjunction with PID delivers the best results.
Without PID I had following errors in the range of 0.1mm at 3m/min speed of travelling which is too much for my application.
Therefore I have implemented a PID controller, which is not too difficult if once set up. By this I managed to reduce following error to 0.01mm and less when connected to the gantry. For Z-Axis I only needed to increase the Integration part - the other axes still need to be tuned.
When using CSP=1 I was not able to reduce following errors with PID. Maybe the reason is that the output of the PID is a velocity command, which is not recongized by the drive when position mode is active.
I have planned to upload my Hal and Ini file as well as the Leadshine configuration as soon as the machine is running to my satisfaction.
Maybe this is helpful to anyone or I can get some helpful advise of what I can improve.
Did you validate your following error in LinuxCNC after connecting the drives to the gantry?
Are you still working with Raspberry Pi4?
Cheers
No worries about the late answer. In the meantime I have made some progress as well.
After performing the latency test with the Raspberry Pi 4, I have realised that the response is too low in order to run my CNC.
For that reason I have purchased a used Lenovo M710q (intel i3 7100T 16GB Ram) for about 180$ as replacement for the RPi4. This solved many of my issues with the Leadshine drives and is a system with much quicker response time in general.
I am using the follwowing settings for the Leadshine drivers:
Pr0.0 Mode Following Control = 1 (automatically sets bandwidth)
Pr0.1 Control Mode = 9 Ethercat
Pr0.2 Real-time auto-gain tuning = 2 (position mode)
Pr0.3 Stiffness = 60-65 (depending on the axis) tuned to minimize following error when using Leadshine's Motion Studio
Pr0.4 Inertia Ratio = 100-250 (determined by Motion Studio
Afterwards I have tried several settings in LinuxCNC.
With and without PID in place as well as CSP mode = 1 (position mode) 0 (velocity mode).
My preliminary conclusion is that CSP = 0 in conjunction with PID delivers the best results.
Without PID I had following errors in the range of 0.1mm at 3m/min speed of travelling which is too much for my application.
Therefore I have implemented a PID controller, which is not too difficult if once set up. By this I managed to reduce following error to 0.01mm and less when connected to the gantry. For Z-Axis I only needed to increase the Integration part - the other axes still need to be tuned.
When using CSP=1 I was not able to reduce following errors with PID. Maybe the reason is that the output of the PID is a velocity command, which is not recongized by the drive when position mode is active.
I have planned to upload my Hal and Ini file as well as the Leadshine configuration as soon as the machine is running to my satisfaction.
Maybe this is helpful to anyone or I can get some helpful advise of what I can improve.
Did you validate your following error in LinuxCNC after connecting the drives to the gantry?
Are you still working with Raspberry Pi4?
Cheers
Please Log in or Create an account to join the conversation.
- LAUSCH
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 3
13 Aug 2022 05:44 #249630
by LAUSCH
Replied by LAUSCH on topic EtherCAT + RPi build log along with questions
Hi pseudo,
Would it be okay for you to share one of your working parameter file from Motion Studio?
Right now I am wondering what is the best setup for parameter P1.15 Control Switching Mode. There are several options.
Cheers
Would it be okay for you to share one of your working parameter file from Motion Studio?
Right now I am wondering what is the best setup for parameter P1.15 Control Switching Mode. There are several options.
Cheers
The following user(s) said Thank You: pseudo
Please Log in or Create an account to join the conversation.
- pseudo
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 7
31 Oct 2022 23:25 #255620
by pseudo
Replied by pseudo on topic EtherCAT + RPi build log along with questions
Hey Lausch, apologies again for the belated response, I'm not on here much.
I just saw your messages and they were actually surprisingly helpful for me... there's been a few issues with my prototype that, in the context of your message, appear to all be related to the issues you covered. My machine has rapids of 60m/min on one axis and the following error can be up to 6mm during a rapid traverse.... which doesn't matter too much for the rapids but I was getting weird cases where the system would overshoot past soft limits which I'd not seen with linuxcnc before... I've been pretty swamped with developing the rest of the machine (I can't post pics/details of it here just yet for business reasons outside my control, I'll try and DM you when I get a chance) so figuring out the source of these issues was on the backburner while I built the rest of it.
The project is getting close to finished and all the 'not right now' problems are getting addressed which lead me to check this thread and your input has made a lot of motion oddities suddenly make sense, thanks
Feel free to upload your current hal/ini if you like, it's highly likely I'll learn a lot from it.
I'll reply later (heading out the door at the moment) with more details from my end but needless to say my config is likely less optimised than yours
I just saw your messages and they were actually surprisingly helpful for me... there's been a few issues with my prototype that, in the context of your message, appear to all be related to the issues you covered. My machine has rapids of 60m/min on one axis and the following error can be up to 6mm during a rapid traverse.... which doesn't matter too much for the rapids but I was getting weird cases where the system would overshoot past soft limits which I'd not seen with linuxcnc before... I've been pretty swamped with developing the rest of the machine (I can't post pics/details of it here just yet for business reasons outside my control, I'll try and DM you when I get a chance) so figuring out the source of these issues was on the backburner while I built the rest of it.
The project is getting close to finished and all the 'not right now' problems are getting addressed which lead me to check this thread and your input has made a lot of motion oddities suddenly make sense, thanks
Feel free to upload your current hal/ini if you like, it's highly likely I'll learn a lot from it.
I'll reply later (heading out the door at the moment) with more details from my end but needless to say my config is likely less optimised than yours
The following user(s) said Thank You: LAUSCH
Please Log in or Create an account to join the conversation.
- pseudo
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 7
06 Feb 2023 00:55 - 06 Feb 2023 00:58 #263783
by pseudo
Replied by pseudo on topic EtherCAT + RPi build log along with questions
Hi Lausch, how did you go with your setup?
I noticed something in one of your posts about leadshine setup that isn't ideal: "Pr0.2 Real-time auto-gain tuning = 2 (position mode)" - that's for point to point motion not interpolated motion... that happens a lot in the manual, a lot of things that have 'position' in their name are for point to point, usually it says in a footnote or somewhere in the 5.2 section of the manual.
Also Pr0.0 Mode Following Control = 1 (automatically sets bandwidth) it says "If multi-axis synchronous movement needed , set Pr000 as the same for all the axes", where 0(auto) or 100+ is valid. I dramatically reduced my following error by increasing it up to 2000... though then I ran into a weird issue where the stiffness settings would be fine in the leadshine motion test page (ie smooth, low following error, no noise) but would get noisy if you moved the motor via ethercat/lcnc.... so I had to lower it which brought some following error back in.
oh and pr1.15... yeah I'm confused as well, digging into that one myself.
An interesting side note of the mode following control value is the timing portion of ethercat - some of the random forum posts etc I've read mentioned that the sync0cycle time should match the position/velocity loop of the drive, and from what I can tell pr0.00 is where you set that.... I think.
If you get a chance upload your ini/hal etc, I'm having trouble setting up the velocity mode with PID and cia402 though I've likely missed something simple. Did you need to change anything on the drive?
I've upped one of my leadshine configs though I'm no expert on them or anything.
Edit: had to zip the leadshine conf file
I noticed something in one of your posts about leadshine setup that isn't ideal: "Pr0.2 Real-time auto-gain tuning = 2 (position mode)" - that's for point to point motion not interpolated motion... that happens a lot in the manual, a lot of things that have 'position' in their name are for point to point, usually it says in a footnote or somewhere in the 5.2 section of the manual.
Also Pr0.0 Mode Following Control = 1 (automatically sets bandwidth) it says "If multi-axis synchronous movement needed , set Pr000 as the same for all the axes", where 0(auto) or 100+ is valid. I dramatically reduced my following error by increasing it up to 2000... though then I ran into a weird issue where the stiffness settings would be fine in the leadshine motion test page (ie smooth, low following error, no noise) but would get noisy if you moved the motor via ethercat/lcnc.... so I had to lower it which brought some following error back in.
oh and pr1.15... yeah I'm confused as well, digging into that one myself.
An interesting side note of the mode following control value is the timing portion of ethercat - some of the random forum posts etc I've read mentioned that the sync0cycle time should match the position/velocity loop of the drive, and from what I can tell pr0.00 is where you set that.... I think.
If you get a chance upload your ini/hal etc, I'm having trouble setting up the velocity mode with PID and cia402 though I've likely missed something simple. Did you need to change anything on the drive?
I've upped one of my leadshine configs though I'm no expert on them or anything.
Edit: had to zip the leadshine conf file
Last edit: 06 Feb 2023 00:58 by pseudo. Reason: attachment format
Please Log in or Create an account to join the conversation.
- pseudo
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 7
06 Feb 2023 04:06 #263791
by pseudo
Replied by pseudo on topic EtherCAT + RPi build log along with questions
Ooook trying to replicate your work took forever... because I was missing one small part: CIA402 in velocity mode needs a setp cia402.0.velo-scale xxx line in your hal (see attached modified CIA402 example hal)... I could not find this info anywhere so I ended up reading through the cia402.comp hal component to figure it out. Adding it here so others don't have to spend ages figuring it out like I did.
Also adding some search terms... setp cia402.0.csp-mode 0 comes up with zero results beyond the github and I spent ages looking for more info
Search junk:
cia402 velocity mode csv cia402.0.drv-target-velocity cia402.0.velocity-cmd
Also adding some search terms... setp cia402.0.csp-mode 0 comes up with zero results beyond the github and I spent ages looking for more info
Search junk:
cia402 velocity mode csv cia402.0.drv-target-velocity cia402.0.velocity-cmd
The following user(s) said Thank You: LAUSCH
Please Log in or Create an account to join the conversation.
Time to create page: 0.110 seconds