Skip to content

Commit

Permalink
Improve optional tool length compensation (G10, G43, G49)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndere1 committed Jan 21, 2025
1 parent b128ab8 commit a0460dd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 26 deletions.
14 changes: 8 additions & 6 deletions Marlin/src/gcode/feature/fwretract/G10_G11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
*/

#include "../../../inc/MarlinConfig.h"
#if ENABLED(FWRETRACT)
#include "../../feature/fwretract.h"
#endif

#if ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS)
#if ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS, HAS_TOOL_LENGTH_COMPENSATION)
#include "../../gcode.h"
#include "../../../module/motion.h"

#if ENABLED(FWRETRACT)
#include "../../../feature/fwretract.h"
#endif


/**
* G10
* S# - Retract filament according to settings of M207
Expand Down Expand Up @@ -157,8 +159,6 @@ void GcodeSuite::G10() {
#endif // ENABLED(CNC_COORDINATE_SYSTEMS)
#endif // ANY(CNC_COORDINATE_SYSTEMS, HAS_TOOL_LENGTH_COMPENSATION)
}
#endif // ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS)


#if ENABLED(FWRETRACT)

Expand All @@ -168,3 +168,5 @@ void GcodeSuite::G10() {
void GcodeSuite::G11() { fwretract.retract(false); }

#endif // FWRETRACT

#endif // ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS, HAS_TOOL_LENGTH_COMPENSATION)
6 changes: 4 additions & 2 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 6: G6(); break; // G6: Direct Stepper Move
#endif

#if ENABLED(FWRETRACT)
#if ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS, HAS_TOOL_LENGTH_COMPENSATION)
case 10: G10(); break; // G10: Retract / Swap Retract
case 11: G11(); break; // G11: Recover / Swap Recover
#if ENABLED(FWRETRACT)
case 11: G11(); break; // G11: Recover / Swap Recover
#endif
#endif

#if ENABLED(NOZZLE_CLEAN_FEATURE)
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* G3 - CCW ARC
* G4 - Dwell S<seconds> or P<milliseconds>
* G5 - Cubic B-spline with XYZE destination and IJPQ offsets
* G10 - Set coordinate system and tool table. Retract filament according to settings of M207 (Requires FWRETRACT)
* G10 - Set coordinate system (Requires CNC_COORDINATE_SYSTEMS) and tool table (Requires DEFAULT_TOOL_CENTERPOINT_CONTROL). Retract filament according to settings of M207 (Requires FWRETRACT)
* G11 - Retract recover filament according to settings of M208 (Requires FWRETRACT)
* G12 - Clean tool (Requires NOZZLE_CLEAN_FEATURE)
* G17 - Select Plane XY (Requires CNC_WORKSPACE_PLANES)
Expand All @@ -64,8 +64,8 @@
* G35 - Read bed corners to help adjust bed screws: T<screw_thread> (Requires ASSISTED_TRAMMING)
* G38 - Probe in any direction using the Z_MIN_PROBE (Requires G38_PROBE_TARGET)
* G42 - Coordinated move to a mesh point (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BLINEAR, or AUTO_BED_LEVELING_UBL)
* G43 - Tool length offset (Tool length compensation, tool centerpoint control)
* G49 - Cancel tool length offset (Cancel tool length compensation and tool centerpoint conrol)
* G43 - Tool length compensation, tool centerpoint control (Requires DEFAULT_TOOL_CENTERPOINT_CONTROL)
* G49 - Cancel tool length compensation (Cancel tool length compensation (Requires DEFAULT_TOOL_CENTERPOINT_CONTROL)
* G60 - Save current position. (Requires SAVED_POSITIONS)
* G61 - Apply/restore saved coordinates. (Requires SAVED_POSITIONS)
* G76 - Calibrate first layer temperature offsets. (Requires PTC_PROBE and PTC_BED)
Expand Down Expand Up @@ -527,7 +527,7 @@ class GcodeSuite {
static void G6();
#endif

#if ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS)
#if ANY(FWRETRACT, CNC_COORDINATE_SYSTEMS, HAS_TOOL_LENGTH_COMPENSATION)
static void G10();
#endif

Expand Down
12 changes: 7 additions & 5 deletions Marlin/src/gcode/geometry/G43_G49.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin2ForPipetBot [https://github.com/DerAndere1/Marlin]
* Copyright 2019 - 2024 DerAndere and other Marlin2ForPipetBot authors [https://github.com/DerAndere1/Marlin]
* Copyright 2019 - 2025 DerAndere and other Marlin2ForPipetBot authors [https://github.com/DerAndere1/Marlin]
*
* Based on:
* Marlin 3D Printer Firmware
Expand Down Expand Up @@ -63,13 +63,13 @@ void GcodeSuite::G43() {
default: return; // Ignore unknown G43.x

case 0: // G43 - Simple Tool Length Compensation Mode.
#if HAS_TOOL_CENTERPOINT_CONTROL
#if ANY(PENTA_AXIS_TRT, PENTA_AXIS_HT)
tool_centerpoint_control = false;
simple_tool_length_compensation = true;
#endif
simple_tool_length_compensation = true;
break;

#if HAS_TOOL_CENTERPOINT_CONTROL
#if ANY(PENTA_AXIS_TRT, PENTA_AXIS_HT)
case 4: // G43.4 - Rotational Tool Center Point Control Mode.
simple_tool_length_compensation = false;
tool_centerpoint_control = true;
Expand All @@ -92,7 +92,9 @@ void GcodeSuite::G43() {
*/
void GcodeSuite::G49() {
simple_tool_length_compensation = false;
tool_centerpoint_control = false;
#if ANY(PENTA_AXIS_TRT, PENTA_AXIS_HT)
tool_centerpoint_control = false;
#endif

current_position -= hotend_offset[active_extruder];
sync_plan_position();
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/inc/Conditionals-1-axes.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@
#undef HOTEND_OFFSET_Z
#endif

#if defined(DEFAULT_TOOL_LENGTH_COMPENSATION)
#define HAS_TOOL_LENGTH_COMPENSATION 1
#define HAS_HOTEND_OFFSET 1
#endif

/**
* Number of Linear Axes (e.g., XYZIJKUVW)
* All the logical axes except for the tool (E) axis
Expand Down
11 changes: 5 additions & 6 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,17 @@ int16_t feedrate_percentage = 100;
xyz_pos_t cartes;

#if HAS_TOOL_LENGTH_COMPENSATION
bool simple_tool_length_compensation = false;
bool simple_tool_length_compensation = DEFAULT_TOOL_LENGTH_COMPENSATION;
#endif

#if IS_KINEMATIC

abce_pos_t delta = LOGICAL_AXIS_ARRAY(0, X_HOME_POS, Y_HOME_POS, Z_INIT_POS, I_HOME_POS, J_HOME_POS, K_HOME_POS, U_HOME_POS, V_HOME_POS, W_HOME_POS);

#if ANY(PENTA_AXIS_TRT, PENTA_AXIS_HT)
bool tool_centerpoint_control = false;
#endif

#if HAS_SCARA_OFFSET
abc_pos_t scara_home_offset;
#endif
Expand All @@ -187,11 +191,6 @@ xyz_pos_t cartes;
delta_max_radius_2 = sq(PRINTABLE_RADIUS);
#endif


#if ANY(PENTA_AXIS_TRT, PENTA_AXIS_HT)
bool tool_centerpoint_control = false;
#endif

#endif

/**
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,10 +1388,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#if HAS_HOTEND_OFFSET
#if HAS_TOOL_LENGTH_COMPENSATION
xyz_pos_t diff{0};
if (simple_tool_length_compensation || tool_centerpoint_control)
if (simple_tool_length_compensation || TERN0(HAS_TOOL_CENTERPOINT_CONTROL, tool_centerpoint_control))
diff = hotend_offset[new_tool] - hotend_offset[old_tool];
#else
const xyz_pos_t diff = hotend_offset[new_tool] - hotend_offset[old_tool];
xyz_pos_t diff = hotend_offset[new_tool] - hotend_offset[old_tool];
#endif
TERN_(DUAL_X_CARRIAGE, diff.x = 0);
#else
Expand Down
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ PARK_HEAD_ON_PAUSE = build_src_filter=+<src/gcode/feature/pa
FILAMENT_LOAD_UNLOAD_GCODES = build_src_filter=+<src/gcode/feature/pause/M701_M702.cpp>
HAS_STEALTHCHOP = build_src_filter=+<src/gcode/feature/trinamic/M569.cpp>
CNC_WORKSPACE_PLANES = build_src_filter=+<src/gcode/geometry/G17-G19.cpp>
CNC_COORDINATE_SYSTEMS = build_src_filter=+<src/gcode/geometry/G53-G59.cpp>
CNC_COORDINATE_SYSTEMS = build_src_filter=+<src/gcode/feature/fwretract> +<src/gcode/feature/fwretract/G10_G11.cpp> +<src/gcode/geometry/G53-G59.cpp>
HAS_TOOL_LENGTH_COMPENSATION = build_src_filter=+<src/gcode/feature/fwretract> +<src/gcode/feature/fwretract/G10_G11.cpp> +<src/gcode/geometry/G43_G49.cpp>
HAS_HOME_OFFSET = build_src_filter=+<src/gcode/geometry/M206_M428.cpp>
EXPECTED_PRINTER_CHECK = build_src_filter=+<src/gcode/host/M16.cpp>
Expand Down

0 comments on commit a0460dd

Please sign in to comment.