ASD-A2 EtherCAT on LinuxCNC

More
05 Dec 2022 21:44 #258627 by jirkam
Replied by jirkam on topic ASD-A2 EtherCAT on LinuxCNC
Hello "db1981"
Thank you very much for the tip.

When I write it like this:
# Generated by stepconf 1.1 at Thu Sep 10 02:41:11 2020
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS num_dio=24 num_aio=8
loadrt pwmgen output_type=1

loadusr ethercat debug 1
loadusr -W lcec_conf delta_pos.xml
loadrt lcec
addf lcec.read-all              servo-thread

loadusr ethercat debug 0

addf pwmgen.make-pulses base-thread

addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf pwmgen.update servo-thread

addf lcec.write-all             servo-thread

so will it be ok?

Will the servos behave completely differently, or will the behavior change slightly?

Thank you very much.
Jirkam

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

More
05 Dec 2022 22:23 #258634 by db1981
Replied by db1981 on topic ASD-A2 EtherCAT on LinuxCNC
that is the correct order.

you are not using pids in linuxcnc. So the behavior will change slightly.

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

More
06 Dec 2022 13:54 #258698 by jirkam
Replied by jirkam on topic ASD-A2 EtherCAT on LinuxCNC
Hello.
So I tried it and the servo motors behave exactly the same.
I'm tracking the servos in the Hal Scope.
Thanks Jirka

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

More
07 Dec 2022 09:51 #258794 by fupeama
Replied by fupeama on topic ASD-A2 EtherCAT on LinuxCNC

Hello Jirka,

i have noticed an "~big" error in your hal file.

you adding lcec.real-all and write-all at the beginning of the hal file.

caused that liunxcnc builds its execution order of task functions in the order they are placed in the hal file, your servo-thread calls ec-read and then immediatly writes out lcec-write. So nothing is done with the Data in the meantime. Lcec.write-all uses "old"data from the last cycle . Which causes timing issues and leads to an bad servo tuning.

the right order would be:

addf lcec.read-all (gets data from hardware)
addf motion, value-converts, pids, classicladder etc.. (works with the data)

last addf lcec.write-all (send new data to hardware).


In your case lcec.write-all is called in front of motion and pids. So it sends "old" data from the last cylce to the drives without the new calculations. You got an 1
cycle offset between input and output data.

(you can search for "execution order" in the forum, i have descripted this in detail somewhere)
 

Hi I think you are wrong,hal file is not a program, but only a "description". It doesn't matter what order the lines are in, because it only runs at the end when linuxcnc starts. Just like when I enter HAL lines into halcmd, I have to enter start at the end, nothing happens until then.
Martin

 

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

More
07 Dec 2022 10:14 #258796 by db1981
Replied by db1981 on topic ASD-A2 EtherCAT on LinuxCNC
Hi,

i am shure im absolutly right.....

Yes, hal is an description / script file. The order from net descriptions doesn't matter, but by parsing the hal also the running-order of the "realtime threads" are created.

lcnc places the running order per cycle from the functions you declare in the same order the addf commands in the hal file are placed.

This is very important for every realtime or plc system.
In every cycle every function is called 1 time, so its important to have the right order to get the expected behaviour of the realtime system.

The top description of an plc system should look like this :

-read Inputs (from Hardware)
-work with Data
-write Outpus (to Hardware)

in case of linuxcnc:
-read from hardware
-Motion Task (controll values)
-PIDs (compare actual hardware date with actual controll data)
-PLC functions
-write to hardware

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

More
07 Dec 2022 10:32 #258797 by db1981

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

More
08 Dec 2022 10:09 #258883 by rodw
Replied by rodw on topic ASD-A2 EtherCAT on LinuxCNC


Hi I think you are wrong,hal file is not a program, but only a "description". It doesn't matter what order the lines are in, because it only runs at the end when linuxcnc starts. Just like when I enter HAL lines into halcmd, I have to enter start at the end, nothing happens until then.
Martin


Sorry in this case the order of lcec read and write calls is absolutley critical. What you want to do is read from the ethercat bus, let Linuxcnc modify things, then write changes back to the bus.

We ar not talking about pins here, we are calling functions so the order is critical.

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

More
09 Dec 2022 00:04 - 09 Dec 2022 00:05 #258941 by db1981
Replied by db1981 on topic ASD-A2 EtherCAT on LinuxCNC
this is also very important for converter or mux functions (conv_to_float etc.)
They have to be in the right order too.

example:
If you convert an incoming encoder value, this function has to be placed between encoder readout (lcec / mesa read) and the motion / pid part. If you need to convert the motion/pid output again for the drive_cmd , this function has to be placed after motion/pid in front of the hardware output (lcec/mesa) write .

For plc/ladder this is the same.

I have read tons of bad hal / inis , when the config is growing many people start to add things at the end of their hal file or more worse in the postgui halfile. You can get very unexpected behaviour . And the issue finding could take years....
Last edit: 09 Dec 2022 00:05 by db1981.
The following user(s) said Thank You: rodw

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

More
09 Dec 2022 08:36 - 09 Dec 2022 08:36 #258978 by fupeama
Replied by fupeama on topic ASD-A2 EtherCAT on LinuxCNC
Yes guys you are both right and i was wrong.
I made easy experiment.
load function or2 (three times) and connect
siggen.clock -> or2.0.in0
or2.0.out -> or2.1.in0
or2.1.out -> or2.2.in0

wrong order
addf or2.2
addf or2.1
addf or2.0
addf siggen.0.update
three cycles are needed to change the signal at the end of the chain

right order
addf siggen.0.update
addf or2.0
addf or2.1
addf or2.2
only one cycle is needed to change the signal at the end of the chain YOU CAN SEE THE TIME SEQUENCE FROM THE PICTURE
You can see the time sequence from pictures.

I apologize once again for the mystification
Martin

 
Attachments:
Last edit: 09 Dec 2022 08:36 by fupeama.
The following user(s) said Thank You: Aciera

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

More
09 Dec 2022 10:54 #258986 by db1981
Replied by db1981 on topic ASD-A2 EtherCAT on LinuxCNC
:-)

Yes, that is an very important Case.

I think this behaviour should be better descripted and point out in the Documentation.

If you are not an prof. PLC Programmer or Microcontroller Developer you will never notice this.
And in the most cases this is also not clear to Prof. IT Guys / PC Programmers, cause they all code "event" based and not familar with the processing of realtime / hardware / atomic coding ...

I would say that > 70% of all the tuning problems in this forum are related to wrong execution order. Control Loops can not work, if the basics are wrong.
The following user(s) said Thank You: rodw

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

Time to create page: 0.200 seconds
Powered by Kunena Forum