OOFEM 3.0
Loading...
Searching...
No Matches
Printer Class Reference

The Printer class is used to process G-code commands and manage the printer state. More...

#include <Printer.h>

Collaboration diagram for Printer:

Public Types

using CommandCallback = std::function<void( const GCodeCommand & )>

Public Member Functions

 Printer (PrinterOptions options)
 Constructor for Printer using PrinterOptions.
PrintStatistics getStatistics () const
 Get the printer statistics.
void registerCallback (const std::string &commandCode, CommandCallback callback)
 Register a callback function for a specific G-code command.
void addCommandToQueue (const GCodeCommand &command)
 Add a G-code command to the command queue.
void popCommandFromQueue ()
 Remove the first G-code command from the command queue.
void processCommand (const GCodeCommand &command)
 Process a G-code command.
VoxelGridgetGrid ()
std::array< double, 4 > calculatePosition (std::array< double, 4 > position, const std::optional< double > &xValue, const std::optional< double > &yValue, const std::optional< double > &zValue)
 Calculate the new position of the printer based on the given values.
std::array< double, 3 > calculateDirectorVector (const std::array< double, 4 > &position_prev, const std::array< double, 4 > &position_next)
 Calculate the director vector between two positions.
double calculateMoveTime (double distance, double vs, double v, double ve)
 Calculate the time taken to move a certain distance with given velocities.
const Model get_model (std::array< double, 4 > start, std::array< double, 4 > end, double h, double w)
void handleG1Command (const GCodeCommand &command)
 Handle the G1 command to manage printer positions.
void handleM83Command (const GCodeCommand &command)
 Handle the M83 command to set the extruder positioning mode to relative.
 Printer ()
 Constructor to register default callbacks.

Public Attributes

double depositionTemperature = 235.
double heatBedTemperature = 60.
double chamberTemperature = 30.
double heatTransferFilmCoefficient = 10.
double depositedMaterialHeatPower = 4200000.0

Private Member Functions

void registerCallbacks ()

Private Attributes

VoxelGrid voxelGrid = { { 0.5, 0.5, 0.5 }, { 1000, 1000, 1000 } }
std::map< std::string, CommandCallbackcommandCallbacks
std::vector< GCodeCommandcommandQueue
PrintStatistics statistics
std::array< double, 4 > position = { 0.0, 0.0, 0.0, 0.0 }
ExtruderPositioning positioning = ExtruderPositioning::Absolute
ExtruderPositioning extruder_positioning = ExtruderPositioning::Absolute
VelocityModel velocity_model = VelocityModel::Trapezoidal
double feedrate = 1000.0
double real_feedrate = 0.0
double max_acceleration [4] = { 500.0, 500.0, 100.0, 5000.0 }
double max_jerk [4] = { 8.0, 8.0, 0.4, 5.0 }
LayerHeightModel layer_height_model = LayerHeightModel::Constant
double layer_height = 0.2
double nozzle_diameter = 0.4
double filament_diameter = 1.75
double extrusion_multiplier = 1.0
double extrusion_width = nozzle_diameter * 1.2

Detailed Description

The Printer class is used to process G-code commands and manage the printer state.

Definition at line 76 of file Printer.h.

Member Typedef Documentation

◆ CommandCallback

using Printer::CommandCallback = std::function<void( const GCodeCommand & )>

Definition at line 80 of file Printer.h.

Constructor & Destructor Documentation

◆ Printer() [1/2]

◆ Printer() [2/2]

Printer::Printer ( )
inline

Constructor to register default callbacks.

Definition at line 458 of file Printer.h.

References registerCallbacks().

Member Function Documentation

◆ addCommandToQueue()

void Printer::addCommandToQueue ( const GCodeCommand & command)
inline

Add a G-code command to the command queue.

Parameters
commandThe G-code command to be added.

Definition at line 127 of file Printer.h.

References commandQueue.

◆ calculateDirectorVector()

std::array< double, 3 > Printer::calculateDirectorVector ( const std::array< double, 4 > & position_prev,
const std::array< double, 4 > & position_next )
inline

