Examining and Adjusting G-code

Hello All; After avoiding it for as long as I reasonably could, I have finally decided to delve into the mysteries of G-code.

I have some G-code that I would like to adjust for SM1. My code sample starts like this…

G21
G90
G1 Z3.810 F228.6
G0 X43.228 Y12.499
G1 Z-0.700 F228.6

A whole string of G1 commands follow and these are interspersed with the occasional G0 command. At the end of the file the last G1 command is followed by…

G21
G90
G1 Z3.810 F228.6
G0 X0.000 Y0.000
G4 P0.1

My first observation is this:
All Luban generated CNC files have an extensive header and the last line states ;Header End I guess that any comment preceded by a semicolon is the computer marking the term as information rather than a command to be executed.

The code I want to adjust has no header information (not even the software that generated it is mentioned). Does this have any implication for where the module head starts?

I would like SM1 to start at 0,0 once I know where that is. Is it adjustable in G-Code? Is the 0,0 (or starting point) in SM1 always at the centre of the table? Could the G-code start the machine in the bottom left hand corner for example?

Here is what I think I know.
G21 specifies metric units
G90 specifies absolute coordinates
G1 Specifies a coordinated movement
F228.6 specifies the feed rate in millimetres per minute
G4 I believe specifies Dwell time (pause or halt)
I have no idea about what the associated P0.1 means.

If I were to specify relative coordinates (G92 instead of G90) at the beginning of the code, would it be possible to adapt the code to start at the specified origin point… which is what I am thinking the jogging of the module head to the geometric centre of the workpiece achieves.

The obvious corollary is what are the coordinates for SM1 at the centre of the table? Are they actually 0,0 for X & Y or is there another coordinate set that I could use to ensure the code starts with my workpiece at the centre of its travel?

Any and all answers would be most welcome. Thank you.

A couple of comments, G90 & G91 are modal, they remain in effect until you switch to the other. You have to be very careful using both in a program. Normally one will turn on relative mode, make some relative moves and then switch back to absolute mode.
G92 lets you set the position of the current location to the X, Y, Z, & E values passed in, you can adjust one or more at a time.
G4 is a pause and you can use “S” for seconds or “P” for milliseconds. So S1 is equal to P1000.
You can find a link to syntax for all the G & M codes in the SnapLinks page.

1 Like

Thank you very much, Tony. I think in time I can learn enough of the syntax to resolve my own problems. I wonder if my simple need is possible… to run the code from Easel on SM1. The reason i like the Easel interface is although it is very simple, it lets you visualise the output really simply. So holes of different sizes, shapes and placed at different depths on the same workpiece appears to be childishly simply in Easel.

I have generated some G code in the online application (Easel) and although it seems to run well (Camotics demonstrates that the code is able to run normally) the starting location appears to be set to top right. Easel is set to other GRBL machine and the code to control the CNC carving is generated as an exported file. This is the code I would like to run on SM1. The sample of the first few lines at the end of this post does not make location sense to me. I suppose I was expecting 0,0 as the starting location, which I thought would then be based upon the set origin at the start off a work run. That somehow the code would always look for the set origin.

You will see from the attached image of my test piece that I am only trying to run code that covers a 98mm square, which is well inside the 130mm table. In Luban 3.7.0, the image shows me what I expected to see but it is set in the upper right quadrant rather than at the centre. I have no idea how to move the file to the centre of the Luban workspace, after having the software open a gcode file, which I believe would solve the code problem. The Luban screen shot shows how the file is located but the X, Y and Z parameters are not adjustable on this screen.

I am not using clamps but a jig so that I only have screwheads at each corner 5mm in from the edges. (see attached image) This means I should have about 120mm square to play with safely. I have my square set to the centre of the table and I set up the CNC module origin as dead centre of my workpiece and just 0.1mm above it.

A test of the code ( first section below) sends the CNC bit to the upper right quadrant after I have set origin to the centre. Is there a way to centre the code in Luban or what must I set in the code sample so that SM1 knows what I want it to do?

G21
G90
G1 Z3.810 F228.6
G0 X43.228 Y12.499
G1 Z-0.700 F228.6
G1 X43.126 Y13.703 F762.0
G1 X43.027 Y12.475 F762.0
G1 X43.114 Y11.340 F762.0
G1 X43.228 Y12.499 F762.0
G1 X43.227 Y10.674 F762.0
G1 X43.421 Y11.216 F762.0
G1 X43.546 Y12.493 F762.0
G1 X43.450 Y13.748 F762.0
G1 X43.231 Y14.310 F762.0
G1 X42.988 Y14.275 F762.0

Any and all assistance is very welcome.