Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added G60/G61 gcodes #16557

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6c36944
G60 & G61 added - first try
Hans007a Jan 7, 2020
fecd91b
Update Configuration_adv.h
Hans007a Jan 7, 2020
023f438
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 8, 2020
9e07176
G60/G61 working
Hans007a Jan 8, 2020
d6cb7a1
Update G61.cpp
Hans007a Jan 8, 2020
625b23c
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 9, 2020
45c142a
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 10, 2020
18937b0
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 11, 2020
49ac730
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 12, 2020
f06748a
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 13, 2020
2343f56
G60/G61 -15 Slots & check
Hans007a Jan 13, 2020
9e0e468
Miscellaneous cleanup
thinkyhead Jan 14, 2020
dca44cb
Misc. whitespace
thinkyhead Jan 14, 2020
ddb55b8
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 14, 2020
9f4487a
Update timers.h
Hans007a Jan 14, 2020
0b22a4e
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 18, 2020
d03ce09
ofline
Hans007a Jan 18, 2020
dc9e1c5
immer wieder der selbe shit
Hans007a Jan 18, 2020
d1e3896
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
Hans007a Jan 19, 2020
f951c51
Update motion.cpp
thinkyhead Jan 27, 2020
4e45c57
Update motion.h
thinkyhead Jan 27, 2020
a4db9b0
Update G61.cpp
thinkyhead Jan 27, 2020
8e720b3
Update G61.cpp
thinkyhead Jan 27, 2020
9d3a668
Rename the option
thinkyhead Jan 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,10 @@

// @section extras

// Defines the number of memory slots for saving/restoring position (G60/G61)
// The values should not be less than 1
#define NUM_POSITON_SLOTS 1

//
// G2/G3 Arc Support
//
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@
#define MSG_SOFT_MIN " Min: "
#define MSG_SOFT_MAX " Max: "

// Slot
#define MSG_SAVED_POS "Saved position"
#define MSG_RESTORING_POS "Restoring position"
#define MSG_INVALID_POS_SLOT "Invalid slot, total slots:"

#define MSG_SD_CANT_OPEN_SUBDIR "Cannot open subdir "
#define MSG_SD_INIT_FAIL "SD init fail"
#define MSG_SD_VOL_INIT_FAIL "volume.init failed"
Expand Down
53 changes: 53 additions & 0 deletions Marlin/src/gcode/feature/pause/G60.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
*
*/


#include "../../../inc/MarlinConfig.h"
#include "../../../core/language.h"
#include "../../gcode.h"
#include "../../../module/motion.h"

/**
* G60: save current position
* S<slot> specifies memory slot # (0-based) to save into (default 0)
*/
void GcodeSuite::G60() {
const uint8_t slot = parser.byteval('S');

if (slot >= NUM_POSITON_SLOTS) {
SERIAL_ERROR_START();
SERIAL_ECHOLNPAIR_F(MSG_INVALID_POS_SLOT, NUM_POSITON_SLOTS);
return;
}
stored_position[slot] = current_position;
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
isPosSaved[slot] = true;
//setPosSaved(true);

SERIAL_ECHOPGM(MSG_SAVED_POS);
SERIAL_ECHOPAIR_F(" S", slot);
SERIAL_ECHOPAIR_F("<-X:", stored_position[slot].x);
SERIAL_ECHOPAIR_F(" Y:", stored_position[slot].y);
SERIAL_ECHOPAIR_F(" Z:", stored_position[slot].z);
SERIAL_ECHOLNPAIR_F(" E:", stored_position[slot].e);

}

thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
70 changes: 70 additions & 0 deletions Marlin/src/gcode/feature/pause/G61.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
*
*/


#include "../../../inc/MarlinConfig.h"
#include "../../../core/language.h"
#include "../../module/planner.h"
#include "../../gcode.h"
#include "../../../module/motion.h"

