A Wish for a Path WB: G41/G42 commands

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
liutas4x4
Posts: 61
Joined: Sat Jul 16, 2016 9:16 am

A Wish for a Path WB: G41/G42 commands

Post by liutas4x4 »

Hi,

Modern CNC machines have their own Tool Offset Table, where Height and Diameter compensation listed. Even more, Wear of the Tool column at this Table helps us to compensate even hardly used or refurbished tool.

So, it will be very nice to create a tool path as "compensated", but not trough changing of points on a path, as it is for now, but trough G41/G42 command. Where, of course, parameter D should be used as compensation parameter, with ability to choose it as Diameter of the tool used, or Radius of it.

Cheers,
Eugenijus.
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: A Wish for a Path WB: G41/G42 commands

Post by chrisb »

I like G41/G42 because they simplify the G-code. Think of a square profile, which is to be milled at the outside. Without G42/42 a path contains four G1 and four G2/G3 commands. When using G41/42 it boils down to the very easy to understand four G1 commands where all points to be programmed are real points of the square; that makes such G-codes easy to validate.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
liutas4x4
Posts: 61
Joined: Sat Jul 16, 2016 9:16 am

Re: A Wish for a Path WB: G41/G42 commands

Post by liutas4x4 »

Exactly.

When your code includes G41/G42, you are on real points of the path of a tool. It is quit to impossible to track some 0.XYZABC differences on the fly.
At the case of G41/42 you leave them for compensations by controller.

And even more:

When you need to leave some material for finish, you can just issue G41 D01 (for T01) with diam offset at the Table of Offsets, say, 0.2 more than actual tool diameter. At a second pass you just switch to G41 DXX (for the same tool T01), where DXX is described as real offset of the tool used. Using same sub for the contour twice, you can obtain quick and predictable result.

Cheers,
Eugenijus.
Last edited by liutas4x4 on Mon Aug 26, 2019 12:22 pm, edited 2 times in total.
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: A Wish for a Path WB: G41/G42 commands

Post by chrisb »

The trick with different tool diameters can be performed in FreeCAD as well.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
liutas4x4
Posts: 61
Joined: Sat Jul 16, 2016 9:16 am

Re: A Wish for a Path WB: G41/G42 commands

Post by liutas4x4 »

It is not a trick on CNC. It is a good practice.
But working on limited G-code set is not.

FreeCAD can not (and seems not been intended for) replace SolidWorks. And also SolidCAM or MasterCAM. It is not tool for items, produced in big volumes.
Exactly because of his target, all 'things' produced by FC must to be clear and readable.

Some improvements at the part of Path should be implemented too.

Cheers,
Eugenijus.
RatonLaveur
Posts: 991
Joined: Wed Mar 27, 2019 10:45 am

Re: A Wish for a Path WB: G41/G42 commands

Post by RatonLaveur »

I agree with liutas' suggestion. Tool compensation can and should be used for best practice with G41/G42/G43 and the GCode should be True to the shape of the part.

That being said, the existing approach of compensating the Path itself is probably more helpful to the hobbyist who has one tool in his CNC router at any given time.

The best in my humble opinion would be to have a choice for CAM compensation (the path is compensated and a G40 command is issued in pseudo code header) or NC compensation (the path is true to geometry and a G41 to G43 compensation is issued). Which is similar if you will to Software or Hardware rendering...terminology at the discretion of the community.
liutas4x4
Posts: 61
Joined: Sat Jul 16, 2016 9:16 am

Re: A Wish for a Path WB: G41/G42 commands

Post by liutas4x4 »

... and Negative Offset for the High of Tool too!

Look: not every machine is allowing you to touch a stock with a spindle. On, say, 4-axis systems some coolant nozzles or even Z body can reach spindle of the 4th axis when you go to Z0 without BT. More, Z spindle have a tooths for BT positioning and you can not reach G54's Z0 on some pre-processed stock.
In this case a Master Tool - long enough cylindrical body - is used. You set it's Z0 to the upper surface of a stock, and all High Offsets for each tool are been calculated from there. It simplifies setup.

Cheers,
Eugenijus.
Satorus
Posts: 5
Joined: Tue Mar 30, 2021 5:37 am

Re: A Wish for a Path WB: G41/G42 commands

Post by Satorus »

Hello Eugenijus,

I had the exact same wish as you and was searching for a solution for quite some time. Since I could not find any sufficient solution I decided to add it into my post-processor. The compensation is just working for profile cuts and when you uncheck the use tool compensation.

In my post-processor file (mach3_4) I have searched following line which is parsing the X,Y,Z etc. movements:

Code: Select all

        # process the operation gcode
        gcode += parse(obj)
I have added the following code before the line which will add either G41 or G42 before starting the first movement of the operation:

Code: Select all

        # Add G41/G42
        if hasattr(obj, "Side") and hasattr(obj, "Direction") and obj.UseComp == False:
            if (obj.Side == 'Inside' and obj.Direction == 'CW') or (obj.Side == 'Outside' and obj.Direction == 'CCW'):
                gcode += linenumber() + 'G42' + '\n'
            if (obj.Side == 'Outside' and obj.Direction == 'CW') or (obj.Side == 'Inside' and obj.Direction == 'CCW'):
                gcode += linenumber() + 'G41' + '\n'
        
        # Add G41/G42 if Obj.Base is used (Path - Dressup)
        if hasattr(obj, 'Base') and  hasattr(obj.Base, "Side") and hasattr(obj.Base, "Direction") and obj.Base.UseComp == False:
                if (obj.Base.Side == 'Inside' and obj.Base.Direction == 'CW') or (obj.Base.Side == 'Outside' and obj.Base.Direction == 'CCW'):
                    gcode += linenumber() + 'G42' + '\n'
                if (obj.Base.Side == 'Outside' and obj.Base.Direction == 'CW') or (obj.Base.Side == 'Inside' and obj.Base.Direction == 'CCW'):
                    gcode += linenumber() + 'G41' + '\n'
And this after the line which will parse G40 after the operation:

Code: Select all

        # Cancel the radius compensation after the operation
        if hasattr(obj, "Side") and hasattr(obj, "Direction") and obj.UseComp == False or hasattr(obj, 'Base') and hasattr(obj.Base, "Side") and  hasattr(obj.Base, "Direction") and obj.Base.UseComp == False:
            gcode += linenumber() + 'G40' + '\n'
Basically it is looking for the arguments "Side" (cutting side), "Direction" (CW or CCW) and the "UseComp" in the Objects and in Object.Base if a path dressup is used. If all arguments are found it will add the G41 or G42 depending on the cutting direction and if it is outside or inside cut.

I have tried it at the first two parts and it seem to work so far.
Please check the g-code before using it.

Hope I could help someone with this.

Greetings!
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: A Wish for a Path WB: G41/G42 commands

Post by chrisb »

It would be great to have these integrated in the Path operations rather than the postprocessor :mrgreen: .
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Satorus
Posts: 5
Joined: Tue Mar 30, 2021 5:37 am

Re: A Wish for a Path WB: G41/G42 commands

Post by Satorus »

Hello chrisb,

yes you are right. First I did the modification in the Profile Operation. But than the PathEntryDressup for example ignored the G41/G42 commands which was added in the profile operation. That's why I have decided to add it into my post processor.

Additionally I found out that some dressup paths do change the cutting direction of the tool which will cause a crash I guess. So I have added an easy X and Y coordinate comparison to the post processor to print an error and stop the g-code processing when a forward and backwards cutting is detected while it is in the G41 or G42 mode.

If anyone knows a better solution to check this I would appreciate a hint.
But so far the post processing is working quite good.

I have attached my modified post processor if anyone is interested.

Greetings!
mach3_mach4_modification_G41_G42post.py
(19.74 KiB) Downloaded 66 times
Post Reply