Tool to modify Snapmaker laser GCode for a rotary module to include z movements.
Snapmaker's Luban tool to generate 4D laser projects only uses two axes:
Y
(backwards / forwards) andB
(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.
The inputs to the tool are:
- GCode file for cylindrical object
- Mechanism for mapping
Y
values toZ
values.
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 aY
lookup of value0
would yield aZ
of0
. - If the map has
y
:z
values of{0:0, 10:5, 20:8}
, Then aY
lookup of value10
would yield aZ
of5
. - If the map has
Y
:Z
values of{0:0, 10:5, 20:8}
, Then aY
lookup of value5
would yield aZ
of2.5
. - If the map has
Y
:Z
values of{0:0, 10:5, 20:8}
, Then aY
lookup of value1
would yield aZ
of0.5
. - If the map has
Y
:Z
values of{0:0, 10:5, 20:8}
, Then aY
lookup of value-1
would yield aZ
of0
. - If the map has
Y
:Z
values of{0:0, 10:5, 20:8}
, Then aY
lookup of value100
would yield aZ
of8
.
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.
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.
Wine glass with slight grayscale boundary between black and white sections. Note that only the top half of the image is used.
- 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.
- Do trial runs well above the object first, and be prepared to E-Stop in a hurry.
- 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.
- 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.
- 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.