Skip to content

Tool to modify Snapmaker laser GCode for a rotary module to include z movements

License

Notifications You must be signed in to change notification settings

jadjab/lasery2z

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

lasery2z

Tool to modify Snapmaker laser GCode for a rotary module to include z movements.

Background

Snapmaker's Luban tool to generate 4D laser projects only uses two axes:

  • Y (backwards / forwards) and
  • B (rotation of rotary module)

The X axis is unused - the laser is always positioned in the centre of the job job.

The Z axis is unused - the tool assumes a cylindrical shape to be lasered.

It is this Z axis that we wish to exploit. If we still assume a circular cross-section of the job, but relax the requirement for parallel sides, then by adjusting the Z axis based on the Y axis, we can follow contours on the job.

Inputs

The inputs to the tool are:

  • GCode file for cylindrical object
  • Mechanism for mapping Y values to Z values.

Coordinate mappings

A table of Y to Z mappings is produced, and for each Y value encountered in the gcode, a Z value is calculated by looking up the value in the map, and using interpolation.

Examples:

  • If the map has Y:Z values of {0:0, 10:5, 20:8}, Then a Y lookup of value 0 would yield a Z of 0.
  • If the map has y:z values of {0:0, 10:5, 20:8}, Then a Y lookup of value 10 would yield a Z of 5.
  • If the map has Y:Z values of {0:0, 10:5, 20:8}, Then a Y lookup of value 5 would yield a Z of 2.5.
  • If the map has Y:Z values of {0:0, 10:5, 20:8}, Then a Y lookup of value 1 would yield a Z of 0.5.
  • If the map has Y:Z values of {0:0, 10:5, 20:8}, Then a Y lookup of value -1 would yield a Z of 0.
  • If the map has Y:Z values of {0:0, 10:5, 20:8}, Then a Y lookup of value 100 would yield a Z of 8.

Image map

One way to create the co-ordinate mappings is to use an image representing the object itself.

The image map takes the following inputs:

  • Filename (jpg or png supported)
  • Image width in gcode units, typically mm. This maps the entire width of the image to range specified.
  • Optional image height in gcode units. If omitted this maintains the aspect ratio of the image itself.

Image Map Workings

The scanner works from left to right over the image, creating a coordinate mapping for values of Y=0 to Y=image width across the image (inclusive).

For example an image 3 pixels wide, defined as 300mm across would create a map with Y indexes of 0mm, 150mm and 300mm.

The origin (Y=0 value, furthest from the rotary module) is taken as the left-most column of the image. Any areas of the picture lower than this become positive Z (closer to the bed than the origin), while areas of the picture higher than this become negative Z (further from the bed than the origin).

For each column of the image, the image is scanned downwards from the top. When it encounters a nonzero RGBA colour, its overall brightness is calculated as a ratio of 0 to 1 (using the formula (r+g+b)/3*a). The depth is then calculated using the vertical position of the pixel, pro rated for its brightness. So dark grey pixels would be calculated closer to the bottom of the pixel, while whiter pixels would be closer to the top.

The ratio of this position relative to the height of image, and its gcode height is then used to determine what the z value would be for that column.

Some examples:

  • If a column has 3 white pixels, and the gcode height is 100mm, the z value is calculated as 0 / (3-1) * 100mm = 0mm.
  • If a column has a black pixel, then two white pixels, and the gcode height is 100mm, the z value is calculated as 1 / (3-1) * 100mm = 50mm.
  • If a column has two black pixels, then a white pixel, and the gcode height is 100mm, the z value is calculated as 2 / (3-1) * 100mm = 100mm.
  • If a column has three black pixels, and the gcode height is 100mm, the z value is calculated as 2 / (3-1) * 100mm = 100mm.
  • If a column has one half-gray pixel, and two white pixels the gcode height is 100mm, the z value is calculated as 0.5 / (3-1) * 100mm = 25mm.

Image map example

Wine glass with slight grayscale boundary between black and white sections. Note that only the top half of the image is used.

Tips and tricks

  1. After opening the modified GCode in Luban, rotate the object to get a good look at the result to be sure it did what you were expecting.
  2. Do trial runs well above the object first, and be prepared to E-Stop in a hurry.
  3. The black portions of the picture MUST be true black. Any non-black region is used to calculate the height, and the algorithm then moves to the next column of the picture.
  4. The only part of the image that has any relevance is the top. Below the first non-black pixel in any given column is ignored.
  5. It is recommended to make the image the correct aspect ratio, and then not specify the image height argument. This allows the app to calculate the height correctly, and allows one to crop the irrelevant portions of the image with impunity.

About

Tool to modify Snapmaker laser GCode for a rotary module to include z movements

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages