My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

M301.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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. #include "../../inc/MarlinConfig.h"
  23. #if ENABLED(PIDTEMP)
  24. #include "../gcode.h"
  25. #include "../../module/temperature.h"
  26. /**
  27. * M301: Set PID parameters P I D (and optionally C, L)
  28. *
  29. * E[extruder] Default: 0
  30. *
  31. * P[float] Kp term
  32. * I[float] Ki term (unscaled)
  33. * D[float] Kd term (unscaled)
  34. *
  35. * With PID_EXTRUSION_SCALING:
  36. *
  37. * C[float] Kc term
  38. * L[int] LPQ length
  39. *
  40. * With PID_FAN_SCALING:
  41. *
  42. * F[float] Kf term
  43. */
  44. void GcodeSuite::M301() {
  45. // multi-extruder PID patch: M301 updates or prints a single extruder's PID values
  46. // default behavior (omitting E parameter) is to update for extruder 0 only
  47. int8_t e = E_TERN0(parser.byteval('E', -1)); // extruder being updated
  48. if (!parser.seen("PID" TERN_(PID_EXTRUSION_SCALING, "CL") TERN_(PID_FAN_SCALING, "F")))
  49. return M301_report(true E_OPTARG(e));
  50. if (e == -1) e = 0;
  51. if (e < HOTENDS) { // catch bad input value
  52. if (parser.seenval('P')) PID_PARAM(Kp, e) = parser.value_float();
  53. if (parser.seenval('I')) PID_PARAM(Ki, e) = scalePID_i(parser.value_float());
  54. if (parser.seenval('D')) PID_PARAM(Kd, e) = scalePID_d(parser.value_float());
  55. #if ENABLED(PID_EXTRUSION_SCALING)
  56. if (parser.seenval('C')) PID_PARAM(Kc, e) = parser.value_float();
  57. if (parser.seenval('L')) thermalManager.lpq_len = parser.value_int();
  58. NOMORE(thermalManager.lpq_len, LPQ_MAX_LEN);
  59. NOLESS(thermalManager.lpq_len, 0);
  60. #endif
  61. #if ENABLED(PID_FAN_SCALING)
  62. if (parser.seenval('F')) PID_PARAM(Kf, e) = parser.value_float();
  63. #endif
  64. thermalManager.updatePID();
  65. }
  66. else
  67. SERIAL_ERROR_MSG(STR_INVALID_EXTRUDER);
  68. }
  69. void GcodeSuite::M301_report(const bool forReplay/*=true*/ E_OPTARG(const int8_t eindex/*=-1*/)) {
  70. report_heading(forReplay, F(STR_HOTEND_PID));
  71. IF_DISABLED(HAS_MULTI_EXTRUDER, constexpr int8_t eindex = -1);
  72. HOTEND_LOOP() {
  73. if (e == eindex || eindex == -1) {
  74. report_echo_start(forReplay);
  75. SERIAL_ECHOPGM_P(
  76. #if ENABLED(PID_PARAMS_PER_HOTEND)
  77. PSTR(" M301 E"), e, SP_P_STR
  78. #else
  79. PSTR(" M301 P")
  80. #endif
  81. , PID_PARAM(Kp, e)
  82. , PSTR(" I"), unscalePID_i(PID_PARAM(Ki, e))
  83. , PSTR(" D"), unscalePID_d(PID_PARAM(Kd, e))
  84. );
  85. #if ENABLED(PID_EXTRUSION_SCALING)
  86. SERIAL_ECHOPGM_P(SP_C_STR, PID_PARAM(Kc, e));
  87. if (e == 0) SERIAL_ECHOPGM(" L", thermalManager.lpq_len);
  88. #endif
  89. #if ENABLED(PID_FAN_SCALING)
  90. SERIAL_ECHOPGM(" F", PID_PARAM(Kf, e));
  91. #endif
  92. SERIAL_EOL();
  93. }
  94. }
  95. }
  96. #endif // PIDTEMP