Selaa lähdekoodia

G60/G61 Position Save/Restore (#16557)

Hans007a 5 vuotta sitten
vanhempi
commit
e2eef1256a

+ 5
- 0
Marlin/Configuration_adv.h Näytä tiedosto

@@ -1577,6 +1577,11 @@
1577 1577
 // @section extras
1578 1578
 
1579 1579
 //
1580
+// G60/G61 Position Save and Return
1581
+//
1582
+//#define SAVED_POSITIONS 1         // Each saved position slot costs 12 bytes
1583
+
1584
+//
1580 1585
 // G2/G3 Arc Support
1581 1586
 //
1582 1587
 #define ARC_SUPPORT                 // Disable this feature to save ~3226 bytes

+ 4
- 6
Marlin/src/HAL/HAL_STM32/timers.h Näytä tiedosto

@@ -61,8 +61,6 @@
61 61
 
62 62
   #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals
63 63
 
64
-  // STM32F401 only has timers 1-5 & 9-11 with timers 4 & 5 usually assigned to TIMER_SERVO and TIMER_TONE
65
-
66 64
   #ifndef STEP_TIMER
67 65
     #define STEP_TIMER 9
68 66
   #endif
@@ -76,19 +74,19 @@
76 74
   #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals
77 75
 
78 76
   #ifndef STEP_TIMER
79
-    #define STEP_TIMER 6
77
+    #define STEP_TIMER 6  // STM32F401 has no TIM6, TIM7, or TIM8
80 78
   #endif
81 79
 
82 80
   #ifndef TEMP_TIMER
83
-    #define TEMP_TIMER 14
81
+    #define TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used.
84 82
   #endif
85 83
 
86 84
 #elif defined(STM32F7xx)
87 85
 
88
-  #define HAL_TIMER_RATE (F_CPU/2) // frequency of timer peripherals
86
+  #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals
89 87
 
90 88
   #ifndef STEP_TIMER
91
-    #define STEP_TIMER 6
89
+    #define STEP_TIMER 6  // the RIGHT timer!
92 90
   #endif
93 91
 
94 92
   #ifndef TEMP_TIMER

+ 4
- 0
Marlin/src/core/language.h Näytä tiedosto

@@ -222,6 +222,10 @@
222 222
 #define MSG_SOFT_MIN                        "  Min: "
223 223
 #define MSG_SOFT_MAX                        "  Max: "
224 224
 
225
+#define MSG_SAVED_POS                       "Position saved"
226
+#define MSG_RESTORING_POS                   "Restoring position"
227
+#define MSG_INVALID_POS_SLOT                "Invalid slot. Total: "
228
+
225 229
 #define MSG_SD_CANT_OPEN_SUBDIR             "Cannot open subdir "
226 230
 #define MSG_SD_INIT_FAIL                    "SD init fail"
227 231
 #define MSG_SD_VOL_INIT_FAIL                "volume.init failed"

+ 59
- 0
Marlin/src/gcode/feature/pause/G60.cpp Näytä tiedosto

@@ -0,0 +1,59 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if SAVED_POSITIONS
26
+
27
+#include "../../../core/language.h"
28
+#include "../../gcode.h"
29
+#include "../../../module/motion.h"
30
+
31
+#define DEBUG_OUT ENABLED(SAVED_POSITIONS_DEBUG)
32
+#include "../../../core/debug_out.h"
33
+
34
+/**
35
+ * G60: Save current position
36
+ *
37
+ *   S<slot> - Memory slot # (0-based) to save into (default 0)
38
+ */
39
+void GcodeSuite::G60() {
40
+  const uint8_t slot = parser.byteval('S');
41
+
42
+  if (slot >= SAVED_POSITIONS) {
43
+    SERIAL_ERROR_MSG(MSG_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS));
44
+    return;
45
+  }
46
+
47
+  stored_position[slot] = current_position;
48
+  SBI(saved_slots, slot);
49
+
50
+  #if ENABLED(SAVED_POSITIONS_DEBUG)
51
+    const xyze_pos_t &pos = stored_position[slot];
52
+    DEBUG_ECHOPAIR_F(MSG_SAVED_POS " S", slot);
53
+    DEBUG_ECHOPAIR_F(" : X", pos.x);
54
+    DEBUG_ECHOPAIR_F_P(SP_Y_STR, pos.y);
55
+    DEBUG_ECHOLNPAIR_F_P(SP_Z_STR, pos.z);
56
+  #endif
57
+}
58
+
59
+#endif // SAVED_POSITIONS

