2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2016-03-24 19:01:20 +01:00
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2012-03-08 21:43:21 +01: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 14:10:14 +02:00
|
|
|
#ifndef TEMPERATURE_H
|
2015-10-03 08:08:58 +02:00
|
|
|
#define TEMPERATURE_H
|
2012-03-08 21:43:21 +01:00
|
|
|
|
|
|
|
#include "Marlin.h"
|
|
|
|
#include "planner.h"
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
2012-03-08 21:43:21 +01:00
|
|
|
#include "stepper.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// public functions
|
2014-02-25 10:52:58 +01:00
|
|
|
void tp_init(); //initialize the heating
|
2012-03-08 21:43:21 +01:00
|
|
|
void manage_heater(); //it is critical that this is called periodically.
|
|
|
|
|
2016-03-30 05:28:23 +02:00
|
|
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
2015-10-03 08:08:58 +02: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 02:30:57 +02: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 15:05:11 +01:00
|
|
|
// low level conversion routines
|
|
|
|
// do not use these routines and variables outside of temperature.cpp
|
2015-10-03 08:08:58 +02:00
|
|
|
extern int target_temperature[4];
|
2015-03-28 00:26:07 +01:00
|
|
|
extern float current_temperature[4];
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2015-03-28 00:26:07 +01:00
|
|
|
extern int current_temperature_raw[4];
|
2013-10-12 15:41:23 +02:00
|
|
|
extern int current_temperature_bed_raw;
|
|
|
|
#endif
|
2012-12-09 23:00:06 +01:00
|
|
|
extern int target_temperature_bed;
|
|
|
|
extern float current_temperature_bed;
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
2013-06-07 00:49:25 +02:00
|
|
|
extern float redundant_temperature;
|
|
|
|
#endif
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2015-04-04 00:31:35 +02:00
|
|
|
#if HAS_CONTROLLERFAN
|
2013-11-28 02:23:06 +01:00
|
|
|
extern unsigned char soft_pwm_bed;
|
|
|
|
#endif
|
|
|
|
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(PIDTEMP)
|
2015-01-11 03:50:17 +01:00
|
|
|
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(PID_PARAMS_PER_EXTRUDER)
|
2016-04-17 04:19:40 +02:00
|
|
|
extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS]; // one param per extruder
|
|
|
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
|
|
extern float Kc[EXTRUDERS];
|
|
|
|
#endif
|
2016-04-02 23:28:17 +02:00
|
|
|
#define PID_PARAM(param, e) param[e] // use macro to point to array value
|
2015-01-11 03:50:17 +01:00
|
|
|
#else
|
2016-04-17 04:19:40 +02:00
|
|
|
extern float Kp, Ki, Kd; // one param per extruder - saves 20 or 36 bytes of ram (inc array pointer)
|
|
|
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
|
|
extern float Kc;
|
|
|
|
#endif
|
2015-01-11 03:50:17 +01:00
|
|
|
#define PID_PARAM(param, e) param // use macro to point directly to value
|
2015-10-03 08:08:58 +02: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 15:05:11 +01:00
|
|
|
float scalePID_i(float i);
|
|
|
|
float scalePID_d(float d);
|
|
|
|
float unscalePID_i(float i);
|
|
|
|
float unscalePID_d(float d);
|
|
|
|
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
2015-04-04 01:38:05 +02:00
|
|
|
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(PIDTEMPBED)
|
2015-10-03 08:08:58 +02:00
|
|
|
extern float bedKp, bedKi, bedKd;
|
2012-09-13 04:01:31 +02:00
|
|
|
#endif
|
2015-10-03 08:08:58 +02:00
|
|
|
|
2015-07-31 07:29:30 +02: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 21:14:51 +02:00
|
|
|
extern volatile int babystepsTodo[3];
|
|
|
|
#endif
|
2015-10-03 08:08:58 +02:00
|
|
|
|
2012-03-08 21:43:21 +01:00
|
|
|
//high level conversion routines, for use outside of temperature.cpp
|
|
|
|
//inline so that there is no performance decrease.
|
|
|
|
//deg=degreeCelsius
|
|
|
|
|
2015-02-24 13:46:11 +01:00
|
|
|
FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
|
|
|
|
FORCE_INLINE float degBed() { return current_temperature_bed; }
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2015-10-03 08:08:58 +02: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 15:41:23 +02:00
|
|
|
#endif
|
|
|
|
|
2015-02-24 13:46:11 +01:00
|
|
|
FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
|
|
|
|
FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2016-04-15 18:27:18 +02:00
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
|
2015-10-03 08:08:58 +02:00
|
|
|
void start_watching_heater(int e = 0);
|
2015-05-21 21:07:37 +02:00
|
|
|
#endif
|
|
|
|
|
2016-04-15 18:27:18 +02:00
|
|
|
#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
|
|
|
|
void start_watching_bed();
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 08:08:58 +02:00
|
|
|
FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
|
2015-05-21 20:36:11 +02:00
|
|
|
target_temperature[extruder] = celsius;
|
2016-04-15 18:27:18 +02:00
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
|
2015-05-21 20:36:11 +02:00
|
|
|
start_watching_heater(extruder);
|
|
|
|
#endif
|
|
|
|
}
|
2016-04-15 18:27:18 +02:00
|
|
|
FORCE_INLINE void setTargetBed(const float& celsius) {
|
|
|
|
target_temperature_bed = celsius;
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
|
|
|
|
start_watching_bed();
|
|
|
|
#endif
|
|
|
|
}
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2015-02-24 13:46:11 +01: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 21:43:21 +01:00
|
|
|
|
2015-02-24 13:46:11 +01: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 21:43:21 +01:00
|
|
|
|
2015-04-02 14:10:14 +02: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 21:43:21 +01:00
|
|
|
#if EXTRUDERS > 1
|
2015-04-02 14:10:14 +02:00
|
|
|
HOTEND_ROUTINES(1);
|
2012-04-27 14:51:32 +02:00
|
|
|
#else
|
2015-04-02 14:10:14 +02:00
|
|
|
#define setTargetHotend1(c) do{}while(0)
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 2
|
2015-04-02 14:10:14 +02:00
|
|
|
HOTEND_ROUTINES(2);
|
2012-04-27 14:51:32 +02:00
|
|
|
#else
|
2015-04-02 14:10:14 +02:00
|
|
|
#define setTargetHotend2(c) do{}while(0)
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 3
|
2015-04-02 14:10:14 +02:00
|
|
|
HOTEND_ROUTINES(3);
|
2015-01-23 23:13:06 +01:00
|
|
|
#else
|
2015-04-02 14:10:14 +02:00
|
|
|
#define setTargetHotend3(c) do{}while(0)
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int getHeaterPower(int heater);
|
2015-04-14 02:17:36 +02:00
|
|
|
void disable_all_heaters();
|
2012-03-08 21:43:21 +01:00
|
|
|
void updatePID();
|
|
|
|
|
2016-04-19 04:01:49 +02:00
|
|
|
#if ENABLED(PIDTEMP)
|
|
|
|
void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
|
|
|
|
#endif
|
2015-03-30 01:58:46 +02:00
|
|
|
|
|
|
|
void setExtruderAutoFanState(int pin, bool state);
|
|
|
|
void checkExtruderAutoFans();
|
2014-06-30 20:22:37 +02:00
|
|
|
|
2015-02-24 13:46:11 +01:00
|
|
|
FORCE_INLINE void autotempShutdown() {
|
2015-07-31 07:29:30 +02:00
|
|
|
#if ENABLED(AUTOTEMP)
|
2015-02-24 13:46:11 +01:00
|
|
|
if (autotemp_enabled) {
|
|
|
|
autotemp_enabled = false;
|
|
|
|
if (degTargetHotend(active_extruder) > autotemp_min)
|
|
|
|
setTargetHotend(0, active_extruder);
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-08 21:43:21 +01:00
|
|
|
}
|
|
|
|
|
2015-04-02 14:10:14 +02:00
|
|
|
#endif // TEMPERATURE_H
|