Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPCTEMP improvements #25503

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b02eb11
Added variable to control how often to test temperature during ambien…
StevilKnevil Mar 9, 2023
f9ed41a
Added a varliable to control how quickly the temperature is checked d…
StevilKnevil Mar 9, 2023
2b33f1f
Fixed previous commit
StevilKnevil Mar 9, 2023
eef587a
Renamed sample_distance to ticks_per_sample
StevilKnevil Mar 9, 2023
c7215f6
Clarified the logic for making sample_count odd
StevilKnevil Mar 9, 2023
32b8196
fix heat_test_tick_interval
thinkyhead Mar 10, 2023
84d98a8
Fixed previous commit
StevilKnevil Mar 10, 2023
1409754
Merge branch 'MPC-Code-Improvements'
StevilKnevil Mar 11, 2023
b6dca2b
Moving tuning logic into utility class
StevilKnevil Mar 11, 2023
a666847
Extracted Ambient and Heatup measurement
StevilKnevil Mar 11, 2023
e028368
renamed variable
StevilKnevil Mar 12, 2023
1b6be88
renamed function
StevilKnevil Mar 12, 2023
9158f3a
Added return enum to self-document result
StevilKnevil Mar 12, 2023
0ef902d
Updated return value checks
StevilKnevil Mar 12, 2023
4bfaaf7
Implemented heat transfer coefficient calcs
StevilKnevil Mar 12, 2023
b3b093c
Renamed functions
StevilKnevil Mar 12, 2023
a86bc3b
Updated functon names
StevilKnevil Mar 12, 2023
8ea7a07
Fixed last commit
StevilKnevil Mar 12, 2023
cb8dca7
Removed unneeded param from housekeeping function
StevilKnevil Mar 12, 2023
393bf6f
Moved timers into class variables to avoid code duplication
StevilKnevil Mar 12, 2023
39338ea
Made current time variable more explicit
StevilKnevil Mar 12, 2023
4a4744b
Update temperature.cpp
StevilKnevil Mar 12, 2023
10bf30f
Pulled test intervals into their own variables
StevilKnevil Mar 12, 2023
46e97be
Added macro to get float time from millis
StevilKnevil Mar 12, 2023
0a16667
Used macros for time conversion
StevilKnevil Mar 12, 2023
afdf9d1
Use variable for test interval
StevilKnevil Mar 12, 2023
ddf28de
Used variable for report interval
StevilKnevil Mar 12, 2023
c59b117
Added _ms postfix to intervals to fit with convention
StevilKnevil Mar 12, 2023
b05af7e
Merge branch 'MPC-Code-Improvements' into #25496-Allow-MPCTEMP-tuning…
StevilKnevil Mar 12, 2023
a56ae63
Revert "Merge branch 'MPC-Code-Improvements' into #25496-Allow-MPCTEM…
StevilKnevil Mar 12, 2023
65603f7
Merge branch 'MarlinFirmware:bugfix-2.1.x' into MPCTEMP-Code-Maintain…
StevilKnevil Mar 12, 2023
a8a5ad2
Updated comment
StevilKnevil Mar 12, 2023
e73675d
Merge branch 'MPCTEMP-Code-Maintainence-Improvements' of https://gith…
StevilKnevil Mar 12, 2023
6d0886e
Merge branch 'bugfix-2.1.x' into pr/25503
thinkyhead Mar 16, 2023
99e5d5e
Merge branch 'bugfix-2.1.x' into pr/25503
thinkyhead Mar 23, 2023
68424a2
ws cleanup
thinkyhead Mar 23, 2023
c009d90
Alternative MPC Tuning methods
thinkyhead Mar 23, 2023
8df3c5f
tweak
thinkyhead Mar 23, 2023
6b796ee
Reuse the sample buffer during auto tune to save memory
StevilKnevil Mar 27, 2023
cc2a900
Avoided unnecessary calculations
StevilKnevil Mar 28, 2023
3afca5a
Fixed debug output for MPC Autotune
StevilKnevil Mar 28, 2023
703d0cf
Merge branch 'bugfix-2.1.x' into pr/25503
thinkyhead Apr 1, 2023
4021571
tweak
thinkyhead Apr 1, 2023
56a6222
Merge branch 'bugfix-2.1.x' into MPCTEMP-Code-Maintainence-Improvements
StevilKnevil Apr 27, 2023
9809949
Fixed using old, uninitialised, variable
StevilKnevil Apr 28, 2023
a7caba3
Added Executable flag
StevilKnevil May 1, 2023
55853da
Update temperature.cpp
StevilKnevil May 3, 2023
70ecf6e
Merge branch 'bugfix-2.1.x' into pr/25503
thinkyhead May 10, 2023
43d21d5
Keep smaller option
thinkyhead May 10, 2023
8848205
Reduce size by 1382 bytes (AVR)
thinkyhead May 11, 2023
9b9a622
Tweak configs, use of hysteresis
thinkyhead May 11, 2023
fec8d50
go for it
thinkyhead May 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,18 @@

// @section hotend temp

// Enable PIDTEMP for PID control or MPCTEMP for Predictive Model.
// temperature control. Disable both for bang-bang heating.
#define PIDTEMP // See the PID Tuning Guide at https://reprap.org/wiki/PID_Tuning
//#define MPCTEMP // ** EXPERIMENTAL **
/**
* Temperature Control
*
* (NONE) : Bang-bang heating
* PIDTEMP : PID temperature control (~4.1K)
* MPCTEMP : Predictive Model temperature control. (~1.8K without auto-tune)
*/
#define PIDTEMP // See the PID Tuning Guide at https://reprap.org/wiki/PID_Tuning
//#define MPCTEMP // ** EXPERIMENTAL ** See https://marlinfw.org/docs/features/model_predictive_control.html

