Skip to content

Commit

Permalink
🎨 Misc. cleanup, string optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 10, 2022
1 parent 46e282b commit e2353be
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@
#define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
// is more than PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.

//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of PROGMEM)
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of PROGMEM)
//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of flash)
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of flash)
#endif

// @section extruder
Expand Down Expand Up @@ -1970,7 +1970,7 @@
* M502 - Revert settings to "factory" defaults. (Follow with M500 to init the EEPROM.)
*/
//#define EEPROM_SETTINGS // Persistent storage with M500 and M501
//#define DISABLE_M503 // Saves ~2700 bytes of PROGMEM. Disable for release!
//#define DISABLE_M503 // Saves ~2700 bytes of flash. Disable for release!
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM.
#define EEPROM_BOOT_SILENT // Keep M503 quiet and only give errors during first load
#if ENABLED(EEPROM_SETTINGS)
Expand Down
8 changes: 6 additions & 2 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
if (do_reset_timeout) gcode.reset_stepper_timeout(ms);

if (gcode.stepper_max_timed_out(ms)) {
SERIAL_ERROR_MSG(STR_KILL_INACTIVE_TIME, parser.command_ptr);
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_KILL_PRE);
SERIAL_ECHOLNPGM(STR_KILL_INACTIVE_TIME, parser.command_ptr);
kill();
}

Expand Down Expand Up @@ -473,7 +475,9 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
// KILL the machine
// ----------------------------------------------------------------
if (killCount >= KILL_DELAY) {
SERIAL_ERROR_MSG(STR_KILL_BUTTON);
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_KILL_PRE);
SERIAL_ECHOLNPGM(STR_KILL_BUTTON);
kill();
}
#endif
Expand Down
22 changes: 13 additions & 9 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,20 @@
#define STR_FILAMENT_CHANGE_INSERT_M108 "Insert filament and send M108"
#define STR_FILAMENT_CHANGE_WAIT_M108 "Send M108 to resume"

#define STR_STOP_BLTOUCH "!! STOP called because of BLTouch error - restart with M999"
#define STR_STOP_UNHOMED "!! STOP called because of unhomed error - restart with M999"
#define STR_KILL_INACTIVE_TIME "!! KILL caused by too much inactive time - current command: "
#define STR_KILL_BUTTON "!! KILL caused by KILL button/pin"
#define STR_STOP_PRE "!! STOP called because of "
#define STR_STOP_POST " error - restart with M999"
#define STR_STOP_BLTOUCH "BLTouch"
#define STR_STOP_UNHOMED "unhomed"
#define STR_KILL_PRE "!! KILL caused by "
#define STR_KILL_INACTIVE_TIME "too much inactive time - current command: "
#define STR_KILL_BUTTON "KILL button/pin"

