Skip to content

CAM: Get Fanuc post processor working and implement several improvements#25850

Merged
sliptonic merged 15 commits intoFreeCAD:mainfrom
petterreinholdtsen:cam-fanuc-post-fixes
Dec 12, 2025
Merged

CAM: Get Fanuc post processor working and implement several improvements#25850
sliptonic merged 15 commits intoFreeCAD:mainfrom
petterreinholdtsen:cam-fanuc-post-fixes

Conversation

@petterreinholdtsen
Copy link
Contributor

@petterreinholdtsen petterreinholdtsen commented Dec 1, 2025

CAM: Made Fanuc post processor compatible with FreeCAD 1.1.
CAM: Adjusted Fanuc post processor to move Z to tool change position before M6
CAM: Added test of Fanuc post processor
CAM: Made Fanuc post processor compatible with FreeCAD 1.0.
CAM: Switched Fanuc post processor to end program with M30, not M2.
CAM: Adjusted Fanuc post processor to use M05 consistently everywhere.
CAM: Provide correct and more relevant header from Fanuc post processor
CAM: Avoid Z overtravel error on Fanuc tool changes
CAM: Avoid adding trailing space to all M6 lines.
CAM: Corrected Fanuc post processor M3 handling
CAM: Made empty spindle at the end optional in Fanuc CAM post processing script
CAM: Adjusted Fanuc post processing script to always start with a percent
CAM: Adjusted Fanuc post processing script to not inherit behaviour between calls
CAM: Print "Show editor" status boolean as string, not integer

Issues

Fixes #14016
Fixes #25723
Fixes #25677

@github-actions github-actions bot added the Mod: CAM Related to the CAM Workbench label Dec 1, 2025
@petterreinholdtsen
Copy link
Contributor Author

This pull request replaces #25722, #25769, #25768, #25799, #25806 and #25698, as requested in #25806. In addition it contain a few more cleanups and is tested on a machine with FreeCAD 1.0. There are still a hickup with tool changes (only work if manually moving the Z axis to its machine zero position), which I hope to figure out later.

@petterreinholdtsen petterreinholdtsen force-pushed the cam-fanuc-post-fixes branch 2 times, most recently from c4a48ff to 708e353 Compare December 1, 2025 15:54
@chennes
Copy link
Member

chennes commented Dec 1, 2025

@LarryWoestman can you look at this?

Copy link
Contributor

@LarryWoestman LarryWoestman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me.

@petterreinholdtsen
Copy link
Contributor Author

petterreinholdtsen commented Dec 2, 2025 via email

@Connor9220
Copy link
Contributor

a15d9e7 CAM: Adjusted Fanuc post processor to move Z to tool change position before M6

Is this something that needs to be handled at the post processor level? That manual is talking about MDI mode from what I can tell. Does this controller not handle this automatically from a program? Is this a specific version of this controller? I'll bring up fusion and see if I have a post processor and post a program for a Fanuc controller.

@petterreinholdtsen
Copy link
Contributor Author

petterreinholdtsen commented Dec 7, 2025 via email

This get rid of a Python style warning and make the output easier
to understand.
…etween calls

Reset line number when using --line-numbers.  Restore all default values when a
command line argument is not used.

This helps the test scripts ensure that the arguments passed during one test is the only
one taking effect during this test.
…cent

The percent signal to the machine that a program follows, and is not
part of the header but a required part when uploading programs into
the machine.
…ing script

Some Fanuc machines do not understand the 'M6 T0' instructions in the
preamble.  Move it out of the preamble and controlled by a new
command line argument --no-end-spindle-empty for the machines
where running to cause a "Tool Number Alarm" and the program to crash
as tool zero is not a valid tool.

Fixes: FreeCAD#25677
The thread tapping implementation in the Fanuc post processor change
behaviour of M3, G81 and G82 when the tool ShapeID matches "tap".
but the code not not expect that the parse() method will be
called with two different classes as arguments.

Rewrite the M3 handling to handle ToolController arguments
instead of crashing with an AttributeError.

Issues:

Fixes FreeCAD#14016
Fixes FreeCAD#25723
The Fanuc post processor add a trailing space to all M6 lines.
This make it problematic to write test for the generated output,
when compiled with the automatic policy enforcer on github
removing trialing space from the expected output.  Avoid the
problem by removing the trailing space from the generated
output.
Enabling tool height compensation will cause the axis to move up
the length of the tool, which will cause a Z overtravel error when
the tool change take place close to the top of the machine.  To
counter this move, ask the machine to move its commanded position
down the length of the tool height, which in effect causes no upward
movement after the tool change.  The FreeCAD#4120 variable contain the
current tool number, and FreeCAD#2000 - #20XX contain the tool heights.
Fanuc only understand upper case letters, no point in providing the
file name in lower case letters.  The provided file name is always "-",
so drop it completely. The first comment is presented in the Fanuc user
interface, it should get more relevant content.

