|
| 1 | +/** |
| 2 | + * Marlin 3D Printer Firmware |
| 3 | + * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] |
| 4 | + * |
| 5 | + * Based on Sprinter and grbl. |
| 6 | + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +#include "../../inc/MarlinConfig.h" |
| 24 | + |
| 25 | +#if ENABLED(MPCTEMP) |
| 26 | + |
| 27 | +#include "../gcode.h" |
| 28 | +#include "../../module/temperature.h" |
| 29 | + |
| 30 | +/** |
| 31 | + * M306: MPC settings and autotune |
| 32 | + * |
| 33 | + * T Autotune the active extruder. |
| 34 | + * |
| 35 | + * A<watts/kelvin> Ambient heat transfer coefficient (no fan). |
| 36 | + * C<joules/kelvin> Block heat capacity. |
| 37 | + * E<extruder> Extruder number to set. (Default: E0) |
| 38 | + * F<watts/kelvin> Ambient heat transfer coefficient (fan on full). |
| 39 | + * P<watts> Heater power. |
| 40 | + * R<kelvin/second/kelvin> Sensor responsiveness (= transfer coefficient / heat capcity). |
| 41 | + */ |
| 42 | + |
| 43 | +void GcodeSuite::M306() { |
| 44 | + if (parser.seen_test('T')) { thermalManager.MPC_autotune(); return; } |
| 45 | + |
| 46 | + if (parser.seen("ACFPR")) { |
| 47 | + const heater_id_t hid = (heater_id_t)parser.intval('E', 0); |
| 48 | + MPC_t &constants = thermalManager.temp_hotend[hid].constants; |
| 49 | + if (parser.seenval('P')) constants.heater_power = parser.value_float(); |
| 50 | + if (parser.seenval('C')) constants.block_heat_capacity = parser.value_float(); |
| 51 | + if (parser.seenval('R')) constants.sensor_responsiveness = parser.value_float(); |
| 52 | + if (parser.seenval('A')) constants.ambient_xfer_coeff_fan0 = parser.value_float(); |
| 53 | + #if ENABLED(MPC_INCLUDE_FAN) |
| 54 | + if (parser.seenval('F')) constants.fan255_adjustment = parser.value_float() - constants.ambient_xfer_coeff_fan0; |
| 55 | + #endif |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + HOTEND_LOOP() { |
| 60 | + SERIAL_ECHOLNPGM("MPC constants for hotend ", e); |
| 61 | + MPC_t& constants = thermalManager.temp_hotend[e].constants; |
| 62 | + SERIAL_ECHOLNPGM("Heater power: ", constants.heater_power); |
| 63 | + SERIAL_ECHOLNPGM("Heatblock heat capacity: ", constants.block_heat_capacity); |
| 64 | + SERIAL_ECHOLNPAIR_F("Sensor responsivness: ", constants.sensor_responsiveness, 4); |
| 65 | + SERIAL_ECHOLNPAIR_F("Ambient heat transfer coeff. (no fan): ", constants.ambient_xfer_coeff_fan0, 4); |
| 66 | + #if ENABLED(MPC_INCLUDE_FAN) |
| 67 | + SERIAL_ECHOLNPAIR_F("Ambient heat transfer coeff. (full fan): ", constants.ambient_xfer_coeff_fan0 + constants.fan255_adjustment, 4); |
| 68 | + #endif |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +void GcodeSuite::M306_report(const bool forReplay/*=true*/) { |
| 73 | + report_heading(forReplay, F("Model predictive control")); |
| 74 | + HOTEND_LOOP() { |
| 75 | + report_echo_start(forReplay); |
| 76 | + MPC_t& constants = thermalManager.temp_hotend[e].constants; |
| 77 | + SERIAL_ECHOPGM(" M306 E", e); |
| 78 | + SERIAL_ECHOPAIR_F(" P", constants.heater_power, 2); |
| 79 | + SERIAL_ECHOPAIR_F(" C", constants.block_heat_capacity, 2); |
| 80 | + SERIAL_ECHOPAIR_F(" R", constants.sensor_responsiveness, 4); |
| 81 | + SERIAL_ECHOPAIR_F(" A", constants.ambient_xfer_coeff_fan0, 4); |
| 82 | + SERIAL_ECHOLNPAIR_F(" F", constants.ambient_xfer_coeff_fan0 + constants.fan255_adjustment, 4); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +#endif // MPCTEMP |
0 commit comments