Browse Source

M282 - Detach Servo (#22760)

vanilla_fb_2.0.x
Dakkaron 3 years ago
committed by Scott Lahteine
parent
commit
1386e78369
  1. 7
      Marlin/Configuration.h
  2. 2
      Marlin/src/gcode/control/M280.cpp
  3. 45
      Marlin/src/gcode/control/M282.cpp
  4. 3
      Marlin/src/gcode/gcode.cpp
  5. 4
      Marlin/src/gcode/gcode.h
  6. 11
      Marlin/src/inc/Conditionals_post.h
  7. 8
      Marlin/src/module/servo.cpp
  8. 1
      Marlin/src/module/servo.h
  9. 3
      buildroot/tests/LPC1768
  10. 1
      ini/features.ini
  11. 5
      platformio.ini

7
Marlin/Configuration.h

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

2
Marlin/src/gcode/control/M280.cpp

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

45
Marlin/src/gcode/control/M282.cpp

@ -0,0 +1,45 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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/>.
*
*/
#include "../../inc/MarlinConfig.h"
#if ENABLED(SERVO_DETACH_GCODE)
#include "../gcode.h"
#include "../../module/servo.h"
/**
* M282: Detach Servo. P<index>
*/
void GcodeSuite::M282() {
if (!parser.seen('P')) return;
const int servo_index = parser.value_int();
if (WITHIN(servo_index, 0, NUM_SERVOS - 1))
DETACH_SERVO(servo_index);
else
SERIAL_ECHO_MSG("Servo ", servo_index, " out of range");
}
#endif // SERVO_DETACH_GCODE

3
Marlin/src/gcode/gcode.cpp

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

4
Marlin/src/gcode/gcode.h

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

11
Marlin/src/inc/Conditionals_post.h

@ -2593,9 +2593,14 @@
#endif #endif
#if NUM_SERVOS > 0 #if NUM_SERVOS > 0
#define HAS_SERVOS 1 #define HAS_SERVOS 1
#endif #if defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT)
#if HAS_SERVOS && defined(PAUSE_SERVO_OUTPUT) && defined(RESUME_SERVO_OUTPUT) #define HAS_PAUSE_SERVO_OUTPUT 1
#define HAS_PAUSE_SERVO_OUTPUT 1 #endif
#else
#undef SERVO_DELAY
#undef DEACTIVATE_SERVOS_AFTER_MOVE
#undef EDITABLE_SERVO_ANGLES
#undef SERVO_DETACH_GCODE
#endif #endif
// Sensors // Sensors

8
Marlin/src/module/servo.cpp

@ -39,19 +39,19 @@ HAL_SERVO_LIB servo[NUM_SERVOS];
void servo_init() { void servo_init() {
#if NUM_SERVOS >= 1 && HAS_SERVO_0 #if NUM_SERVOS >= 1 && HAS_SERVO_0
servo[0].attach(SERVO0_PIN); servo[0].attach(SERVO0_PIN);
servo[0].detach(); // Just set up the pin. We don't have a position yet. Don't move to a random position. DETACH_SERVO(0); // Just set up the pin. We don't have a position yet. Don't move to a random position.
#endif #endif
#if NUM_SERVOS >= 2 && HAS_SERVO_1 #if NUM_SERVOS >= 2 && HAS_SERVO_1
servo[1].attach(SERVO1_PIN); servo[1].attach(SERVO1_PIN);
servo[1].detach(); DETACH_SERVO(1);
#endif #endif
#if NUM_SERVOS >= 3 && HAS_SERVO_2 #if NUM_SERVOS >= 3 && HAS_SERVO_2
servo[2].attach(SERVO2_PIN); servo[2].attach(SERVO2_PIN);
servo[2].detach(); DETACH_SERVO(2);
#endif #endif
#if NUM_SERVOS >= 4 && HAS_SERVO_3 #if NUM_SERVOS >= 4 && HAS_SERVO_3
servo[3].attach(SERVO3_PIN); servo[3].attach(SERVO3_PIN);
servo[3].detach(); DETACH_SERVO(3);
#endif #endif
} }

1
Marlin/src/module/servo.h

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

3
buildroot/tests/LPC1768

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

1
ini/features.ini

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

5
platformio.ini

@ -87,7 +87,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/lcd/touch/touch_buttons.cpp> -<src/lcd/touch/touch_buttons.cpp>
-<src/sd/usb_flashdrive/lib-uhs2> -<src/sd/usb_flashdrive/lib-uhs3> -<src/sd/usb_flashdrive/lib-uhs2> -<src/sd/usb_flashdrive/lib-uhs3>
-<src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp> -<src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp>
-<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> -<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/HAL/shared/backtrace> -<src/HAL/shared/backtrace>
-<src/HAL/shared/cpu_exception> -<src/HAL/shared/cpu_exception>
-<src/HAL/shared/eeprom_if_i2c.cpp> -<src/HAL/shared/eeprom_if_i2c.cpp>
@ -166,7 +166,6 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/gcode/config/M217.cpp> -<src/gcode/config/M217.cpp>
-<src/gcode/config/M218.cpp> -<src/gcode/config/M218.cpp>
-<src/gcode/config/M221.cpp> -<src/gcode/config/M221.cpp>
-<src/gcode/config/M281.cpp>
-<src/gcode/config/M301.cpp> -<src/gcode/config/M301.cpp>
-<src/gcode/config/M302.cpp> -<src/gcode/config/M302.cpp>
-<src/gcode/config/M304.cpp> -<src/gcode/config/M304.cpp>
@ -243,7 +242,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/module/printcounter.cpp> -<src/module/printcounter.cpp>
-<src/module/probe.cpp> -<src/module/probe.cpp>
-<src/module/scara.cpp> -<src/gcode/calibrate/M665.cpp> -<src/module/scara.cpp> -<src/gcode/calibrate/M665.cpp>
-<src/module/servo.cpp> -<src/gcode/control/M280.cpp> -<src/module/servo.cpp> -<src/gcode/control/M280.cpp> -<src/gcode/config/M281.cpp> -<src/gcode/control/M282.cpp>
-<src/module/stepper/TMC26X.cpp> -<src/module/stepper/TMC26X.cpp>
# #

Loading…
Cancel
Save