Hal, twopasses and ethercat lcec

More
24 Jan 2019 02:42 #124707 by Nico2017
Hi,

I have been trying to use the twopass feature of hal ( linuxcnc.org/docs/html/hal/twopass.html ) to get an easier to develop and debug file architecture and hal code. However it does not seem to function with the ethercat component

My files project work fine when not using two passes and when I go into twopasses option, moving the loadrt of the POSTGUI_HAFILE into a HALFILE called before I got:

twopass:found ./postgui_load_hal.hal
HAL: ERROR: bad position: 0
twopass: Error in file ./lam-v1.hal:
addf failed
Note: Using POSIX realtime
LCEC: lcec_conf is not loaded
lcec: rtapi_app_main: Invalid argument (-22)

twopass: load_the_modules cmd=<orig_loadrt lcec>
waitpid failed /usr/bin/rtapi_app lcec
/usr/bin/rtapi_app exited without becoming ready
insmod for lcec failed, returned -1

Note: Using POSIX realtime
HAL: ERROR: function 'lcec.read-all' not found
twopass: Error in file ./lam-v1.hal:
addf failed

I think the issue can come from those lines:
loadusr -W lcec_conf lam-ethercat-v1.xml
loadrt lcec
addf lcec.read-all servo-thread
addf lcec.write-all servo-thread
loaded in my first HALFILE which might need to be moved around if using twopasses.

Any rules or recommendation to make the hal and lcec ethercat working with twopasses option of HAL?

Thank you,

Nicolas

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

More
24 Jan 2019 03:45 #124710 by dgarrett
I'm not familiar with lcec and cannot guess what is in a
configuration's ini and hal files if they are not posted.

This is a rare error:
twopass:found ./postgui_load_hal.hal
HAL: ERROR: bad position: 0
twopass: Error in file ./lam-v1.hal:
addf failed

this error is found in src/hal/hal_lib.c
    if (position == 0) {
	/* zero is not allowed */
	rtapi_mutex_give(&(hal_data->mutex));
	rtapi_print_msg(RTAPI_MSG_ERR, "HAL: ERROR: bad position: 0\n");
	return -EINVAL;
    }

Ref for 2.7: github.com/LinuxCNC/linuxcnc/blob/2.7/src/hal/hal_lib.c#L1997

'bad position' refers to use of addf with a seldom used 'position'
parameter (having a value of 0 in the reported case):
$ halrun
halcmd: help addf
addf functname threadname [position]
  Adds function 'functname' to thread 'threadname'.  If
  'position' is specified, adds the function to that spot
  in the thread, otherwise adds it to the end.  Negative
  'position' means position with respect to the end of the
  thread.  For example '1' is start of thread, '-1' is the
  end of the thread, '-3' is third from the end.

A quick test shows using addf with position 0 is *never* allowed
(not a twopass issue) so that is likely a secondary error.
Rereading, the hal_lib.c codes states that 'zero is not
allowed'
I think the issue can come from those lines:
loadusr -W lcec_conf lam-ethercat-v1.xml
loadrt lcec

Yes, I'm guessing this message indicates the problem:

LCEC: lcec_conf is not loaded
lcec: rtapi_app_main: Invalid argument (-22)

This is likely a consequent error:
HAL: ERROR: function 'lcec.read-all' not found
twopass: Error in file ./lam-v1.hal:
addf failed

It says clearly that an attempt is made to load a
non-existent function named 'lcec.read-all"

So I would suggest running halrun (cd to the ini directory)
by itself and verifying the commands:
loadusr -W lcec_conf lam-ethercat-v1.xml
and
loadrt lcec with_its_required_parms_if_any

work independent of LinuxCNC -- e.g., verify that
you configure so that there is an executable named
'lcec_conf' that is in the PATH and exports a hal
component named 'lcec_conf'. Similarly, a module
named lcec.so or.ko must be in the expected location.

It is also probably necessary that a file named
lam-ethercat-v1.xml is in the ini directory since a fullpath
is not shown.

As a guess, it may be the lcec_conf is not in the PATH
Test if its properly found using:
$ which lcec_conf

I can't help anymore unless you post a complete
configuration -- a tar or zip file of the directory.
Also post the output of the command 'linuxcnc_info'

