Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f14988c

Browse files
committedFeb 1, 2023
Extend M306 T
Let MPC autotune to specify extruder
1 parent 3be967b commit f14988c

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed
 

‎Marlin/src/gcode/temp/M306.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@
4444

4545
void GcodeSuite::M306() {
4646
if (parser.seen_test('T')) {
47+
const heater_id_t hid = (heater_id_t)parser.intval('E', active_extruder);
48+
4749
LCD_MESSAGE(MSG_MPC_AUTOTUNE);
48-
thermalManager.MPC_autotune();
50+
thermalManager.MPC_autotune(hid);
4951
ui.reset_status();
5052
return;
5153
}
5254

5355
if (parser.seen("ACFPRH")) {
5456
const heater_id_t hid = (heater_id_t)parser.intval('E', 0);
57+
5558
MPC_t &mpc = thermalManager.temp_hotend[hid].mpc;
5659
if (parser.seenval('P')) mpc.heater_power = parser.value_float();
5760
if (parser.seenval('C')) mpc.block_heat_capacity = parser.value_float();

‎Marlin/src/lcd/e3v2/proui/dwin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3542,7 +3542,7 @@ void Draw_Steps_Menu() {
35423542

35433543
#if ENABLED(MPCTEMP)
35443544

3545-
void HotendMPC() { thermalManager.MPC_autotune(); }
3545+
void HotendMPC() { thermalManager.MPC_autotune(active_extruder); }
35463546
void SetHeaterPower() { SetPFloatOnClick(1, 200, 1); }
35473547
void SetBlkHeatCapacity() { SetPFloatOnClick(0, 40, 2); }
35483548
void SetSensorRespons() { SetPFloatOnClick(0, 1, 4); }

‎Marlin/src/module/temperature.cpp

+21-19
Original file line numberDiff line numberDiff line change
@@ -884,19 +884,19 @@ volatile bool Temperature::raw_temps_ready = false;
884884

885885
#if ENABLED(MPCTEMP)
886886

887-
void Temperature::MPC_autotune() {
888-
auto housekeeping = [] (millis_t &ms, celsius_float_t &current_temp, millis_t &next_report_ms) {
887+
void Temperature::MPC_autotune(const heater_id_t e) {
888+
auto housekeeping = [] (millis_t &ms, const heater_id_t e, celsius_float_t &current_temp, millis_t &next_report_ms) {
889889
ms = millis();
890890

891891
if (updateTemperaturesIfReady()) { // temp sample ready
892-
current_temp = degHotend(active_extruder);
892+
current_temp = degHotend(e);
893893
TERN_(HAS_FAN_LOGIC, manage_extruder_fans(ms));
894894
}
895895

896896
if (ELAPSED(ms, next_report_ms)) {
897897
next_report_ms += 1000UL;
898898

899-
print_heater_states(active_extruder);
899+
print_heater_states(e);
900900
SERIAL_EOL();
901901
}
902902

@@ -914,27 +914,29 @@ volatile bool Temperature::raw_temps_ready = false;
914914
};
915915

916916
struct OnExit {
917+
heater_id_t e;
918+
OnExit(const heater_id_t e) {this->e = e;}
917919
~OnExit() {
918920
wait_for_heatup = false;
919921

920922
ui.reset_status();
921923

922-
temp_hotend[active_extruder].target = 0.0f;
923-
temp_hotend[active_extruder].soft_pwm_amount = 0;
924+
temp_hotend[e].target = 0.0f;
925+
temp_hotend[e].soft_pwm_amount = 0;
924926
#if HAS_FAN
925-
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0);
927+
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e, 0);
926928
planner.sync_fan_speeds(fan_speed);
927929
#endif
928930

929931
do_z_clearance(MPC_TUNING_END_Z);
930932

931933
TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = true);
932934
}
933-
} on_exit;
935+
} on_exit(e);
934936

935937
SERIAL_ECHOPGM(STR_MPC_AUTOTUNE);
936-
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_START, active_extruder);
937-
MPCHeaterInfo &hotend = temp_hotend[active_extruder];
938+
SERIAL_ECHOLNPGM(STR_MPC_AUTOTUNE_START, e);
939+
MPCHeaterInfo &hotend = temp_hotend[e];
938940
MPC_t &mpc = hotend.mpc;
939941

940942
TERN_(TEMP_TUNING_MAINTAIN_FAN, adaptive_fan_slowing = false);
@@ -944,7 +946,7 @@ volatile bool Temperature::raw_temps_ready = false;
944946
disable_all_heaters();
945947
#if HAS_FAN
946948
zero_fan_speeds();
947-
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255);
949+
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e, 255);
948950
planner.sync_fan_speeds(fan_speed);
949951
#endif
950952
do_blocking_move_to(xyz_pos_t(MPC_TUNING_POS));
@@ -958,12 +960,12 @@ volatile bool Temperature::raw_temps_ready = false;
958960
#endif
959961