+ 71
- 0
Marlin/src/gcode/feature/pause/G61.cpp Näytä tiedosto

@@ -0,0 +1,71 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if SAVED_POSITIONS
26
+
27
+#include "../../../core/language.h"
28
+#include "../../module/planner.h"
29
+#include "../../gcode.h"
30
+#include "../../../module/motion.h"
31
+
32
+/**
33
+ * G61: Return to saved position
34
+ *
35
+ *   F<rate>  - Feedrate (optional) for the move back.
36
+ *   S<slot>  - Slot # (0-based) to restore from (default 0).
37
+ *   X Y Z    - Axes to restore. At least one is required.
38
+ */
39
+void GcodeSuite::G61(void) {
40
+
41
+  const uint8_t slot = parser.byteval('S');
42
+
43
+  #if SAVED_POSITIONS < 256
44
+    if (slot >= SAVED_POSITIONS) {
45
+      SERIAL_ERROR_MSG(MSG_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS));
46
+      return;
47
+    }
48
+  #endif
49
+
50
+  // No saved position? No axes being restored?
51
+  if (!TEST(saved_slots, slot) || !parser.seen("XYZ")) return;
52
+
53
+  // Apply any given feedrate over 0.0
54
+  const float fr = parser.linearval('F');
55
+  if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr);
56
+
57
+  SERIAL_ECHOPAIR(MSG_RESTORING_POS " S", int(slot));
58
+  LOOP_XYZ(i) {
59
+    destination[i] = parser.seen(axis_codes[i])
60
+      ? stored_position[slot][i] + parser.value_axis_units((AxisEnum)i)
61
+      : current_position[i];
62
+    SERIAL_CHAR(' ', axis_codes[i]);
63
+    SERIAL_ECHO_F(destination[i]);
64
+  }
65
+  SERIAL_EOL();
66
+
67
+  // Move to the saved position
68
+  prepare_move_to_destination();
69
+}
70
+
71
+#endif // SAVED_POSITIONS

+ 15
- 7
Marlin/src/gcode/gcode.cpp Näytä tiedosto

@@ -314,19 +314,27 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
314 314
       #endif
315 315
 
316 316
       #if ENABLED(CNC_COORDINATE_SYSTEMS)
317
-        case 53: G53(); break;
318
-        case 54: G54(); break;
319
-        case 55: G55(); break;
320
-        case 56: G56(); break;
321
-        case 57: G57(); break;
322
-        case 58: G58(); break;
323
-        case 59: G59(); break;
317
+        case 53: G53(); break;                                    // G53: (prefix) Apply native workspace
318
+        case 54: G54(); break;                                    // G54: Switch to Workspace 1
319
+        case 55: G55(); break;                                    // G55: Switch to Workspace 2
320
+        case 56: G56(); break;                                    // G56: Switch to Workspace 3
321
+        case 57: G57(); break;                                    // G57: Switch to Workspace 4
322
+        case 58: G58(); break;                                    // G58: Switch to Workspace 5
323
+        case 59: G59(); break;                                    // G59.0 - G59.3: Switch to Workspace 6-9
324
+      #endif
325
+
326
+      #if SAVED_POSITIONS
327
+        case 60: G60(); break;                                    // G60:  save current position
328
+        case 61: G61(); break;                                    // G61:  Apply/restore saved coordinates.
324 329
       #endif
