gcode_reader.emulate.extruders

Classes

Extruder

A generic base class for an additive manufacturing extruder.

LinearScrewModel

A linear model for a screw extruder.

MeltPumpExtruder

A special ScrewExtruder where the control value directly specifies deposition volume.

MeltPumpModel

A special model where the control value directly specifies deposition volume.

ScrewExtruder

An extruder controlled by screw RPM, which processes pellets into a bead.

ScrewModel

(Abstract) Defines the physical calculation interface for a screw extruder.

StepperExtruder

An extruder controlled by filament length, common in FDM/FFF printers.

Module Contents

class gcode_reader.emulate.extruders.Extruder(options: gcode_reader.emulate.machine_options.MachineOptions = None)[source]

Bases: gcode_reader.emulate.tools.Tool

A generic base class for an additive manufacturing extruder.

This class provides the core structure for tracking extrusion state, such as the last deposited volume and extrusion rate. It is not meant to be used directly but should be subclassed to implement a specific physical model for a given extrusion technology.

last_deposited_volume

The volume of material deposited by the most recent commands.Extrude command.

Type:

float

last_extrusion_rate

The control value for the extrusion rate (e.g., RPM, mm/s, volumetric flow) set by the most recent command.

Type:

float

Initializes a new Extruder instance.

Parameters:

options (MachineOptions) – Configuration settings for the machine and this tool.

