I made a derogatory comment on interpreter/task plugin capabilities recently,
so I had to eat my own dogfood. Here is the result:
The interpreter has a Python plugin capability.
It's daunting to follow through the rest of this mail but I feel this approach
is viable and potentially VERY useful.
Please understand this as a 'technology demo' at this point, and not in a
production-usable state. I'm posting this to entertain feedback.
--
What this snapshot can do:
- remap Tx,M6,M61 to Gcoode subs (that's nothing new)
- remap unused M- and G-codes to Gcode subs, defining new codes this way (I
made a comment on the developers list about that)
what is completely new:
- all of the above may also be directed to Python functions which extend the
interpreter
- the Python functions have a fairly complete canon environment, and access to
the Interpreter (proof of concept stage)
--> This means that the toolchange ops, and any remapped codes may be EITHER be
a oword sub,
--> OR a Python function running in the interpreter context, issuing arbitrary
canon commandds from Python
I know this sounds whacky - let me give you an example and bear with me for a
moment:
In py.ini I declare an Interpreter Python extension as follows:
[RS274NGC]
# from this directory
PYDIR=pysubs
# import the following Python module:
PYIMPORT=testmod.py # example snippet below
Then I remap unused codes G88.6 and M310 to subs 'g886' and 'm310' respectively:
[CUSTOM]
GCODE=88.6,1,XYZpqr
MCODE=310,10,pqr
Now if, say, M310 is executed, the interpreter does the following:
- if a 'm310' callable is defined in the Python extension, that is called with
argumens as per argspec *)
- if no such callable is found, the interpreter looks for an 'm310.ngc' file
and executes that
- if neither, fail with an appropriate error message.
Remapping Tx,M6,and M61 is just marginally different, execution is as above
(Python first, then oword sub is searched for):
#T_COMMAND=o<pytdemo>call # either Python, assuming pytdemo is a callable
in testmod.py as per above
T_COMMAND=o<tdemo>call # or .ngc file
#M6_COMMAND=o<pym6demo>call
M6_COMMAND=o<m6demo>call
#M61_COMMAND=o<pym61demo>call
M61_COMMAND=o<m61demo>call
Now lets have a look at the Python extension - it has magic access to
interpreter and canon calls through InterpMod and CanonMod.
Here is a - useless - code example for G88.6 and M310:
#------------ testmod.py interpreter plugin ------
...
def g886(params,**words):
# an absolute move
# the argspec requires XYZ words *) so they are in words or the call
# has failed beforehand
CanonMod.STRAIGHT_TRAVERSE(InterpMod.interp.sequence_number(),
words['x'],words['y'],words['z'],
0,0,0,0,0,0)
# the oword params #1..#30 are not used in remapped codes
# any words as per argspec come through the words dict
def m310(params,**words):
for key in words:
CanonMod.MESSAGE("word '%s' = %s" % (key, str(words[key])))
# access into Interp
line = InterpMod.interp.sequence_number()
CanonMod.MESSAGE("current line= " + str(line))
# demo queued canon interface
if (words.has_key('r')):
if words['r'] > 0:
CanonMod.FLOOD_ON()
else:
CanonMod.FLOOD_OFF()
#------------- end testmod.py --------------
If you're still with me, we can now execute these MDI commands:
run emc py.ini, and execute in MDI:
m310q47r1 (watch the flood M8/M9 change in Axis)
m310
(this creates an absolute move)
g88.6x1y2z30p5
(and back to z=0)
g88.6x1y2z0p5
What I havent done is extensive Tx/M6/M61 exercising through Python, but there
are no conceptual issues.
you might want to set DEBUG to 0x7FFFFFFF to see the full monty.
Summary: since this remapping works for Tx/M6/M61 as well as unused M- and
G-codes
AND canon commands may be generated, this opens a lot of configurability options
(and a long rope for the user to hang himself ;).
Building cycles should be straighforward although care must be taken wrt the
limited canon
environment (offsets, coordinate systems etc must be taken into account).
Conceptually this is a readahead-time interpreter extension; but nothing
hinders us to
think about the same trick for task, making task command issuing
plugin-capable, if one
can come up with a good use case for that.
I'd be curious what you think about this.
If you would like to play with this, here it is:
http://git.mah.priv.at/gitweb/emc2-dev.git/shortlog/refs/heads/python-subs-boost-try3
do a 'apt-get install python-dev libboost-python-dev' before building. I hope
this catches all dependencies.
*) argspec: the first parameter is the modal group for execution order, the
second is the argument spec - uppercase characters mean 'word must be set',
lowercase means 'word may be set'
ps: the m310 and g886 functions can also be called like 'O<g886> call [1] [2]
[3]' and params[1] ff will be set, the words dict is empty then.
psps: I am amazed by the power of boost.python - the whole interp_python.cc
file including solid interp and canon modules is some 360 lines
pspsps: runtests still succeeds but then rs274 hasnt much chance to exercise
any of this. This needs to be rethought.
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers