diff options
author | Michael Haberler <git@mah.priv.at> | 2011-05-25 08:13:16 +0200 |
---|---|---|
committer | Michael Haberler <git@mah.priv.at> | 2011-10-28 08:25:34 +0200 |
commit | 766a841b38cfaf78b72b501ca52d490e8d3aaddc (patch) | |
tree | 91071f50cc3c9fef9b27d0422fe5c1f066a16f6b | |
parent | 8cebf72782b9c25957b7ce2607c424814d8bfbf5 (diff) | |
download | linuxcnc-766a841b38cfaf78b72b501ca52d490e8d3aaddc.tar.gz linuxcnc-766a841b38cfaf78b72b501ca52d490e8d3aaddc.zip |
interp/remap: complete T/M6 example using py pro/epilogs and NGC handlers
also sports M61 handler in all-Python
-rw-r--r-- | configs/sim/py.ini | 18 | ||||
-rw-r--r-- | configs/sim/pysubs/pythonsubs.py | 81 | ||||
-rw-r--r-- | nc_files/remap-subroutines/change.ngc | 93 | ||||
-rw-r--r-- | nc_files/remap-subroutines/prepare.ngc | 3 |
4 files changed, 63 insertions, 132 deletions
diff --git a/configs/sim/py.ini b/configs/sim/py.ini index d5602c44a..91265a564 100644 --- a/configs/sim/py.ini +++ b/configs/sim/py.ini @@ -14,11 +14,11 @@ VERSION = $Revision$ MACHINE = EMC-HAL-SIM-AXIS # Debug level, 0 means no messages. See src/emc/nml_int/emcglb.h for others -DEBUG = 0x7FFFFFFF +#DEBUG = 0x7FFFFFFF #DEBUG = 0x7FFFDEFF #no interp,oword #DEBUG = 0x00008000 # py only #DEBUG = 0x0000E000 # py + remap + Oword -#DEBUG = 0x0000C000 # py + remap +DEBUG = 0x0000C000 # py + remap #DEBUG = 0x0000C100 # py + remap + Interpreter #DEBUG = 0x0000E100 # py + remap + Interpreter + oword #DEBUG = 0x00008000 @@ -170,13 +170,13 @@ PARAMETER_FILE = sim_mm.var #REMAP=F argspec=- python=blah deppert -aanix REMAP=G88.1 modalgroup=1 argspec=xyzpqr ngc=g881min + + REMAP=G88.2 modalgroup=1 argspec=xyzpqr ngc=g882min prolog=addlocals #prolog=fooprolog epilog=fooepilog REMAP=G88.6 modalgroup=1 argspec=XYZ- python=g886 REMAP=G88.8 modalgroup=1 argspec=XYZ- python=m315 -REMAP=M6 modalgroup=6 argspec=- ngc=change -# prolog=whoami REMAP=M75 modalgroup=10 argspec=- python=m250 REMAP=M250 modalgroup=10 argspec=xyzpqr- python=whoami prolog=fooprolog epilog=fooepilog @@ -189,19 +189,11 @@ REMAP=M316 modalgroup=10 ngc=null_sub REMAP=F argspec=- ngc=null_sub # python=null_remap REMAP=S argspec=- python=null_remap +# see pythonsubs.py and nc_files/remap-subroutines REMAP=T argspec=T- prolog=prepare_prolog epilog=prepare_epilog ngc=prepare REMAP=M61 modalgroup=6 argspec=Q- python=set_tool_number REMAP=M6 modalgroup=6 argspec=- prolog=change_prolog ngc=change epilog=change_epilog -#prepare -#REMAP=M400 argspec=tq- python=prepare - -#REMAP=T argspec=tq- ngc=tdemo prolog=prepare_ngc_prolog epilog=prepare_ngc_epilog - -#REMAP=T argspec=tq- ngc=tdemo -#prolog=whoami - - # a plain .ngc sub call by M42: # #REMAP= code=M42 modalgroup=9 argspec= prolog=noargs remapto=m42.ngc epilog=failon_notzero diff --git a/configs/sim/pysubs/pythonsubs.py b/configs/sim/pysubs/pythonsubs.py index bc557ed44..aa9f460ab 100644 --- a/configs/sim/pysubs/pythonsubs.py +++ b/configs/sim/pysubs/pythonsubs.py @@ -37,7 +37,6 @@ TOLERANCE_EQUAL = 0.0001 def prepare_prolog(userdata,**words): toolno = words['t'] - p = params (status,pocket) = interp.find_tool_pocket(toolno) if status != INTERP_OK: interp.push_errormsg("T%d: pocket not found" % (toolno)) @@ -45,15 +44,14 @@ def prepare_prolog(userdata,**words): # these variables will be visible in the following ngc oword sub # as #<tool> and #<pocket> as local variables - p["tool"] = toolno - p["pocket"] = pocket + params["tool"] = toolno + params["pocket"] = pocket return (INTERP_OK,) # The actual ngc procedure looks like so: # # o<r_prepare> sub -# (debug, r_prepare call_level= #<_call_level> remap_level=#<_remap_level>) -# (debug, n_args=#<n_args> tool=#<tool> pocket=#<pocket>) +# (debug, r_prepare call_level= #<_call_level> remap_level=#<_remap_level> tool=#<tool> pocket=#<pocket>) # # ; show aborting a prepare on tool 2 by returning a negative value # o<testabort> if [#<tool> EQ 2] @@ -71,7 +69,50 @@ def prepare_epilog(userdata,**words): CanonMod.INTERP_ABORT(int(retval),"T%d: aborted (return code %.4f)" % (words['t'],retval)) return (INTERP_OK,) -# M61 remapped to a python handler + +# +# M6 remapped to a NGC handler, with Python prolog+epilog +# +# Incantation: +# REMAP=M6 modalgroup=6 argspec=- prolog=change_prolog ngc=change epilog=change_epilog +# +def change_prolog(userdata,**words): + if interp.selected_pocket < 0: + interp.push_errormsg("Need tool prepared -Txx- for toolchange") + return (INTERP_ERROR,) + if interp.cutter_comp_side: + interp.push_errormsg("Cannot change tools with cutter radius compensation on") + return (INTERP_ERROR,) + params["tool_in_spindle" ] = interp.current_tool + + # bug in interp_convert.cc: WONT WORK - isnt valid anymore + ## settings->selected_pocket); + ## settings->tool_table[0].toolno, <--- BROKEN + ## block->t_number, + #params["prepared" ] = 2 + + params["pocket" ] = interp.selected_pocket + return (INTERP_OK,) + +def change_epilog(userdata,**words): + retval = interp.return_value + if retval > 0: + # commit change + CanonMod.CHANGE_TOOL(interp.selected_pocket) + interp.current_pocket = interp.selected_pocket + # cause a sync() + interp.tool_change_flag = True + interp.set_tool_parameters(); + else: + # abort + CanonMod.INTERP_ABORT(int(retval),"M6 aborted (return code %.4f)" % (retval)) + return (INTERP_OK,) + + +# +# M61 remapped to an all-Python handler +# demo - this really does the same thing as the builtin (non-remapped) M61 +# # Incantation: # # REMAP=M61 modalgroup=6 argspec=Q- python=set_tool_number @@ -90,8 +131,8 @@ def set_tool_number(userdata,**words): if status != INTERP_OK: return (status,) if words['q'] > -TOLERANCE_EQUAL: - interp.current_pocket = toolno - CanonMod.SELECT_POCKET(toolno) + interp.current_pocket = pocket + CanonMod.CHANGE_TOOL_NUMBER(pocket) # cause a sync() interp.tool_change_flag = True return (INTERP_OK,) @@ -99,27 +140,3 @@ def set_tool_number(userdata,**words): interp.push_errormsg("M61 failed: Q=%4" % (toolno)) return (INTERP_ERROR,) - -# REMAP=M6 modalgroup=6 argspec=- prolog=change_prolog ngc=change epilog=change_epilog -# (DEBUG, executing M6 O-word sub, tool-in-spindle=#1 prepared=#2 pocket=#3) -def change_prolog(userdata,**words): - - p["tool_in_spindle" ] = 1 - p["prepared" ] = 2 - p["pocket" ] = 3 - return (INTERP_OK,) - -def change_epilog(userdata,**words): - retval = interp.return_value - if retval > 0: - # commit change - CanonMod.CHANGE_TOOL(interp.selected_pocket) - interp.current_pocket = interp.selected_pocket - # cause a sync() - interp.tool_change_flag = True - else: - # abort - CanonMod.INTERP_ABORT(int(retval),"M6 aborted (return code %.4f)" % (retval)) - return (INTERP_OK,) - - diff --git a/nc_files/remap-subroutines/change.ngc b/nc_files/remap-subroutines/change.ngc index a73c37e54..e01e28590 100644 --- a/nc_files/remap-subroutines/change.ngc +++ b/nc_files/remap-subroutines/change.ngc @@ -1,88 +1,11 @@ -; This demonstrates doing an M6 remapped to a named oword sub -; -; to activate, incantate as follows in the ini file: -; -; [RS274NGC] +o<change> sub +(debug, change call_level= #<_call_level> remap_level=#<_remap_level>) +(debug, change tool_in_spindle=#<tool_in_spindle> pocket=#<pocket>) -; # remap M6 to a named oword subroutine. -; M6_COMMAND=o<change>call -; -; parameter #1: the current tool-in-spindle -; parameter #2: the tool number requested in the last T (prepare) command -; parameter #3: pocket of new tool -; -; -; -O<change> sub -; -(DEBUG, executing M6 O-word sub, tool-in-spindle=#1 prepared=#2 pocket=#3) -; -M66 P2 L0 -;(debug, digital-input-02=#5399) +; demonstrate aborting a change on pocket 3 by returning a negative value + o<testabort> if [#<tool> EQ 3] + o<testabort> return [-1] + o<testabort> endif -#<tool_change_with_spindle_on> = 0 -#<tool_change_quill_up> = 0 -#<tool_change_at_g30> = 0 - -; number of seconds to wait for 'tool-changed' equivalent -#<timeout> = 9999 -; -O<change_spindle_off> if [#<tool_change_with_spindle_on>] EQ 0 - M5 -O<change_spindle_off> endif - -O<change_quill_up> if [#<tool_change_quill_up> NE 0] - G0 G53 Z0 -O<change_quill_up> endif - -O<change_tc_at_g30> if [#<tool_change_at_g30> NE 0] - G30 -O<change_tc_at_g30> endif - -; set analog output pin #2 to signal the pocket number -; iocontrol.tool-number becomes motion.analog-out-02 -M68 E2 Q[#2] -;(DEBUG, set current tool number on motion.analog-out-02: #2) -; -; assert the equivalent of the iocontrol.tool-change pin -; which is now motion.digital-out-01 -M64 P1 -;(DEBUG, motion.digital-out-01 set high, waiting for motion.digital-in-01) - - -; wait for the equivalent of the iocontrol.tool-changed pin to go high -; we use motion.digital-in-01 -; -M66 P1 L3 Q#<timeout> -; -; if we waited too long, fail change and abort. -; -O<change_timeout> if [#5399 EQ -1] - (DEBUG, timeout waiting for digital-in-01 to become true - failing change ) - O<change> return [-1] -O<change_timeout> endif - -; retract iocontrol.tool-change equivalent -;(DEBUG, deasserting motion.digital-out-01) -M65 P1 -; - -; test fail-change line from gladevcp -M66 P2 L0 -; (debug, digital-input-02=#5399) -O<change_fail> if [#5399 EQ 1] - (DEBUG, returning -1 to fail change) - O<change> return [-1] -O<change_fail> else - (debug, change ok, returning +1 to commit change) - ; a positive return value commits the tool change - O<change> return [1] -O<change_fail> endif -; -; return a positive value commit the change. -; a negative return value will fail the change and -; abort the interpreter with a message like -; "M6 failed (<return value>)" -; -O<change> endsub +o<change> endsub [1] m2 diff --git a/nc_files/remap-subroutines/prepare.ngc b/nc_files/remap-subroutines/prepare.ngc index 3e087aa83..9a59e27b7 100644 --- a/nc_files/remap-subroutines/prepare.ngc +++ b/nc_files/remap-subroutines/prepare.ngc @@ -1,6 +1,5 @@ o<prepare> sub -(debug, prepare call_level= #<_call_level> remap_level=#<_remap_level>) -(debug, n_args=#<n_args> tool=#<tool> pocket=#<pocket>) +(debug, prepare call_level= #<_call_level> remap_level=#<_remap_level> tool=#<tool> pocket=#<pocket>) ; show aborting a prepare on tool 2 by returning a negative value o<testabort> if [#<tool> EQ 2] |