Dropped useless semicolon.
The difference according to the documentation is that M30 will rewind
the paper tape while M2 will not.  The effect on a CNC from 1994 is
that M30 turn on the indicator light marking that the program has
completed, while M2 do not, and the light is wanted to know when
the machine is done.
Several methods introduced 2025-05-04 are preferred, but the methods
available in version 1.0 are used as fallback sources
for active status and coolent enabled.
Used TestMach3Mach4LegacyPost.py as the starting point with input from
other test scripts too.

The test demonstrate a fix for FreeCAD#25723, as the Fanuc post processor has not been not updated to the latest changes in
the Path module.

This is related to FreeCAD#24676, where thread tapping was added to LinuxCNC, but the equivalent code in the Fanuc
postprocessor were not adjusted to cope, and FreeCAD#25677 where it was observed that the Fanuc postprocessor was
broken in versions 0.20 and 1.0.

Added MockTool class to provide ShapeName to fanuc_post.py, used to
convert drill cycles to threading cycles if the tool has shapeid "tap".
…before M6

A "G28 G91 Z0" is needed according to testing and page 195 (6-1-2 Procedure for ATC operation) in
<URL: https://www.milco.bg/source/Technical%20Service/Documentation%20Dahlih/MCV%20510_1250B%20Operation%20and%20maintenance%20manual%20V2_2.pdf >
to get the spindle into the correct position for a tool change.
Use setPlainText() if available, otherwise use setText().
Workaround for a regression from FreeCAD#23862.
Copy link
Contributor

@LarryWoestman LarryWoestman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me.

Copy link
Contributor

@Connor9220 Connor9220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@sliptonic sliptonic merged commit 96d1084 into FreeCAD:main Dec 12, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from Merge Meeting to Done in Merge Queue Dec 12, 2025
@github-actions
Copy link
Contributor

Backport failed for releases/FreeCAD-1-1, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin releases/FreeCAD-1-1
git worktree add -d .worktree/backport-25850-to-releases/FreeCAD-1-1 origin/releases/FreeCAD-1-1
cd .worktree/backport-25850-to-releases/FreeCAD-1-1
git switch --create backport-25850-to-releases/FreeCAD-1-1
git cherry-pick -x 533e957f80b4fae2fcd64d0c0631665af9d3e254 ef794c31bd85cd2d5a11df47b8a07e93e8982be3 0cdf9abc4b3af866928960a07fc324c5bd67583d 87185c8135e6ff8a2b1cb7efda0576208a368def 06fe4b37bac410d0c96bf3003eff4f6b8cf3fd5b 3c5f39c0caf084bb88779cf105b54e09ea120a6a bcb569977d3072ecbdc79cf3430fd48ea26447d9 e4862572aecd5ca2878c3d199724a5cf3d317932 4c18ac6c5480f741f0a2ad1594e8aa67a23b141f 8b500ca9a36c7e12e2f2f63161b06a669b237cdd 34a53018624ffdddf0eecbcdbbec22141353a7bf 38c3eebd7ab81756b6d6d29039c375f0d08dbc9d e6c95dbb9158dd48957b073446dd1784eba6ac52 8386f1394e4c88e56132e68888076c48c8f3a6ec 9c78ced00c67a6c2554d8fbfbeb84282a90d3363

@petterreinholdtsen petterreinholdtsen deleted the cam-fanuc-post-fixes branch December 12, 2025 17:06
@petterreinholdtsen
Copy link
Contributor Author

Is there anything I can do or should do to get this included in the 1.1 release?

@Connor9220
Copy link
Contributor

@sliptonic @maxwxyz Can we see about getting this backported to 1.1?

@maxwxyz maxwxyz added the Approved: Code Quality The PR was checked for code quality and approved label Dec 24, 2025
@maxwxyz
Copy link
Collaborator

maxwxyz commented Dec 24, 2025

The automatic backport failed. Ideally you can open a separate PR against the 1-1 branch.

@petterreinholdtsen
Copy link
Contributor Author

petterreinholdtsen commented Dec 24, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved: Code Quality The PR was checked for code quality and approved backport releases/FreeCAD-1-1 Applied to a PR that is on main to trigger the automatic creation of another PR onto 1.1 Mod: CAM Related to the CAM Workbench Type: Bug This issue or PR is related to a bug

Projects

Archived in project
Archived in project

6 participants