Fix issues, make optional

This commit is contained in:
Scott Lahteine 2018-08-24 21:53:42 -05:00
parent aa80e448e2
commit 3e81745e81
13 changed files with 98 additions and 52 deletions

View file

@ -1947,9 +1947,10 @@
// 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 }
// Servo deactivation // Only power servos during movement, otherwise leave off to prevent jitter
//
// With this option servos are powered only during movement, then turned off to prevent jitter.
//#define DEACTIVATE_SERVOS_AFTER_MOVE //#define DEACTIVATE_SERVOS_AFTER_MOVE
// Allow servo angle to be edited and saved to EEPROM
//#define EDITABLE_SERVO_ANGLES
#endif // CONFIGURATION_H #endif // CONFIGURATION_H

View file

@ -1946,9 +1946,10 @@
// 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 }
// Servo deactivation // Only power servos during movement, otherwise leave off to prevent jitter
//
// With this option servos are powered only during movement, then turned off to prevent jitter.
//#define DEACTIVATE_SERVOS_AFTER_MOVE //#define DEACTIVATE_SERVOS_AFTER_MOVE
// Allow servo angle to be edited and saved to EEPROM
//#define EDITABLE_SERVO_ANGLES
#endif // CONFIGURATION_H #endif // CONFIGURATION_H

View file

@ -21,13 +21,13 @@
*/ */
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if HAS_SERVOS #if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
#include "../gcode.h" #include "../gcode.h"
#include "../../module/servo.h" #include "../../module/servo.h"
void GcodeSuite::M281() { void GcodeSuite::M281() {
if (!parser.seen('P')) return; if (!parser.seenval('P')) return;
const int servo_index = parser.value_int(); const int servo_index = parser.value_int();
if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) { if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
bool angle_change = false; bool angle_change = false;
@ -53,4 +53,4 @@ void GcodeSuite::M281() {
} }
} }
#endif #endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES

View file

@ -146,10 +146,10 @@ inline void servo_probe_test() {
uint8_t i = 0; uint8_t i = 0;
bool deploy_state, stow_state; bool deploy_state, stow_state;
do { do {
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); //deploy MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
safe_delay(500); safe_delay(500);
deploy_state = READ(PROBE_TEST_PIN); deploy_state = READ(PROBE_TEST_PIN);
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); //stow MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
safe_delay(500); safe_delay(500);
stow_state = READ(PROBE_TEST_PIN); stow_state = READ(PROBE_TEST_PIN);
} while (++i < 4); } while (++i < 4);
@ -170,7 +170,7 @@ inline void servo_probe_test() {
#endif #endif
} }
else { // measure active signal length else { // measure active signal length
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // deploy MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
safe_delay(500); safe_delay(500);
SERIAL_PROTOCOLLNPGM("please trigger probe"); SERIAL_PROTOCOLLNPGM("please trigger probe");
uint16_t probe_counter = 0; uint16_t probe_counter = 0;
@ -194,7 +194,7 @@ inline void servo_probe_test() {
else else
SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse SERIAL_PROTOCOLLNPGM("noise detected - please re-run test"); // less than 2mS pulse
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); //stow MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
} // pulse detected } // pulse detected

View file

@ -487,7 +487,9 @@ void GcodeSuite::process_parsed_command(
#if HAS_SERVOS #if HAS_SERVOS
case 280: M280(); break; // M280: Set servo position absolute case 280: M280(); break; // M280: Set servo position absolute
case 281: M281(); break; #if ENABLED(EDITABLE_SERVO_ANGLES)
case 281: M281(); break; // M281: Set servo angles
#endif
#endif #endif
#if ENABLED(BABYSTEPPING) #if ENABLED(BABYSTEPPING)

View file

@ -172,7 +172,7 @@
* M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS) * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
* 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 servos) * M281 - Set servo min|max position: "M281 P<index> L<min> U<max>". (Requires EDITABLE_SERVO_ANGLES)
* 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)
@ -628,8 +628,10 @@ private:
#if HAS_SERVOS #if HAS_SERVOS
static void M280(); static void M280();
#if ENABLED(EDITABLE_SERVO_ANGLES)
static void M281(); static void M281();
#endif #endif
#endif
#if ENABLED(BABYSTEPPING) #if ENABLED(BABYSTEPPING)
static void M290(); static void M290();

