浏览代码

✨ M282 - Detach Servo (#22760)

Dakkaron 3 年前
父节点
当前提交
21e8f99500
没有帐户链接到提交者的电子邮件

+ 5
- 2
Marlin/Configuration.h 查看文件

@@ -2936,9 +2936,9 @@
2936 2936
  * Set this manually if there are extra servos needing manual control.
2937 2937
  * Set to 0 to turn off servo support.
2938 2938
  */
2939
-//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command
2939
+//#define NUM_SERVOS 3 // Note: Servo index starts with 0 for M280-M282 commands
2940 2940
 
2941
-// (ms) Delay  before the next move will start, to give the servo time to reach its target angle.
2941
+// (ms) Delay before the next move will start, to give the servo time to reach its target angle.
2942 2942
 // 300ms is a good value but you can try less delay.
2943 2943
 // If the servo can't reach the requested position, increase it.
2944 2944
 #define SERVO_DELAY { 300 }
@@ -2948,3 +2948,6 @@
2948 2948
 
2949 2949
 // Edit servo angles with M281 and save to EEPROM with M500
2950 2950
 //#define EDITABLE_SERVO_ANGLES
2951
+
2952
+// Disable servo with M282 to reduce power consumption, noise, and heat when not in use
2953
+//#define SERVO_DETACH_GCODE

+ 1
- 1
Marlin/src/gcode/control/M280.cpp 查看文件

@@ -39,7 +39,7 @@ void GcodeSuite::M280() {
39 39
     if (parser.seen('S')) {
40 40
       const int a = parser.value_int();
41 41
       if (a == -1)
42
-        servo[servo_index].detach();
42
+        DETACH_SERVO(servo_index);
43 43
       else
44 44
         MOVE_SERVO(servo_index, a);
45 45
     }

+ 45
- 0
Marlin/src/gcode/control/M282.cpp 查看文件

@@ -0,0 +1,45 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(SERVO_DETACH_GCODE)
26
+
27
+#include "../gcode.h"
28
+#include "../../module/servo.h"
29
+
30
+/**
31
+ * M282: Detach Servo. P<index>
32
+ */
33
+void GcodeSuite::M282() {
34
+
35
+  if (!parser.seen('P')) return;
36
+
37
+  const int servo_index = parser.value_int();
38
+  if (WITHIN(servo_index, 0, NUM_SERVOS - 1))
39
+    DETACH_SERVO(servo_index);
40
+  else
41
+    SERIAL_ECHO_MSG("Servo ", servo_index, " out of range");
42
+
43
+}
44
+
45
+#endif // SERVO_DETACH_GCODE

+ 3
- 0
Marlin/src/gcode/gcode.cpp 查看文件

@@ -717,6 +717,9 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
717 717
         #if ENABLED(EDITABLE_SERVO_ANGLES)
718 718
           case 281: M281(); break;                                // M281: Set servo angles
719 719
         #endif
720
+        #if ENABLED(SERVO_DETACH_GCODE)
721
+          case 282: M282(); break;                                // M282: Detach servo
722
+        #endif
720 723
       #endif
721 724
 
722 725
       #if ENABLED(BABYSTEPPING)

+ 4
- 0
Marlin/src/gcode/gcode.h 查看文件

@@ -192,6 +192,7 @@
192 192
  * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
193 193
  * M280 - Set servo position absolute: "M280 P<index> S<angle|µs>". (Requires servos)
194 194
  * M281 - Set servo min|max position: "M281 P<index> L<min> U<max>". (Requires EDITABLE_SERVO_ANGLES)
195
+ * M282 - Detach servo: "M282 P<index>". (Requires SERVO_DETACH_GCODE)
195 196
  * M290 - Babystepping (Requires BABYSTEPPING)
196 197
  * M300 - Play beep sound S<frequency Hz> P<duration ms>
197 198
  * M301 - Set PID parameters P I and D. (Requires PIDTEMP)
@@ -862,6 +863,9 @@ private:
862 863
       static void M281();
863 864
       static void M281_report(const bool forReplay=true);
864 865
     #endif
866
+    #if ENABLED(SERVO_DETACH_GCODE)
867
+      static void M282();
868
+    #endif
865 869
   #endif
866 870
 
867 871
   #if ENABLED(BABYSTEPPING)

+ 8
- 3
Marlin/src/inc/Conditionals_post.h 查看文件

@@ -2593,9 +2593,14 @@
2593 2593
 #endif
2594 2594
 #if NUM_SERVOS > 0
2595 2595
   #define HAS_SERVOS 1
2596
-#endif
2597
-#if HAS_SERVOS && defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT)
2598
-  #define HAS_PAUSE_SERVO_OUTPUT 1
2596
+  #if defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT)
2597
+    #define HAS_PAUSE_SERVO_OUTPUT 1
2598
+  #endif
2599
+#else
2600
+  #undef SERVO_DELAY
2601
+  #undef DEACTIVATE_SERVOS_AFTER_MOVE
2602
+  #undef EDITABLE_SERVO_ANGLES
2603
+  #undef SERVO_DETACH_GCODE
2599 2604
 #endif
2600 2605
 
2601 2606
 // Sensors

+ 4
- 4
Marlin/src/module/servo.cpp 查看文件

@@ -39,19 +39,19 @@ HAL_SERVO_LIB servo[NUM_SERVOS];
39 39
 void servo_init() {
40 40
   #if NUM_SERVOS >= 1 && HAS_SERVO_0
41 41
     servo[0].attach(SERVO0_PIN);
42
-    servo[0].detach(); // Just set up the pin. We don't have a position yet. Don't move to a random position.
42
+    DETACH_SERVO(0); // Just set up the pin. We don't have a position yet. Don't move to a random position.
43 43
   #endif
44 44
   #if NUM_SERVOS >= 2 && HAS_SERVO_1
45 45
     servo[1].attach(SERVO1_PIN);
46
-    servo[1].detach();
46
+    DETACH_SERVO(1);
47 47
   #endif
48 48
   #if NUM_SERVOS >= 3 && HAS_SERVO_2
49 49
     servo[2].attach(SERVO2_PIN);
50
-    servo[2].detach();
50
+    DETACH_SERVO(2);
51 51
   #endif
52 52
   #if NUM_SERVOS >= 4 && HAS_SERVO_3
53 53
     servo[3].attach(SERVO3_PIN);
54
-    servo[3].detach();
54
+    DETACH_SERVO(3);
55 55
   #endif
56 56
 }
57 57
 

+ 1
- 0
Marlin/src/module/servo.h 查看文件

@@ -110,6 +110,7 @@
110 110
 #endif // HAS_SERVO_ANGLES
111 111
 
112 112
 #define MOVE_SERVO(I, P) servo[I].move(P)
113
+#define DETACH_SERVO(I) servo[I].detach()
113 114
 
114 115
 extern HAL_SERVO_LIB servo[NUM_SERVOS];
115 116
 void servo_init();

+ 2
- 1
buildroot/tests/LPC1768 查看文件

@@ -28,7 +28,8 @@ restore_configs
28 28
 opt_set MOTHERBOARD BOARD_MKS_SBASE \
29 29
         EXTRUDERS 2 TEMP_SENSOR_1 1 \
30 30
         NUM_SERVOS 2 SERVO_DELAY '{ 300, 300 }'
31
-opt_enable SWITCHING_NOZZLE SWITCHING_NOZZLE_E1_SERVO_NR ULTIMAKERCONTROLLER REALTIME_REPORTING_COMMANDS FULL_REPORT_TO_HOST_FEATURE
31
+opt_enable SWITCHING_NOZZLE SWITCHING_NOZZLE_E1_SERVO_NR EDITABLE_SERVO_ANGLES SERVO_DETACH_GCODE \
32
+           ULTIMAKERCONTROLLER REALTIME_REPORTING_COMMANDS FULL_REPORT_TO_HOST_FEATURE
32 33
 exec_test $1 $2 "MKS SBASE with SWITCHING_NOZZLE, Grbl Realtime Report" "$3"
33 34
 
34 35
 restore_configs

+ 1
- 0
ini/features.ini 查看文件

@@ -173,6 +173,7 @@ HAS_SMART_EFF_MOD                      = src_filter=+<src/gcode/config/M672.cpp>
173 173
 COOLANT_CONTROL|AIR_ASSIST             = src_filter=+<src/gcode/control/M7-M9.cpp>
174 174
 AIR_EVACUATION                         = src_filter=+<src/gcode/control/M10-M11.cpp>
175 175
 HAS_SOFTWARE_ENDSTOPS                  = src_filter=+<src/gcode/control/M211.cpp>
176
+SERVO_DETACH_GCODE                     = src_filter=+<src/gcode/control/M282.cpp>
176 177
 HAS_DUPLICATION_MODE                   = src_filter=+<src/gcode/control/M605.cpp>
177 178
 LIN_ADVANCE                            = src_filter=+<src/gcode/feature/advance>
178 179
 PHOTO_GCODE                            = src_filter=+<src/gcode/feature/camera>

+ 2
- 3
platformio.ini 查看文件

@@ -87,7 +87,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
87 87
   -<src/lcd/touch/touch_buttons.cpp>
88 88
   -<src/sd/usb_flashdrive/lib-uhs2> -<src/sd/usb_flashdrive/lib-uhs3>
89 89
   -<src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp>
90
-  -<src/sd/cardreader.cpp> -<src/sd/Sd2Card.cpp> -<src/sd/SdBaseFile.cpp> -<src/sd/SdFatUtil.cpp> -<src/sd/SdFile.cpp> -<src/sd/SdVolume.cpp> -<src/gcode/sd>
90
+  -<src/sd/cardreader.cpp> -<src/sd/Sd2Card.cpp> -<src/sd/SdBaseFile.cpp> -<src/sd/SdFatUtil.cpp> -<src/sd/SdFile.cpp> -<src/sd/SdVolume.cpp>
91 91
   -<src/HAL/shared/backtrace>
92 92
   -<src/HAL/shared/cpu_exception>
93 93
   -<src/HAL/shared/eeprom_if_i2c.cpp>
@@ -166,7 +166,6 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
166 166
   -<src/gcode/config/M217.cpp>
167 167
   -<src/gcode/config/M218.cpp>
168 168
   -<src/gcode/config/M221.cpp>
169
-  -<src/gcode/config/M281.cpp>
170 169
   -<src/gcode/config/M301.cpp>
171 170
   -<src/gcode/config/M302.cpp>
172 171
   -<src/gcode/config/M304.cpp>
@@ -243,7 +242,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
243 242
   -<src/module/printcounter.cpp>
244 243
   -<src/module/probe.cpp>
245 244
   -<src/module/scara.cpp> -<src/gcode/calibrate/M665.cpp>
246
-  -<src/module/servo.cpp> -<src/gcode/control/M280.cpp>
245
+  -<src/module/servo.cpp> -<src/gcode/control/M280.cpp> -<src/gcode/config/M281.cpp> -<src/gcode/control/M282.cpp>
247 246
   -<src/module/stepper/TMC26X.cpp>
248 247
 
249 248
 #

正在加载...
取消
保存