linuxcnc.stat.homed and ok_for_mdi() changes?

More
02 Oct 2016 17:23 - 02 Oct 2016 17:24 #81155 by kentavv
The LinuxCNC Python module is fantastic tool!

There may potentially be a small oversight in the documentation. The definition of linuxcnc.stat.homed appears to have changed from returning an integer (LinuxCNC 2.6) to a tuple of integers (LinuxCNC 2.7). If so, the ok_for_mdi() example should be updated to reflect that change. Perhaps something along the lines of the following? Thank you
def ok_for_mdi26():
      s.poll()
      return not s.estop and s.enabled and s.homed and (s.interp_state == linuxcnc.INTERP_IDLE)

# to calculated homed, we iterate over the axes, finding those that are present on this machine, and checking if those axes are homed.
def ok_for_mdi27():
      s.poll()
      homed = True
      for i in range(len(s.axis)):
            homed = homed and ((not s.axis[i]['enabled']) or (s.axis[i]['homed'] != 0))
      return not s.estop and s.enabled and homed and (s.interp_state == linuxcnc.INTERP_IDLE)

linuxcnc.org/docs/2.7/html/config/python-interface.html
linuxcnc.org/docs/2.6/html/common/python-interface.html
Last edit: 02 Oct 2016 17:24 by kentavv. Reason: Added code tags so spacing appears

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

More
03 Oct 2016 05:07 #81166 by cmorley
I don't think the code was changed between 2.6 and 2.7.. I believe the docs were wrong in 2.6.
Is the behaviour not as the 2.7 docs specify?
I admit the code should probably be changed at least to make the code more clear.
What program is your code excerpt from?

Chris M

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

More
03 Oct 2016 05:17 #81168 by kentavv
Hi. The ok_for_mdi26() function is from the documentation. (I added the "26" suffix. I only have experience with 2.7, so didn't know if the semantics had changed or not.) The ok_for_mdi27() function is a slightly modified version of what's in the documentation and, I believe, correctly works with the tuple implementation of homed, considering which axes are enabled and checking the homed state of only the enabled axes. I could have some detail wrong, and there's probably a more Python-like way to write it, but it's working as expected for me. If it looks OK, perhaps it or something similar could be used to update the docs. Thank you

linuxcnc.org/docs/2.7/html/config/python-interface.html
linuxcnc.org/docs/2.6/html/common/python-interface.html

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

More
04 Oct 2016 00:33 #81198 by cmorley
ahh yes I see now ..The example code in the docs is wrong.

Chris M

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

More
06 Oct 2016 19:52 #81309 by newbynobi
And the OK for mdi should check also for NoForceHoming!

Norbert

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

More
06 Oct 2016 20:43 #81314 by kentavv
Is the only way to check NoForceHoming via with linuxcnc.ini(...) and the associated find(...)?

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

More
08 Oct 2016 13:32 #81410 by newbynobi
As far as know, Yes!

Norbert

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

More
08 Oct 2016 16:21 #81423 by kentavv
The following is how I added the check. I didn't see a nice way to find what is the current INI file in use, so that was hard coded to the one I use. Maybe someone else will have a better way.

import linuxcnc

cnc_s = linuxcnc.stat()
cnc_c = linuxcnc.command()

# check the ini file if homing is required
cnc_i = linuxcnc.ini('/home/kent/linuxcnc/configs/mill.pico/univstep.ini')
force_homing = int(cnc_i.find('TRAJ', 'NO_FORCE_HOMING') or 0) == 0

# to calculate homed, we iterate over the axes, finding those that are present on this machine,
# and logically combining their homed state (for LinuxCNC 2.7)
def ok_for_mdi27():
  cnc_s.poll()
  homed = True
  if force_homing:
    for axis in cnc_s.axis:
      homed = homed and ((not axis['enabled']) or (axis['homed'] != 0))
  return (cnc_s.estop == 0) and cnc_s.enabled and homed and (cnc_s.interp_state == linuxcnc.INTERP_IDLE)

def verify_ok_for_mdi():
  if not ok_for_mdi27():
    print 'Not ready for MDI commands'
    sys.exit(1)

print ok_for_mdi27()

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

More
08 Oct 2016 17:53 #81427 by cmorley

The following is how I added the check. I didn't see a nice way to find what is the current INI file in use, so that was hard coded to the one I use. Maybe someone else will have a better way.

import linuxcnc

cnc_s = linuxcnc.stat()
cnc_c = linuxcnc.command()

# check the ini file if homing is required
cnc_i = linuxcnc.ini('/home/kent/linuxcnc/configs/mill.pico/univstep.ini')
force_homing = int(cnc_i.find('TRAJ', 'NO_FORCE_HOMING') or 0) == 0

# to calculate homed, we iterate over the axes, finding those that are present on this machine,
# and logically combining their homed state (for LinuxCNC 2.7)
def ok_for_mdi27():
  cnc_s.poll()
  homed = True
  if force_homing:
    for axis in cnc_s.axis:
      homed = homed and ((not axis['enabled']) or (axis['homed'] != 0))
  return (cnc_s.estop == 0) and cnc_s.enabled and homed and (cnc_s.interp_state == linuxcnc.INTERP_IDLE)

def verify_ok_for_mdi():
  if not ok_for_mdi27():
    print 'Not ready for MDI commands'
    sys.exit(1)

print ok_for_mdi27()


Try adding this:
import os
INIPATH = os.environ['INI_FILE_NAME']

Then use INIPATH instead of hard coded path

Chris M

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

More
08 Oct 2016 18:54 #81428 by kentavv
Thank you, I learned something new again. What I found, suggested that INI_FILE_NAME is defined in the environment if a script is called by LinuxCNC. Since my script is run external to LinuxCNC, INI_FILE_NAME is not defined.

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

Moderators: HansU
Time to create page: 0.082 seconds
Powered by Kunena Forum