TOC PREV NEXT INDEX

National Institute of Standards and Technology


5 Stand-Alone Interpreter


This section describes the Stand-Alone Interpreter (SAI). The section is intended to be useful to SAI installers, NC programmers, developers, and researchers. Machine operators might find it useful.

The SAI is valuable because it allows a user to pre-test an NC program without having to run it on the machine controller itself. Any computer for which the SAI can be compiled can be used to pre-test NC programs.

The SAI includes the Interpreter, a driver, and a version of the canonical machining functions. Pre-tests of NC programs on the SAI are strong tests because the Interpreter runs exactly the same way in the SAI as it does integrated with the EMC control system.

The SAI has two input modes: keyboard (MDI) mode and file (batch) mode. In the MDI mode, the user types lines of RS274/NGC code at the keyboard. In the batch mode, the Interpreter reads lines of code from a file.

The set of canonical machining functions which prints text has been linked into the SAI, so the output is always text. The output is printed either to the computer terminal or to a file. In general, an output file is useful only if input is taken from a file and errors do not occur during interpretation.

5.1 Running the SAI

5.1.1 Starting the SAI

The SAI is started by giving a command in a terminal window. After the SAI starts, the user is presented with a number of options. The user must press the "return" key after each choice; the return key presses are not printed here. Many different versions of the SAI executable may be compiled from the same source code. This section uses the name "rs274" for the executable. The name of your SAI executable may be different; if so, use your name, instead of "rs274."

The Interpreter requires parameter data (which it reads from a file) and tool data (which it obtains by calling world-give-information functions - see Appendix D.6). In the SAI, the driver reads a tool file so it can provide the tool data the Interpreter asks for by function call. There is a default parameter file, "rs274ngc.var," and a default tool file, "rs274ngc.tool_default". The default data does not represent the actual state of any machining center or set of tools.

In the SAI, the parameter data and tool data files may be designated by the user. The data in the files may be actual or hypothetical. When the SAI starts up, the user is offered the opportunity to provide the name of a parameter file and the name of a tool file. In both cases, if a name is provided, the named file is used. If a name is not provided, the default is used. The default files are shown in Table 1 and Table 2. If a file is missing or in bad format, the SAI prints a message to that effect and quits.

Either way the SAI is used, when it starts, the following menu is printed:

When the user selects 1, the menu disappears, and interpretation begins. The user may select any of 2 through 5 zero, one, or many times; only the last setting of those items is used.

If the user selects 2 or 3, the user is prompted for the name of a file and offered the same menu again.

If the user selects 4, the user is offered the same menu again, with "turn block delete switch ON" changed to "turn block delete switch OFF"; the two toggle back and forth when 4 is selected.

If the user selects 5, another menu is offered, as follows, and then the above menu is offered again.

When the user selects 1, the previous menu comes up again.

If the user selects 2, the user is offered the same menu again, with "print stack on error" changed to "do not print stack on error"; the two toggle back and forth when 2 is selected. The meaning of item 2 is that the user has a choice of whether, if there is an error, the system will print the stack of function calls that was active when the error occurred. The default setting is not to print the stack.

With file input, there is a number 3 choice on the second menu, as described a few paragraphs hence.

5.1.2 Running with Keyboard Input

The SAI is invoked with keyboard (MDI) input by giving the command:

rs274

The user is presented with the menus shown above. When the user finishes with the menus, the following two-step cycle repeats until the user exits.

1. The SAI prints the prompt READ =>

2. The user enters a line of RS274/NGC code at the keyboard, hits the carriage return button, and the line is interpreted.

When using keyboard input, the SAI exits only if it reads a line with the one word "quit". Most variations of "quit" are valid, e.g., "Q uI t".

The user interface provides no capability to edit ahead, undo, or anything else involving more than the current line.

