ngcgui.tcl is a tcl script for testing and using emc gcode subroutines. It can run as a standalone app or as a tab page in the axis gui. Screenshot: http://www.panix.com/~dgarrett/ngcgui/ngcgui.png Youtube: http://www.youtube.com/watch?v=Bn8T5Fw0ISs To get and try examples, download the gzipped tar file: wget http://www.panix.com/~dgarrett/ngcgui/ngcgui.tgz tar zxf ngcgui.tgz ;# extract the test area emc ngcgui_tst/ngcgui.ini ;# start emc>=2.4 simulator ------------------------------------------------------------------------ Example inifiles for emc2.4: (support for emc2.4 will be discontinued when emc2.5 is released) ngcgui_tst/ngcgui.ini Help images for subfiles (when provided) are placed in the tab page. This eliminates some controls for space reasons so an additional "Custom" tab page is provided to allow complete control and opening of new files ngcgui_tst/ngcgui_simple.ini Two simple pages with few user controls emc ngcgui_tst/ngcgui_ttt.ini includes a tab page to generate another page for truetype-tracer output for text engraving. requires truetype-tracer version 4.x ngcgui_tst/ngcgui_complex.ini custom pages are added with all controls. images are placed in separate toplevels, Incudes example of another simple tcl/tk embedded application emc ngcgui_tst/ngcgui_lathe.ini lathe example Example inifiles for emc2.5: emc ngcgui_tst/ngcgui2.5.ini uses emc2.5 (git master) features that makes use: [RS274NGC]SUBROUTINE_PATH [RS274]USER_M_PATH [DISPLAY]TKAPP to organize subroutines better. It also includes an xembed for an xterm. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 Note: The emc2.4 example files can be used for emc2.5 but you will get error messages until you remove the line in the ini file that specifies tkapp.py: USER_COMMAND_FILE = ./tkapp.py This is because emc2.5 (git master as of 27dec10) supports a built-in to support [DISPLAY]TKAPP and tkapp.py is no longer required ------------------------------------------------------------------------ ngcgui can be started independently as a standalone application. Example: $ ngcgui_tst/ngcgui.tcl --font small --horiz --vwidth 0 -D . -S ./ngcgui_tst/testsuite/gosper.ngc -a demo.ngc & ------------------------------------------------------------------------ Features: 1) Makes entry boxes for subroutine parameters 2) Builds an ngc file for one or more features from (optionally) multiple subfiles 3) Supports default values for subroutines parameters 4) Supports preamble and postamble files for common setup blocks 5) Supports immediate preamble/postamble gcode commands 6) Sends a prepared ngc file to the axis gui for execution 7) Supports a one-level expansion of subroutines which allows the axis gui to highlight the lines within a subroutine that correspond to the lines selected on the program preview display (with a left-click) 8) ngcgui can be embedded in multiple axis tabs 9) current coordinate values can be transferred to entry boxes by typing coordinate letter (like x) in any parameter entry box 10) an image file can be associated with a subfile to help clarify parameters. The image file must be in the same directory as the subfile and named the same but with an image suffix (.png,.gif,.jpg, or .pgm) 11) inifile can specify options to disallow new tab page creation and to disallow tab page removal and simplify the number of controls presented to user to make it simpler to use A testsuite of routines (mill-based) includes programs that demonstrate recursion (modified flowsnake), text engraving (using true-type-tracer), a helix (and dhole), slot, arbitrary quadrangle, hexagon, etc. Routines demonstrate inside/outside cutting with provisions for specifying cw or ccw traversal. Some include provisions for lead-in moves for cutter radius compensation and some include parameters for scaling, rotating, and offsetting their feature. ------------------------------------------------------------------------ Example simple subroutine file showing how to format: $ cat ngcgui_tst/simp.ngc (info: simp -- simple subroutine example -- Ctrl-U to examine) o sub # = #1 (=.6 Radius A) ;Example parm with comment # = #2 (=0.4) ;Example parm with no comment g0x0y0z1 g3 i# f100 g3 i-# f100 o endsub See the examples in the testsuite for formatting requirements and extensive notes on usage documented at the top of the tcl script. ------------------------------------------------------------------------ Four new files are required for direct embedding in axis: tkapp.py: !!! use only for emc2.4 !!! not required for emc2.5 after 27dec10 [DISPLAY]USER_COMMAND_FILE that axis finds and executes at the end of its initializations. If this file exists, it supersedes the ~/.axisrc file but tkapp.py looks for ~/.axisrc and executes it too so you don't have to change any existing ~/.axisrc files This file looks for one or more [DISPLAY]TKAPP entries ngcgui_app.tcl: [DISPLAY]TKAPP supports running custom tk apps in axis tab pages. It reads ngcgui-specific items in the inifile and passes them to ngcgui.tcl ngcgui.tcl: [DISPLAY]NGCGUI source file that supports direct embedding in axis as well as standalone usage. ngcgui_ttt.tcl [DISPLAY}TKAPP that supports creating ngcgui-compatible gcode files and new pages in axis gui. requires truetype-tracer v4.x ----------------------------------------------------------------------- To modify an existing inifile: 1) copy the four new files: tkapp.py (not required for emc2.5) ngcgui.tcl ngcgui_app.tcl ngcgui_ttt.tcl to: a) the directory containing your inifile so you can specify locations in your inifile using relative addressing like: ./tkapp.py (not required for emc2.5) ./ngcgui.tcl ./ngcgui_app.tcl ./ngcgui_ttt.tcl or b) someotherdirectory and use absolute addressing like: /fullpath_to_someotherdirectory/tkapp.py (not required for emc2.5) /fullpath_to_someotherdirectory/ngcgui.tcl /fullpath_to_someotherdirectory/ngcgui_app.tcl /fullpath_to_someotherdirectory/ngcgui_ttt.tcl method b) is best if you support multiple inifiles since then you need maintain only a single copy of the four files 2) create new lines in your inifile. Following the example from ngcgui.ini (that uses relative paths): [DISPLAY] USER_COMMAND_FILE = ./tkapp.py TKAPP = ./ngcgui_app.tcl NGCGUI = ./ngcgui.tcl NGCGUI_SUBFILE = ./testsuite2.5/xyz.ngc NGCGUI_SUBFILE = ./testsuite2.5/iquad.ngc NGCGUI_SUBFILE = ./testsuite2.5/ihex.ngc NGCGUI_SUBFILE = ./testsuite2.5/gosper.ngc NGCGUI_SUBFILE = ./testsuite2.5/hw.ngc NGCGUI_FONT = Helvetica -10 bold NGCGUI_OPTIONS = see below #note: for a custom tab page, use NGCGUI_SUBFILE = "" #note: ngcgui_app.tcl must precede ngcgui_ttt.tcl TKAPP = ./ngcgui_ttt.tcl TTT = /usr/local/bin/truetype-tracer TTT_PREAMBLE = ./testsuite2.5/utilitysubs/in_std.ngc The files specified by the items: USER_COMMAND_FILE, NGCGUI, and _each_ TKAPP must specify correct absolute or relative path as mentioned above. The TTT entry should specify the location to a truetype-tracer (version 4 required) Each NGCGUI_SUBFILE should specify a correct absolute or relative path to a ngcgui-compatible subroutine file AND that file (and any file called by it) should be located in: the directory specifyed by: [DISPLAY]PROGRAM_PREFIX (for emc2.4) For emc2.5 (git-master) subroutines can be in any directory specified in the search path: [RS274NGC]SUBROUTINE_PATH The font used for ngcgui is specified by NGCGUI_FONT. You may want to experiment with other font sizes depending upon your display size. Not in the examples, but you can also specify a single instance of both [DISPLAY]NGCGUI_PREAMBLE [DISPLAY]NGCGUI_POSTAMBLE with a path to appropriate files for preamble and postamble. These will apply to all ngcgui tabs. Options can be specifed to constrain the gui complexity: NGCGUI_OPTIONS = opt1 opt2 ... opt items: nonew -- disallow making new tab page noremove -- disallow removing any tab page imageframe -- put image inside tabpage (make sure images are small) (some controls are deleted to make room) noauto -- noautosend (makeFile, then manually send) ---------------------------------------------------------------------------- Notes: 1) ngcgui is developed using emc2.5.0~pre (git master) but most things should work for emc2.4.x 2) new feature: instead of entering a preamble or postamble file name, you can put immediate commands in the entry field. Begin with a : (colon) and separate with a ; (semicolon). Examples: :t0m6 :t1m6;(debug, S to continue);m0 3) When you embed ngcgui in an axis tab, you can create multiple features for the initial subfile and/or open new subfiles and create features for each. You have access to all ngcgui-compatible subfiles in the places emc searches for subroutine files. You can also embed multiple instances of ngcgui in several axis tabs. (This corresponds to the example inifiles) Each instance is independent and can create multiple features from any accessible subfile. If you embed multiple instances of ngcgui, then create features in several of them, then Finalize, a prompt will appear to allow you to finalize one instance or _all_ of them. Beware that the ordering will be in the left-to-right order of the ngcgui tabs which is the order specified in the inifile. If the order is not what you want, Cancel, then move tabs with the move buttons first. ----------------------------------------------------------------------- Testsuite -- included in the tar archive is a testsuite directory of example files and files with helper routines. Items marked with * apply cutter radius compensation with entry moves Items marked with + allow feature to be scaled, rotated, and offset Preamble Files: in_std.ngc Defines a standard setup (G17,G20, etc) mm_std.ngc same as in_std.ngc except for mm (G21 millimeters) g59preview.ngc Preview usage using G59 (be sure to set g59 above the part) Subfiles: gosper.ngc Recursive-calls example (adapted from flowsnake.ngc) The inputs for gosper specify the two end points of a line that are one side of an equilateral triangle * helix.ngc Helix (inside/outside, cw/ccw) Also does D Shape. * helix_rtheta.ngc Invoke helix.ngc with center specified as r,theta * hole_circle.ngc Invoke helix.ngc for holes milled on a circular pattern *+ slot.ngc Slot (inside, ccw) (adapted from useful-subroutines.ngc) *+ iquad.ngc inside quadrilateral (cw/ccw) *+ oquad.ngc outside quadrilateral (cw/ccw) *+ ihex.ngc inside regular hexagon (cw/ccw) *+ ohex.ngc outside regular hexagon (cw/ccw) hw.ngc Text from truetype-tracer Generated with the following shell commands: cat <|hw.ngc o sub # = #1 # = #2 # = #3 (=0.0003) # = #4 eof truetype-tracer HelloWorld | grep -Eiv =\|m2\|m02 >>hw.ngc echo "o endsub" >>hw.ngc xyz.ngc Axis exerciser-- test program for running x,y,z axes in simple patterns useful for servo tuning etc. backlash.ngc Use for backlash measurements with indicator on x,y,or z axis Postamble Files: bye.ngc Simple example postamble with user message ------------------------------------------------------------------------ Helper files (these contain utility routines used by the Subfiles above): gosper_sub.ngc Recursive function used with gosper.ngc dir.ngc Determine direction for polygon traversal entry.ngc Compute a quarter-arc preentry and radius vector cross.ngc Cross product for two vectors dot.ngc Dot product and cosine for two vectors line.ngc Compute length, angle, cos, and sin for a line move.ngc Compute coordinants for rotation, scale, and offset ostop.ngc Insert optional stop with continue message spin.ngc Startup message for user to set spindle speed M110 Clear notifications in axis-gui ----------------------------------------------------------------------- The ngcgui.tcl script has been developed with emc-2.4.x and some things wont work with earlier versions of emc. New features in 2.4 which are useful for this gui: a) M110 (user command file) uses a new hal pin in the axisui named axisui.notifications-clear-info b) ngcgui.tcl uses new functions (remote) in axis for accepting remote commands to improve error detection. d) a 2.4pre bugfix corrects a problem where a subroutine error prevents future displays of the program preview in axis ----------------------------------------------------------------------- To use standalone, make a link so that ngcgui is in your path, example: $ ln -s somewhere/ngcgui.tcl yourpath/ngcgui Then: $ ngcgui --help Usage: ngcgui --help ngcgui [Options] -D nc_files_directory_name ngcgui [Options] -i emc_inifile_name ngcgui [Options] Options: [-S subroutine_file] [-p preamble_file] [-P postamble_file] [-o output_file] [-a autosend_file] (autosend to axis default:auto.ngc) [--noauto] (no autosend to axis) [--font [big|small|fontspec]] (default: "Helvetica -10 bold") [--horiz|--vert] (default: --horiz) [--cwidth comment_width] (width of comment field) [--vwidth varname_width] (width of varname field) [--quiet] (fewer comments in outfile) [--imageframe] (default: separate widget for image) ----------------------------------------------------------------------- Note: with the tcl/tk implementation on recent ubuntu 10.04 there may be problems with the tcl send command, message is: "X server insecure (must use xauth-style authorization); command ignored" To work around this problem, ngcgui attempts to fix but if it occurs you can try a script like unxhost.sh: $ cat unxhost.sh #!/bin/sh xhost - SI:localuser:gdm xhost - SI:localuser:root Then chmod and execute it before starting ngcgui: $ chmod 755 unxhost.sh $ unxhost.sh # 110328:09.44 Note: this problem is fixed in emc2.5 with commit: e8630029 2011-02-01 axis: work around tk send bug ----------------------------------------------------------------------- Send comments/bugs to dgarrett at panix dot com ----------------------------------------------------------------------- update notes: # 101122:12.39 added image display # 101123:20.40 added NGCGUI_OPTIONS # NGCGUI_OPTIONS = opt1 opt2 ... # opt items: # nonew -- disallow making new tab page # noremove -- disallow removing any tab page # noiframe -- put image on top level to leave more room in page # 101127:15.08 add support for truetype-tracer helper page # 101208:12.33 add ngcgui_lathe.ini example allow rotations with truetype-tracer example improve ngcgui_ttt focus/keybinding behavior # 101212:06.37 add d (for diameter) to entrykeybindings # 101227:18.28 in git master, commit af6ae9907e1c0e adds builtin support for TKAPP so tkapp.py is no longer required in ini files # 110101:13.00 update for use with emc-master on hardy emc fix for python2.5 compat: 6d2a1d01ed98 # 110102:16.46 improve key bindings for entry keys # 110106:09.16 changed names to clarify preambles: std.ngc --> in_std.ngc mm.mgc --> mm_std.ngc # 110201:17.05 add note re declining support of emc2.4 # 110319:10.15 bug fix for erroneously included parameters, eg #=#5063 is not a positional parameter definition # 110328:09.44 note fix in axis for tk send problem