layerview.simulation.machine module

RepRap FDM machine abstraction.

class layerview.simulation.machine.Machine(skip_unknown: bool | None = False)[source]

Bases: object

FDM Machine abstraction.

property _command_type_to_handler: Dict[Type, Callable]

Return dict mapping Command types to handler callables.

Returns:

Dict mapping Command types to handler callables.

Return type:

Callable

_get_handler(command: Command) Callable | None[source]

Return handler callable for specified command.

Returned callable expects NO parameters.

Parameters:

command (str) – G-code command token.

Return type:

Callable

_handle_move(command: Move)[source]

Handle Move commands.

Parameters:

command (Move) – The Move command to handle.

_move_to_origin(command: G28)[source]

Perform effector homing.

Parameters:

command (commands.G28) – G28 command.

_set_abs_positioning(*args, **kwargs)[source]

Set nozzle positioning mode to absolute.

_set_extruder_abs_mode(*args, **kwargs)[source]

Set effector positioning mode to absolute.

_set_extruder_rel_mode(*args, **kwargs)[source]

Set extruder positioning mode to relative.

_set_position(command: G92)[source]

Set effector position.

Parameters:

command (commands.G92) – Input command.

_set_rel_positioning(*args, **kwargs)[source]

Set effector positioning mode to relative.

_set_temperature_extruder(command: SetTemperatureExtruder)[source]

Set extruder (nozzle) temperature.

Parameters:

command (SetTemperatureExtruder) – Input command.

_set_units_to_inches(*args, **kwargs)[source]

Set input units to inches.

_set_units_to_millis(*args, **kwargs)[source]

Set input units to millimeters.

handle_command(command: Command)[source]

Handle command.

Parameters:

command (Command) – Command to handle.

Raises:

UnknownCommandError – If command is unknown and self._skip_unknown is False.

class layerview.simulation.machine.MachineState(position: LPoint3d = LPoint3d(0, 0, 0), offset_position: LPoint3d = LPoint3d(0, 0, 0), extruder: float = 0, offset_extruder: float = 0, feedrate: float = 40, temp_extruder: float = 0, is_positioning_rel: bool = False, is_extruder_rel: bool = False, is_imperial: bool = False)[source]

Bases: object

FDM machine’s state abstraction.

property extruder_abs: float

Return absolute extruder value.

Returns:

Absolute extruder position (E axis).

Return type:

float

property position_abs: LPoint3d

Return absolute effector position.

Returns:

Absolute effector position.

Return type:

Point3D

property unit_multiplier: float

Return unit multiplier for incoming length values.

Returned value depends on imperial mode flag state (inches).

Returns:

Unit multiplier.

Return type:

float

update(state: MachineState)[source]

Update this state.

Parameters:

state (MachineState) – The new state to update this state with.

exception layerview.simulation.machine.UnknownCommandError[source]

Bases: Exception

Thrown when an unknown (unsupported) command is provided to Machine.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

layerview.simulation.machine.get_xyz_from_command(command: Move) Tuple[float | None, float | None, float | None][source]

Extract X, Y, Z values from the provided Move command.

Parameters:

command (Move) – A Move command.

Returns:

Tuple containing (X, Y, Z) values extracted from the provided command. Axis values that are not present in the provided Move command default to None.

Return type:

tuple

Raises:

TypeError – If command is not an instance of Move (G0, G1, G2 or G3).