#define BANG_MAX 255 // Limits current to nozzle while in bang-bang mode; 255=full current
#define PID_MAX BANG_MAX // Limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#define PID_K1 0.95 // Smoothing factor within any PID loop
#define PID_MAX 255 // Limit hotend current while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#define PID_K1 0.95 // Smoothing factor within any PID loop

#if ENABLED(PIDTEMP)
//#define PID_DEBUG // Print PID debug data to the serial port. Use 'M303 D' to toggle activation.
Expand All @@ -675,6 +679,8 @@
#define DEFAULT_Ki 1.08
#define DEFAULT_Kd 114.00
#endif
#else
#define BANG_MAX 255 // Limit hotend current while in bang-bang mode; 255=full current
#endif

/**
Expand All @@ -686,11 +692,11 @@
* @section mpctemp
*/
#if ENABLED(MPCTEMP)
//#define MPC_AUTOTUNE // Include a method to do MPC auto-tuning (~5664-5882 bytes of flash)
//#define MPC_EDIT_MENU // Add MPC editing to the "Advanced Settings" menu. (~1300 bytes of flash)
//#define MPC_AUTOTUNE // Include a method to do MPC auto-tuning (~6.3K bytes of flash)
//#define MPC_EDIT_MENU // Add MPC editing to the "Advanced Settings" menu. (~1.3K bytes of flash)
//#define MPC_AUTOTUNE_MENU // Add MPC auto-tuning to the "Advanced Settings" menu. (~350 bytes of flash)

#define MPC_MAX BANG_MAX // (0..255) Current to nozzle while MPC is active.
#define MPC_MAX 255 // (0..255) Current to nozzle while MPC is active.
#define MPC_HEATER_POWER { 40.0f } // (W) Heat cartridge powers.

#define MPC_INCLUDE_FAN // Model the fan speed?
Expand Down Expand Up @@ -725,32 +731,30 @@
//====================== PID > Bed Temperature Control ======================
//===========================================================================

// @section bed temp

/**
* Max Bed Power
* Applies to all forms of bed control (PID, bang-bang, and bang-bang with hysteresis).
* When set to any value below 255, enables a form of PWM to the bed that acts like a divider
* so don't use it unless you are OK with PWM on your bed. (See the comment on enabling PIDTEMPBED)
*/
#define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current

/**
* PID Bed Heating
*
* If this option is enabled set PID constants below.
* If this option is disabled, bang-bang will be used and BED_LIMIT_SWITCHING will enable hysteresis.
*
* The PID frequency will be the same as the extruder PWM.
* If PID_dT is the default, and correct for the hardware/configuration, that means 7.689Hz,
* which is fine for driving a square wave into a resistive load and does not significantly
* impact FET heating. This also works fine on a Fotek SSR-10DA Solid State Relay into a 250W
* heater. If your configuration is significantly different than this and you don't understand
* the issues involved, don't use bed PID until someone else verifies that your hardware works.
* @section bed temp
*
* With this option disabled, bang-bang will be used. BED_LIMIT_SWITCHING enables hysteresis.
*/
//#define PIDTEMPBED

//#define BED_LIMIT_SWITCHING

/**
* Max Bed Power
* Applies to all forms of bed control (PID, bang-bang, and bang-bang with hysteresis).
* When set to any value below 255, enables a form of PWM to the bed that acts like a divider
* so don't use it unless you are OK with PWM on your bed. (See the comment on enabling PIDTEMPBED)
*/
#define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current

#if ENABLED(PIDTEMPBED)
//#define MIN_BED_POWER 0
//#define PID_BED_DEBUG // Print Bed PID debug data to the serial port.
Expand All @@ -762,7 +766,9 @@
#define DEFAULT_bedKd 305.4

// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
#endif // PIDTEMPBED
#else
//#define BED_LIMIT_SWITCHING // Keep the bed temperature within BED_HYSTERESIS of the target
#endif

//===========================================================================
//==================== PID > Chamber Temperature Control ====================
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/core/millis_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef uint32_t millis_t;
#define SEC_TO_MS(N) millis_t((N)*1000UL)
#define MIN_TO_MS(N) SEC_TO_MS((N)*60UL)
#define MS_TO_SEC(N) millis_t((N)/1000UL)
#define MS_TO_SEC_PRECISE(N) (float(N)/1000.0f)

#define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
14 changes: 12 additions & 2 deletions Marlin/src/gcode/temp/M306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
* R<kelvin/second/kelvin> Sensor responsiveness (= transfer coefficient / heat capcity).
*
* With MPC_AUTOTUNE:
* T Autotune the specified or active extruder.
* T Autotune the extruder specified with 'E' or the active extruder.
* S0 : Autotuning method AUTO (default)
* S1 : Autotuning method DIFFERENTIAL
* S2 : Autotuning method ASYMPTOTIC
*/

void GcodeSuite::M306() {
Expand All @@ -54,8 +57,15 @@ void GcodeSuite::M306() {

#if ENABLED(MPC_AUTOTUNE)
if (parser.seen_test('T')) {
Temperature::MPCTuningType tuning_type;
const uint8_t type = parser.byteval('S', 0);
switch (type) {
case 1: tuning_type = Temperature::MPCTuningType::FORCE_DIFFERENTIAL; break;
case 2: tuning_type = Temperature::MPCTuningType::FORCE_ASYMPTOTIC; break;
default: tuning_type = Temperature::MPCTuningType::AUTO; break;
}
LCD_MESSAGE(MSG_MPC_AUTOTUNE);
thermalManager.MPC_autotune(e);
thermalManager.MPC_autotune(e, tuning_type);
ui.reset_status();
return;
}
Expand Down
Loading