A transcript of a short session with the SAI using keyboard input is shown in Table 10.
rs274
enter a number:
1 = start interpreting
2 = choose parameter file ...
3 = read tool file ...
4 = turn block delete switch ON
5 = adjust error handling...
enter choice => 3
name of tool file => rs274ngc.tool_default
enter a number:
1 = start interpreting
2 = choose parameter file ...
3 = read tool file ...
4 = turn block delete switch ON
5 = adjust error handling...
enter choice => 1
executing
1 N..... USE_LENGTH_UNITS(CANON_UNITS_MM)
2 N..... SET_ORIGIN_OFFSETS(0.0000, 0.0000, 0.0000)
3 N..... SET_FEED_REFERENCE(CANON_XYZ)
READ => g1 x3 y1 f20.0
4 N..... SET_FEED_RATE(20.0000)
5 N..... STRAIGHT_FEED(3.0000, 1.0000, 0.0000)
READ => g2 x[6-[4*3/2]] r 7.01 z0.5
6 N..... ARC_FEED(0.0000, 1.0000, 1.5000, 7.8476, -1, 0.5000)
READ => (that was a helical arc)
7 N..... COMMENT("that was a helical arc")
READ => t2
8 N..... SELECT_TOOL(2)
READ => m6 g43 h2
9 N..... CHANGE_TOOL(2)
10 N..... USE_TOOL_LENGTH_OFFSET(1.0000)
READ => m2
11 N..... SET_ORIGIN_OFFSETS(0.0000, 0.0000, 0.0000)
12 N..... STOP_SPINDLE_TURNING()
13 N..... PROGRAM_END()
READ => g1 x asim[0.5]
Unknown word starting with a
g1 x asim[0.5]
READ => g1 x asin[0.5]
14 N..... STRAIGHT_FEED(30.0000, 1.0000, -0.5000)
READ => g91 g81 x3 y2 z-0.8 r1.5 l2
15 N..... COMMENT("interpreter: distance mode changed to incremental")
16 N..... STRAIGHT_TRAVERSE(30.0000, 1.0000, 1.0000)
17 N..... SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH)
18 N..... STRAIGHT_TRAVERSE(33.0000, 3.0000, 1.0000)
19 N..... STRAIGHT_FEED(33.0000, 3.0000, 0.2000)
20 N..... STRAIGHT_TRAVERSE(33.0000, 3.0000, 1.0000)
21 N..... STRAIGHT_TRAVERSE(36.0000, 5.0000, 1.0000)
22 N..... STRAIGHT_FEED(36.0000, 5.0000, 0.2000)
23 N..... STRAIGHT_TRAVERSE(36.0000, 5.0000, 1.0000)
24 N..... SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS)
READ => quit
Table 10. Transcript of an SAI Session Using Keyboard Input

5.1.3 Running with RS274/NGC File Input

There are two ways to use the SAI with file input: with terminal output or with file output. In both cases the output is printed canonical machining function calls. Also in both cases, a third option for error handling is given.

If file output is used, the third option is to choose between "continue on error" and "stop on error". The menu item for the option toggles between the two. The default is stop.

If file output is not being used, the third option is to choose among "continue on error", "stop on error", and "MDI on error". The menu item for the option cycles among the three. The default is stop. If the SAI gets into the MDI mode this way, the user must enter "quit" to get out of MDI, and after quitting MDI, must decide whether or not to continue interpreting. If the user decides to continue, interpretation starts at the line of the file following the line where the error occurred that put the SAI into MDI mode.

For terminal output, give a command of the form:

rs274 input_filename

where input_filename is the name of an RS274/NGC input file. With this invocation, normal printed output from the SAI (everything but error messages) appears on stdout, which is normally the terminal on which the command was invoked. Printed output may be redirected from the terminal to an output file, but it is usually simpler to call the SAI as shown below to get output in a file.

For file output, give a command of the form:

rs274 input_filename output_filename

where output_filename is the name the output file should have. This file will be created if it does not exist; if it does exist, it will be overwritten.

If there are errors during interpretation and "continue on error" has been selected, any input line which causes an error will not be interpreted, and the output file may be incorrect on any line after the last line which was output before the first error occurred.

When running with file input, the SAI exits if any of the following happens:

1. the SAI executes a line with an M2 or M30 command on it. In this case, the rest of the line is executed before the SAI exits. If there are more lines in the file following the line with the M2 or M30, they are ignored.

2. the "stop on error" option is in effect, and an error occurs.

3. the "MDI on error" option is in effect, the user has quit MDI, and the user decides to not to continue, when prompted to decide.

4. the file ended at the previous line, that line did not include M2 or M30, and the "MDI on error" option is not in effect.

5.2 Building an SAI Executable

On a SUN SPARCstation 20, an executable file for the SAI may be built from source code in about half a minute, as described below. The same procedure should work on any computer running a Unix operating system and having the standard C++ libraries. On computers running other operating systems, compilation should be similarly easy, provided the standard C++ libraries are available.

To make an executable, seven source code files must be placed in the same directory along with the Makefile shown in Table 11. The source code files are:

The first two files are the header file and function definitions for the canonical machining functions and the world-give-information functions described in Appendix D.6, which the Interpreter calls to get information about the world outside itself.

The version of canon.cc which prints function calls is used with the SAI. This file also contains a minimal model of the world outside the Interpreter. The canonical machining functions defined in this file update the model when they are called, as well as printing themselves. The world-give-information functions take information from the outside world model and give it to the Interpreter.

The third file, driver.cc, contains the SAI driver. The driver handles interaction between the user and the Interpreter. It also helps maintain the model of the world outside the Interpreter.

The fourth file, rs274ngc.hh is the header file for the Interpreter.

The rs274ngc_errors.cc file defines an array containing all the Interpreter error messages. It works with the last file, rs274ngc_return.hh, which has symbolic values for the indexes of the array. These two files were prepared automatically from the source file rs274ngc.cc.

The sixth file, rs274ngc_pre.cc, contains the function definitions for the Interpreter. It is a pre-preprocessed version of rs274ngc.cc, also prepared automatically from rs274ngc.cc. The source file rs274ngc.cc is not needed to compile the SAI but is available on request.

An executable SAI for 3-axis machining named "rs274" is built in the same directory by giving the command:
make rs274.

In the Makefile, we are using the Gnu C++ compiler, "g++." Any other C++ compiler may be substituted for g++.

