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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef temperature_h
|
|
|
|
#define temperature_h
|
|
|
|
|
|
|
|
#include "Marlin.h"
|
|
|
|
#include "planner.h"
|
|
|
|
#ifdef PID_ADD_EXTRUSION_RATE
|
|
|
|
#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.
|
|
|
|
|
2014-08-07 02:30:57 +02:00
|
|
|
#ifdef FILAMENT_SENSOR
|
|
|
|
// For converting raw Filament Width to milimeters
|
|
|
|
float analog2widthFil();
|
|
|
|
|
|
|
|
// For converting raw Filament Width to an extrusion ratio
|
|
|
|
int widthFil_to_size_ratio();
|
|
|
|
#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-03-28 00:26:07 +01:00
|
|
|
extern int target_temperature[4];
|
|
|
|
extern float current_temperature[4];
|
2013-10-12 15:41:23 +02:00
|
|
|
#ifdef 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;
|
2013-06-07 00:49:25 +02:00
|
|
|
#ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
|
|
|
extern float redundant_temperature;
|
|
|
|
#endif
|
2012-03-08 21:43:21 +01:00
|
|
|
|
2013-11-28 02:23:06 +01:00
|
|
|
#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
|
|
|
|
extern unsigned char soft_pwm_bed;
|
|
|
|
#endif
|
|
|
|
|
2012-03-08 21:43:21 +01:00
|
|
|
#ifdef PIDTEMP
|
2015-01-11 03:50:17 +01:00
|
|
|
|
|
|
|
#ifdef PID_PARAMS_PER_EXTRUDER
|
|
|
|
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
|
|
|
|
#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
|
|
|
|
2012-09-13 04:01:31 +02:00
|
|
|
#ifdef PIDTEMPBED
|
|
|
|
extern float bedKp,bedKi,bedKd;
|
|
|
|
#endif
|
2012-03-08 21:43:21 +01:00
|
|
|
|
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
|
|
|
#ifdef BABYSTEPPING
|
|
|
|
extern volatile int babystepsTodo[3];
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2013-10-12 15:41:23 +02:00
|
|
|
#ifdef SHOW_TEMP_ADC_VALUES
|
2015-02-24 13:46:11 +01: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
|
|
|
|
2015-02-24 13:46:11 +01:00
|
|
|
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { target_temperature[extruder] = celsius; }
|
|
|
|
FORCE_INLINE void setTargetBed(const float &celsius) { target_temperature_bed = celsius; }
|
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
|
|
|
|
|
|
|
#define degHotend0() degHotend(0)
|
|
|
|
#define degTargetHotend0() degTargetHotend(0)
|
|
|
|
#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
|
|
|
|
#define isHeatingHotend0() isHeatingHotend(0)
|
|
|
|
#define isCoolingHotend0() isCoolingHotend(0)
|
|
|
|
#if EXTRUDERS > 1
|
2015-02-24 13:46:11 +01:00
|
|
|
#define degHotend1() degHotend(1)
|
|
|
|
#define degTargetHotend1() degTargetHotend(1)
|
|
|
|
#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
|
|
|
|
#define isHeatingHotend1() isHeatingHotend(1)
|
|
|
|
#define isCoolingHotend1() isCoolingHotend(1)
|
2012-04-27 14:51:32 +02:00
|
|
|
#else
|
2015-02-24 13:46:11 +01:00
|
|
|
#define setTargetHotend1(_celsius) do{}while(0)
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 2
|
2015-02-24 13:46:11 +01:00
|
|
|
#define degHotend2() degHotend(2)
|
|
|
|
#define degTargetHotend2() degTargetHotend(2)
|
|
|
|
#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
|
|
|
|
#define isHeatingHotend2() isHeatingHotend(2)
|
|
|
|
#define isCoolingHotend2() isCoolingHotend(2)
|
2012-04-27 14:51:32 +02:00
|
|
|
#else
|
2015-02-24 13:46:11 +01:00
|
|
|
#define setTargetHotend2(_celsius) do{}while(0)
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 3
|
2015-02-24 13:46:11 +01:00
|
|
|
#define degHotend3() degHotend(3)
|
|
|
|
#define degTargetHotend3() degTargetHotend(3)
|
|
|
|
#define setTargetHotend3(_celsius) setTargetHotend((_celsius), 3)
|
|
|
|
#define isHeatingHotend3() isHeatingHotend(3)
|
|
|
|
#define isCoolingHotend3() isCoolingHotend(3)
|
2015-01-23 23:13:06 +01:00
|
|
|
#else
|
2015-02-24 13:46:11 +01:00
|
|
|
#define setTargetHotend3(_celsius) do{}while(0)
|
2015-01-23 23:13:06 +01:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 4
|
2015-02-24 13:46:11 +01:00
|
|
|
#error Invalid number of extruders
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int getHeaterPower(int heater);
|
|
|
|
void disable_heater();
|
|
|
|
void setWatch();
|
|
|
|
void updatePID();
|
|
|
|
|
2015-03-30 01:58:46 +02:00
|
|
|
void PID_autotune(float temp, int extruder, int ncycles);
|
|
|
|
|
|
|
|
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() {
|
|
|
|
#ifdef AUTOTEMP
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-24 05:35:54 +01:00
|
|
|
|
2012-03-08 21:43:21 +01:00
|
|
|
#endif
|