Method for independently drawing and carving on carving machine
By integrating a touch screen and intelligent path optimization algorithm on the engraving machine, independent operation of the entire drawing and engraving process is achieved, solving the problem of the separation of drawing and engraving in existing technologies and improving the real-time creation and efficiency of the laser engraving machine.
Patent Information
- Application Number
- CN202510545656.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-09-23
AI Technical Summary
Existing laser engraving machines are separated in the drawing and engraving stages, resulting in limited real-time creation and insufficient path optimization, making it difficult to meet the needs of high-precision and high-efficiency independent processing.
A touch screen and intelligent path optimization algorithm are integrated into the engraving machine. Through the collaborative work of real-time canvas and optimized canvas, the full process of drawing, path generation and engraving is realized. Manhattan distance filtering and Bezier quadratic curve interpolation technology are used to optimize the touch trajectory and generate G-code motion instructions to control engraving.
It realizes the independent creation and efficient processing of the laser engraving machine, eliminates touch track jitter and redundant line segments, improves the real-time creation and device independence, reduces the processor load and extends the battery life.
Smart Images

Figure CN120689456A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of engraving machines, and in particular relates to a method for independently realizing drawing and engraving on an engraving machine. Background Art
[0002] Existing laser engraving machines have significant flaws in linking drawing and engraving: traditional devices rely on external computer software (such as CAD and CorelDraw) to complete graphic design, and then transmit the design files to the engraving machine via a data cable or network for execution. This operating mode disconnects the drawing and engraving processes, preventing users from directly creating graphics and making real-time adjustments on the engraving device. Frequent file transfers are also susceptible to device compatibility and transmission rate limitations, resulting in interruptions to the creative process and loss of efficiency. Furthermore, existing devices have weak touch interaction capabilities and lack the ability to optimize real-time drawing trajectories. This results in redundant line segments and jitter errors in the engraving path, affecting engraving accuracy and surface quality.
[0003] Existing laser engraving machines are physically isolated from the drawing and engraving stages, resulting in limited real-time creation and insufficient path optimization, making it difficult to meet the needs of high-precision and high-efficiency independent processing. Summary of the Invention
[0004] The purpose of the present invention is to provide a method for independently realizing drawing and engraving on an engraving machine, realizing the whole process operation of drawing, path generation and engraving on the engraving machine terminal, so as to solve the problems raised in the above background technology.
[0005] To achieve the above object, the present invention adopts the following technical solution: a method for independently realizing drawing and engraving on an engraving machine, comprising the following steps: The touch track drawn by the user is collected in real time through the touch screen of the embedded device, raw line segment data without optimization is generated, and the data is synchronously displayed on the real-time canvas of the touch screen; Performing redundant point filtering on the original line segment data, removing consecutive endpoints whose distance is less than a preset threshold, and generating optimized line segment data; Rendering and displaying the optimized line segment data on an optimized canvas, wherein the optimized canvas smoothes the optimized line segment data using a Bezier quadratic curve interpolation algorithm; Select brush properties or operation commands in the side adsorption menu bar; generating image data in a bitmap format according to the path in the optimized canvas and the selected brush attributes, and converting the image data into a grayscale value mapping table; The grayscale value mapping table is converted into a G-code motion instruction of a laser engraving machine to control the engraving machine to perform engraving operations.
[0006] Preferably, performing redundant point filtering on the original line segment data includes: Calculate the Manhattan distance between two adjacent endpoints using the formula: d = |x2−x1|+|y2−y1|, where (x1, y1) and (x2, y2) are the coordinates of the two endpoints. If the Manhattan distance is less than the minimum line segment length threshold Lmin=8 pixels, the endpoints are merged until the distance requirement is met.
[0007] Preferably, the optimized canvas smoothes the optimized line segment data using a Bezier quadratic curve interpolation algorithm, including: Take three adjacent points {P i-1 ,P i ,P i+1}, with P i is the control point; Calculate the interpolation point coordinates according to the interpolation parameter t∈[0,n]: ; ;
[0008] Where a=t / n, n=d / dmin, n is the total number of interpolated coordinate points, t is the serial number of the current coordinate point, a is the interpolation parameter, and the value of a is the serial number t of the current point divided by the total number of previous points n, indicating the relative position relationship of the current interpolation point on all endpoints. dmin is the minimum line segment pixel value.
[0009] Preferably, the dynamic characteristics of the side adsorption menu bar include: By default, it is hidden at the left edge of the screen, and the width of the trigger bar is 5% of the screen width; Swipe the edge by 15 pixels or longer press the trigger bar for 1 second to call out the full menu bar, which expands to 20% of the screen width. The screen automatically retracts if the user's finger leaves the screen without any interaction for 2 seconds or touches the sketchpad.
[0010] Preferably, converting the image data into a grayscale value mapping table includes: The gray value is calculated using the weighted average method: Gray = 0.333R + 0.333G + 0.333B; Adjust the grayscale value based on the transparency weight: Gray.value = ((255 − Gray.value) × color.alpha) / 255; The grayscale value range is mapped to 0-255 levels, 0 represents black and 255 represents white; Among them, Gray.value is the adjusted grayscale value, and color.alpha is the transparency.
[0011] Preferably, converting the grayscale value mapping table into a G-code motion instruction of a laser engraving machine comprises: Map the grayscale value to laser power using the formula: Power = (((Gray.value × (maxPower − minPower)) / 255) + minPower); Calculate pixel coordinates (sx, sy) based on the engraving area size and pixel sampling ratio res: sx=(position->x)*m_factorX; sy=(position->y)*m_factorY; Generate G code command: G1X[position->x]Y[position->y]S[Power]; Among them, Power is the optical power, S is the laser power parameter keyword, maxPower is the maximum power of the laser, minPower is the minimum power of the laser, position->x is the x-axis coordinate value of the engraving area, position->y is the y-axis coordinate value of the engraving area, sx is the x-axis coordinate value of the original image pixel, and sy is the y-axis coordinate value of the original image pixel.
[0012] Preferably, the collaborative working mechanism of the real-time canvas and the optimized canvas includes: The real-time canvas displays unoptimized touch traces in real time; Optimize the canvas to display the smoothed path after the touch ends; Undo the last operation by switching canvases, preserving the original data.
[0013] Preferably, the brush attributes include brush thickness, eraser size and color parameters.
[0014] Preferably, the setting of the brush attributes includes: 5-level brush thickness options, corresponding to line segment width w∈{1,2,3,4,5} pixels; 5-level eraser size options, corresponding to erasing radius r∈{5,10,15,20,25} pixels.
[0015] Preferably, controlling the engraving machine to perform the engraving operation includes: Divide the engraving area into grids, where each grid corresponds to a pixel of the image; Adjust the laser power according to the pixel grayscale value to control the engraving depth; Adapt to different resolution requirements through repeated spot sampling or interval sampling.
[0016] Technical effects and advantages of the present invention: The method of independently realizing drawing and engraving on an engraving machine proposed by the present invention has the following advantages compared with the prior art: The present invention achieves a leapfrog upgrade of laser engraving machines from reliance on external devices to independent creation and efficient processing by integrating a dual-drawing board collaborative working mechanism and an intelligent path optimization algorithm; through the alternating display mechanism of the real-time canvas and the optimized canvas, users can directly complete the closed-loop operation from graphic creation to path generation on the engraving machine terminal, completely getting rid of the shackles of file transfer, and significantly improving the real-time nature of creation and device independence; redundant point filtering and Bezier curve interpolation technology based on Manhattan distance effectively eliminate touch trajectory jitter and redundant line segments, and through dynamic parameter mapping and spot sampling optimization, greatly reduce processor load and extend battery life; achieve a coordinated breakthrough in drawing accuracy, processing efficiency and human-computer experience, and reconstruct the independent and intelligent operation paradigm of laser engraving machines. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 This is a flow chart of a method for independently realizing drawing and engraving on an engraving machine according to the present invention; Figure 2 This is a block diagram of a system for independently realizing drawing and engraving on an engraving machine according to the present invention; Figure 3 The present invention is a system workflow diagram for independently realizing drawing and engraving on an engraving machine. DETAILED DESCRIPTION
[0018] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. The specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0019] Example 1 The present invention provides Figure 1 A method for independently implementing drawing and engraving on an engraving machine includes the following steps: The touch track drawn by the user is collected in real time through the touch screen of the embedded device, raw line segment data without optimization is generated, and the data is synchronously displayed on the real-time canvas of the touch screen; Performing redundant point filtering on the original line segment data, removing consecutive endpoints whose distance is less than a preset threshold, and generating optimized line segment data; Furthermore, the original line segment data is subjected to redundant point filtering, including: Calculate the Manhattan distance between two adjacent endpoints using the formula: d = |x2−x1|+|y2−y1|, where (x1, y1) and (x2, y2) are the coordinates of the two endpoints. If the Manhattan distance is less than the minimum line segment length threshold Lmin=8 pixels, merge the endpoints until the distance requirement is met.
[0020] Rendering and displaying the optimized line segment data on an optimized canvas, wherein the optimized canvas smoothes the optimized line segment data using a Bezier quadratic curve interpolation algorithm; further comprising: Take three adjacent points {P i-1 ,P i ,P i+1}, with P i is the control point; Calculate the interpolation point coordinates according to the interpolation parameter t∈[0,n]: ;
[0021] ;
[0022] Where a=t / n, n=d / dmin, n is the total number of interpolated coordinate points, t is the serial number of the current coordinate point, a is the interpolation parameter, and the value of a is the serial number t of the current point divided by the total number of previous points n, indicating the relative position relationship of the current interpolation point on all endpoints. dmin is the minimum line segment pixel value.
[0023] Select brush properties or operation commands in the side menu bar, including: By default, it is hidden at the left edge of the screen, and the width of the trigger bar is 5% of the screen width; Swipe the edge by 15 pixels or longer press the trigger bar for 1 second to call out the full menu bar, which expands to 20% of the screen width. The screen automatically retracts if the user's finger leaves the screen without any interaction for 2 seconds or touches the sketchpad.
[0024] Brush properties include brush thickness, eraser size, and color parameters. Brush property settings include: 5-level brush thickness options, corresponding to line segment width w∈{1,2,3,4,5} pixels; 5-level eraser size options, corresponding to erasing radius r∈{5,10,15,20,25} pixels.
[0025] Generating image data in a bitmap format according to the path in the optimized canvas and the selected brush attributes, and converting the image data into a grayscale value mapping table; specifically comprising: The gray value is calculated using the weighted average method: Gray = 0.333R + 0.333G + 0.333B; Adjust the grayscale value based on the transparency weight: Gray.value = ((255 − Gray.value) × color.alpha) / 255; The grayscale value range is mapped to 0-255 levels, 0 represents black and 255 represents white; Among them, Gray.value is the adjusted grayscale value, and color.alpha is the transparency.
[0026] The grayscale value mapping table is converted into a G-code motion instruction of a laser engraving machine, including: Map the grayscale value to laser power using the formula: Power = (((Gray.value × (maxPower − minPower)) / 255) + minPower); Calculate pixel coordinates (sx, sy) based on the engraving area size and pixel sampling ratio res: sx=(position->x)*m_factorX; sy=(position->y)*m_factorY; Generate G code command: G1X[position->x]Y[position->y]S[Power]; Among them, Power is the optical power, S is the laser power parameter keyword, maxPower is the maximum power of the laser, minPower is the minimum power of the laser, position->x is the x-axis coordinate value of the engraving area, position->y is the y-axis coordinate value of the engraving area, sx is the x-axis coordinate value of the original image pixel, and sy is the y-axis coordinate value of the original image pixel.
[0027] Furthermore, the collaborative working mechanism of the above-mentioned real-time canvas and optimized canvas includes: The real-time canvas displays unoptimized touch traces in real time; Optimize the canvas to display the smoothed path after the touch ends; Undo the last operation by switching canvases, preserving the original data.
[0028] To control the engraving machine to perform engraving operations, including: Divide the engraving area into grids, where each grid corresponds to a pixel of the image; Adjust the laser power according to the pixel grayscale value to control the engraving depth; Adapt to different resolution requirements through repeated spot sampling or interval sampling.
[0029] Example 2 In this embodiment, a system for independently drawing and engraving on an engraving machine is proposed. Figure 2 As shown, including: Main control unit: A single-chip microcontroller (such as the ESP32 series) controls the touch screen (with the LVGL graphics library), laser module, and motion mechanism; Touch module: 3.5-inch embedded screen (capacitive, 480*320 resolution) supports multi-touch and collects user drawing traces in real time; Laser module: 450nm blue laser, power 0-40W, laser power adjustment method: PWM control; laser module power adjustment method is PWM control.
[0030] Motion mechanism: XY axis moving platform driven by stepper motor, receiving standard Gcode motion instructions (or called G code, accuracy ±0.05mm).
[0031] like Figure 3 As shown, the workflow of the system that independently realizes drawing and engraving on the engraving machine is as follows: 1. Touch drawing and data processing: 1) Real-time trajectory collection: The user draws a pattern on the screen with a stylus or finger, and the touch point coordinates are collected at a sampling frequency of fs (100 Hz) to generate an original point sequence Q = {(x1, y1), (x2, y2), ..., (x n ,y n )}.
[0032] Convert continuous touch points into a path consisting of a sequence of line segments, mathematical expression: P={L1,L2,...,L n}, where L i =(x start ,y start )→(x end ,y end ); 2) Dual-artboard collaborative working mechanism: The drawing board consists of two canvases: the real-time canvas (Canvas_R) and the optimized canvas (Canvas_O). The real-time canvas displays the user's touch trajectory in real time, representing the original, unoptimized and unrendered line segments. The optimized canvas displays the smoothed path. The two canvases are displayed alternately. During touch drawing, the content on the real-time canvas is displayed. When touch drawing ends, the optimized line begins drawing on the optimized canvas. When drawing is complete, the real-time canvas is displayed and hidden. When the next stroke begins, the content of the optimized canvas is copied to the real-time canvas. If the user needs to undo a previous stroke, the current canvas is determined. If it is the real-time canvas, the display switches to the optimized canvas, and vice versa.
[0033] The function of the real-time canvas is to display the touch trajectory at the fastest speed, keeping the painting action and the line display synchronized. When drawing and displaying on an embedded device, it takes a relatively long time, usually about 20 ms. If the user draws at a relatively fast speed, before one line segment is fully displayed, the user has already drawn several line segments, which will cause an obvious delay between the painting action and the display, making the painting look unsynchronized. Filtering short line segments and overlapping points can improve the drawing efficiency, reduce the memory occupancy of the embedded device, and reduce the resource invocation of the processor.
[0034] Filtering of short line segments: During drawing, the endpoints of the touch are collected at regular intervals. If the distance between two adjacent endpoints is too short, they need to be merged with the adjacent line segment until the line segment is greater than a threshold. Then, the head and tail of these endpoints are connected to form a straight line and drawn on the canvas, while the middle endpoints are discarded. For two points with the sequence {(x1, y1), (x2, y2)}, calculate the distance between the two points using the "Manhattan distance" method, which calculates the total absolute axis distance of the two points in the standard coordinate system. The formula is: d = |x2 - x1| + |y2 - y1| The unit of d is the number of pixel points, and the threshold for the minimum line segment length is Lmin = 8 pixels (8 pixels is the length of the smallest object on the current screen). When d < Lmin, add the next adjacent endpoint (x3, y3), continue the calculation and compare again until d >= Lmin, indicating that a valid line segment has been obtained and display it on the canvas.
[0035] While using the "Manhattan distance" method to reduce overlapping points and redundant points, it will also filter out the points marked by the user and the last stroke, resulting in the inability to mark points and the last stroke not being displayed.
[0036] To solve the problem of unable to mark points, it can be achieved by detecting the start action of the touch. Draw a solid circle with the thickness of the paintbrush on the screen. If the user immediately lifts the finger after touching, a dot will be displayed; if the user continues to touch without moving, it will be discarded because the line segment length is less than the threshold; if the user moves the touch point to draw a line, the starting point of the first line is connected to the solid circle.
[0037] Solve the problem of the last stroke not being displayed. The reason why the last stroke is not displayed is that the length of the last line segment is less than the threshold and will not be drawn. By detecting the touch lift action, it can be determined whether a valid line segment has been formed at the time of touch lift. If the current line segment length is less than the threshold Lmin, it is not considered a valid line segment, but rather a mark that the user intends to end the current drawing action. At this time, the last endpoint can be connected to the previous endpoint to form a line segment, and then it can be drawn. In this way, even if the actual length of the last line segment is less than the threshold, the user can still see a complete line segment on the canvas, thus solving the problem of the last stroke not being displayed.
[0038] Contour display: Provides 5 levels of brush thickness and 5 levels of eraser size options. By adjusting the line segment width w (w∈{1,2,3,4,5} pixels) and the erasing area radius r (r∈{5,10,15,20,25} pixels), a circle with a radius of r or w / 2 is displayed on the parent layer of the artboard according to the touch position.
[0039] Brush outline: A semi-transparent circle with a radius of w / 2 (w is the brush thickness) is displayed on the canvas with the current touch point as the center. The color matches the brush. Eraser outline: Displays a circle with a radius of r (eraser size level) on the parent level of the canvas. The circle has a gray border and a colorless and transparent background. The circle updates in real time as the touch point moves. Hide outlines when clearing the screen: After the clear screen operation is triggered, the outline display is turned off until a new drawing begins.
[0040] While the real-time canvas displays the trajectory, the endpoint coordinates of the touch point sampling are saved. At the end of a line segment, the sampled data is optimized through the algorithm and drawn on the optimized canvas. At this time, the real-time canvas is hidden and the optimized canvas is displayed.
[0041] Optimize canvas: To optimize the canvas, the lines need to be smoothed and displayed after rendering. This is achieved using a curve fitting interpolation algorithm.
[0042] The fitting curve interpolation adopts Bezier quadratic curve to fit. In the acquired line segment data, three adjacent points {P i-1 ,P i ,P i+1}, converted into a smooth curve, the control points are:
[0043] Generate n interpolation points. The value of n is calculated based on the minimum line segment length after interpolation. The calculation formula is: ; ;
[0044] dmin is the minimum pixel length of a line segment. Here, dmin=5 is selected after adjustment based on the actual display effect.
[0045] Calculate the interpolated coordinate value Pt,t∈[0,n]: ;
[0046] ;
[0047] ;
[0048] After calculating the coordinates of all interpolation points, draw them on the optimized canvas.
[0049] Undo to the last transaction: The live canvas and optimized canvas switch back and forth. The live canvas is currently displayed. When a touch point is pressed, the contents of the live canvas are copied to the optimized canvas, and the real-time painting content is then displayed on the live canvas. When the touch point is lifted, the live canvas is cleared and hidden, and the contents of the optimized canvas are copied to the live canvas, and the latest rendered painting content is displayed on the optimized canvas. At this time, if you undo to the previous stroke, the optimized canvas is hidden and the live canvas is displayed, you can return to the previous stroke.
[0050] 2. Side adsorption menu bar: Layout Mode: By default, the menu bar is hidden at the left edge of the screen, and only a trigger bar with a width of Wmin = 5% × screen width (e.g. 10 pixels wide) is displayed. The user calls out the full menu bar by sliding the edge (swiping inward from the left by ≥15 pixels) or long pressing the trigger bar (for 1 second). The expanded width Wmax = 20% × screen width.
[0051] Dynamic adsorption mechanism: During the expansion process, the menu bar slides out smoothly in an animated form (duration 300ms), covering the upper layer of the canvas with a semi-transparent background; When the user's finger leaves the screen and there is no interaction within 2 seconds, or touches the sketchpad, the menu bar automatically retracts and hides.
[0052] Menu function item design: Icon-based interaction, the menu bar contains the following function buttons (supports touch click): Brush thickness (levels 1 to 5, icon size changes with level); Eraser size (levels 1 to 5, with size numbers embedded in the icon); Clear screen (trash can icon); Save (floppy disk icon); Settings (gear icon, contains advanced options such as coordinate mapping calibration, filter threshold adjustment, etc.).
[0053] 3. Image generation and engraving control Generate a canvas through the lvgl graphics library, draw on the canvas, and save the currently displayed canvas content in a bitmap format as an image file in a specific format. This file can be parsed and displayed by the file system.
[0054] To paint on the canvas, you need to set the brush properties. The property structure is as follows: typedefstruct{ lv_color_tcolor; lv_coord_twidth; lv_coord_tdash_width; lv_coord_tdash_gap; lv_opa_topa; lv_blend_mode_tblend_mode: 2; uint8_tround_start: 1; uint8_tround_end: 1; uint8_traw_end: 1; }lv_draw_line_dsc_t; Some of the main features related to the brush are: transparency opa, brush color color, brush thickness width, starting point rounding flag round_start, end point rounding flag round_end, length of each dashed segment dash_width, interval dash_gap between dashed segments, blend mode type blend_mode, and skip line segment end optimization flag raw_end.
[0055] The image data structure is as follows: {Image header information, image size, image pixel data} typedefstruct{ img_header_theader; uint32_tdata_size; constuint8_t *data; }img_dsc_t; Image header information includes: {image format, image length, image width} typedefstruct{ uint32_tcf:5; uint32_totalways_zero: 3; uint32_treserved: 2; uint32_tw:11; uint32_th:11; }img_header_t; The image format is designed to be 16 colors, namely RGB565 format, compatible with an 8-bit alpha channel to indicate image transparency. The format supports two formats, namely TRUE_COLOR and TRUE_COLOR_ALPHA.
[0056] The pixel data format is: TRUE_COLOR
[0057] TRUE_COLOR_ALPHA
[0058] Generate image pixel data according to the image format and save the image structure data in a blank file with the file suffix .pixi to complete the image generation.
[0059] Add the pixi format image to the system image format support library. When it needs to be displayed or engraved, retrieve the saved .pixi file through the file system, parse the file header information, obtain the image format, length and width, and then parse the image pixel data. Restore it to a bitmap according to the format requirements and it can be displayed on the screen.
[0060] The process of converting image data to GCode motion instructions is to convert the pixels in the image into light power and correspond the pixels in the image to the position of the engraving area.
[0061] By converting the color value of each pixel in the image into a grayscale value and then mapping the grayscale value and laser power, the optical power distribution map of the entire image can be obtained.
[0062] Color to grayscale: Color consists of four components: green G, red R, blue B, and transparency A. There are many different calculation methods for grayscale conversion, such as weighted average method, maximum method, and minimum method. The following are the calculation formulas of several linear weighted methods: BT.601, Gray=0.299R+0.587G+0.114B; BT.709, Gray=0.2126R+0.7152G+0.07224B; BT.2100, Gray=0.2627R+0.6780G+0.0593B; Weighted average method, Gray=0.333R+0.333G+0.333B; BT.601, BT.709, and BT.2100 all increase the weight of green. Laser engraving imaging is black and white, so their laser imaging effects are not good. Here, the weighted average method is used to convert them into grayscale values.
[0063] The contrast and brightness characteristic values of the image need to be calculated during the grayscale conversion process. The calculation is as follows: The proportion of the red channel: redFactor=gray.red*(contrast / 100.0f); redFactor=red channel weight; gray.red=red weight of weighted average method; contrast=contrast, range 40 to 160.
[0064] Similarly, the calculation methods for the other two channels are: greenFactor=gray.green*(contrast / 100.0f); blueFactor=gray.blue*(contrast / 100.0f); brightness=-(100-brightness) / 100.0f; brightness = brightness weight, range 40 to 160.
[0065] The grayscale value is calculated by the color value of the pixel. The calculation formula is as follows: Gray.value=(int)ceil(redFactor*color.red+greenFactor*color.green+blueFactor*color.blue+0*color.alpha+brightness*255); Gray.value = grayscale value, color.red = red component value, color.green = green component value, color.blue = blue component value.
[0066] The obtained grayscale value also needs to be added with the transparency weight, which is calculated as follows: Gray.value=((255-Gray.value)*color.alpha) / 255; The calculated grayscale value is quantized into 256 levels, and the grayscale value range is 0-255, where 0 represents black, 255 represents white, and the intermediate values represent different levels of gray.
[0067] Grayscale to light power: The mapping relationship between grayscale value and laser power is based on the performance parameters of the laser engraving machine. The laser power range is set, such as 0-1000, and the grayscale value range of 0-255 is mapped to the laser power range of 0-1000. The larger the grayscale value, the smaller the laser power, that is, the lighter the color, the smaller the laser power, and the shallower the engraving depth. Conversely, the smaller the grayscale value, the greater the laser power, and the deeper the engraving depth.
[0068] The calculation formula is as follows: Power=(((Gray.value*(maxPower-minPower)) / 255)+minPower); Power=optical power, maxPower=maximum power of the laser (default is 1000), minPower=minimum power of the laser (default is 0).
[0069] The image is scanned row by row according to the pixels, and the grayscale value of each pixel is converted into the corresponding laser power to obtain the light power value distribution on the image.
[0070] The pixels in the image correspond to the position of the engraving area. You need to scale the image to the engraving area, map the pixels to the engraving area, and then associate the pixel coordinates with the position of the engraving area one-to-one.
[0071] The relationship between engraving size and image size is not fixed; users typically adjust the engraving size to suit the material being engraved. Normally, the width of the laser spot used for engraving is between 0.05mm and 0.15mm. The relationship between engraving length and spot size is typically 10 points / mm, meaning 10 spots are required for a linear distance of 1mm. Therefore, if the spot is circular or square, the length and width of an image will both be 10 points / mm.
[0072] If the sampling ratio of pixels and engraving size is 10pixel / mm, the engraving image and the original image are a one-to-one replica. If the ratio res is less than 10pixel / mm, the same pixel needs to be sampled repeatedly on the image; if the ratio res is greater than 10pixel / mm, the pixels need to be sampled on the image. The calculation method for repeated sampling and interval sampling is as follows: maxHeight=printHeight*res; maxWidth=printWidth*res; m_factorX=image->width / m_maxWidth; m_factorY=image->height / m_maxHeight; sx=(position->x)*m_factorX; sy=(position->y)*m_factorY; Among them, res = 10 sampling ratio, printHeight = engraving area height, printWidth = engraving area width, image->width = original image width, image->height = original image height, position->x = x-axis coordinate value of engraving area, position->y = y-axis coordinate value of engraving area, sx = x-axis coordinate value of original image pixel, sy = y-axis coordinate value of original image pixel.
[0073] After obtaining the pixel coordinate position (sx, sy) through the above formula, the color data corresponding to the pixel point in the image can be obtained, and the color data can be converted into light power. After the engraving position and light power are obtained, they can be converted into GCODE instructions. The instructions are as follows: G1X[position->x]Y[position->y]S[Power].
[0074] By sending Gcode motion instructions to the grbl motion control system, you can control the motion control and light output of the laser to complete the drawing engraving task.
[0075] In summary, the present invention realizes a leapfrog upgrade of the laser engraving machine from dependence on external equipment to independent creation and efficient processing by integrating the dual-drawing board collaborative working mechanism and the intelligent path optimization algorithm; through the alternating display mechanism of the real-time canvas and the optimized canvas, the user can directly complete the closed-loop operation from graphic creation to path generation on the engraving machine terminal, completely getting rid of the shackles of file transfer, and significantly improving the real-time creation and device independence; the redundant point filtering and Bezier curve interpolation technology based on Manhattan distance effectively eliminates touch trajectory jitter and redundant line segments, and through dynamic parameter mapping and spot sampling optimization, greatly reduces the processor load and extends the battery life; it achieves a coordinated breakthrough in drawing accuracy, processing efficiency and human-computer experience, and reconstructs the independent and intelligent operation paradigm of the laser engraving machine.
[0076] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for independently realizing drawing and engraving on an engraving machine, characterized in that: The following steps are involved: The touch track drawn by the user is collected in real time through the touch screen of the embedded device, raw line segment data without optimization is generated, and the data is synchronously displayed on the real-time canvas of the touch screen; Performing redundant point filtering on the original line segment data, removing consecutive endpoints whose distance is less than a preset threshold, and generating optimized line segment data; Rendering and displaying the optimized line segment data on an optimized canvas, wherein the optimized canvas smoothes the optimized line segment data using a Bezier quadratic curve interpolation algorithm; Select brush properties or operation commands in the side adsorption menu bar; generating image data in a bitmap format according to the path in the optimized canvas and the selected brush attributes, and converting the image data into a grayscale value mapping table; The grayscale value mapping table is converted into a G-code motion instruction of a laser engraving machine to control the engraving machine to perform engraving operations.
2. A method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: The redundant point filtering process is performed on the original line segment data, including: Calculate the Manhattan distance between two adjacent endpoints using the formula: d = |x2−x1|+|y2−y1|, where (x1, y1) and (x2, y2) are the coordinates of the two endpoints. If the Manhattan distance is less than the minimum line segment length threshold Lmin=8 pixels, the endpoints are merged until the distance requirement is met.
3. The method for independently realizing drawing and engraving on an engraving machine according to claim 1, characterized in that: The optimized canvas uses the Bezier quadratic curve interpolation algorithm to smooth the optimized line segment data, including: Take three adjacent points {P i-1 ,P i ,P i+1 }, with P i is the control point; Calculate the interpolation point coordinates according to the interpolation parameter t∈[0,n]: ; ; Where a=t / n, n=d / dmin, n is the total number of interpolated coordinate points, t is the serial number of the current coordinate point, a is the interpolation parameter, and the value of a is the serial number t of the current point divided by the total number of previous points n, indicating the relative position relationship of the current interpolation point on all endpoints. dmin is the minimum line segment pixel value.
4. The method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: The dynamic characteristics of the side adsorption menu bar include: By default, it is hidden at the left edge of the screen, and the width of the trigger bar is 5% of the screen width; Swipe the edge by 15 pixels or longer press the trigger bar for 1 second to call out the full menu bar, which expands to 20% of the screen width. The screen automatically retracts if the user's finger leaves the screen without any interaction for 2 seconds or touches the sketchpad.
5. The method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: Convert image data into a grayscale value map, including: The gray value is calculated using the weighted average method: Gray = 0.333R + 0.333G + 0.333B; Adjust the grayscale value based on the transparency weight: Gray.value = ((255 − Gray.value) × color.alpha) / 255; The grayscale value range is mapped to 0-255 levels, 0 represents black and 255 represents white; Among them, Gray.value is the adjusted grayscale value, and color.alpha is the transparency.
6. The method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: The grayscale value mapping table is converted into a G-code motion instruction of a laser engraving machine, including: Map the grayscale value to laser power using the formula: Power = (((Gray.value × (maxPower − minPower)) / 255) + minPower); Calculate pixel coordinates (sx, sy) based on the engraving area size and pixel sampling ratio res: sx=(position->x)*m_factorX; sy=(position->y)*m_factorY; Generate G code command: G1X[position->x]Y[position->y]S[Power]; Among them, Power is the optical power, S is the laser power parameter keyword, maxPower is the maximum power of the laser, minPower is the minimum power of the laser, position->x is the x-axis coordinate value of the engraving area, position->y is the y-axis coordinate value of the engraving area, sx is the x-axis coordinate value of the original image pixel, and sy is the y-axis coordinate value of the original image pixel.
7. The method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: The collaborative working mechanism of the real-time canvas and the optimized canvas includes: The real-time canvas displays unoptimized touch traces in real time; Optimize the canvas to display the smoothed path after the touch ends; Undo the last operation by switching canvases, preserving the original data.
8. The method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: The brush attributes include brush thickness, eraser size and color parameters.
9. The method for independently achieving drawing and engraving on an engraving machine according to claim 8, characterized in that: The settings of the brush properties include: 5-level brush thickness options, corresponding to line segment width w∈{1,2,3,4,5} pixels; 5-level eraser size options, corresponding to erasing radius r∈{5,10,15,20,25} pixels.
10. The method for independently achieving drawing and engraving on an engraving machine according to claim 1, characterized in that: Control the engraving machine to perform engraving operations, including: Divide the engraving area into grids, where each grid corresponds to a pixel of the image; Adjust the laser power according to the pixel grayscale value to control the engraving depth; Adapt to different resolution requirements through repeated spot sampling or interval sampling.