960962
millis_t ms = millis(), next_report_ms = ms, next_test_ms = ms + 10000UL;
961-
celsius_float_t current_temp = degHotend(active_extruder),
963+
celsius_float_t current_temp = degHotend(e),
962964
ambient_temp = current_temp;
963965

964966
wait_for_heatup = true;
965967
for (;;) { // Can be interrupted with M108
966-
if (housekeeping(ms, current_temp, next_report_ms)) return;
968+
if (housekeeping(ms, e, current_temp, next_report_ms)) return;
967969

968970
if (ELAPSED(ms, next_test_ms)) {
969971
if (current_temp >= ambient_temp) {
@@ -977,7 +979,7 @@ volatile bool Temperature::raw_temps_ready = false;
977979
wait_for_heatup = false;
978980

979981
#if HAS_FAN
980-
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 0);
982+
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e, 0);
981983
planner.sync_fan_speeds(fan_speed);
982984
#endif
983985

@@ -995,7 +997,7 @@ volatile bool Temperature::raw_temps_ready = false;
995997

996998
wait_for_heatup = true;
997999
for (;;) { // Can be interrupted with M108
998-
if (housekeeping(ms, current_temp, next_report_ms)) return;
1000+
if (housekeeping(ms, e, current_temp, next_report_ms)) return;
9991001

10001002
if (ELAPSED(ms, next_test_ms)) {
10011003
// Record samples between 100C and 200C
@@ -1054,16 +1056,16 @@ volatile bool Temperature::raw_temps_ready = false;
10541056

10551057
wait_for_heatup = true;
10561058
for (;;) { // Can be interrupted with M108
1057-
if (housekeeping(ms, current_temp, next_report_ms)) return;
1059+
if (housekeeping(ms, e, current_temp, next_report_ms)) return;
10581060

10591061
if (ELAPSED(ms, next_test_ms)) {
1060-
hotend.soft_pwm_amount = (int)get_pid_output_hotend(active_extruder) >> 1;
1062+
hotend.soft_pwm_amount = (int)get_pid_output_hotend(e) >> 1;
10611063

10621064
if (ELAPSED(ms, settle_end_ms) && !ELAPSED(ms, test_end_ms) && TERN1(HAS_FAN, !fan0_done))
10631065
total_energy_fan0 += mpc.heater_power * hotend.soft_pwm_amount / 127 * MPC_dT + (last_temp - current_temp) * mpc.block_heat_capacity;
10641066
#if HAS_FAN
10651067
else if (ELAPSED(ms, test_end_ms) && !fan0_done) {
1066-
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : active_extruder, 255);
1068+
set_fan_speed(EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : e, 255);
10671069
planner.sync_fan_speeds(fan_speed);
10681070
settle_end_ms = ms + settle_time;
10691071
test_end_ms = settle_end_ms + test_duration;
@@ -1451,7 +1453,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id) {
14511453

14521454
float ambient_xfer_coeff = mpc.ambient_xfer_coeff_fan0;
14531455
#if ENABLED(MPC_INCLUDE_FAN)
1454-
const uint8_t fan_index = EITHER(MPC_FAN_0_ACTIVE_HOTEND, MPC_FAN_0_ALL_HOTENDS) ? 0 : ee;
1456+
const uint8_t fan_index = EITHER(MPC_FAN_0_ALL_HOTENDS, MPC_FAN_0_ACTIVE_HOTEND) ? 0 : ee;
14551457
const float fan_fraction = TERN_(MPC_FAN_0_ACTIVE_HOTEND, !this_hotend ? 0.0f : ) fan_speed[fan_index] * RECIPROCAL(255);
14561458
ambient_xfer_coeff += fan_fraction * mpc.fan255_adjustment;
14571459
#endif

‎Marlin/src/module/temperature.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ class Temperature {
11951195
#endif
11961196

11971197
#if ENABLED(MPCTEMP)
1198-
void MPC_autotune();
1198+
void MPC_autotune(const heater_id_t e);
11991199
#endif
12001200

12011201
#if ENABLED(PROBING_HEATERS_OFF)

0 commit comments

Comments
 (0)
Please sign in to comment.