Преглед изворни кода

Add external closed loop controller support

Sam Lane пре 5 година
родитељ
комит
1b6bc19427

+ 7
- 0
Marlin/Configuration_adv.h Прегледај датотеку

@@ -287,6 +287,13 @@
287 287
 
288 288
 //#define Z_LATE_ENABLE // Enable Z the last moment. Needed if your Z driver overheats.
289 289
 
290
+// Employ an external closed loop controller. Override pins here if needed.
291
+//#define EXTERNAL_CLOSED_LOOP_CONTROLLER
292
+#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
293
+  //#define CLOSED_LOOP_ENABLE_PIN        -1
294
+  //#define CLOSED_LOOP_MOVE_COMPLETE_PIN -1
295
+#endif
296
+
290 297
 /**
291 298
  * Dual Steppers / Dual Endstops
292 299
  *

+ 6
- 0
Marlin/src/Marlin.cpp Прегледај датотеку

@@ -40,6 +40,8 @@
40 40
 #include "sd/cardreader.h"
41 41
 #include "module/configuration_store.h"
42 42
 #include "module/printcounter.h" // PrintCounter or Stopwatch
43
+#include "feature/closedloop.h"
44
+
43 45
 #ifdef ARDUINO
44 46
   #include <pins_arduino.h>
45 47
 #endif
@@ -903,6 +905,10 @@ void setup() {
903 905
   #if ENABLED(USE_WATCHDOG) // Reinit watchdog after HAL_get_reset_source call
904 906
     watchdog_init();
905 907
   #endif
908
+
909
+  #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
910
+    init_closedloop();
911
+  #endif
906 912
 }
907 913
 
908 914
 /**

+ 7
- 0
Marlin/src/config/default/Configuration_adv.h Прегледај датотеку

@@ -287,6 +287,13 @@
287 287
 
288 288
 //#define Z_LATE_ENABLE // Enable Z the last moment. Needed if your Z driver overheats.
289 289
 
290
+// Employ an external closed loop controller. Override pins here if needed.
291
+//#define EXTERNAL_CLOSED_LOOP_CONTROLLER
292
+#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
293
+  //#define CLOSED_LOOP_ENABLE_PIN        -1
294
+  //#define CLOSED_LOOP_MOVE_COMPLETE_PIN -1
295
+#endif
296
+
290 297
 /**
291 298
  * Dual Steppers / Dual Endstops
292 299
  *

+ 41
- 0
Marlin/src/feature/closedloop.cpp Прегледај датотеку

@@ -0,0 +1,41 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 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
+#include "../inc/MarlinConfig.h"
23
+
24
+#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
25
+
26
+#if !PIN_EXISTS(CLOSED_LOOP_ENABLE) || !PIN_EXISTS(CLOSED_LOOP_MOVE_COMPLETE)
27
+  #error "CLOSED_LOOP_ENABLE_PIN and CLOSED_LOOP_MOVE_COMPLETE_PIN are required for EXTERNAL_CLOSED_LOOP_CONTROLLER."
28
+#endif
29
+
30
+#include "closedloop.h"
31
+
32
+void init_closedloop() {
33
+  OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, LOW);
34
+  SET_INPUT_PULLUP(CLOSED_LOOP_MOVE_COMPLETE_PIN);
35
+}
36
+
37
+void set_closedloop(const byte val) {
38
+  OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, val);
39
+}
40
+
41
+#endif // EXTERNAL_CLOSED_LOOP_CONTROLLER

+ 25
- 0
Marlin/src/feature/closedloop.h Прегледај датотеку

@@ -0,0 +1,25 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 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
+#pragma once
23
+
24
+void init_closedloop();
25
+void set_closedloop(const byte val);

+ 36
- 0
Marlin/src/gcode/calibrate/M12.cpp Прегледај датотеку

@@ -0,0 +1,36 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 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
+#include "../../inc/MarlinConfigPre.h"
23
+
24
+#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
25
+
26
+#include "../gcode.h"
27
+#include "../../module/planner.h"
28
+#include "../../feature/closedloop.h"
29
+
30
+void GcodeSuite::M12() {
31
+  planner.synchronize();
32
+  if (parser.seenval('S'))
33
+    set_closedloop(parser.value_int()); // Force a CLC set
34
+}
35
+
36
+#endif

+ 4
- 0
Marlin/src/gcode/gcode.cpp Прегледај датотеку

@@ -292,6 +292,10 @@ void GcodeSuite::process_parsed_command(
292 292
         case 5: M5(); break;                                      // M5 - turn spindle/laser off
293 293
       #endif
294 294
 
295
+      #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
296
+        case 12: M12(); break;                                    // M12: Synchronize and optionally force a CLC set
297
+      #endif
298
+
295 299
       case 17: M17(); break;                                      // M17: Enable all stepper motors
296 300
 
297 301
       #if ENABLED(SDSUPPORT)

+ 5
- 0
Marlin/src/gcode/gcode.h Прегледај датотеку

@@ -76,6 +76,7 @@
76 76
  * M3   - Turn laser/spindle on, set spindle/laser speed/power, set rotation to clockwise
77 77
  * M4   - Turn laser/spindle on, set spindle/laser speed/power, set rotation to counter-clockwise
78 78
  * M5   - Turn laser/spindle off
79
+ * M12  - Set up closed loop control system. More features coming soon. (Requires EXTERNAL_CLOSED_LOOP_CONTROLLER)
79 80
  * M17  - Enable/Power all stepper motors
80 81
  * M18  - Disable all stepper motors; same as M84
81 82
  * M20  - List SD card. (Requires SDSUPPORT)
@@ -438,6 +439,10 @@ private:
438 439
     static void M5();
439 440
   #endif
440 441
 
442
+  #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
443
+    static void M12();
444
+  #endif
445
+
441 446
   static void M17();
442 447
 
443 448
   static void M18_M84();

+ 8
- 1
Marlin/src/module/planner.cpp Прегледај датотеку

@@ -1539,7 +1539,14 @@ float Planner::get_axis_position_mm(const AxisEnum axis) {
1539 1539
 /**
1540 1540
  * Block until all buffered steps are executed / cleaned
1541 1541
  */
1542
-void Planner::synchronize() { while (has_blocks_queued() || cleaning_buffer_counter) idle(); }
1542
+void Planner::synchronize() {
1543
+  while (
1544
+    has_blocks_queued() || cleaning_buffer_counter
1545
+    #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
1546
+      || !READ(CLOSED_LOOP_MOVE_COMPLETE_PIN)
1547
+    #endif
1548
+  ) idle();
1549
+}
1543 1550
 
1544 1551
 /**
1545 1552
  * Planner::_buffer_steps

Loading…
Откажи
Сачувај