325 330
 
326 331
       #if ENABLED(PROBE_TEMP_COMPENSATION)
327 332
         case 76: G76(); break;                                    // G76: Calibrate first layer compensation values
328 333
       #endif
329 334
 
335
+      case 60: G60(); break;                                      // G60:  save current position
336
+      case 61: G61(); break;                                      // G61:  Apply/restore saved coordinates.
337
+
330 338
       #if ENABLED(GCODE_MOTION_MODES)
331 339
         case 80: G80(); break;                                    // G80: Reset the current motion mode
332 340
       #endif

+ 7
- 0
Marlin/src/gcode/gcode.h Näytä tiedosto

@@ -67,6 +67,8 @@
67 67
  * G34  - Z Stepper automatic alignment using probe: I<iterations> T<accuracy> A<amplification> (Requires Z_STEPPER_AUTO_ALIGN)
68 68
  * G38  - Probe in any direction using the Z_MIN_PROBE (Requires G38_PROBE_TARGET)
69 69
  * G42  - Coordinated move to a mesh point (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BLINEAR, or AUTO_BED_LEVELING_UBL)
70
+ * G60  - Save current position. (Requires SAVED_POSITIONS)
71
+ * G61  - Apply/restore saved coordinates. (Requires SAVED_POSITIONS)
70 72
  * G76  - Calibrate first layer temperature offsets. (Requires PROBE_TEMP_COMPENSATION)
71 73
  * G80  - Cancel current motion mode (Requires GCODE_MOTION_MODES)
72 74
  * G90  - Use Absolute Coordinates
@@ -471,6 +473,11 @@ private:
471 473
     static void G76();
472 474
   #endif
473 475
 
476
+  #if SAVED_POSITIONS
477
+    static void G60();
478
+    static void G61();
479
+  #endif
480
+
474 481
   #if ENABLED(GCODE_MOTION_MODES)
475 482
     static void G80();
476 483
   #endif

+ 5
- 0
Marlin/src/inc/Conditionals_adv.h Näytä tiedosto

@@ -142,3 +142,8 @@
142 142
 #if ENABLED(JOYSTICK)
143 143
   #define POLL_JOG
144 144
 #endif
145
+
146
+// G60/G61 Position Save
147
+#if SAVED_POSITIONS > 256
148
+  #error "SAVED_POSITIONS must be an integer from 0 to 256."
149
+#endif

+ 7
- 1
Marlin/src/module/motion.cpp Näytä tiedosto

@@ -109,9 +109,15 @@ xyze_pos_t current_position = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS };
109 109
  */
110 110
 xyze_pos_t destination; // {0}
111 111
 
112
+// G60/G61 Position Save and Return
113
+#if SAVED_POSITIONS
114
+  uint8_t saved_slots;
115
+  xyz_pos_t stored_position[SAVED_POSITIONS];
116
+#endif
117
+
112 118
 // The active extruder (tool). Set with T<extruder> command.
113 119
 #if EXTRUDERS > 1
114
-  uint8_t active_extruder; // = 0
120
+  uint8_t active_extruder = 0; // = 0
115 121
 #endif
116 122
 
117 123
 #if ENABLED(LCD_SHOW_E_TOTAL)

+ 6
- 0
Marlin/src/module/motion.h Näytä tiedosto

@@ -65,6 +65,12 @@ extern bool relative_mode;
65 65
 extern xyze_pos_t current_position,  // High-level current tool position
66 66
                   destination;       // Destination for a move
67 67
 
68
+// G60/G61 Position Save and Return
69
+#if SAVED_POSITIONS
70
+  extern uint8_t saved_slots;
71
+  extern xyz_pos_t stored_position[SAVED_POSITIONS];
72
+#endif
73
+
68 74
 // Scratch space for a cartesian result
69 75
 extern xyz_pos_t cartes;
70 76
 

Loading…
Peruuta
Tallenna