Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
Automatically save PID settings to EEPROM after M301, M304, and M303 U1
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlloyd committed Jun 28, 2021
1 parent 20ff746 commit a1fb94b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ a few goodies:
* **OctoPrint screen**: Adds support for `M73` (print progress) and `M117`
(LCD messages).
* **Sound**: Adds support for `M300` (play a sound).
* **PID tuning**: Automatically writes PID settings to EEPROM after `M303 U1` (autotune),
`M301` (set hotend PID), and `M304` (set bed PID).

All settings are automatically saved to EEPROM and loaded on boot.

Expand Down Expand Up @@ -137,6 +139,25 @@ mesh bed leveling. A skew factor of e.g. 0.01 equates to
`0.01 * 180mm = 1.8mm` of movement at the far end of the bed,
so your usable print area will be reduced accordingly.

### Configuring PID Parameters

The stock firmware allows you to run an `M303` PID autotune, but the new
settings are lost on reset. In Llama, PID settings are *automatically* written
to EEPROM after any command that updates Marlin's PID values, which could be
an `M301` (set hotend PID), `M304` (set bed PID), or an `M303 U1` (autotune and
use the PID result). These values will then be restored on reset, too. You do not
need to use `M500`.

If you need to restore the default PID values, they can be reset by running
the following commands:

* Hotend: `M301 P7.00 I0.50 D45.00`
* Bed: `M304 P120.00 I1.50 D600.0`

Note that if you run `M303` (autotune) without the `U1` parameter, Marlin
will just print out the suggested PID values without changing the settings,
and they won't get written to EEPROM.

---

### Print Progress
Expand Down
14 changes: 14 additions & 0 deletions src/common/marlin_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ void marlin_server_settings_save(void) {
#endif
}

void marlin_server_settings_save_bed_pid(void) {
eeprom_set_var(EEVAR_PID_BED_P, variant8_flt(Temperature::temp_bed.pid.Kp));
eeprom_set_var(EEVAR_PID_BED_I, variant8_flt(Temperature::temp_bed.pid.Ki));
eeprom_set_var(EEVAR_PID_BED_D, variant8_flt(Temperature::temp_bed.pid.Kd));
}

void marlin_server_settings_save_noz_pid(void) {
#if ENABLED(PIDTEMP)
eeprom_set_var(EEVAR_PID_NOZ_P, variant8_flt(Temperature::temp_hotend[0].pid.Kp));
eeprom_set_var(EEVAR_PID_NOZ_I, variant8_flt(Temperature::temp_hotend[0].pid.Ki));
eeprom_set_var(EEVAR_PID_NOZ_D, variant8_flt(Temperature::temp_hotend[0].pid.Kd));
#endif
}

void marlin_server_settings_load(void) {
(void)settings.reset();
#if HAS_BED_PROBE
Expand Down
2 changes: 2 additions & 0 deletions src/common/marlin_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ extern int marlin_server_inject_gcode(const char *gcode);

// direct call of settings.save()
extern void marlin_server_settings_save(void);
extern void marlin_server_settings_save_bed_pid(void);
extern void marlin_server_settings_save_noz_pid(void);

// direct call of settings.load()
extern void marlin_server_settings_load(void);
Expand Down
25 changes: 25 additions & 0 deletions src/marlin_stubs/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../../lib/Marlin/Marlin/src/gcode/queue.h"

#include "PrusaGcodeSuite.hpp"
#include "../common/marlin_server.h"

#include "M330.h"
#include "M50.hpp"
Expand All @@ -22,6 +23,30 @@ bool GcodeSuite::process_parsed_command_custom(bool no_ok) {
PrusaGcodeSuite::M300();
if (!no_ok) queue.ok_to_send();
return true;
case 301:
M301();
marlin_server_settings_save_noz_pid();
if (!no_ok) queue.ok_to_send();
return true;
case 303: {
M303();
const int16_t e = parser.intval('E');
const bool u = parser.boolval('U');
if (u) {
if (e == -1)
marlin_server_settings_save_bed_pid();
else if (e == 0)
marlin_server_settings_save_noz_pid();
}
if (!no_ok)
queue.ok_to_send();
return true;
}
case 304:
M304();
marlin_server_settings_save_bed_pid();
if (!no_ok) queue.ok_to_send();
return true;
#if defined(_DEBUG)
case 330:
PrusaGcodeSuite::M330();
Expand Down

0 comments on commit a1fb94b

Please sign in to comment.