Calculate the director vector between two positions.

Parameters
position_prevThe previous position.
position_nextThe next position.
Returns
The director vector.

Definition at line 205 of file Printer.h.

Referenced by handleG1Command().

◆ calculateMoveTime()

double Printer::calculateMoveTime ( double distance,
double vs,
double v,
double ve )
inline

Calculate the time taken to move a certain distance with given velocities.

Parameters
distanceThe distance to be moved.
vsThe starting velocity.
vThe target velocity.
veThe ending velocity.
Returns
The time taken to move the distance.

Definition at line 232 of file Printer.h.

References max_acceleration.

Referenced by handleG1Command().

◆ calculatePosition()

std::array< double, 4 > Printer::calculatePosition ( std::array< double, 4 > position,
const std::optional< double > & xValue,
const std::optional< double > & yValue,
const std::optional< double > & zValue )
inline

Calculate the new position of the printer based on the given values.

Parameters
positionThe current position of the printer.
xValueThe optional X-axis value.
yValueThe optional Y-axis value.
zValueThe optional Z-axis value.
Returns
The new position of the printer.

Definition at line 171 of file Printer.h.

References position, positioning, and Relative.

Referenced by handleG1Command().

◆ get_model()

const Model Printer::get_model ( std::array< double, 4 > start,
std::array< double, 4 > end,
double h,
double w )
inline

Definition at line 243 of file Printer.h.

References modelfrompolygons().

Referenced by handleG1Command().

◆ getGrid()

VoxelGrid & Printer::getGrid ( )
inline

Definition at line 158 of file Printer.h.

References voxelGrid.

Referenced by handleG1Command().

◆ getStatistics()

PrintStatistics Printer::getStatistics ( ) const
inline

Get the printer statistics.

Returns
The printer statistics.

Definition at line 108 of file Printer.h.

References statistics.

◆ handleG1Command()

void Printer::handleG1Command ( const GCodeCommand & command)
inline

◆ handleM83Command()

void Printer::handleM83Command ( const GCodeCommand & command)
inline

Handle the M83 command to set the extruder positioning mode to relative.

Parameters
commandThe G-code command.

Definition at line 450 of file Printer.h.

References extruder_positioning, and Relative.

Referenced by registerCallbacks().

◆ popCommandFromQueue()

void Printer::popCommandFromQueue ( )
inline

Remove the first G-code command from the command queue.

Definition at line 135 of file Printer.h.

References commandQueue.

◆ processCommand()

void Printer::processCommand ( const GCodeCommand & command)
inline

Process a G-code command.

Parameters
commandThe G-code command to be processed.

Definition at line 145 of file Printer.h.

References commandCallbacks, GCodeCommand::getCode(), and statistics.

◆ registerCallback()

void Printer::registerCallback ( const std::string & commandCode,
CommandCallback callback )
inline

Register a callback function for a specific G-code command.

Parameters
commandCodeThe G-code command code.
callbackThe callback function to be registered.

Definition at line 118 of file Printer.h.

References commandCallbacks.

Referenced by registerCallbacks().

◆ registerCallbacks()

void Printer::registerCallbacks ( )
inlineprivate

Definition at line 464 of file Printer.h.

References handleG1Command(), handleM83Command(), and registerCallback().

Referenced by Printer(), and Printer().

Member Data Documentation

◆ chamberTemperature

double Printer::chamberTemperature = 30.

Definition at line 500 of file Printer.h.

Referenced by Printer().

◆ commandCallbacks

std::map<std::string, CommandCallback> Printer::commandCallbacks
private

Map of command codes to callback functions.

Definition at line 472 of file Printer.h.

Referenced by processCommand(), and registerCallback().

◆ commandQueue

std::vector<GCodeCommand> Printer::commandQueue
private

Queue of G-code commands to be processed.

Definition at line 473 of file Printer.h.

Referenced by addCommandToQueue(), handleG1Command(), and popCommandFromQueue().

◆ depositedMaterialHeatPower

