Fix angles for disabled EDITABLE_SERVO_ANGLES (#12559)

This commit is contained in:
Scott Lahteine 2018-11-30 12:31:42 -06:00 committed by GitHub
parent c986239837
commit aaf862aef2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 149 additions and 83 deletions

View file

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

View file

@ -974,6 +974,12 @@
#define Z_PROBE_SERVO_NR -1 #define Z_PROBE_SERVO_NR -1
#endif #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 // Sensors
#define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH)) #define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))

View file

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

View file

@ -31,7 +31,10 @@
#include "servo.h" #include "servo.h"
HAL_SERVO_LIB servo[NUM_SERVOS]; 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() { void servo_init() {
#if NUM_SERVOS >= 1 && HAS_SERVO_0 #if NUM_SERVOS >= 1 && HAS_SERVO_0

View file

@ -28,13 +28,60 @@
#include "../inc/MarlinConfig.h" #include "../inc/MarlinConfig.h"
#include "../HAL/shared/servo.h" #include "../HAL/shared/servo.h"
extern HAL_SERVO_LIB servo[NUM_SERVOS]; #if HAS_SERVO_ANGLES
extern uint16_t servo_angles[NUM_SERVOS][2];
extern void servo_init(); #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
#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 // HAS_SERVO_ANGLES
#define MOVE_SERVO(I, P) servo[I].move(P) #define MOVE_SERVO(I, P) servo[I].move(P)
#if HAS_Z_SERVO_PROBE extern HAL_SERVO_LIB servo[NUM_SERVOS];
#define DEPLOY_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][0]) extern void servo_init();
#define STOW_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][1])
#endif