/**
* G61: Apply/restore saved coordinates.
* X Y Z E - Value to add at stored coordinates.
* F<speed> - Set Feedrate.
* S<slot> specifies memory slot # (0-based) to save into (default 0).
*/
void GcodeSuite::G61(void) {

const uint8_t slot = parser.byteval('S');

if (slot >= NUM_POSITON_SLOTS) {
SERIAL_ERROR_START();
SERIAL_ECHOLNPAIR_F(MSG_INVALID_POS_SLOT, NUM_POSITON_SLOTS);
return;
}

if (!isPosSaved[slot]) return;

SERIAL_ECHOPGM(MSG_RESTORING_POS);
SERIAL_ECHOPAIR_F(" S", int(slot));
SERIAL_ECHOPGM("->");

if (parser.seen('F') && parser.value_linear_units() > 0.0)
feedrate_mm_s = MMM_TO_MMS(parser.value_linear_units());

LOOP_XYZE(i) {
if (parser.seen(axis_codes[i])) {
destination[i] = parser.value_axis_units((AxisEnum)i) + stored_position[slot][i];
}
else {
destination[i] = current_position[i];
}
SERIAL_ECHOPAIR_F(" ", axis_codes[i]);
SERIAL_ECHOPAIR_F(":", destination[i]);
}
SERIAL_EOL();

// finish moves
prepare_move_to_destination();
planner.synchronize();
}
5 changes: 5 additions & 0 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ int8_t GcodeSuite::get_target_extruder_from_command() {
SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", int(e));
return -1;
}
#if ENABLED(SINGLENOZZLE)
if(active_extruder<0) return 0;
#endif
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
return active_extruder;
}

Expand Down Expand Up @@ -323,6 +326,8 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 59: G59(); break;
#endif

case 60: G60(); break; // G60: save current position
case 61: G61(); break; // G61: Apply/restore saved coordinates.
#if ENABLED(GCODE_MOTION_MODES)
case 80: G80(); break; // G80: Reset the current motion mode
#endif
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
* G34 - Z Stepper automatic alignment using probe: I<iterations> T<accuracy> A<amplification> (Requires Z_STEPPER_AUTO_ALIGN)
* 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)
* G60 - Save current position
* G61 - Apply/restore saved coordinates.
* G80 - Cancel current motion mode (Requires GCODE_MOTION_MODES)
* G90 - Use Absolute Coordinates
* G91 - Use Relative Coordinates
Expand Down Expand Up @@ -464,6 +466,9 @@ class GcodeSuite {
static void G59();
#endif

static void G60();
static void G61();

#if ENABLED(GCODE_MOTION_MODES)
static void G80();
#endif
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,9 @@
#if ENABLED(JOYSTICK)
#define POLL_JOG
#endif

// Number of memory slots for saving/restoring position (G60/G61) should be between 1 and 5.
#if NUM_POSITON_SLOTS < 1 || NUM_POSITON_SLOTS > 5
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#error "Number of memory slots for saving/restoring position (G60/G61) should be between 1 and 5."
#endif

6 changes: 5 additions & 1 deletion Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ xyze_pos_t current_position = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS };
*/
xyze_pos_t destination; // {0}

xyze_pos_t stored_position[NUM_POSITON_SLOTS];
bool isPosSaved[NUM_POSITON_SLOTS];


// The active extruder (tool). Set with T<extruder> command.
#if EXTRUDERS > 1
uint8_t active_extruder; // = 0
uint8_t active_extruder = 0; // = 0
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#endif

#if ENABLED(LCD_SHOW_E_TOTAL)
Expand Down
10 changes: 10 additions & 0 deletions Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ extern bool relative_mode;
extern xyze_pos_t current_position, // High-level current tool position
destination; // Destination for a move

/**
* Stored Position
* Used to save native machine position as moves are queued.
* Used by G60 for stored.
* Used by G61 for move to.
*/
extern xyze_pos_t stored_position[NUM_POSITON_SLOTS];
// Various flag bit 1 PosSaved
extern bool isPosSaved[NUM_POSITON_SLOTS];

// Scratch space for a cartesian result
extern xyz_pos_t cartes;

Expand Down