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

Allow servo features in combination #16960

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions Marlin/src/feature/bltouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,4 @@ class BLTouch {
static void mode_conv_proc(const bool M5V);
};

// Deploy/stow angles for use by servo.cpp / servo.h
#define BLTOUCH_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }

extern BLTouch bltouch;
6 changes: 6 additions & 0 deletions Marlin/src/gcode/config/M281.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ void GcodeSuite::M281() {
if (!parser.seenval('P')) return;
const int servo_index = parser.value_int();
if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
#if ENABLED(BLTOUCH)
if (servo_index == Z_PROBE_SERVO_NR) {
SERIAL_ERROR_MSG("BLTouch angles can't be changed.");
return;
}
#endif
bool angle_change = false;
if (parser.seen('L')) {
servo_angles[servo_index][0] = parser.value_int();
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@
* Set a flag for a servo probe (or BLTouch)
*/
#define HAS_Z_SERVO_PROBE (defined(Z_PROBE_SERVO_NR) && Z_PROBE_SERVO_NR >= 0)
#define HAS_SERVO_ANGLES (HAS_Z_SERVO_PROBE || EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE))
#if !HAS_SERVO_ANGLES
#undef EDITABLE_SERVO_ANGLES
#endif

/**
* Set flags for enabled probes
Expand Down
10 changes: 0 additions & 10 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -1546,16 +1546,6 @@
#define HAS_SERVO_3 (PIN_EXISTS(SERVO3) && NUM_SERVOS > 3)
#define HAS_SERVOS (NUM_SERVOS > 0)

#if HAS_SERVOS && !defined(Z_PROBE_SERVO_NR)
#define Z_PROBE_SERVO_NR -1
#endif

#define HAS_SERVO_ANGLES (EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE) || (HAS_Z_SERVO_PROBE && defined(Z_PROBE_SERVO_NR)))

#if !HAS_SERVO_ANGLES || ENABLED(BLTOUCH)
#undef EDITABLE_SERVO_ANGLES
#endif

// Sensors
#define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ void MarlinSettings::reset() {
//

#if ENABLED(EDITABLE_SERVO_ANGLES)
COPY(servo_angles, base_servo_angles);
COPY(servo_angles, base_servo_angles); // When not editable only one copy of servo angles exists
#endif

//
Expand Down Expand Up @@ -3082,7 +3082,7 @@ void MarlinSettings::reset() {
#endif
#elif ENABLED(SWITCHING_NOZZLE)
case SWITCHING_NOZZLE_SERVO_NR:
#elif (ENABLED(BLTOUCH) && defined(BLTOUCH_ANGLES)) || (defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR))
#elif ENABLED(BLTOUCH) || (HAS_Z_SERVO_PROBE && defined(Z_SERVO_ANGLES))
case Z_PROBE_SERVO_NR:
#endif
CONFIG_ECHO_START();
Expand Down
69 changes: 44 additions & 25 deletions Marlin/src/module/servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,65 @@
#if HAS_SERVO_ANGLES

#if ENABLED(SWITCHING_EXTRUDER)
#ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
#define SWITCHING_EXTRUDER_E23_SERVO_NR -1
#endif
// Switching extruder can have 2 or 4 angles
#if EXTRUDERS > 3
#define REQ_ANGLES 4
#else
#define REQ_ANGLES 2
#endif
#define SADATA SWITCHING_EXTRUDER_SERVO_ANGLES
#define ASRC(N,E) (SWITCHING_EXTRUDER_SERVO_NR == N ? asrc[E] : SWITCHING_EXTRUDER_E23_SERVO_NR == N ? asrc[E+2] : 0)
#elif ENABLED(SWITCHING_NOZZLE)
#define SADATA SWITCHING_NOZZLE_SERVO_ANGLES
#define ASRC(N,E) (SWITCHING_NOZZLE_SERVO_NR == N ? asrc[E] : 0)
#elif defined(Z_PROBE_SERVO_NR)
#define ASRC(N,E) (Z_PROBE_SERVO_NR == N ? asrc[E] : 0)
constexpr uint16_t sase[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
static_assert(COUNT(sase) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
#else
constexpr uint16_t sase[4] = { 0 };
#endif

#if ENABLED(SWITCHING_NOZZLE)
constexpr uint16_t sasn[] = SWITCHING_NOZZLE_SERVO_ANGLES;
static_assert(COUNT(sasn) == 2, "SWITCHING_NOZZLE_SERVO_ANGLES needs 2 angles.");
#else
constexpr uint16_t sasn[2] = { 0 };
#endif

#ifdef Z_PROBE_SERVO_NR
#if ENABLED(BLTOUCH)
#include "../feature/bltouch.h"
#undef Z_SERVO_ANGLES
#define Z_SERVO_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
#endif
#ifdef BLTOUCH_ANGLES
#define SADATA BLTOUCH_ANGLES
#elif defined(Z_SERVO_ANGLES)
#define SADATA Z_SERVO_ANGLES
#else
#error "Servo angles are needed!"
#endif
constexpr uint16_t sazp[] = Z_SERVO_ANGLES;
static_assert(COUNT(sazp) == 2, "Z_SERVO_ANGLES needs 2 angles.");
#else
constexpr uint16_t sazp[2] = { 0 };
#endif

#ifndef SWITCHING_EXTRUDER_SERVO_NR
#define SWITCHING_EXTRUDER_SERVO_NR -1
#endif
#ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
#define SWITCHING_EXTRUDER_E23_SERVO_NR -1
#endif
#ifndef SWITCHING_NOZZLE_SERVO_NR
#define SWITCHING_NOZZLE_SERVO_NR -1
#endif
#ifndef Z_PROBE_SERVO_NR
#define Z_PROBE_SERVO_NR -1
#endif

#define ASRC(N,I) ( \
N == SWITCHING_EXTRUDER_SERVO_NR ? sase[I] \
: N == SWITCHING_EXTRUDER_E23_SERVO_NR ? sase[I+2] \
: N == SWITCHING_NOZZLE_SERVO_NR ? sasn[I] \
: N == Z_PROBE_SERVO_NR ? sazp[I] \
: 0 )

#if ENABLED(EDITABLE_SERVO_ANGLES)
extern uint16_t servo_angles[NUM_SERVOS][2];
#define BASE_SERVO_ANGLES base_servo_angles
#define CONST_SERVO_ANGLES base_servo_angles
#else
#define BASE_SERVO_ANGLES servo_angles
#endif

constexpr uint16_t asrc[] = SADATA;
#if REQ_ANGLES
static_assert(COUNT(asrc) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
#define CONST_SERVO_ANGLES servo_angles
#endif

constexpr uint16_t BASE_SERVO_ANGLES [NUM_SERVOS][2] = {
constexpr uint16_t CONST_SERVO_ANGLES [NUM_SERVOS][2] = {
{ ASRC(0,0), ASRC(0,1) }
#if NUM_SERVOS > 1
, { ASRC(1,0), ASRC(1,1) }
Expand Down