I don't understand how the non-realtime program 'lcec_conf'
requested with 'loadusr' relates to the realtime
module 'lcec'. There may be a timing race if one
depends on the other.

#
NOTE: The master branch (2.8~pre) includes provisions for
excluding problematic halfiles in order to isolate
problems or handle loadrt lines that are foreign to
the usual parameter-specifying methods.

linuxcnc.org/docs/devel/html/hal/twopass...#_exluding_hal_files
linuxcnc.org/docs/devel/html/hal/twopass.html
Ref: github.com/LinuxCNC/linuxcnc/commit/a7ca8053a
The following user(s) said Thank You: Nico2017

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

More
24 Jan 2019 20:07 #124758 by Nico2017
Hi, thank you for your answer.

I managed to reproduce the problem on a case provided as a sim configuration to make it simpler instead of posting my working configuration which starts to be more complicated. Attached are the two folders of the same default simulation axis where I added ethercat:
  • File Attachment:

    File Name: ethercatwi...sses.zip
    File Size:67 KB
    works fine as long as you have your ethercat configured and running with the physical hardware connected. So this is working well to me as in my current configuration at the moment.
  • File Attachment:

    File Name: ethercatwi...sses.zip
    File Size:67 KB
    is the same case but I just added the twopass feature in the axis.ini HAL section. This gives me an error

    File Attachment:

    File Name: error.txt
    File Size:2 KB
    and I aslo get

    File Attachment:

    File Name: linuxcnc_debug.txt
    File Size:0 KB
    and

    File Attachment:

    File Name: linuxcnc_print.txt
    File Size:1 KB
So between the two cases there is only the twopass option in the ini files which differs. The first case works fine and when I manually do it it works fine too.

Unfortunately debugging ethercat is hard if you have not got the hardware connected as it will gives you an error. In this simple example I just used two modules EL1008 and EL2008 as described in the ethercat xml files.

Thank you,
Nicolas
Attachments:

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

More
24 Jan 2019 20:58 #124762 by dgarrett
As asked before:
post the output of the command 'linuxcnc_info'

and result of:
$ which lcec_conf
The following user(s) said Thank You: Nico2017

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

More
24 Jan 2019 22:25 #124768 by dgarrett
It looks like the module lcec depends on state
created by the user space lcec_conf but with
twopass managing loads, the sequencing is
not in the order required by the dependency.

Since you are using a master branch deb, you can
load lcec_conf and lcec outside of the loading
managed by twopass processing.

Ref: linuxcnc.org/docs/devel/html/hal/twopass...#_exluding_hal_files

Try the following:

1) remove the load statements for both lcec and lcec_conf
in lcec_ini.hal
2) create a file excluded from twopass processing named
lcec_load.hal like:
$ cat lcec_load.hal
# NOTWOPASS
# load and wait for the user component lcec_conf
loadusr -W lcec_conf ethercat-conf.xml
loadrt lcec
show pin lcec
show funct lcec

3) in your sim config (axis.ini), order halfiles like:
[HAL]
TWOPASS = on
HALFILE = lcec_load.hal
HALFILE = core_sim.hal
HALFILE = lcec_ini.hal
HALFILE = sim_spindle_encoder.hal
HALFILE = axis_manualtoolchange.hal
HALFILE = simulated_home.hal
HALFILE = check_xyz_constraints.hal
POSTGUI_HALFILE = postgui.hal
The following user(s) said Thank You: Nico2017

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

More
24 Jan 2019 22:29 - 24 Jan 2019 22:37 #124769 by Nico2017
Here are the output of the linuxcnc.info (by the way the .info extension cannot be uploaded on the forum):

File Attachment:

File Name: linuxcncdotinfo.txt
File Size:2 KB


and the other command is:
which lcec_conf
/usr/bin/lcec_conf

Will try your suggestion and keep you posted,

Thank you,

Nicolas
Attachments:
Last edit: 24 Jan 2019 22:37 by Nico2017.

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

More
24 Jan 2019 22:45 - 24 Jan 2019 22:45 #124771 by Nico2017
Ok following your instructions makes the ethercat with two passes hal features working.
Brillant!