There are three types of compiler options: (1) axis existence options -DAA, -DBB, and -DCC, (2) -DALL_AXES, and (3) -DAXIS_ERROR.

The axis existence options are for compiling for machining centers with different sets of rotational axes. Eight combinations of rotational axes are possible: none, all, any one of three, and missing one of three. Only two of the eight are shown in the Makefile below. The rules for rs274ac.o and rs274ac may be copied and easily modified for the other six combinations of axes. -DAA means include an A-axis. -DBB means include a B-axis. -DCC means include a C-axis.

The -DALL_AXES option is used if you want the Interpreter to include all three rotational axes in the canonical machining function calls it makes, even though the Interpreter is compiled with two or fewer rotational axes. When this option is used, the value zero is used in the canonical machining function calls for the otherwise missing axes.

The -DAXIS_ERROR option is used if you want the Interpreter to signal an error if an input RS274/NGC program uses a rotational axis the Interpreter was not compiled with. If this option is not used, the Interpreter will read and ignore axis values for rotational axes with which it was not compiled.

The Makefile gives an example of each option. The options may be combined to make a total of 29 different executables (1 with all three rotational axes, 4 with each of the 7 combinations of fewer than three rotational axes).

  • COMPILE = g++ -c -v -g
  • LINK = g++ -v
  • canon.o: canon_pre.cc canon.hh
  • $(COMPILE) -o canon.o canon_pre.cc
  • canon_abc.o: canon_pre.cc canon.hh
  • $(COMPILE) -DAA -DBB -DCC -o canon_abc.o canon_pre.cc
  • canon_ac.o: canon_pre.cc canon.hh
  • $(COMPILE) -DAA -DCC -o canon_ac.o canon_pre.cc
  • driver.o: driver.cc canon.hh rs274ngc.hh rs274ngc_return.hh
  • $(COMPILE) -o driver.o driver.cc
  • rs274: rs274.o canon.o driver.o
  • $(LINK) -o rs274 rs274.o canon.o driver.o -lm
  • rs274.o: rs274ngc_pre.cc canon.hh rs274ngc.hh rs274ngc_errors.cc rs274ngc_return.hh
  • $(COMPILE) -o rs274.o rs274ngc_pre.cc
  • rs274ac: rs274ac.o canon_ac.o driver.o
  • $(LINK) -o rs274ac rs274ac.o canon_ac.o driver.o -lm
  • rs274ac.o: rs274ngc_pre.cc canon.hh rs274ngc.hh rs274ngc_errors.cc rs274ngc_return.hh
  • $(COMPILE) -DAA -DCC -o rs274ac.o rs274ngc_pre.cc
  • rs274_all.o: rs274ngc_pre.cc canon.hh rs274ngc.hh rs274ngc_errors.cc rs274ngc_return.hh
  • $(COMPILE) -DALL_AXES -o rs274_all.o rs274ngc_pre.cc
  • rs274_all: rs274_all.o canon_abc.o driver.o
  • $(LINK) -o rs274_all rs274_all.o canon_abc.o driver.o -lm
  • rs274_no.o: rs274ngc_pre.cc canon.hh rs274ngc.hh rs274ngc_errors.cc rs274ngc_return.hh
  • $(COMPILE) -DAXIS_ERROR -o rs274_no.o rs274ngc_pre.cc
  • rs274_no: rs274_no.o canon.o driver.o
  • $(LINK) -o rs274_no rs274_no.o canon.o driver.o -lm

Table 11. Makefile for Interpreter

5.3 Interpreter Speed

Using a 2004-line input test file for machining 2000 straight cuts, running on a Sun SPARCstation 20 using the Solaris operating system, the SAI wrote an output file in 1.6 seconds elapsed time, as measured by the "time" utility. A 3605-line file for machining 3600 arcs took 2.5 seconds. These tests show a rate of over 1000 lines per second for the SAI on a Sun SPARCstation 20 computer.

Running on a PC using the Red Hat Linux operating system with a 200 megahertz processor, the (recompiled) SAI handled the same two test files somewhat faster - 0.8 seconds and 1.7 seconds. The output from the two computers was byte-by-byte identical for the two input programs. A Gnu C++ compiler was used for both the Sun and the PC.

Tests with other types of programs show similar results. Thus, it is clear that using the SAI system for pre-testing NC programs takes little time.

When the Interpreter is being used integrated with the EMC control system, there are relatively few situations in which a modern PC would be challenged, since the tool path prescribed by a line found in a typical program will rarely take less than a tenth of a second to cut, while interpreting that line will rarely take more than a hundredth of a second. Thus, for most NC programs, the Interpreter speed will not be a significant factor.

There is one known class of program for which Interpreter speed may be a significant factor. This class is those programs which include many consecutive short lines or arcs (say 0.1 millimeter long each). This type of program is produced by many NC program post-processors for following complex contours approximately. At 1000 millimeters per minute feed rate (a realistic value), a 2000-line file should run in 12 seconds. The test results above show that the Interpreter runs about ten times that fast on computers with moderate (in year 2000) speed, so the Interpreter should not be a bottleneck in dealing with that class of programs.


TOC PREV NEXT INDEX