// temperature.cpp strings
#define STR_PID_AUTOTUNE_START "PID Autotune start"
#define STR_PID_BAD_HEATER_ID "PID Autotune failed! Bad heater id"
#define STR_PID_TEMP_TOO_HIGH "PID Autotune failed! Temperature too high"
#define STR_PID_TIMEOUT "PID Autotune failed! timeout"
#define STR_PID_AUTOTUNE "PID Autotune"
#define STR_PID_AUTOTUNE_START " start"
#define STR_PID_BAD_HEATER_ID " failed! Bad heater id"
#define STR_PID_TEMP_TOO_HIGH " failed! Temperature too high"
#define STR_PID_TIMEOUT " failed! timeout"
#define STR_BIAS " bias: "
#define STR_D_COLON " d: "
#define STR_T_MIN " min: "
Expand All @@ -219,7 +223,7 @@
#define STR_KP " Kp: "
#define STR_KI " Ki: "
#define STR_KD " Kd: "
#define STR_PID_AUTOTUNE_FINISHED "PID Autotune finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
#define STR_PID_AUTOTUNE_FINISHED " finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
#define STR_PID_DEBUG " PID_DEBUG "
#define STR_PID_DEBUG_INPUT ": Input "
#define STR_PID_DEBUG_OUTPUT " Output "
Expand Down
15 changes: 4 additions & 11 deletions Marlin/src/feature/bltouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ bool BLTouch::deploy_proc() {
// Last attempt to DEPLOY
if (_deploy_query_alarm()) {
// The deploy might have failed or the probe is actually triggered (nozzle too low?) again
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");

SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
stop(); // but it's not too bad, no need to kill, allow restart

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Deploy Failed");
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
}
}
Expand Down Expand Up @@ -153,12 +150,8 @@ bool BLTouch::stow_proc() {
// But one more STOW will catch that
// Last attempt to STOW
if (_stow_query_alarm()) { // so if there is now STILL an ALARM condition:

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Recovery Failed");

SERIAL_ERROR_MSG(STR_STOP_BLTOUCH); // Tell the user something is wrong, needs action
stop(); // but it's not too bad, no need to kill, allow restart

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("BLTouch Stow Failed");
probe.probe_error_stop(); // Something is wrong, needs action, but not too bad, allow restart
return true; // Tell our caller we goofed in case he cares to know
}
}
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void GcodeSuite::M303() {
case H_CHAMBER: default_temp = PREHEAT_1_TEMP_CHAMBER; break;
#endif
default:
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_BAD_EXTRUDER_NUM));
Expand Down
12 changes: 4 additions & 8 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2960,10 +2960,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#if ENABLED(DWIN_CREALITY_LCD)
#if DISABLED(SDSUPPORT)
#error "DWIN_CREALITY_LCD requires SDSUPPORT to be enabled."
#elif ENABLED(PID_EDIT_MENU)
#error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU."
#elif ENABLED(PID_AUTOTUNE_MENU)
#error "DWIN_CREALITY_LCD does not support PID_AUTOTUNE_MENU."
#elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
#error "DWIN_CREALITY_LCD does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
#elif ENABLED(LEVEL_BED_CORNERS)
#error "DWIN_CREALITY_LCD does not support LEVEL_BED_CORNERS."
#elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)
Expand All @@ -2972,10 +2970,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#elif ENABLED(DWIN_LCD_PROUI)
#if DISABLED(SDSUPPORT)
#error "DWIN_LCD_PROUI requires SDSUPPORT to be enabled."
#elif ENABLED(PID_EDIT_MENU)
#error "DWIN_LCD_PROUI does not support PID_EDIT_MENU."
#elif ENABLED(PID_AUTOTUNE_MENU)
#error "DWIN_LCD_PROUI does not support PID_AUTOTUNE_MENU."
#elif EITHER(PID_EDIT_MENU, PID_AUTOTUNE_MENU)
#error "DWIN_LCD_PROUI does not support PID_EDIT_MENU or PID_AUTOTUNE_MENU."
#elif ENABLED(LEVEL_BED_CORNERS)
#error "DWIN_LCD_PROUI does not support LEVEL_BED_CORNERS."
#elif BOTH(LCD_BED_LEVELING, PROBE_MANUALLY)
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void menu_backlash();
void menu_advanced_temperature() {
START_MENU();
BACK_ITEM(MSG_ADVANCED_SETTINGS);

//
// Autotemp, Min, Max, Fact
//
Expand Down Expand Up @@ -325,7 +326,7 @@ void menu_backlash();

HOTEND_PID_EDIT_MENU_ITEMS(0);
#if ENABLED(PID_PARAMS_PER_HOTEND)
REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS)
REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS);
#endif
#endif