View file

@ -687,8 +687,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
/** /**
* Limited number of servos * Limited number of servos
*/ */
#if NUM_SERVOS > 4 #if NUM_SERVOS > MAX_SERVOS
#error "The maximum number of SERVOS in Marlin is 4." #error "The selected board doesn't support enough servos for your configuration. Reduce NUM_SERVOS."
#endif #endif
/** /**

View file

@ -181,9 +181,7 @@ typedef struct SettingsDataStruct {
// //
// SERVO_ANGLES // SERVO_ANGLES
// //
#if HAS_SERVOS uint16_t servo_angles[MAX_SERVOS][2]; // M281 P L U
uint8_t servo_angles[NUM_SERVOS][2];
#endif
// //
// DELTA / [XYZ]_DUAL_ENDSTOPS // DELTA / [XYZ]_DUAL_ENDSTOPS
@ -543,9 +541,25 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(storage_slot); EEPROM_WRITE(storage_slot);
#endif // AUTO_BED_LEVELING_UBL #endif // AUTO_BED_LEVELING_UBL
#if HAS_SERVOS #if !HAS_SERVOS || DISABLED(EDITABLE_SERVO_ANGLES)
EEPROM_WRITE(servo_angles); #if ENABLED(SWITCHING_EXTRUDER)
constexpr uint16_t sesa[][2] = SWITCHING_EXTRUDER_SERVO_ANGLES;
#endif #endif
constexpr uint16_t servo_angles[MAX_SERVOS][2] = {
#if ENABLED(SWITCHING_EXTRUDER)
[SWITCHING_EXTRUDER_SERVO_NR] = { sesa[0], sesa[1] }
#if EXTRUDERS > 3
, [SWITCHING_EXTRUDER_E23_SERVO_NR] = { sesa[2], sesa[3] }
#endif
#elif ENABLED(SWITCHING_NOZZLE)
[SWITCHING_NOZZLE_SERVO_NR] = SWITCHING_NOZZLE_SERVO_ANGLES
#elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
[Z_PROBE_SERVO_NR] = Z_SERVO_ANGLES
#endif
};
#endif
EEPROM_WRITE(servo_angles);
// 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS // 11 floats for DELTA / [XYZ]_DUAL_ENDSTOPS
#if ENABLED(DELTA) #if ENABLED(DELTA)
@ -1153,10 +1167,10 @@ void MarlinSettings::postprocess() {
// //
// SERVO_ANGLES // SERVO_ANGLES
// //
#if HAS_SERVOS #if !HAS_SERVOS || DISABLED(EDITABLE_SERVO_ANGLES)
EEPROM_READ(servo_angles); uint16_t servo_angles[MAX_SERVOS][2];
#endif #endif
EEPROM_READ(servo_angles);
// //
// DELTA Geometry or Dual Endstops offsets // DELTA Geometry or Dual Endstops offsets
@ -1801,33 +1815,40 @@ void MarlinSettings::reset(PORTARG_SOLO) {
// Servo Angles // Servo Angles
// //
#if HAS_SERVOS #if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
#if ENABLED(SWITCHING_EXTRUDER) #if ENABLED(SWITCHING_EXTRUDER)
#if EXTRUDERS > 3 #if EXTRUDERS > 3
#define REQ_ANGLES 4 #define REQ_ANGLES 4
#else #else
#define REQ_ANGLES 2 #define REQ_ANGLES 2
#endif #endif
const uint8_t extruder_angles[2] = SWITCHING_EXTRUDER_SERVO_ANGLES; constexpr uint16_t extruder_angles[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
static_assert(COUNT(extruder_angles) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles."); static_assert(COUNT(extruder_angles) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
servo_angles[SWITCHING_EXTRUDER_SERVO_NR][0] = extruder_angles[0]; servo_angles[SWITCHING_EXTRUDER_SERVO_NR][0] = extruder_angles[0];
servo_angles[SWITCHING_EXTRUDER_SERVO_NR][1] = extruder_angles[1]; servo_angles[SWITCHING_EXTRUDER_SERVO_NR][1] = extruder_angles[1];
#if EXTRUDERS > 3
servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][0] = extruder_angles[2];
servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][1] = extruder_angles[3];
#endif #endif
#if ENABLED(SWITCHING_NOZZLE) #elif ENABLED(SWITCHING_NOZZLE)
const uint8_t nozzel_angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
servo_angles[SWITCHING_NOZZLE_SERVO_NR][0] = nozzel_angles[0];
servo_angles[SWITCHING_NOZZLE_SERVO_NR][1] = nozzel_angles[1];
#endif
#if defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR) constexpr uint16_t nozzle_angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
const uint8_t z_probe_angles[2] = Z_SERVO_ANGLES; servo_angles[SWITCHING_NOZZLE_SERVO_NR][0] = nozzle_angles[0];
servo_angles[SWITCHING_NOZZLE_SERVO_NR][1] = nozzle_angles[1];
#elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
constexpr uint16_t z_probe_angles[2] = Z_SERVO_ANGLES;
servo_angles[Z_PROBE_SERVO_NR][0] = z_probe_angles[0]; servo_angles[Z_PROBE_SERVO_NR][0] = z_probe_angles[0];
servo_angles[Z_PROBE_SERVO_NR][1] = z_probe_angles[1]; servo_angles[Z_PROBE_SERVO_NR][1] = z_probe_angles[1];
#endif
#endif #endif
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
#if ENABLED(DELTA) #if ENABLED(DELTA)
const float adj[ABC] = DELTA_ENDSTOP_ADJ, const float adj[ABC] = DELTA_ENDSTOP_ADJ,
dta[ABC] = DELTA_TOWER_ANGLE_TRIM; dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
@ -2306,19 +2327,34 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif // HAS_LEVELING #endif // HAS_LEVELING
#if HAS_SERVOS #if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
if (!forReplay) { if (!forReplay) {
CONFIG_ECHO_START; CONFIG_ECHO_START;
SERIAL_ECHOLNPGM_P(port, "Servo Angles:"); SERIAL_ECHOLNPGM_P(port, "Servo Angles:");
} }
for (uint8_t i = 0; i < NUM_SERVOS; i++) { for (uint8_t i = 0; i < NUM_SERVOS; i++) {
CONFIG_ECHO_START; switch (i) {
SERIAL_ECHOPAIR_P(port, " M281 P", i); #if ENABLED(SWITCHING_EXTRUDER)
SERIAL_ECHOPAIR_P(port, " L",servo_angles[i][0]); case SWITCHING_EXTRUDER_SERVO_NR:
SERIAL_ECHOPAIR_P(port, " U",servo_angles[i][1]); #if EXTRUDERS > 3
SERIAL_EOL_P(port); case SWITCHING_EXTRUDER_E23_SERVO_NR:
}
#endif #endif
#elif ENABLED(SWITCHING_NOZZLE)
case SWITCHING_NOZZLE_SERVO_NR:
#elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
case Z_PROBE_SERVO_NR:
#endif
CONFIG_ECHO_START;
SERIAL_ECHOPAIR_P(port, " M281 P", int(i));
SERIAL_ECHOPAIR_P(port, " L", servo_angles[i][0]);
SERIAL_ECHOPAIR_P(port, " U", servo_angles[i][1]);
SERIAL_EOL_P(port);
default: break;
}
}
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
#if ENABLED(DELTA) #if ENABLED(DELTA)

View file

@ -434,7 +434,7 @@ bool set_probe_deployed(const bool deploy) {
#elif HAS_Z_SERVO_PROBE && DISABLED(BLTOUCH) #elif HAS_Z_SERVO_PROBE && DISABLED(BLTOUCH)
MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][(deploy ? 0 : 1)]); MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][deploy ? 0 : 1]);
#elif ENABLED(Z_PROBE_ALLEN_KEY) #elif ENABLED(Z_PROBE_ALLEN_KEY)

View file

@ -31,7 +31,7 @@
#include "servo.h" #include "servo.h"
HAL_SERVO_LIB servo[NUM_SERVOS]; HAL_SERVO_LIB servo[NUM_SERVOS];
uint8_t servo_angles[NUM_SERVOS][2]; uint16_t servo_angles[NUM_SERVOS][2];
void servo_init() { void servo_init() {
#if NUM_SERVOS >= 1 && HAS_SERVO_0 #if NUM_SERVOS >= 1 && HAS_SERVO_0

View file

@ -30,7 +30,7 @@
#include "../HAL/shared/servo.h" #include "../HAL/shared/servo.h"
extern HAL_SERVO_LIB servo[NUM_SERVOS]; extern HAL_SERVO_LIB servo[NUM_SERVOS];
extern uint8_t servo_angles[NUM_SERVOS][2]; extern uint16_t servo_angles[NUM_SERVOS][2];
extern void servo_init(); extern void servo_init();
#define MOVE_SERVO(I, P) servo[I].move(P) #define MOVE_SERVO(I, P) servo[I].move(P)

View file

@ -60,9 +60,9 @@
#if DO_SWITCH_EXTRUDER #if DO_SWITCH_EXTRUDER
#if EXTRUDERS > 3 #if EXTRUDERS > 3
#define _SERVO_NR (e < 2 ? SWITCHING_EXTRUDER_SERVO_NR : SWITCHING_EXTRUDER_E23_SERVO_NR) #define _SERVO_NR(E) ((E) < 2 ? SWITCHING_EXTRUDER_SERVO_NR : SWITCHING_EXTRUDER_E23_SERVO_NR)
#else #else
#define _SERVO_NR SWITCHING_EXTRUDER_SERVO_NR #define _SERVO_NR(E) SWITCHING_EXTRUDER_SERVO_NR
#endif #endif
void move_extruder_servo(const uint8_t e) { void move_extruder_servo(const uint8_t e) {
@ -71,7 +71,7 @@
if (e < EXTRUDERS - 1) if (e < EXTRUDERS - 1)
#endif #endif
{ {
MOVE_SERVO(_SERVO_NR, servo_angles[_SERVO_NR][e]); MOVE_SERVO(_SERVO_NR(e), servo_angles[_SERVO_NR(e)][e]);
safe_delay(500); safe_delay(500);
} }
} }
@ -82,7 +82,7 @@
void move_nozzle_servo(const uint8_t e) { void move_nozzle_servo(const uint8_t e) {
planner.synchronize(); planner.synchronize();
MOVE_SERVO(SWITCHING_NOZZLE_SERVO_NR, servo_angles[SWITCHING_EXTRUDER_SERVO_NR][e]); MOVE_SERVO(SWITCHING_NOZZLE_SERVO_NR, servo_angles[SWITCHING_NOZZLE_SERVO_NR][e]);
safe_delay(500); safe_delay(500);
} }

View file

@ -625,6 +625,10 @@
#define MAX_EXTRUDERS 5 #define MAX_EXTRUDERS 5
#endif #endif
#ifndef MAX_SERVOS
#define MAX_SERVOS 4
#endif
// //
// Assign auto fan pins if needed // Assign auto fan pins if needed
// //