2012-03-08 20:43:21 +00:00
|
|
|
/*
|
|
|
|
temperature.h - temperature controller
|
|
|
|
Part of Marlin
|
|
|
|
|
|
|
|
Copyright (c) 2011 Erik van der Zalm
|
|
|
|
|
|
|
|
Grbl 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.
|
|
|
|
|
|
|
|
Grbl 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 Grbl. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-04-02 12:10:14 +00:00
|
|
|
#ifndef TEMPERATURE_H
|
2015-10-03 06:08:58 +00:00
|
|
|
#define TEMPERATURE_H
|
2012-03-08 20:43:21 +00:00
|
|
|
|
|
|
|
#include "Marlin.h"
|
|
|
|
#include "planner.h"
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
2012-03-08 20:43:21 +00:00
|
|
|
#include "stepper.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// public functions
|
2014-02-25 09:52:58 +00:00
|
|
|
void tp_init(); //initialize the heating
|
2012-03-08 20:43:21 +00:00
|
|
|
void manage_heater(); //it is critical that this is called periodically.
|
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(FILAMENT_SENSOR)
|
2015-10-03 06:08:58 +00:00
|
|
|
// For converting raw Filament Width to milimeters
|
|
|
|
float analog2widthFil();
|
|
|
|
|
|
|
|
// For converting raw Filament Width to an extrusion ratio
|
|
|
|
int widthFil_to_size_ratio();
|
2014-08-07 00:30:57 +00:00
|
|
|
#endif
|
|
|
|
|
Allow Edit menu to call fn after edit; Fix PID Ki and Kd display in menus; Actually use changed PID and Max Accel values
Add new 'callback' edit-menu types that call a function after the edit is done. Use this to display and edit Ki and Kd correctly (removing the scaling first and reapplying it after). Also use it to reset maximum stepwise acceleration rates, after updating mm/s^2 rates via menus. (Previously, changes did nothing to affect planner unless saved back to EEPROM, and the machine reset).
Add calls to updatePID() so that PID loop uses updated values whether set by gcode (it already did this), or by restoring defaults, or loading from EEPROM (it didn't do those last two). Similarly, update the maximum step/s^2 accel rates when the mm/s^2 values are changed - whether by menu edits, restore defaults, or EEPROM read.
Refactor the acceleration rate update logic, and the PID scaling logic, into new functions that can be called from wherever, including the callbacks.
Add menu items to allow the z jerk and e jerk to be viewed/edited in the Control->Motion menu, as per xy jerk.
Conflicts:
Marlin/language.h
2013-03-19 14:05:11 +00:00
|
|
|
// low level conversion routines
|
|
|
|
// do not use these routines and variables outside of temperature.cpp
|
2015-10-03 06:08:58 +00:00
|
|
|
extern int target_temperature[4];
|
2015-03-27 23:26:07 +00:00
|
|
|
extern float current_temperature[4];
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2015-03-27 23:26:07 +00:00
|
|
|
extern int current_temperature_raw[4];
|
2013-10-12 13:41:23 +00:00
|
|
|
extern int current_temperature_bed_raw;
|
|
|
|
#endif
|
2012-12-09 22:00:06 +00:00
|
|
|
extern int target_temperature_bed;
|
|
|
|
extern float current_temperature_bed;
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
2013-06-06 22:49:25 +00:00
|
|
|
extern float redundant_temperature;
|
|
|
|
#endif
|
2012-03-08 20:43:21 +00:00
|
|
|
|
2015-04-03 22:31:35 +00:00
|
|
|
#if HAS_CONTROLLERFAN
|
2013-11-28 01:23:06 +00:00
|
|
|
extern unsigned char soft_pwm_bed;
|
|
|
|
#endif
|
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(PIDTEMP)
|
2015-01-11 02:50:17 +00:00
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(PID_PARAMS_PER_EXTRUDER)
|
2015-01-11 02:50:17 +00:00
|
|
|
extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
|
|
|
|
#define PID_PARAM(param,e) param[e] // use macro to point to array value
|
|
|
|
#else
|
|
|
|
extern float Kp, Ki, Kd, Kc; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
|
|
|
|
#define PID_PARAM(param, e) param // use macro to point directly to value
|
2015-10-03 06:08:58 +00:00
|
|
|
#endif // PID_PARAMS_PER_EXTRUDER
|
Allow Edit menu to call fn after edit; Fix PID Ki and Kd display in menus; Actually use changed PID and Max Accel values
Add new 'callback' edit-menu types that call a function after the edit is done. Use this to display and edit Ki and Kd correctly (removing the scaling first and reapplying it after). Also use it to reset maximum stepwise acceleration rates, after updating mm/s^2 rates via menus. (Previously, changes did nothing to affect planner unless saved back to EEPROM, and the machine reset).
Add calls to updatePID() so that PID loop uses updated values whether set by gcode (it already did this), or by restoring defaults, or loading from EEPROM (it didn't do those last two). Similarly, update the maximum step/s^2 accel rates when the mm/s^2 values are changed - whether by menu edits, restore defaults, or EEPROM read.
Refactor the acceleration rate update logic, and the PID scaling logic, into new functions that can be called from wherever, including the callbacks.
Add menu items to allow the z jerk and e jerk to be viewed/edited in the Control->Motion menu, as per xy jerk.
Conflicts:
Marlin/language.h
2013-03-19 14:05:11 +00:00
|
|
|
float scalePID_i(float i);
|
|
|
|
float scalePID_d(float d);
|
|
|
|
float unscalePID_i(float i);
|
|
|
|
float unscalePID_d(float d);
|
|
|
|
|
2012-03-08 20:43:21 +00:00
|
|
|
#endif
|
2015-04-03 23:38:05 +00:00
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(PIDTEMPBED)
|
2015-10-03 06:08:58 +00:00
|
|
|
extern float bedKp, bedKi, bedKd;
|
2012-09-13 02:01:31 +00:00
|
|
|
#endif
|
2015-10-03 06:08:58 +00:00
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(BABYSTEPPING)
|
Add the socalled "Babystepping" feature.
It is a realtime control over the head position via the LCD menu system that works _while_ printing.
Using it, one can e.g. tune the z-position in realtime, while printing the first layer.
Also, lost steps can be manually added/removed, but thats not the prime feature.
Stuff is placed into the Tune->Babystep *
It is not possible to have realtime control via gcode sending due to the buffering, so I did not include a gcode yet. However, it could be added, but it movements will not be realtime then.
Historically, a very similar thing was implemented for the "Kaamermaker" project, while Joris was babysitting his offspring, hence the name.
say goodby to fuddling around with the z-axis.
2013-10-06 19:14:51 +00:00
|
|
|
extern volatile int babystepsTodo[3];
|
|
|
|
#endif
|
2015-10-03 06:08:58 +00:00
|
|
|
|
2012-03-08 20:43:21 +00:00
|
|
|
//high level conversion routines, for use outside of temperature.cpp
|
|
|
|
//inline so that there is no performance decrease.
|
|
|
|
//deg=degreeCelsius
|
|
|
|
|
2015-02-24 12:46:11 +00:00
|
|
|
FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
|
|
|
|
FORCE_INLINE float degBed() { return current_temperature_bed; }
|
2012-03-08 20:43:21 +00:00
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2015-10-03 06:08:58 +00:00
|
|
|
FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
|
|
|
|
FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
|
2013-10-12 13:41:23 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-24 12:46:11 +00:00
|
|
|
FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
|
|
|
|
FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
|
2012-03-08 20:43:21 +00:00
|
|
|
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
2015-10-03 06:08:58 +00:00
|
|
|
void start_watching_heater(int e = 0);
|
2015-05-21 19:07:37 +00:00
|
|
|
#endif
|
|
|
|
|
2015-10-03 06:08:58 +00:00
|
|
|
FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
|
2015-05-21 18:36:11 +00:00
|
|
|
target_temperature[extruder] = celsius;
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
2015-05-21 18:36:11 +00:00
|
|
|
start_watching_heater(extruder);
|
|
|
|
#endif
|
|
|
|
}
|
2015-10-03 06:08:58 +00:00
|
|
|
FORCE_INLINE void setTargetBed(const float& celsius) { target_temperature_bed = celsius; }
|
2012-03-08 20:43:21 +00:00
|
|
|
|
2015-02-24 12:46:11 +00:00
|
|
|
FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
|
|
|
|
FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
|
2012-03-08 20:43:21 +00:00
|
|
|
|
2015-02-24 12:46:11 +00:00
|
|
|
FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
|
|
|
|
FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
|
2012-03-08 20:43:21 +00:00
|
|
|
|
2015-04-02 12:10:14 +00:00
|
|
|
#define HOTEND_ROUTINES(NR) \
|
|
|
|
FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
|
|
|
|
FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
|
|
|
|
FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
|
|
|
|
FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
|
|
|
|
FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
|
|
|
|
HOTEND_ROUTINES(0);
|
2012-03-08 20:43:21 +00:00
|
|
|
#if EXTRUDERS > 1
|
2015-04-02 12:10:14 +00:00
|
|
|
HOTEND_ROUTINES(1);
|
2012-04-27 12:51:32 +00:00
|
|
|
#else
|
2015-04-02 12:10:14 +00:00
|
|
|
#define setTargetHotend1(c) do{}while(0)
|
2012-03-08 20:43:21 +00:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 2
|
2015-04-02 12:10:14 +00:00
|
|
|
HOTEND_ROUTINES(2);
|
2012-04-27 12:51:32 +00:00
|
|
|
#else
|
2015-04-02 12:10:14 +00:00
|
|
|
#define setTargetHotend2(c) do{}while(0)
|
2012-03-08 20:43:21 +00:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 3
|
2015-04-02 12:10:14 +00:00
|
|
|
HOTEND_ROUTINES(3);
|
2015-01-23 22:13:06 +00:00
|
|
|
#else
|
2015-04-02 12:10:14 +00:00
|
|
|
#define setTargetHotend3(c) do{}while(0)
|
2012-03-08 20:43:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int getHeaterPower(int heater);
|
2015-04-14 00:17:36 +00:00
|
|
|
void disable_all_heaters();
|
2012-03-08 20:43:21 +00:00
|
|
|
void updatePID();
|
|
|
|
|
2016-03-21 18:02:31 +00:00
|
|
|
void PID_autotune(float temp, int extruder, int ncycles, bool set_result = false);
|
2015-03-29 23:58:46 +00:00
|
|
|
|
|
|
|
void setExtruderAutoFanState(int pin, bool state);
|
|
|
|
void checkExtruderAutoFans();
|
2014-06-30 18:22:37 +00:00
|
|
|
|
2015-02-24 12:46:11 +00:00
|
|
|
FORCE_INLINE void autotempShutdown() {
|
2015-07-31 05:29:30 +00:00
|
|
|
#if ENABLED(AUTOTEMP)
|
2015-02-24 12:46:11 +00:00
|
|
|
if (autotemp_enabled) {
|
|
|
|
autotemp_enabled = false;
|
|
|
|
if (degTargetHotend(active_extruder) > autotemp_min)
|
|
|
|
setTargetHotend(0, active_extruder);
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-08 20:43:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 12:10:14 +00:00
|
|
|
#endif // TEMPERATURE_H
|