Fix angles for disabled EDITABLE_SERVO_ANGLES (#12559)

2.0.x
Scott Lahteine 6 years ago committed by GitHub
parent c986239837
commit aaf862aef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,7 @@
*/
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
#if ENABLED(EDITABLE_SERVO_ANGLES)
#include "../gcode.h"
#include "../../module/servo.h"
@ -53,4 +53,4 @@ void GcodeSuite::M281() {
}
}
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
#endif // EDITABLE_SERVO_ANGLES

@ -974,6 +974,12 @@
#define Z_PROBE_SERVO_NR -1
#endif
#define HAS_SERVO_ANGLES (ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE) || (HAS_Z_SERVO_PROBE && defined(Z_PROBE_SERVO_NR)))
#if !HAS_SERVO_ANGLES
#undef EDITABLE_SERVO_ANGLES
#endif
// Sensors
#define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))

@ -76,9 +76,9 @@
#if HAS_SERVOS
#include "servo.h"
#define EEPROM_NUM_SERVOS NUM_SERVOS
#else
#undef NUM_SERVOS
#define NUM_SERVOS NUM_SERVO_PLUGS
#define EEPROM_NUM_SERVOS NUM_SERVO_PLUGS
#endif
#if HAS_BED_PROBE
@ -187,7 +187,7 @@ typedef struct SettingsDataStruct {
//
// SERVO_ANGLES
//
uint16_t servo_angles[NUM_SERVOS][2]; // M281 P L U
uint16_t servo_angles[EEPROM_NUM_SERVOS][2]; // M281 P L U
//
// DELTA / [XYZ]_DUAL_ENDSTOPS
@ -632,36 +632,11 @@ void MarlinSettings::postprocess() {
// Servo Angles
//
{
#if !(HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES))
uint16_t servo_angles[NUM_SERVOS][2] = { { 0, 0 } };
#if ENABLED(SWITCHING_EXTRUDER)
constexpr uint16_t sesa[][2] = SWITCHING_EXTRUDER_SERVO_ANGLES;
servo_angles[SWITCHING_EXTRUDER_SERVO_NR][0] = sesa[0][0];
servo_angles[SWITCHING_EXTRUDER_SERVO_NR][1] = sesa[0][1];
#if EXTRUDERS > 3
servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][0] = sesa[1][0];
servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][1] = sesa[1][1];
#endif
#elif ENABLED(SWITCHING_NOZZLE)
constexpr uint16_t snsa[] = SWITCHING_NOZZLE_SERVO_ANGLES;
servo_angles[SWITCHING_NOZZLE_SERVO_NR][0] = snsa[0];
servo_angles[SWITCHING_NOZZLE_SERVO_NR][1] = snsa[1];
#elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
constexpr uint16_t zsa[] = Z_SERVO_ANGLES;
servo_angles[Z_PROBE_SERVO_NR][0] = zsa[0];
servo_angles[Z_PROBE_SERVO_NR][1] = zsa[1];
_FIELD_TEST(servo_angles);
#if !HAS_SERVOS
uint16_t servo_angles[NUM_SERVO_PLUGS][2] = { { 0, 0 } };
#endif
#endif // !HAS_SERVOS || !EDITABLE_SERVO_ANGLES
EEPROM_WRITE(servo_angles);
}
@ -1311,10 +1286,14 @@ void MarlinSettings::postprocess() {
// SERVO_ANGLES
//
{
#if !(HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES))
uint16_t servo_angles[NUM_SERVOS][2];
_FIELD_TEST(servo_angles);
#if ENABLED(EDITABLE_SERVO_ANGLES)
uint16_t (&servo_angles_arr)[EEPROM_NUM_SERVOS][2] = servo_angles;
#else
uint16_t servo_angles_arr[EEPROM_NUM_SERVOS][2];
#endif
EEPROM_READ(servo_angles);
EEPROM_READ(servo_angles_arr);
}
//
@ -1992,39 +1971,13 @@ void MarlinSettings::reset(PORTARG_SOLO) {
// Servo Angles
//
#if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
#if ENABLED(SWITCHING_EXTRUDER)
#if EXTRUDERS > 3
#define REQ_ANGLES 4
#else
#define REQ_ANGLES 2
#endif
constexpr uint16_t sesa[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
static_assert(COUNT(sesa) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
servo_angles[SWITCHING_EXTRUDER_SERVO_NR][0] = sesa[0];
servo_angles[SWITCHING_EXTRUDER_SERVO_NR][1] = sesa[1];
#if EXTRUDERS > 3
servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][0] = sesa[2];
servo_angles[SWITCHING_EXTRUDER_E23_SERVO_NR][1] = sesa[3];
#if ENABLED(EDITABLE_SERVO_ANGLES)
COPY(servo_angles, base_servo_angles);
#endif
#elif ENABLED(SWITCHING_NOZZLE)
constexpr uint16_t snsa[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
servo_angles[SWITCHING_NOZZLE_SERVO_NR][0] = snsa[0];
servo_angles[SWITCHING_NOZZLE_SERVO_NR][1] = snsa[1];
#elif defined(Z_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
constexpr uint16_t zsa[2] = Z_SERVO_ANGLES;
servo_angles[Z_PROBE_SERVO_NR][0] = zsa[0];
servo_angles[Z_PROBE_SERVO_NR][1] = zsa[1];
#endif
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
//
// Endstop Adjustments
//
#if ENABLED(DELTA)
const float adj[ABC] = DELTA_ENDSTOP_ADJ, dta[ABC] = DELTA_TOWER_ANGLE_TRIM;
@ -2083,6 +2036,10 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif
//
// Preheat parameters
//
#if HAS_LCD_MENU
ui.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
ui.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
@ -2092,6 +2049,10 @@ void MarlinSettings::reset(PORTARG_SOLO) {
ui.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
#endif
//
// Hotend PID
//
#if ENABLED(PIDTEMP)
HOTEND_LOOP() {
PID_PARAM(Kp, e) = float(DEFAULT_Kp);
@ -2101,10 +2062,19 @@ void MarlinSettings::reset(PORTARG_SOLO) {
PID_PARAM(Kc, e) = DEFAULT_Kc;
#endif
}
#endif
//
// PID Extrusion Scaling
//
#if ENABLED(PID_EXTRUSION_SCALING)
thermalManager.lpq_len = 20; // default last-position-queue size
thermalManager.lpq_len = 20; // Default last-position-queue size
#endif
#endif // PIDTEMP
//
// Heated Bed PID
//
#if ENABLED(PIDTEMPBED)
thermalManager.bed_pid.Kp = DEFAULT_bedKp;
@ -2112,18 +2082,34 @@ void MarlinSettings::reset(PORTARG_SOLO) {
thermalManager.bed_pid.Kd = scalePID_d(DEFAULT_bedKd);
#endif
//
// LCD Contrast
//
#if HAS_LCD_CONTRAST
ui.set_contrast(DEFAULT_LCD_CONTRAST);
#endif
//
// Power-Loss Recovery
//
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.enable(true);
#endif
//
// Firmware Retraction
//
#if ENABLED(FWRETRACT)
fwretract.reset();
#endif
//
// Volumetric & Filament Size
//
#if DISABLED(NO_VOLUMETRICS)
parser.volumetric_enabled =
@ -2148,16 +2134,36 @@ void MarlinSettings::reset(PORTARG_SOLO) {
reset_stepper_drivers();
//
// Linear Advance
//
#if ENABLED(LIN_ADVANCE)
LOOP_L_N(i, EXTRUDERS) planner.extruder_advance_K[i] = LIN_ADVANCE_K;
#endif
//
// Motor Current PWM
//
#if HAS_MOTOR_CURRENT_PWM
uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT;
for (uint8_t q = 3; q--;)
stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
#endif
//
// CNC Coordinate System
//
#if ENABLED(CNC_COORDINATE_SYSTEMS)
(void)gcode.select_coordinate_system(-1); // Go back to machine space
#endif
//
// Skew Correction
//
#if ENABLED(SKEW_CORRECTION_GCODE)
planner.skew_factor.xy = XY_SKEW_FACTOR;
#if ENABLED(SKEW_CORRECTION_FOR_Z)
@ -2166,6 +2172,10 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif
#endif
//
// Advanced Pause filament load & unload lengths
//
#if ENABLED(ADVANCED_PAUSE_FEATURE)
for (uint8_t e = 0; e < EXTRUDERS; e++) {
fc_settings[e].unload_length = FILAMENT_CHANGE_UNLOAD_LENGTH;
@ -2491,7 +2501,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
#endif // HAS_LEVELING
#if HAS_SERVOS && ENABLED(EDITABLE_SERVO_ANGLES)
#if ENABLED(EDITABLE_SERVO_ANGLES)
CONFIG_ECHO_HEADING("Servo Angles:");
for (uint8_t i = 0; i < NUM_SERVOS; i++) {
@ -2515,7 +2525,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
}
}
#endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES
#endif // EDITABLE_SERVO_ANGLES
#if HAS_SCARA_OFFSET

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

@ -28,13 +28,60 @@
#include "../inc/MarlinConfig.h"
#include "../HAL/shared/servo.h"
extern HAL_SERVO_LIB servo[NUM_SERVOS];
extern uint16_t servo_angles[NUM_SERVOS][2];
extern void servo_init();
#if HAS_SERVO_ANGLES
#define MOVE_SERVO(I, P) servo[I].move(P)
#if ENABLED(SWITCHING_EXTRUDER)
#ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
#define SWITCHING_EXTRUDER_E23_SERVO_NR -1
#endif
#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_SERVO_ANGLES) && defined(Z_PROBE_SERVO_NR)
#define SADATA Z_SERVO_ANGLES
#define ASRC(N,E) (Z_PROBE_SERVO_NR == N ? asrc[E] : 0)
#endif
#if ENABLED(EDITABLE_SERVO_ANGLES)
extern uint16_t servo_angles[NUM_SERVOS][2];
#define BASE_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.");
#endif
constexpr uint16_t BASE_SERVO_ANGLES [NUM_SERVOS][2] = {
{ ASRC(0,0), ASRC(0,1) }
#if NUM_SERVOS > 1
, { ASRC(1,0), ASRC(1,1) }
#if NUM_SERVOS > 2
, { ASRC(2,0), ASRC(2,1) }
#if NUM_SERVOS > 3
, { ASRC(3,0), ASRC(3,1) }
#endif
#endif
#endif
};
#if HAS_Z_SERVO_PROBE
#if HAS_Z_SERVO_PROBE
#define DEPLOY_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][0])
#define STOW_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][1])
#endif
#endif
#endif // HAS_SERVO_ANGLES
#define MOVE_SERVO(I, P) servo[I].move(P)
extern HAL_SERVO_LIB servo[NUM_SERVOS];
extern void servo_init();

Loading…
Cancel
Save