|
BowlerKernel
|

Public Member Functions | |
| GCodeInterpreter () | |
| void | processSingleGCODELine (String line) throws Exception |
| void | interpretStream (InputStream in) throws Exception |
| void | tryInterpretStream (InputStream in) throws Exception |
| boolean | cancel () |
| void | addGHandler (int code, CodeHandler handler) |
| void | setGHandler (int code, CodeHandler handler) |
| void | addMHandler (int code, CodeHandler handler) |
| void | setMHandler (int code, CodeHandler handler) |
| void | addGSorting (final Comparator< Integer > c) |
| void | setGSorting (@SuppressWarnings("rawtypes") Comparator c) |
| void | addDefaultHandlers () |
| CodeHandler | getErrorHandler () |
| void | setErrorHandler (CodeHandler errorHandler) |
Static Public Member Functions | |
| static void | main (String args[]) throws Exception |
Private Member Functions | |
| void | parseLine (InputStream r) throws Exception |
| void | executeLine (String rawLine) throws Exception |
Private Attributes | |
| CodeHandler | errorHandler =null |
| int | lineNumber =0 |
An extensible G-code interpreter. Parses a stream containing G-code commands, stores register values, and executes handlers. The default handler set converts position axes to mm if neccessary, converts relative positioning to absolute, and prints a message for rapid and interpolated linear motion. You can register additional handlers using addGHandler and addMHandler, which compose with, rather than replacing, the previous implementations. GCodeInterpreter#addDefaultHandlers
To use, bind handlers to at least G00 and G01, and feed in a stream of G-code. An example can be found in
Definition at line 30 of file GCodeInterpreter.java.
| com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.GCodeInterpreter | ( | ) |
Default Constructor. This builds an interpreter and adds the default set of handlers and configuration to it.
Definition at line 117 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers().
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.main().

| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers | ( | ) |
Add the default set of handlers to this interpreter.
Definition at line 492 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addGHandler(), com.neuronrobotics.sdk.common.Log.debug(), com.neuronrobotics.sdk.common.Log.error(), com.neuronrobotics.replicator.driver.interpreter.GCodeLineData.getWord(), com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setGSorting(), and com.neuronrobotics.replicator.driver.interpreter.GCodeLineData.storeWord().
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.GCodeInterpreter().

| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addGHandler | ( | int | code, |
| CodeHandler | handler | ||
| ) |
Add a handler for a G code. The new handler executes before any previously installed handler for the code, to permit composition; for instance, where the first-installed G01 handler specifies motion and flushes the commands to device, a handler installed later could handle tool behavior without flushing the device, and provide coordinated behavior.
| code | the G code to bind this handler to. |
| handler | the handler implementation. |
Definition at line 346 of file GCodeInterpreter.java.
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers().
| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addGSorting | ( | final Comparator< Integer > | c | ) |
Add rules for how to sort G codes before executing them. The new and old Comparators are combined; whenever the new comparator returns equal, the old comparator is consulted, permitting straightforward overridability.
For instance, to add a rule stating that the handlers for code G07 should always execute after those for G09:
interp.addGSorting(new Comparator<Integer>() {
public int compare(Integer c1, Integer c2) {
if (c1 == 7 && c2 == 9)
return -1;
if (c1 == 9 && c2 == 7)
return 1;
return 0;
}
});
Note: this does not implement any sort of transitivity, that is left to the new comparator, and is required for the contract of a comparator.
| c | the comparator implementing the new ordering rules. |
Definition at line 444 of file GCodeInterpreter.java.
| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addMHandler | ( | int | code, |
| CodeHandler | handler | ||
| ) |
Add a handler for an M code. The new handler executes before any previously installed handler for the code, to permit composition; for instance, where the first-installed G01 handler specifies motion and flushes the commands to device, a handler installed later could handle tool behavior without flushing the device, and provide coordinated behavior.
| code | the G code to bind this handler to. |
| handler | the handler implementation. |
Definition at line 388 of file GCodeInterpreter.java.
| boolean com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.cancel | ( | ) |
Cancel a run of a G-code stream. This interrupts the thread that is currently parsing a G-code stream, canceling its execution.
Definition at line 325 of file GCodeInterpreter.java.
|
private |
Execute the action(s) specified by the already built-up line of G-code.
| rawLine | the raw line |
| Exception | the exception |
Definition at line 244 of file GCodeInterpreter.java.
References com.neuronrobotics.sdk.common.Log.debug(), com.neuronrobotics.replicator.driver.interpreter.CodeHandler.execute(), and com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.getErrorHandler().
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.processSingleGCODELine().

| CodeHandler com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.getErrorHandler | ( | ) |
Gets the error handler.
Definition at line 605 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.errorHandler.
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.executeLine().
| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.interpretStream | ( | InputStream | in | ) | throws Exception |
Main entry point; take an InputStream of G code and run the sequence of actions it describes.
| in | the in |
| Exception | the exception |
Definition at line 288 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.parseLine().
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.main(), and com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.tryInterpretStream().

|
static |
Default executable; runs as a pipe, parsing standard input with the default handlers.
| args | the arguments |
| Exception | the exception |
Definition at line 595 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.GCodeInterpreter(), and com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.interpretStream().

|
private |
Parses the line.
| r | the r |
| Exception | the exception |
Definition at line 176 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.lineNumber, and com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.processSingleGCODELine().
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.interpretStream().

| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.processSingleGCODELine | ( | String | line | ) | throws Exception |
Process single gcode line.
| line | the line |
| Exception | the exception |
Definition at line 137 of file GCodeInterpreter.java.
References com.neuronrobotics.sdk.common.Log.debug(), com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.executeLine(), com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.lineNumber, and com.neuronrobotics.replicator.driver.interpreter.GCodeLineData.storeWord().
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.parseLine().

| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setErrorHandler | ( | CodeHandler | errorHandler | ) |
Sets the error handler.
| errorHandler | the new error handler |
Definition at line 614 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.errorHandler.
| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setGHandler | ( | int | code, |
| CodeHandler | handler | ||
| ) |
Clear any previous handlers for a code, and install a new one. This is usually unneccessary, but it allows you to clear a handler set and start from scratch.
| code | the G code to bind this handler to. |
| handler | the handler implementation. |
Definition at line 366 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.CodeHandler.setSubHandlers().

| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setGSorting | ( | @SuppressWarnings("rawtypes") Comparator | c | ) |
Override the default sort for G codes. Not recommended unless all G codes are being written by the user; this can break dependencies between handlers.
| c | the new comparator. |
Definition at line 483 of file GCodeInterpreter.java.
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers().
| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setMHandler | ( | int | code, |
| CodeHandler | handler | ||
| ) |
Clear any previous handlers for a code, and install a new one. This is usually unneccessary, but it allows you to clear a handler set and start from scratch.
| code | the G code to bind this handler to. |
| handler | the handler implementation. |
Definition at line 408 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.CodeHandler.setSubHandlers().

| void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.tryInterpretStream | ( | InputStream | in | ) | throws Exception |
Nonblocking version of interpretStream(); fails rather than waiting.
| in | the in |
| Exception | the exception |
Definition at line 307 of file GCodeInterpreter.java.
References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.interpretStream().

|
private |
The error handler.
Definition at line 50 of file GCodeInterpreter.java.
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.getErrorHandler(), and com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setErrorHandler().
|
private |
The line number.
Definition at line 110 of file GCodeInterpreter.java.
Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.parseLine(), and com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.processSingleGCODELine().