[Home]PythonBindings

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Proposal

I would like to have a python shell that controls the machine. In order to do so, we need to provide an API for all the canonical functions like LINEAR_FEED etc. This will allow a programmer to call
 feed(x,y,z) 
or (since python supports named arguments)
 rapid(a=90, b=360) 
or (home is a tuple)
 safe_rapid(home) 


It is also necessary to provide access to the old gcode interpreter to ease the transistion for g-code programmers who wish to use a library of "conversational" python routines. One simple and straightforward way to do this would be to redirect the output of "print" to the rs274ngc interp.
 print "G0 X1 Y%f Z%f" (y, z)
or
 print "G0 X1 Y", y, "Z", z
or
 print """
 <50 lines of unmodified gcode>
 """

the "print" function could even be renamed to "gcode" for clarity and to free up the print function for displaying messages to the machine operator

lerman suggested modifying the python interpreter to read any line starting with a colon and to substitute python variable after a # mark, a la

 :g1 f10 x#endX y#endY


"rs274.author" provides a bit of what you are asking for, but it outputs g-code instead of calling canon: http://git.linuxcnc.org/gitweb?p=emc2.git;a=blob_plain;f=lib/python/rs274/author.py;hb=HEAD

using a gcode subset is better than using canon, because for instance using canon means you have to account for tool length, coordinate system offsets, and (worst!) cutter radius compensation yourself

rs274.author.Gcode's constructor takes an argument called 'target', which is a function to be called with each line of gcode produced. it's tempting to think that you could have this simply issue each command as an mdi over nml


i think the python module 'emc' does a lot of what i want already - it's just poorly documented

 $ pydoc emc
     |  abort(...)
     |  
     |  auto(...)
     |  
     |  brake(...)
     |  
     |  debug(...)
     |  
     |  feedrate(...)
     |  
     |  flood(...)
     |  
     |  home(...)
     |  
     |  jog(...)
     |  
     |  load_tool_table(...)
     |  
     |  mdi(...)
     |  
     |  mist(...)
     |  
     |  mode(...)
     |  
     |  override_limits(...)
     |  
     |  program_open(...)

etc.


LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited June 21, 2009 1:50 pm by JeffEpler (diff)
Search:
Published under a Creative Commons License