double Printer::depositedMaterialHeatPower = 4200000.0

Definition at line 502 of file Printer.h.

Referenced by Printer().

◆ depositionTemperature

double Printer::depositionTemperature = 235.

Definition at line 498 of file Printer.h.

Referenced by Printer().

◆ extruder_positioning

ExtruderPositioning Printer::extruder_positioning = ExtruderPositioning::Absolute
private

The positioning mode of the extruder (E axis).

Definition at line 479 of file Printer.h.

Referenced by handleG1Command(), and handleM83Command().

◆ extrusion_multiplier

double Printer::extrusion_multiplier = 1.0
private

Extrusion multiplier

Definition at line 495 of file Printer.h.

◆ extrusion_width

double Printer::extrusion_width = nozzle_diameter * 1.2
private

Current extrusion width

Definition at line 496 of file Printer.h.

Referenced by handleG1Command(), and Printer().

◆ feedrate

double Printer::feedrate = 1000.0
private

The current desired velocity of the printer.

Definition at line 483 of file Printer.h.

Referenced by handleG1Command().

◆ filament_diameter

double Printer::filament_diameter = 1.75
private

Filament diameter, not used

Definition at line 494 of file Printer.h.

Referenced by handleG1Command(), and Printer().

◆ heatBedTemperature

double Printer::heatBedTemperature = 60.

Temperature of deposited material

Definition at line 499 of file Printer.h.

Referenced by Printer().

◆ heatTransferFilmCoefficient

double Printer::heatTransferFilmCoefficient = 10.

Definition at line 501 of file Printer.h.

Referenced by Printer().

◆ layer_height

double Printer::layer_height = 0.2
private

The layer height value.

Definition at line 492 of file Printer.h.

Referenced by handleG1Command(), and Printer().

◆ layer_height_model

LayerHeightModel Printer::layer_height_model = LayerHeightModel::Constant
private

The layer height model of the printer.

Definition at line 491 of file Printer.h.

Referenced by handleG1Command(), and Printer().

◆ max_acceleration

double Printer::max_acceleration[4] = { 500.0, 500.0, 100.0, 5000.0 }
private

The maximum acceleration for X, Y, Z, and E axes.

Definition at line 487 of file Printer.h.

Referenced by calculateMoveTime().

◆ max_jerk

double Printer::max_jerk[4] = { 8.0, 8.0, 0.4, 5.0 }
private

Definition at line 488 of file Printer.h.

Referenced by handleG1Command().

◆ nozzle_diameter

double Printer::nozzle_diameter = 0.4
private

Nozzle diameter, not used

Definition at line 493 of file Printer.h.

◆ position

std::array<double, 4> Printer::position = { 0.0, 0.0, 0.0, 0.0 }
private

The position of the print head in X, Y, Z, and E axes.

Definition at line 477 of file Printer.h.

Referenced by calculatePosition(), and handleG1Command().

◆ positioning

ExtruderPositioning Printer::positioning = ExtruderPositioning::Absolute
private

The positioning mode of the printhead in space (XYZ).

Definition at line 478 of file Printer.h.

Referenced by calculatePosition().

◆ real_feedrate

double Printer::real_feedrate = 0.0
private

The real velocity of the printer.

Definition at line 484 of file Printer.h.

Referenced by handleG1Command().

◆ statistics

PrintStatistics Printer::statistics
private

The printer statistics.

Definition at line 474 of file Printer.h.

Referenced by getStatistics(), handleG1Command(), and processCommand().

◆ velocity_model

VelocityModel Printer::velocity_model = VelocityModel::Trapezoidal
private

The velocity model of the printer.

Definition at line 482 of file Printer.h.

Referenced by Printer().

◆ voxelGrid

VoxelGrid Printer::voxelGrid = { { 0.5, 0.5, 0.5 }, { 1000, 1000, 1000 } }
private

3d Voxel Grid

Definition at line 470 of file Printer.h.

Referenced by getGrid(), handleG1Command(), and Printer().


The documentation for this class was generated from the following file:

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011