Expand Down
25 changes: 18 additions & 7 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,21 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {

#endif

/**
* Print an error and stop()
*/
void Probe::probe_error_stop() {
SERIAL_ERROR_START();
SERIAL_ECHOPGM(STR_STOP_PRE);
#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
SERIAL_ECHOPGM(STR_STOP_UNHOMED);
#elif ENABLED(BLTOUCH)
SERIAL_ECHOPGM(STR_STOP_BLTOUCH);
#endif
SERIAL_ECHOLNPGM(STR_STOP_POST);
stop();
}

/**
* Attempt to deploy or stow the probe
*
Expand Down Expand Up @@ -443,8 +458,7 @@ bool Probe::set_deployed(const bool deploy) {

#if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY)
if (homing_needed_error(TERN_(Z_PROBE_SLED, _BV(X_AXIS)))) {
SERIAL_ERROR_MSG(STR_STOP_UNHOMED);
stop();
probe_error_stop();
return true;
}
#endif
Expand Down Expand Up @@ -484,15 +498,12 @@ bool Probe::set_deployed(const bool deploy) {
}

/**
* @brief Used by run_z_probe to do a single Z probe move.
* @brief Move down until the probe triggers or the low limit is reached
* Used by run_z_probe to do a single Z probe move.
*
* @param z Z destination
* @param fr_mm_s Feedrate in mm/s
* @return true to indicate an error
*/

/**
* @brief Move down until the probe triggers or the low limit is reached
*
* @details Used by run_z_probe to get each bed Z height measurement.
* Sets current_position.z to the height where the probe triggered
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Probe {
static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp);
#endif

static void probe_error_stop();

static bool set_deployed(const bool deploy);

#if IS_KINEMATIC
Expand Down
36 changes: 20 additions & 16 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,15 @@ volatile bool Temperature::raw_temps_ready = false;
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(isbed ? PID_BED_START : PID_EXTR_START));

if (target > GHV(CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id].maxtemp - (HOTEND_OVERSHOOT))) {
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_TEMP_TOO_HIGH)));
return;
}

SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_START);

disable_all_heaters();
Expand All @@ -654,10 +656,11 @@ volatile bool Temperature::raw_temps_ready = false;

TERN_(NO_FAN_SLOWING_IN_PID_TUNING, adaptive_fan_slowing = false);

// PID Tuning loop
wait_for_heatup = true; // Can be interrupted with M108
LCD_MESSAGE(MSG_HEATING);
while (wait_for_heatup) {

// PID Tuning loop
wait_for_heatup = true;
while (wait_for_heatup) { // Can be interrupted with M108

const millis_t ms = millis();

Expand Down Expand Up @@ -723,6 +726,7 @@ volatile bool Temperature::raw_temps_ready = false;
#define MAX_OVERSHOOT_PID_AUTOTUNE 30
#endif
if (current_temp > target + MAX_OVERSHOOT_PID_AUTOTUNE) {
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH));
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TEMP_TOO_HIGH));
Expand Down Expand Up @@ -765,11 +769,13 @@ volatile bool Temperature::raw_temps_ready = false;
TERN_(DWIN_LCD_PROUI, DWIN_PidTuning(PID_TUNING_TIMEOUT));
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));
TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_TIMEOUT)));
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_TIMEOUT);
break;
}

if (cycles > ncycles && cycles > 2) {
SERIAL_ECHOPGM(STR_PID_AUTOTUNE);
SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_FINISHED);
TERN_(HOST_PROMPT_SUPPORT, hostui.notify(GET_TEXT_F(MSG_PID_AUTOTUNE_DONE)));

Expand Down Expand Up @@ -869,7 +875,6 @@ volatile bool Temperature::raw_temps_ready = false;
MPC_t& constants = hotend.constants;

// move to center of bed, just above bed height and cool with max fan
SERIAL_ECHOLNPGM("Moving to tuning position");
TERN_(HAS_FAN, zero_fan_speeds());
disable_all_heaters();
TERN_(HAS_FAN, set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255));
Expand All @@ -896,15 +901,15 @@ volatile bool Temperature::raw_temps_ready = false;
next_test_ms += 10000UL;
}
}

TERN_(HAS_FAN, set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0));
TERN_(HAS_FAN, planner.sync_fan_speeds(fan_speed));

hotend.modeled_ambient_temp = ambient_temp;

SERIAL_ECHOLNPGM("Heating to 200C");
hotend.soft_pwm_amount = MPC_MAX >> 1;
const millis_t heat_start_time = ms;
next_test_ms = ms;
const millis_t heat_start_time = next_test_ms = ms;
celsius_float_t temp_samples[16];
uint8_t sample_count = 0;
uint16_t sample_distance = 1;
Expand Down Expand Up @@ -935,7 +940,7 @@ volatile bool Temperature::raw_temps_ready = false;
}
hotend.soft_pwm_amount = 0;

// calculate physical constants from three equally spaced samples
// Calculate physical constants from three equally-spaced samples
sample_count = (sample_count + 1) / 2 * 2 - 1;
const float t1 = temp_samples[0],
t2 = temp_samples[(sample_count - 1) >> 1],
Expand All @@ -951,14 +956,13 @@ volatile bool Temperature::raw_temps_ready = false;
hotend.modeled_block_temp = asymp_temp + (ambient_temp - asymp_temp) * exp(-block_responsiveness * (ms - heat_start_time) / 1000.0f);
hotend.modeled_sensor_temp = current_temp;

// let the system stabilise under MPC control then get a better measure of ambient loss without and with fan
// Allow the system to stabilize under MPC, then get a better measure of ambient loss with and without fan
SERIAL_ECHOLNPGM("Measuring ambient heatloss at target ", hotend.modeled_block_temp);
hotend.target = hotend.modeled_block_temp;
next_test_ms = ms + MPC_dT * 1000;
constexpr millis_t settle_time = 20000UL,
test_length = 20000UL;
constexpr millis_t settle_time = 20000UL, test_duration = 20000UL;
millis_t settle_end_ms = ms + settle_time,
test_end_ms = settle_end_ms + test_length;
test_end_ms = settle_end_ms + test_duration;
float total_energy_fan0 = 0.0f;
#if HAS_FAN
bool fan0_done = false;
Expand All @@ -981,7 +985,7 @@ volatile bool Temperature::raw_temps_ready = false;
set_fan_speed(ANY(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255);
planner.sync_fan_speeds(fan_speed);
settle_end_ms = ms + settle_time;
test_end_ms = settle_end_ms + test_length;
test_end_ms = settle_end_ms + test_duration;
fan0_done = true;
}
else if (ELAPSED(ms, settle_end_ms) && !ELAPSED(ms, test_end_ms))
Expand All @@ -999,11 +1003,11 @@ volatile bool Temperature::raw_temps_ready = false;
}
}

const float power_fan0 = total_energy_fan0 * 1000 / test_length;
const float power_fan0 = total_energy_fan0 * 1000 / test_duration;
constants.ambient_xfer_coeff_fan0 = power_fan0 / (hotend.target - ambient_temp);

#if HAS_FAN
const float power_fan255 = total_energy_fan255 * 1000 / test_length,
const float power_fan255 = total_energy_fan255 * 1000 / test_duration,
ambient_xfer_coeff_fan255 = power_fan255 / (hotend.target - ambient_temp);
constants.fan255_adjustment = ambient_xfer_coeff_fan255 - constants.ambient_xfer_coeff_fan0;
#endif
Expand Down Expand Up @@ -1369,8 +1373,8 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
#endif

#elif ENABLED(MPCTEMP)
MPCHeaterInfo& hotend = temp_hotend[ee];
MPC_t& constants = hotend.constants;
MPCHeaterInfo &hotend = temp_hotend[ee];
MPC_t &constants = hotend.constants;

// At startup, initialize modeled temperatures
if (isnan(hotend.modeled_block_temp)) {
Expand Down

0 comments on commit e2353be

Please sign in to comment.