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

M282 - Detach Servo #22760

Merged
merged 10 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2934,7 +2934,7 @@
* Set this manually if there are extra servos needing manual control.
* Set to 0 to turn off servo support.
*/
//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command
//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 and M282 commands

// (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.
Expand Down
46 changes: 46 additions & 0 deletions Marlin/src/gcode/control/M282.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 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 HAS_SERVOS

#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_ERROR_MSG("Servo ", servo_index, " out of range");
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

}

#endif // HAS_SERVOS
1 change: 1 addition & 0 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
#if ENABLED(EDITABLE_SERVO_ANGLES)
case 281: M281(); break; // M281: Set servo angles
#endif
case 282: M282(); break; // M282: Detach servo
#endif

#if ENABLED(BABYSTEPPING)
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
* M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
* 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)
* M282 - Detach servo: "M282 P<index>". (Requires servos)
* M290 - Babystepping (Requires BABYSTEPPING)
* M300 - Play beep sound S<frequency Hz> P<duration ms>
* M301 - Set PID parameters P I and D. (Requires PIDTEMP)
Expand Down Expand Up @@ -862,6 +863,7 @@ class GcodeSuite {
static void M281();
static void M281_report(const bool forReplay=true);
#endif
static void M282();
#endif

#if ENABLED(BABYSTEPPING)
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/module/servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
#endif // HAS_SERVO_ANGLES

#define MOVE_SERVO(I, P) servo[I].move(P)
#define DETACH_SERVO(I) servo[I].detach()

extern HAL_SERVO_LIB servo[NUM_SERVOS];
void servo_init();
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ BEZIER_CURVE_SUPPORT = src_filter=+<src/module/planner_bezier.
PRINTCOUNTER = src_filter=+<src/module/printcounter.cpp>
HAS_BED_PROBE = src_filter=+<src/module/probe.cpp> +<src/gcode/probe/G30.cpp> +<src/gcode/probe/M401_M402.cpp> +<src/gcode/probe/M851.cpp>
IS_SCARA = src_filter=+<src/module/scara.cpp>
HAS_SERVOS = src_filter=+<src/module/servo.cpp> +<src/gcode/control/M280.cpp>
HAS_SERVOS = src_filter=+<src/module/servo.cpp> +<src/gcode/control/M280.cpp> +<src/gcode/control/M282.cpp>
MORGAN_SCARA = src_filter=+<src/gcode/scara>
HAS_MICROSTEPS = src_filter=+<src/gcode/control/M350_M351.cpp>
(ESP3D_)?WIFISUPPORT = AsyncTCP, ESP Async WebServer
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
-<src/module/printcounter.cpp>
-<src/module/probe.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/control/M282.cpp>
-<src/module/stepper/TMC26X.cpp>

#
Expand Down