532,030 active members*
3,681 visitors online*

# Thread: Arithmetic expression is gcode?

1. ## Arithmetic expression is gcode?

Can I use arithmetic expressions in gcode for CNCUSB?

For example: G1 [Z]+0.1

I am thinking about this as a way to position my laser cutter while still retaining the ability the adjust Z height. This would allow me to engrave along a curved surface while maintaining a consistent depth of cut. Is there a better way to do this?

2. ## Re: Arithmetic expression is gcode?

One way to engrave a non-flat part is to probe the surface and adjust the G-code for the height variations. A program called AutoLeveller does just that (and does it quite well). Do you have a way to attach a probe to your machine?

3. ## Re: Arithmetic expression is gcode?

TNG has very powerful arithmetic that you can use in g-code. However I don't understand how this will help you in your case.
You can use Warp feature to engrave curved surfaces. You don't need AutoLeveller if you use Warp.

4. ## Re: Arithmetic expression is gcode?

I apologize for not being clearer. I am thinking specifically about engraving on non-planar surfaces as part of the creation process. Example: I made a loose change dish for my son, and I wanted to engrave scripture in the bottom as just another toolpath within a single project. Since the g-code already contains the contour information, It seems (to my simple mind) like it would be more straightforward to use mathematical expressions to keep the laser head 10 mm above the workpiece surface as the head moves along. But maybe I'm approaching it wrong...

5. ## Re: Arithmetic expression is gcode?

I'm afraid what are you planning to do is way beyond "arithmetics in G-code". Imagine you are engraving a straight line across your dish - the Z would have to change constantlty as a (non-linear) function of X and Y. This math needs to be done either on the controller level (this is what the Warp feature does, I presume), or in a 3D CAM program, or in a program like Autoleveller.

6. ## Re: Arithmetic expression is gcode?

Please send me dish and scripture g-code.
I'll check if something can be one.

7. ## Re: Arithmetic expression is gcode?

Here is the file. I completed the initial project before I have a laser, so I used a small-diameter bit to engrave the scripture. Now that I have a laser, I would like to use it for engravings since it has a significantly higher resolution.

Thank you for you trouble!

8. ## Re: Arithmetic expression is gcode?

I just realized the first file I uploaded was the dish and engraving as a single file. So here they are as separate files (in a single zip):

9. ## Re: Arithmetic expression is gcode?

I am embarrassed at how difficult I was making this. After some more digging, I realized I could use a combination of G49 and G42 to accomplish exactly what I wanted to do. Thanks to all who used some of their limited time on my (really simple) problem...