Thank you so much.

Nicolas
Last edit: 24 Jan 2019 22:45 by Nico2017.

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

More
24 Jan 2019 23:19 #124776 by dgarrett
The following user(s) said Thank You: rodw, Nico2017

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

More
24 Sep 2019 05:09 - 24 Sep 2019 06:00 #146035 by Nico2017
Hi,
the two passes was working on a simple etherCAT config, but as I have advanced in my project and trying again the Twopasses, as I want to use names instead of counts, it no longer works:

I am currently having in my ini file, with lamgui my glade and python files for the machine I want to work on:

[DISPLAY]
DISPLAY = lamgui
[HAL]
TWOPASS = on
#Use loadusr -W if TWOPASS activated
HALUI = halui
HALFILE = loadrt_lcec_threads.hal
HALFILE = loadrt_addf_setp.hal
HALFILE = lam-v1.hal
POSTGUI_HALFILE = postgui.hal

Only the loadrt_lcec_threads.hal and loadrt_addf_setp.hal

I have therefore several specific things used with TWOPASS:
  • the custom made display loaded which contains a h = hal.component("passthrough") hal component with plenty of pins define din the python file
  • the halui, which I am not sure how it reacts compared to the TWOPASS and the POSTGUI_HALFILE.
  • the POSTGUI_HALFILE for hich I have set up # NOTWOPASS to see if it was making a difference or not
  • I am using the message hal component in my loadrt_addf_setp.hal

Here is the resulting cmd line: apparently linuxcnc gets shut down but I am unable to kill the process.

Warning: Spoiler!


When I do:
LINUXCNC - 2.9.0~pre0
Machine configuration directory is '/home/machine/linuxcnc/configs/sim.axis'
Machine configuration file is 'axis.ini'
LinuxCNC is still running.  Restart it? [Y/n] Y
Cleaning up old LinuxCNC...
Shutting down and cleaning up LinuxCNC...
Waiting for other session to finish exiting...lockfile still not removed
It stays like that forever

I have removed the get from my comment which apparently was creating an error when used in a comment with TWOPASS. I still got the same kind of results being locked without being able not to do anything on the terminal.

Warning: Spoiler!


I enventually made it work as in my loadrt_lcec_threads.hal I had:
loadrt [KINS]KINEMATICS #To be used linux 2.8.x
loadrt motmod base_period_nsec=[EMCMOT]BASE_PERIOD base_thread_fp=0 servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]JOINTS num_dio=20 num_aio=20

TO make the TWOPASS work I need:
loadrt trivkins coordinates=XY kinstype=BOTH #To be used linux 2.8.x
loadrt motmod base_period_nsec=100000 base_thread_fp=0 servo_period_nsec=100000 num_joints=2 num_dio=20 num_aio=20

Apparently when using TWOPASS the hal parsing loose the ability to read some variables from the ini file: here it was [KINS]KINEMATICS [EMCMOT]BASE_PERIOD. This is a bit strange as I have # NOTWOPASS in the file containing those lines.
Last edit: 24 Sep 2019 06:00 by Nico2017.

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

More
24 Sep 2019 12:35 #146062 by dgarrett

It stays like that forever

Your session shut down because of a core dump:
rtapi_app: caught signal 8 - dumping core

On most systems, Signal 8 is SIGFPE -- a floating point
fault -- unusual so something is very wrong with that run.

Since LinuxCNC runs several processes, some may remain
running after such a failure and prevent a new start. If
you start in a terminal, you can find the processes with ps
and kill them (you may also need halrun -U). If you don't
know how to do these things, a reboot will work.

I enventually made it work...


Regarding this line that didn't work:
loadrt motmod base_period_nsec=[EMCMOT]BASE_PERIOD base_thread_fp=0 servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]JOINTS num_dio=20 num_aio=20
[TRAJ]JOINTS is not a supported ini file setting,
[KINS]JOINTS is the proper setting

As a guess, you may have had an error because of this.

You have a complicated configuration so it would better to
post a tar or zip file of the entire configuration and a
complete transcript of the failing terminal session.

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

Time to create page: 0.099 seconds
Powered by Kunena Forum