Chamber Heater PID (#21156)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Ken Sanislo
2021-02-24 16:26:51 -08:00
committed by GitHub
parent 03160719eb
commit a3a10b62f2
15 changed files with 519 additions and 236 deletions

View File

@ -0,0 +1,48 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfig.h"
#if ENABLED(PIDTEMPCHAMBER)
#include "../gcode.h"
#include "../../module/temperature.h"
/**
* M309 - Set and/or Report the current Chamber PID values
*
* P<pval> - Set the P value
* I<ival> - Set the I value
* D<dval> - Set the D value
*/
void GcodeSuite::M309() {
if (parser.seen('P')) thermalManager.temp_chamber.pid.Kp = parser.value_float();
if (parser.seen('I')) thermalManager.temp_chamber.pid.Ki = scalePID_i(parser.value_float());
if (parser.seen('D')) thermalManager.temp_chamber.pid.Kd = scalePID_d(parser.value_float());
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(" p:", thermalManager.temp_chamber.pid.Kp,
" i:", unscalePID_i(thermalManager.temp_chamber.pid.Ki),
" d:", unscalePID_d(thermalManager.temp_chamber.pid.Kd));
}
#endif // PIDTEMPCHAMBER

View File

@ -682,6 +682,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 304: M304(); break; // M304: Set bed PID parameters
#endif
#if ENABLED(PIDTEMPCHAMBER)
case 309: M309(); break; // M309: Set chamber PID parameters
#endif
#if ENABLED(PHOTO_GCODE)
case 240: M240(); break; // M240: Trigger a camera
#endif

View File

@ -197,6 +197,7 @@
* M303 - PID relay autotune S<temperature> sets the target temperature. Default 150C. (Requires PIDTEMP)
* M304 - Set bed PID parameters P I and D. (Requires PIDTEMPBED)
* M305 - Set user thermistor parameters R T and P. (Requires TEMP_SENSOR_x 1000)
* M309 - Set chamber PID parameters P I and D. (Requires PIDTEMPCHAMBER)
* M350 - Set microstepping mode. (Requires digital microstepping pins.)
* M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.)
* M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN)
@ -711,6 +712,8 @@ private:
TERN_(HAS_USER_THERMISTORS, static void M305());
TERN_(PIDTEMPCHAMBER, static void M309());
#if HAS_MICROSTEPS
static void M350();
static void M351();

View File

@ -40,19 +40,15 @@
* C<cycles> Number of times to repeat the procedure. (Minimum: 3, Default: 5)
* U<bool> Flag to apply the result to the current PID values
*
* With PID_DEBUG:
* With PID_DEBUG, PID_BED_DEBUG, or PID_CHAMBER_DEBUG:
* D Toggle PID debugging and EXIT without further action.
*/
#if ENABLED(PID_DEBUG)
bool pid_debug_flag = 0;
#endif
void GcodeSuite::M303() {
#if ENABLED(PID_DEBUG)
#if ANY(PID_DEBUG, PID_BED_DEBUG, PID_CHAMBER_DEBUG)
if (parser.seen('D')) {
pid_debug_flag = !pid_debug_flag;
thermalManager.pid_debug_flag ^= true;
SERIAL_ECHO_START();
SERIAL_ECHOPGM("PID Debug ");
serialprintln_onoff(pid_debug_flag);
@ -60,25 +56,34 @@ void GcodeSuite::M303() {
}
#endif
#define SI TERN(PIDTEMPBED, H_BED, H_E0)
#define EI TERN(PIDTEMP, HOTENDS - 1, H_BED)
const heater_id_t e = (heater_id_t)parser.intval('E');
if (!WITHIN(e, SI, EI)) {
SERIAL_ECHOLNPGM(STR_PID_BAD_EXTRUDER_NUM);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
return;
const heater_id_t hid = (heater_id_t)parser.intval('E');
int16_t default_temp;
switch (hid) {
#if ENABLED(PIDTEMP)
case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break;
#endif
#if ENABLED(PIDTEMPBED)
case H_BED: default_temp = PREHEAT_1_TEMP_BED; break;
#endif
#if ENABLED(PIDTEMPCHAMBER)
case H_CHAMBER: default_temp = PREHEAT_1_TEMP_CHAMBER; break;
#endif
default:
SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID);
TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM));
return;
}
const int16_t temp = parser.celsiusval('S', default_temp);
const int c = parser.intval('C', 5);
const bool u = parser.boolval('U');
const int16_t temp = parser.celsiusval('S', e < 0 ? PREHEAT_1_TEMP_BED : PREHEAT_1_TEMP_HOTEND);
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
#endif
LCD_MESSAGEPGM(MSG_PID_AUTOTUNE);
thermalManager.PID_autotune(temp, e, c, u);
thermalManager.PID_autotune(temp, hid, c, u);
ui.reset_status();
}