FreeCAD Logo FreeCAD 1.0
  • English Afrikaans Arabic Belarusian Catalan Czech German Greek Spanish Spanish Basque Finnish Filipino French Galician Croatian Hungarian Indonesian Italian Japanese Kabyle Korean Lithuanian Dutch Norwegian Bokmal Polish Portuguese Portuguese Romanian Russian Slovak Slovenian Serbian Swedish Turkish Ukrainian Valencian Vietnamese Chinese Chinese
  • Features
  • Download
  • Blog
  • Documentation
    Documentation index Getting started Users documentation The FreeCAD manual Workbenches documentation Python coding documentation C++ coding documentation Tutorials Frequently asked questions Privacy policy About FreeCAD
  • Contribute
    How to help Sponsor Report a bug Make a pull request Jobs and funding Contribution guidelines Developers handbook Translations
  • Community
    Code of conduct Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Calendar
  • ♥ Donate

Donate

$
SEPA Information
Please set up your SEPA bank transfer to:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Bank agency: BNP Paribas Fortis
Address: Rue de la Station 64, 1360 Perwez, Belgium

While Stripe doesn't support monthly donations, you can still become a sponsor! Simply make a one-time donation equivalent to 12 months of support, and you'll gain access to the corresponding sponsoring tier. It's an easy and flexible way to contribute.

If you are not sure or not able to commit to a regular donation, but still want to help the project, you can do a one-time donation, of any amount.

Choose freely the amount you wish to donate one time only.

You can support FreeCAD by sponsoring it as an individual or organization through various platforms. Sponsorship provides a steady income for developers, allowing the FPA to plan ahead and enabling greater investment in FreeCAD. To encourage sponsorship, we offer different tiers, and unless you choose to remain anonymous, your name or company logo will be featured on our website accordingly.

from 1 USD / 1 EUR per month. You will not have your name displayed here, but you will have helped the project a lot anyway. Together, normal sponsors maintain the project on its feet as much as the bigger sponsors.

from 25 USD / 25 EUR per month. Your name or company name is displayed on this page.

from 100 USD / 100 EUR per month. Your name or company name is displayed on this page, with a link to your website, and a one-line description text.

from 200 USD / 200 EUR per month. Your name or company name and logo displayed on this page, with a link to your website and a custom description text. Companies that have helped FreeCAD early on also appear under Gold sponsors.

Instead of donating each month, you might find it more comfortable to make a one-time donation that, when divided by twelve, would give you right to enter a sponsoring tier. Don't hesitate to do so!

Choose freely the amount you wish to donate each month.

Please inform your forum name or twitter handle as a notein your transfer, or reach to us, so we can give you proper credits!

CAM Postprocessor Customization

Introduction

FreeCAD uses as internal representation for the generated paths, so called G-codes. They can describe such things as: speed and feed rates, stopping the motor etc... But the most important thing is the movements they describe. These movements are rather simple: They can be straight lines or they can be circular arcs. More sophisticated curves such as B-splines are already approximated by FreeCAD\'s CAM Workbench.

What the postprocessor can do for you

Many mills use G-codes as well to control the milling process. They may look almost like the internal codes, but there may be some differences:

  • the machine can have a special startup sequence
  • it can have a special stop sequence
  • arcs can be defined with a relative or an absolute center
  • it may require line numbers in a certain format
  • it can used so called canned cycles for predefined subprocesses such as drilling
  • you might prefer your G-code output in either metric or imperial units.
  • it might be useful to perform a set of moves prior to calling for a tool change to make the action easier for the operator
  • you might wish to include comments for readability or suppress them to keep the program small
  • you might wish to include a custom header to identify or document the program for future reference.
  • ...

Furthermore there are other languages to control a mill, such as HPGL, DXF, or others.

The postprocessor is a program which translates the internal codes into a complete file, that can be uploaded to your machine.

Preparation for writing your own postprocessor

You may start with a very simple model showing how your machine reads straight lines and arcs. Prepare it with any program suitable for your machine.

A file for such paths starting at (0,0,0) and going towards Y would be helpful. Make sure it is the tool itself moving along this path, i.e. no tool radius compensation must be applied.

The path in FreeCAD would look like this. Please note the small blue arrow, it indicates the starting direction. For a very first go you may provide only one level in the XY-plane.

You can then have a look at the file and compare it to the output of existing postprocessors such as linux_cnc_post.py or grbl_post.py and try yourself to adapt them or you upload your to the Path/CAM forum to get some help.

Naming convention

The postprocessor can be placed in your FreeCAD macro directory. For a prefix the postprocessor should get the name _post.py. Please note that the postfix and extension, _post.py, have to be lower case.

The new name should be reflected at the head of the parser arguments list in the _post.py file, e.g.:

{{Code|lang=text|code= parser = argparse.ArgumentParser(prog="grbl", add_help=False) }}

If you are testing, place it in your macro directory. If it functions well, please consider providing it for others to benefit (post it to the FreeCAD Path/CAM forum) so that it can be included in the FreeCAD distribution going forward.

Other existing postprocessors

For comparison you may look at the postprocessors which come with your FreeCAD installation. They are located under the directory /Mod/CAM/Path/Post/scripts. Widely used are the linuxcnc and the grbl postprocessors. Studying their code can give helpful insights.

Programming your own postprocessor

This post discusses some internals from the linuxcnc postprocessors. The same strucure is used in other postprocessors as well.

Looking at linux_cnc_post.py, you\'ll see the export function (as of 0.19.20514 it\'s at line 156)

def export(objectslist, filename, argstring):
    # pylint: disable=global-statement
    ...
    gcode = ""
    ...
    ...

it collects step by step in the variable \"gcode\" the processed G-codes and handles the overall exporting of post-processable objects (operations, tools, jobs ,etc). Export handles the high level stuff like comments and coolant but any objects that have multiple CAM commands (tool changes and operations) it delegates to the parse function (as of 0.19.20514 it\'s at line 288).

def parse(pathobj):
    ...
    out = ""
    lastcommand = None
    ...
    ...

Similarly to the \"export\" function collects parse the G-codes in the variable \"out\". In the variable \"command\" the commands as seen in the CAM workbench\'s \"inspect G-code\" function are stored and can be investigated for further processing.

        for c in pathobj.Path.Commands:

            command = c.Name

It recognizes the different G, M, F, S, and other G-codes. By remembering the last command in the variable \"lastcommand\" it can suppress subsequent repetitions of modal commands.

Both parse and export are just formatting strings and concatenating them together into what will be the final output.

You\'ll see that both functions also call the \"linenumber()\" function. If the user wants line numbers, the linenumber function returns the string to stick in to the appropriate spot, otherwise it returns an empty string so nothing is added.

Related

  • [CAM PostProcess](wiki-test2.php?gitpage=CAM_Post)

{{CAM_Tools_navi}}


⏵ documentation index > CAM > CAM Postprocessor Customization

This page is retrieved from https://github.com/FreeCAD/FreeCAD-documentation/blob/main/wiki/CAM_Postprocessor_Customization.md

Get in touch!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© The FreeCAD Team. Homepage image credits (top to bottom): ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

This project is supported by: , KiCad Services Corp. and other sponsors

GitHubImprove this page on GitHub