gcode

package
v0.0.0-...-752f67b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	A = Code('A')
	B = Code('B')
	C = Code('C')
	D = Code('D')
	E = Code('E')
	F = Code('F')
	G = Code('G')
	H = Code('H')
	I = Code('I')
	J = Code('J')
	K = Code('K')
	L = Code('L')
	M = Code('M')
	N = Code('M')
	O = Code('O')
	P = Code('P')
	Q = Code('Q')
	R = Code('R')
	S = Code('S')
	T = Code('T')
	U = Code('U')
	V = Code('V')
	W = Code('W')
	X = Code('X')
	Y = Code('Y')
	Z = Code('Z')

	String  = Argument('_')
	Comment = Argument(';')
)
View Source
var (
	Initializer = code{
				// contains filtered or unexported fields
	}

	Finalizer = code{
				// contains filtered or unexported fields
	}
)
View Source
var PanicOnLimitFailure bool
View Source
var Precision = 2

Functions

func Argument

func Argument(address byte) stringFunc

Argument is similar to Code, but rather than have a function that takes a float64 as its value, it accepts a string. This way you can have commands like M400 that optionally have a string value to write to an LCD.

func Code

func Code(address byte) codeFunc

Code creates a code func for the given address. For example: `banana : =Code('X')` returns a code function, `banana()` that can be used to represent an X code in the final output.

func Command

func Command(address Addressable, v float64, accepts ...Addressable) commandFunc

Command is a slightly higher order GCode, that is, one that can accept arguments/parameters. This function will generate a function for creating functions (trippy, I know), that allows you to define what commands are available to your gcode program.

Why would you even go down this route? This lets the compiler help enforce the available commands and it also lets us add constraints rather than it just being a simple string.

The command returned by this function will only accept values that are provided and will consume them in the order defined in the argument list. That is to say, if you want to accept Z Y into your M9001 command, you can with `Command(M, 9001.0, Z, Y)`.

The address is the GCode underwhich this command lives(M, G, etc.).

func LimitCode

func LimitCode(c codeFunc, min float64, max float64) codeFunc

LimitCode adds a limiter to the possible values of a code. Any code wrapped with this function can only have values between the min and max.

func LimitCommand

func LimitCommand(c commandFunc, limits ...Parameter) commandFunc

LimitCommand wraps the given commandFunc and applies a series of limits to its inputs. The limits are expected to be in tupes (min, max) and share the same address (X, Y, etc.). If the address is not the same or the count of the limits in not even either: - the error is ignored and all limits are ignored - a panic is triggered

This is controlled by the PanicOnLimitFailure variable.

Types

type Addressable

type Addressable interface {
	Address() byte
}

type CodePoint

type CodePoint = code

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is a gcode document or program that controls a machine of some kind. It supports the addition of hooks to alter the behavior of gcode on a per-document level. This allows the document to be changed to suit different machines or limitations. For example, let's say that at a general level, you want to change from tool 1 to tool 2. Not all machines have automatic tool changers and some require a different procedure to change the tool.

Having a hook on the M600 command, for example, allows the original generator of the gcode to be unconcerned with _how_ the "filament" (in this case) changes, just that it changes. A machine can override the M600 command and insert the correct procedure (move to a specific point, pause, re-probe, etc.).

*Any* gcode can be intercepted with a hook, with the addition of a couple extra ones. There are Initializer and Finalizer hooks available, to do exactly what their names are -- add a fragment to the beginning or end of the document, respectively.

func (*Document) AddFragment

func (d *Document) AddFragment(f Fragment)

AddFragment appends the contents of a fragment to the document

func (*Document) AddHook

func (d *Document) AddHook(cf Keyable, fn HookFn)

AddHook sets the hook function for the given command. There can only be one hook per command.

func (*Document) AddLines

func (d *Document) AddLines(l ...code)

/ AddLines adds one or more lines of Codes to the document

func (*Document) Finalizer

func (d *Document) Finalizer(fn HookFn)

func (*Document) Initalizer

func (d *Document) Initalizer(fn HookFn)

func (*Document) String

func (d *Document) String() string

String implements the Stringer interface. All hooks are applied at the generation of the string output.

type Fragment

type Fragment []code

Fragment is a collection of codes, intended to be part of a final gcode document

func Parse

func Parse(r io.Reader) (Fragment, error)

Parse works through the reader line-wise, converting each line into the correct code values. It attempts to use the correct addresses and vaues that will match the original input. Addresses (G,M, T, etc.) are expected to be upper case, otherwise they will be considered as string arguments.

Empty lines are ignored and will not be present in the resulting output of Fragment.String().

func ParseString

func ParseString(input string) (Fragment, error)

ParseString is a helper function. Rather than a reader, it takes a string and turns it into a reader for you.

func (Fragment) Append

func (f Fragment) Append(others Fragment) Fragment

Append another Fragment onto the current fragment

func (Fragment) String

func (f Fragment) String() string

String implements the stringer interface, creating the near-final gcode output of the fragment. Note, this does not apply any hooks or other code modifications.

type HookFn

type HookFn func(CodePoint) Fragment

HookFn is a function that accepts a CodePoint and returns a Fragment that contains a replacement definition. The original codepoint will not be part of the final document *unless it is returned as part of the Fragment*.

type Keyable

type Keyable interface {
	Key() mapKey
}

type Parameter

type Parameter interface {
	Addressable
	Valuable
}

type Valuable

type Valuable interface {
	Value() float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL