Skip to content

compas_cnc.postprocessor.Postprocessor ¤

Postprocessor(tool=None, tool_number=1, feed=200.0, plunge_feed=None, spindle_speed=12000, coolant='mist', rapid_z=None, material='Aluminum', stock_size=(300.0, 200.0, 20.0), program='2D Contour', precision=4, travel=CARVERA_AIR_TRAVEL, margin=0.0, on_exceed='raise')

Convert tool-path polylines into Carvera Air G-code and write a .nc file.

The Carvera / Carvera Air desktop CNC (Makera) runs a Smoothieware-derived controller that reads ordinary RS-274 G-code. This post-processor turns the tool-CENTRE polylines produced by the toolpath_2d_* generators (or any merged path from :func:toolpath_merge) into the dialect the machine expects: a % start marker, a commented header (units, tool change, coolant/air, spindle), a body of G1 linear moves, and a shutdown footer.

The path already encodes its own safe-Z approach, plunge, cut and retract, so every motion is emitted as a G1 linear feed after a single initial G0 lift to the rapid clearance plane -- exactly as a hand-written Carvera program does. Only the axis words that CHANGE between consecutive points are written (modal coordinates), so a move that keeps Z prints just X.. Y...

Before any G-code is written the path is checked against the machine travel envelope (:data:CARVERA_AIR_TRAVEL, the factory soft-endstop spans -- the practical hard limit, since the far end of each axis has no switch). A job whose bounding-box span overruns the reach raises by default (see :attr:on_exceed), so an out-of-bounds program is caught here instead of as a soft-limit halt mid-cut.

The output reproduces this shape::

%
; 3-Axis
; Material: Aluminum
; Stock Size: 300(X) * 200(Y) * 20(Z) mm
; Tool List
; T1-3.175*19mm Flat End
; Path List
; [T1]2D Contour
G90 G21              ; Absolute positioning, units in millimeters
T1 M6                ; Tool change to Tool 1
M7                   ; Coolant ON (mist)
S12000 M3            ; Spindle ON clockwise at 12000 RPM
G0 Z50
G1 F200
G1 X-149.8351 Y36.0727
G1 Z20
G1 X-149.8351 Y36.0727 Z-18.8
...
M9        ; Turn off coolant
M05       ; Stop the spindle
G28       ; Return all axes to the machine home position
M02       ; End of program

Parameters:

  • tool (:class:`compas_cnc.tools.Tool`, default: None ) –

    The cutting tool. Its name, diameter and height fill the tool-list comment (T{n}-{diameter}*{height}mm {name}). If omitted a generic description is written.

  • tool_number (int, default: 1 ) –

    Carvera tool-changer slot, used in the T{n} M6 tool change and the header comments. Defaults to 1.

  • feed (float, default: 200.0 ) –

    Cutting feed rate (mm/min) set once with G1 F{feed}. Defaults to 200.

  • spindle_speed (int, default: 12000 ) –

    Spindle RPM for S{rpm} M3. Defaults to 12000.

  • coolant (str | None, default: 'mist' ) –

    "mist" / "air" -> M7, "flood" -> M8, None (or False) turns coolant off entirely (no M7/M9). Defaults to "mist".

  • rapid_z (float, default: None ) –

    World-Z for the opening G0 lift to the travel plane. Defaults to the highest Z in the path (the tool-path's own safe traverse height), so the first cutting move starts from a known clearance height.

  • material (str, default: 'Aluminum' ) –

    Stock material, written into the header comment. Defaults to "Aluminum".

  • stock_size (tuple(float, float, float) | None, default: (300.0, 200.0, 20.0) ) –

    (X, Y, Z) stock dimensions in mm for the header comment. None omits the line. Defaults to (300, 200, 20).

  • program (str, default: '2D Contour' ) –

    Path-list label in the header (; [T{n}]{program}). Defaults to "2D Contour".

  • precision (int, default: 4 ) –

    Decimal places for coordinates; trailing zeros are stripped. Defaults to 4.

  • travel (tuple(float, float, float) | None, default: CARVERA_AIR_TRAVEL ) –

    Per-axis (X, Y, Z) machine reach in mm the job must fit within. A None entry skips that axis; travel=None disables the check entirely. Defaults to :data:CARVERA_AIR_TRAVEL (302, 212, 121). Pass your own jogged values (Makera advise verifying per machine) or :data:CARVERA_AIR_WORKAREA for the conservative rated area.

  • margin (float, default: 0.0 ) –

    Safety margin in mm subtracted from every travel axis before checking, so the job must fit with this much to spare. Defaults to 0.0.

  • on_exceed (str, default: 'raise' ) –

    What to do when the path overruns the envelope: "raise" (default) a :class:ValueError, "warn" a :class:UserWarning, or "ignore".

Attributes:

  • tool, tool_number, feed, spindle_speed, coolant, rapid_z, material,
  • stock_size, program, precision, travel, margin, on_exceed

    The configured options above.

body ¤

body(points)

Motion block printing X, Y and Z on EVERY line, so the height is explicit.

Moves that reach the safe plane (rapid_z) are non-cutting retracts / repositions and go out as rapid G0; everything below it cuts and goes out as G1 at feed (or plunge_feed for a straight Z-down plunge). The feed word is modal, emitted only when it changes.

check_limits ¤

check_limits(*toolpaths)

Travel-envelope violations for toolpaths -- one dict per axis whose path SPAN exceeds the machine reach.

Returns a list with an entry {"axis", "min", "max", "span", "limit", "over"} for every axis where the bounding-box span is larger than :attr:travel (shrunk by :attr:margin); an empty list means the job fits. The SPAN (not the absolute coordinate) is checked because the work origin is set on the machine at setup, so what matters at post time is whether the part fits the reachable travel -- the firmware soft-endstop span, which on the Carvera Air is the practical hard limit (the far end of each axis has no switch, only a crash beyond it).

footer ¤

footer()

Shutdown block (coolant off, spindle stop, home, end of program).

header ¤

header(points)

Header block (% marker, comments, units, tool change, coolant, spindle).

to_gcode ¤

to_gcode(*toolpaths)

Full .nc program text for one or more tool-paths / polylines.

Each argument may be a toolpath_2d_* object (anything with a .path) or a raw :class:compas.geometry.Polyline; they are concatenated in order. The path is checked against the machine travel envelope first (see :attr:on_exceed).

write ¤

write(filepath, *toolpaths)

Write the .nc program for toolpaths to filepath (.nc added if missing). Returns the resolved :class:pathlib.Path.