BowlerKernel
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter Class Reference
Collaboration diagram for com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter:
Collaboration graph
[legend]

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
 

Detailed Description

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

Author
Jonathan D.K. Gibbons
Version
1

Definition at line 30 of file GCodeInterpreter.java.

Constructor & Destructor Documentation

◆ GCodeInterpreter()

com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.GCodeInterpreter ( )

Default Constructor. This builds an interpreter and adds the default set of handlers and configuration to it.

See also
GCodeInterpreter::addDefaultHandlers

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().

Here is the call graph for this function:

Member Function Documentation

◆ addDefaultHandlers()

void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers ( )

◆ addGHandler()

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.

Parameters
codethe G code to bind this handler to.
handlerthe handler implementation.

Definition at line 346 of file GCodeInterpreter.java.

Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers().

◆ addGSorting()

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.

Parameters
cthe comparator implementing the new ordering rules.

Definition at line 444 of file GCodeInterpreter.java.

◆ addMHandler()

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.

Parameters
codethe G code to bind this handler to.
handlerthe handler implementation.

Definition at line 388 of file GCodeInterpreter.java.

◆ cancel()

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.

Returns
true, if successful

Definition at line 325 of file GCodeInterpreter.java.

◆ executeLine()

void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.executeLine ( String  rawLine) throws Exception
private

Execute the action(s) specified by the already built-up line of G-code.

Parameters
rawLinethe raw line
Exceptions
Exceptionthe 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().

Here is the call graph for this function:

◆ getErrorHandler()

CodeHandler com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.getErrorHandler ( )

◆ interpretStream()

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.

Parameters
inthe in
Exceptions
Exceptionthe 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().

Here is the call graph for this function:

◆ main()

static void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.main ( String  args[]) throws Exception
static

Default executable; runs as a pipe, parsing standard input with the default handlers.

Parameters
argsthe arguments
Exceptions
Exceptionthe 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().

Here is the call graph for this function:

◆ parseLine()

void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.parseLine ( InputStream  r) throws Exception
private

◆ processSingleGCODELine()

void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.processSingleGCODELine ( String  line) throws Exception

◆ setErrorHandler()

void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.setErrorHandler ( CodeHandler  errorHandler)

Sets the error handler.

Parameters
errorHandlerthe new error handler

Definition at line 614 of file GCodeInterpreter.java.

References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.errorHandler.

◆ setGHandler()

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.

Parameters
codethe G code to bind this handler to.
handlerthe handler implementation.

Definition at line 366 of file GCodeInterpreter.java.

References com.neuronrobotics.replicator.driver.interpreter.CodeHandler.setSubHandlers().

Here is the call graph for this function:

◆ setGSorting()

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.

Parameters
cthe new comparator.

Definition at line 483 of file GCodeInterpreter.java.

Referenced by com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.addDefaultHandlers().

◆ setMHandler()

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.

Parameters
codethe G code to bind this handler to.
handlerthe handler implementation.

Definition at line 408 of file GCodeInterpreter.java.

References com.neuronrobotics.replicator.driver.interpreter.CodeHandler.setSubHandlers().

Here is the call graph for this function:

◆ tryInterpretStream()

void com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.tryInterpretStream ( InputStream  in) throws Exception

Nonblocking version of interpretStream(); fails rather than waiting.

Parameters
inthe in
Exceptions
Exceptionthe exception

Definition at line 307 of file GCodeInterpreter.java.

References com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.interpretStream().

Here is the call graph for this function:

Member Data Documentation

◆ errorHandler

CodeHandler com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.errorHandler =null
private

◆ lineNumber

int com.neuronrobotics.replicator.driver.interpreter.GCodeInterpreter.lineNumber =0
private

The documentation for this class was generated from the following file: