Who knows Python (FreeCAD PostProcessor)

More
17 Nov 2023 00:59 #285675 by blazini36
FreeCAD has experimental 4th axis support but it's basically hidden. Since it's really the only CAM game in town for Linux I tried it, the previewed toolpath looks pretty good but the rotary (A) axis output is bad.

I realised if I output in millimeters, the A axis output is fine, it looks like degrees. My machine is setup in inches so when I output the inches gcode the A axis output is basically divided by 25.4. So I need to get this postprocessor script to ignore the A axis when it's converting to inches. I'm not a Python guy so I'm looking for help here.

 

File Attachment:

File Name: linuxcnc_post.py
File Size:15 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 08:04 #285707 by Aciera

So I need to get this postprocessor script to ignore the A axis when it's converting to inches.

I'm not a python expert either but I don't see anything that looks like unit conversion in that script.

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 09:26 #285712 by blazini36

So I need to get this postprocessor script to ignore the A axis when it's converting to inches.
I'm not a python expert either but I don't see anything that looks like unit conversion in that script.

AFAICT your right, looks like it's passing the inch argument back to Freecad and it's doing the conversion. I figured maybe something could be passed to tell it not to convert the rotary axis, or at the very least multiply the rotary outputs by 25.4 to convert it back to degrees.

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 09:55 #285714 by tommylight
There is also BlenderCAM, single word, but i have no idea what it does.

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 10:06 #285717 by Aciera
Actually I think I was wrong, looking at this again I think I may have found the conversion part after all:
       
                            pos = Units.Quantity(
                                c.Parameters[param], FreeCAD.Units.Length
                            )
                            outstring.append(
                                param
                                + format(
                                    float(pos.getValueAs(UNIT_FORMAT)), precision_string
                                )
                            )

When processing the 'A' word then 'param' would be equal to 'A' and 'pos' would be the angle value (wrongly getting divided by 25.4) so may be you could add an if statement that would multiply the pos value by 25.4 IF param == 'A'.

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 10:13 #285719 by Aciera
Maybe something like this as hack and slash attempt:
                            pos = Units.Quantity(
                                c.Parameters[param], FreeCAD.Units.Length
                            )

                            if param == 'A':
                               pos = pos * 25.4

                            outstring.append(
                                param
                                + format(
                                    float(pos.getValueAs(UNIT_FORMAT)), precision_string
                                )
                            )
The following user(s) said Thank You: blazini36

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 18:09 - 17 Nov 2023 19:14 #285763 by blazini36
Hey that actually works, that's great man thanks. Since I use inches it works out but I tested it without the --inches flag and it still multiplies by 25.4 so if using mm this one would have the opposite problem.

Is it possible to have that if statement consider the --inches parser argument?

Didn't mention it in the first post but the A-axis Gcode  FreeCAD was outputting also ran -180 to 180. I don't know if that's normal or if LinuxCNC can be configured to use that setup. Mine is setup as "wrapped rotary"  and it will travel infinite degrees in either direction. The code it was originally outputting looked like it would travel halfway around the part and then travel back in the other direction on my setup. One of the guys on the FreeCAD forum fixed that in the PP script so it now outputs 0-360 then returns to 0 for the next pass, it looks more convincing now.

So this is the current script with Aciera's changes as well as what bmsaus4ax on the FreeCAD forum did. 
 

File Attachment:

File Name: linuxcnc_f..._post.py
File Size:15 KB
Attachments:
Last edit: 17 Nov 2023 19:14 by blazini36.

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 19:25 #285768 by Aciera
Sure try this:
                        else:
                            pos = Units.Quantity(
                                c.Parameters[param], FreeCAD.Units.Length
                            )

                            if param == 'A' and UNITS == 'G20':
                               pos = pos * 25.4

                            outstring.append(
                                param
                                + format(
                                    float(pos.getValueAs(UNIT_FORMAT)), precision_string
                                )
                            )

Please Log in or Create an account to join the conversation.

More
17 Nov 2023 21:26 #285781 by blazini36
Hey much obliged,

That seems to do the trick for mm and inches. I think I can run this output after I manually fix the feedrate.

Gonna post this on the freecad forum as well since it might be helpful.
 

File Attachment:

File Name: linuxcnc_f...11-17.py
File Size:16 KB
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: Skullworks
Time to create page: 0.147 seconds
Powered by Kunena Forum