Skip to content

Commit

Permalink
Add G43, G43.4 and G49
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndere1 committed Oct 3, 2024
1 parent 42ac4a8 commit ec159cd
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/gcode/feature/fwretract/G10_G11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void GcodeSuite::G10() {

default: break; // Ignore unknown G10 Lx

case 1: // Sets the tool offset
case 1: // Sets the tool offset. Intended to work as in LinuxCNC.
LOOP_NUM_AXES(i) {
if (parser.seen(axis_codes[i])) {
const float axis_value = parser.value_axis_units((AxisEnum)i);
Expand All @@ -86,7 +86,7 @@ void GcodeSuite::G10() {

// G10 L10 changes the tool table entry for tool P so that if the tool offset is reloaded, with the machine in its
// current position and with the current G5x and G52/G92 offsets active, the current coordinates for the given axes
// will become the given values. (Intended to work the same as LinuxCNC).
// will become the given values. Intended to work as in LinuxCNC.
// e.g. G10 L10 P1 Z1.5 followed by G43 sets the current position for Z to be 1.5.
case 10:
LOOP_NUM_AXES(i) {
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 42: G42(); break; // G42: Coordinated move to a mesh point
#endif

#if HAS_TOOL_LENGTH_COMPENSATION
case 43: G43(); break; // G43.4: Rotational Tool Center Point Control Mode
case 49: G49(); break;
#endif

#if ENABLED(CNC_COORDINATE_SYSTEMS)
case 53: G53(); break; // G53: (prefix) Apply native workspace
case 54: G54(); break; // G54: Switch to Workspace 1
Expand Down
101 changes: 101 additions & 0 deletions Marlin/src/gcode/geometry/G43_G49.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Marlin2ForPipetBot [https://github.com/DerAndere1/Marlin]
* Copyright 2019 - 2024 DerAndere and other Marlin2ForPipetBot authors [https://github.com/DerAndere1/Marlin]
*
* Based on:
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/


/**
* @file G43_G49.cpp
* @author DerAndere
* @brief G-codes related to Tool Length Compensation and Rotational Tool Center Point Control
*
* Copyright 2024 DerAndere
*/

#include "../../inc/MarlinConfig.h"

#if HAS_TOOL_LENGTH_COMPENSATION

#include "../gcode.h"
#include "../../module/motion.h"

/**
* G43: Enable Tool Length Compensation.
*
* G43: Enable Simple Tool Length Compensation.
* G43 Tool Length Compensation can be canceled with G49.
*
* G43.4: Enable Rotational Tool Center Point Control Mode.
* G43.4 Rotational Tool Center Point Control Mode can be canceled with G49.
*
* Only one can be active at any time.
*/
void GcodeSuite::G43() {

#if USE_GCODE_SUBCODES
const uint8_t subcode_G43 = parser.subcode;
#else
constexpr uint8_t subcode_G43 = 0;
#endif

switch (subcode_G43) {
default: return; // Ignore unknown G43.x

case 0: // G43 - Simple Tool Length Compensation Mode.
#if HAS_TOOL_CENTERPOINT_CONTROL
tool_centerpoint_control = false;
simple_tool_length_compensation = true;
#endif
break;

#if HAS_TOOL_CENTERPOINT_CONTROL
case 4: // G43.4 - Rotational Tool Center Point Control Mode.
simple_tool_length_compensation = false;
tool_centerpoint_control = true;
break;
#endif
}

current_position += hotend_offset[active_extruder];
sync_plan_position();
}


/**
* G49: Cancel Tool Length Compensation
*
* Cancels Simple Tool Length Compensation Mode and Rotational Tool Center Point Control Mode.
*
* Simple Tool Length Compensation Mode can be enabled with G43
* Rotational Tool Center Point Control Mode can be enabled with G43.4
*/
void GcodeSuite::G49() {
simple_tool_length_compensation = false;
tool_centerpoint_control = false;

current_position -= hotend_offset[active_extruder];
sync_plan_position();
}

#endif
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals-5-post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@
#endif

// G92 shifts the workspace
#if DISABLED(NO_WORKSPACE_OFFSETS)
#if DISABLED(NO_WORKSPACE_OFFSETS) || HAS_TOOL_LENGTH_COMPENSATION
#define HAS_WORKSPACE_OFFSET 1
#endif
#if DISABLED(NO_HOME_OFFSETS)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ xyz_pos_t cartes;


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

#endif
Expand Down
8 changes: 7 additions & 1 deletion Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,13 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#endif

#if HAS_HOTEND_OFFSET
xyz_pos_t diff = hotend_offset[new_tool] - hotend_offset[old_tool];
#if HAS_TOOL_LENGTH_COMPENSATION
xyz_pos_t diff{0};
if (simple_tool_length_compensation || 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];
#endif
TERN_(DUAL_X_CARRIAGE, diff.x = 0);
#else
constexpr xyz_pos_t diff{0};
Expand Down
1 change: 1 addition & 0 deletions ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ FILAMENT_LOAD_UNLOAD_GCODES = build_src_filter=+<src/gcode/feature/pa
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>
HAS_TOOL_LENGTH_COMPENSATION = src_filter=+<src/gcode/geometry/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>
HOST_KEEPALIVE_FEATURE = build_src_filter=+<src/gcode/host/M113.cpp>
Expand Down

0 comments on commit ec159cd

Please sign in to comment.