process_command(command: gcode_reader.emulate.commands.Command, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Processes a command to update the extruder’s state.

If the command is an commands.Extrude command, this method dispatches to the appropriate _calc_* method to update the tool’s state based on the extrusion model implemented by the subclass.

Parameters:
  • command (Command) – The command to process.

  • process_data (AdditiveProcessData) – The data object to populate with post-processing information.

Returns:

The updated AdditiveProcessData object.

reset_history()[source]
property extrusion_type
last_bead_area: float = None
last_deposited_volume: float = 0.0
last_extrusion_rate: float = 0.0
property relative_extrusion
class gcode_reader.emulate.extruders.LinearScrewModel(nozzle_diameter=0, displacement=1.0)[source]

Bases: ScrewModel

A linear model for a screw extruder.

This model assumes a direct, linear relationship between the screw’s rotational speed (RPM) and the volumetric flow rate: Flow Rate (units³/min) = RPM * displacement.

Initializes the screw model’s physical parameters.

Parameters:
  • nozzle_diameter (float) – The diameter of the extruder nozzle (in length units).

  • displacement (float) – The volume of material extruded per full revolution of the screw (e.g., in units³/revolution).

calc_deposited_volume(extruder, command: gcode_reader.emulate.commands.Command, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Calculates deposited volume based on RPM and time.

Uses the formula: Volume = (RPM * displacement / self.flow_rate_time_base_s) * elapsed_time

Returns:

A tuple of (deposited_volume, extrusion_rate).

Return type:

(float, float)

calc_extrusion_rate(extruder, command: gcode_reader.emulate.commands.Extrude, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Calculates the required screw RPM to achieve a target deposited volume.

Uses the formula: RPM = (Volume / elapsed_time * self.flow_rate_time_base_s) / displacement

Returns:

A tuple of (extrusion_rate, deposited_volume).

Return type:

(float, float)

class gcode_reader.emulate.extruders.MeltPumpExtruder(options: gcode_reader.emulate.machine_options.MachineOptions = None, model: ScrewModel = None)[source]

Bases: ScrewExtruder

A special ScrewExtruder where the control value directly specifies deposition volume.

This model assumes the extrusion_rate in a command is a direct specification of the volume to be deposited for that command’s duration. It operates in a relative mode.

Initializes a new Extruder instance.

Parameters:

options (MachineOptions) – Configuration settings for the machine and this tool.

model = None
class gcode_reader.emulate.extruders.MeltPumpModel(nozzle_diameter=0, displacement=1.0)[source]

Bases: ScrewModel

A special model where the control value directly specifies deposition volume.

This model assumes the extrusion_rate in a command (e.g., ‘E100’) is a direct specification of the cumulative volume deposited so far (e.g., 100 mm³). The volume deposited for a given move is the delta between the current E value and the previous E value: deposited_volume = max(E_current - E_last, 0).

Time and displacement are ignored — rate == volume.

calc_deposited_volume is the method called for both MoveExtrude commands (explicit E) and plain Move commands (no E, i.e. implicit extruder off).

Initializes the screw model’s physical parameters.

Parameters:
  • nozzle_diameter (float) – The diameter of the extruder nozzle (in length units).

  • displacement (float) – The volume of material extruded per full revolution of the screw (e.g., in units³/revolution).

calc_deposited_volume(extruder, command: gcode_reader.emulate.commands.Command, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Calculates the deposited volume based on the command’s extrusion rate.

For the MeltPump, the command’s extrusion rate is taken directly as the deposited volume, as they are equivalent.

Returns:

A tuple of (deposited_volume, extrusion_rate).

Return type:

(float, float)

calc_extrusion_rate(extruder, command: gcode_reader.emulate.commands.Extrude, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Calculates the required extrusion rate based on the command’s deposited volume.

For the MeltPumpExtruder, the command’s volume is taken directly as the required tool extrusion rate, as they are equivalent.

Returns:

A tuple of (extrusion_rate, deposited_volume).

Return type:

(float, float)

class gcode_reader.emulate.extruders.ScrewExtruder(options: gcode_reader.emulate.machine_options.MachineOptions = None, model: ScrewModel = None)[source]

Bases: Extruder

An extruder controlled by screw RPM, which processes pellets into a bead.

The extrusion_rate control value is interpreted as the screw’s rotational speed (e.g., in RPM). The deposited volume is calculated based on this speed, the tool’s displacement factor, and the command’s duration.

nozzle_diameter

The diameter of the extruder nozzle.

Type:

float

displacement

A factor representing the volume of material extruded per full revolution of the screw (e.g., in mm^3/revolution).

Type:

float

Initializes a new Extruder instance.

Parameters:

options (MachineOptions) – Configuration settings for the machine and this tool.

process_command(command: gcode_reader.emulate.commands.Command, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Processes a command to update the extruder’s state.

If the command is an commands.Extrude command, this method dispatches to the appropriate _calc_* method to update the tool’s state based on the extrusion model implemented by the subclass.

Parameters:
  • command (Command) – The command to process.

  • process_data (AdditiveProcessData) – The data object to populate with post-processing information.

Returns:

The updated AdditiveProcessData object.

model = None
class gcode_reader.emulate.extruders.ScrewModel(nozzle_diameter=0, displacement=1.0)[source]

(Abstract) Defines the physical calculation interface for a screw extruder.

This class acts as a strategy for the ScrewExtruder, separating the physical model (how RPM relates to volume) from the extruder’s state-holding logic.

nozzle_diameter

The diameter of the extruder nozzle (in length units).

Type:

float

displacement

The volume of material extruded per full revolution of the screw (e.g., in units³/revolution).

Type:

float

flow_rate_time_base_s

The conversion factor (in seconds) for the extrusion rate. Defaults to 60.0 to convert RPM (units/minute) to the emulator’s standard units/second.

Type:

float

Initializes the screw model’s physical parameters.

Parameters:
  • nozzle_diameter (float) – The diameter of the extruder nozzle (in length units).

  • displacement (float) – The volume of material extruded per full revolution of the screw (e.g., in units³/revolution).

abstract calc_deposited_volume(extruder, command: gcode_reader.emulate.commands.Command, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Calculates deposited volume from screw RPM and elapsed time.

Returns:

A tuple of (deposited_volume, extrusion_rate).

Return type:

(float, float)

abstract calc_extrusion_rate(extruder, command: gcode_reader.emulate.commands.Extrude, process_data: gcode_reader.emulate.operations.AdditiveProcessData)[source]

Calculates the required screw RPM to achieve a target deposited volume.

Returns:

A tuple of (extrusion_rate, deposited_volume).

Return type:

(float, float)

displacement
flow_rate_time_base_s = 60.0
nozzle_diameter
class gcode_reader.emulate.extruders.StepperExtruder(options: gcode_reader.emulate.machine_options.MachineOptions = None, filament_area=1.0, extrusion_multiplier=1.0)[source]

Bases: Extruder

An extruder controlled by filament length, common in FDM/FFF printers.

This model processes a continuous filament. The extrusion_rate control value represents the length of filament to feed (in relative mode) or the absolute position of the extruder motor (in absolute mode).

filament_area

The cross-sectional area of the filament, calculated from its diameter.

Type:

float

Initializes a new Extruder instance.

Parameters:

options (MachineOptions) – Configuration settings for the machine and this tool.

extrusion_multiplier = 1.0
filament_area = 1.0
relative_extrusion = True