gcoder

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

README

gcoder

Overview

The gcoder Go package can be used to generate g-code for the Snapmaker A350 device. This is all part of a project to make operations on that device fully scriptable. Using this package, one can make g-code files runnable on the device, either through the Snapmaker official software, or a tool like snappy.

Example

The examples directory contains an example of using this zappem.net/pub/io/gcoder package. When run as follows,

$ go run examples/stripes.go
2025/07/05 22:08:25 generated "stripes.nc" and "stripes.nc.png"

it generates a stripes.nc g-code file for use with the Snapmaker, and a PNG image file:

stripes.nc.png

This is the image of what is rastered by the 1.6W Snapmaker A350 laser device when running the generated stripes.nc g-code file. Note: the small red/black X mark(s) in the bottom left of that image refer to the expected work origin position. The red mark (obscured by the black one in this case) marks the work origin at the start of running the job, and the black one is the work origin at the end of the job. For jobs that change the work origin, these two marks will differ in location.

Plans

Only bug fixes as needed.

Reporting bugs

The gcoder package has been developed purely out of self-interest and offers no guarantee of fixes or support. That being said, if you would like to suggest a feature addition or suggest a fix, please use the bug tracker.

License information

See the LICENSE file: the same BSD 3-clause license as that used by golang itself.

Documentation

Overview

Package gcoder builds up g-code step sequences, referred to as an Image. The package includes native support for the Snapmaker A350 3-in-1 system (Laser, CNC, 3D printer).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTool  = errors.New("invalid tool selection")
	ErrInvalidPower = errors.New("invalid tool power")
)

ErrInvalidTool etc are the error return values for the gcoder package.

View Source
var LaserWattage = map[string]HeadType{
	"1.6": Laser1pt6W,
	"2":   Laser2W,
	"10":  Laser10W,
}
View Source
var LaserWidth = map[HeadType]float64{
	Laser1pt6W: 0.1,
	Laser2W:    0.01,
	Laser10W:   0.1,
}

LaserWidth is the mm width of the laser beam.

View Source
var ToolName = map[HeadType]string{
	Laser1pt6W: "levelOneLaserToolheadForSM2",
	Laser2W:    "2W Laser Module",
	Laser10W:   "levelTwoLaserToolheadForSM2",
}
View Source
var ToolType = map[HeadType]string{
	Laser1pt6W: "laser",
	Laser2W:    "laser",
	Laser10W:   "laser",
}

Functions

func MakeRGBA

func MakeRGBA(g *Image, width, height int) (*image.RGBA, error)

Make an image.RGBA of size (width,height).

Types

type BBox

type BBox struct {
	MinX, MaxX, MinY, MaxY     float64
	SpeedActive, SpeedInactive int
}

BBox holds the bounds for an image. Use the BBox() function to compute it.

type Bound

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

func (*Bound) Command

func (b *Bound) Command(cmd Command) error

func (*Bound) LineTo

func (b *Bound) LineTo(x, y, z float64) error

func (*Bound) MoveTo

func (b *Bound) MoveTo(x, y, z float64) error

type Command

type Command int
const (
	CmdInvalid Command = iota
	CmdSetOrigin
)

type HeadType

type HeadType headType
const (
	Laser1pt6W HeadType = iota
	Laser10W
	Laser2W
)

func (HeadType) String

func (ht HeadType) String() string

type Image

type Image struct {
	Steps  []*Step
	Copies int
}

Image holds a series of (*Step) values.

func NewImage

func NewImage() *Image

Start a new, empty, Image.

func (*Image) A350CNC

func (im *Image) A350CNC(wr io.Writer, pngImage []byte) error

A350CNC writes the gcode formatted for a Snapmaker 2 A350 standard CNC head. The work origin is an important feature, as all X,Y moves are absolute.

func (*Image) A350Laser

func (im *Image) A350Laser(ht HeadType, wr io.Writer, pngImage []byte) error

A350Laser writes the gcode formatted for a Snapmaker 2 A350 level one laser tool head.

func (*Image) BBox

func (im *Image) BBox() *BBox

func (*Image) Drill

func (im *Image) Drill(dz float64, power float64) error

Drill increases the relative Z value while drawing. To lower while drilling provide a negative value for dz.

func (*Image) LineXY

func (im *Image) LineXY(x, y, power float64) error

Cut a line from the current location to (x, y) with power level [0,100].

func (*Image) MoveXY

func (im *Image) MoveXY(x, y float64) error

MoveXY relocates the tool head to a specific location. This move is accomplished without the tool being active.

func (*Image) Note

func (im *Image) Note(note string)

Note adds a comment to the image stream.

func (*Image) Plot

func (im *Image) Plot(plotter Plotter) error

Plot executes the Image using the provided Plotter.

func (*Image) Raise

func (im *Image) Raise(dz float64) error

Raise increases the relative Z value without any line drawn.

func (*Image) SetOrigin

func (im *Image) SetOrigin() error

SetOrigin resets the coordinate system to have the current location become the new (0,0,0) coordinate.

func (*Image) SetSpeed

func (im *Image) SetSpeed(active bool, speed int)

SetSpeed sets the tool n speed (in mm/minute).

type Plotter

type Plotter interface {
	Command(cmd Command) error
	MoveTo(x, y, z float64) error
	LineTo(x, y, z float64) error
}

Plotter is an interface to a 3D pen plotter.

type Step

type Step struct {
	X, Y, Z float64
	Rel     bool
	Active  bool
	Power   float64
	Speed   int
	Comment string
	Command Command
}

Step holds an atom of g-code work.

func (*Step) String

func (s *Step) String() string

String serializes a (*Step) value.

Directories

Path Synopsis
Program stripes generates some g-code for the A350 1.6W laser to scribe some different width stripes.
Program stripes generates some g-code for the A350 1.6W laser to scribe some different width stripes.

Jump to

Keyboard shortcuts

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