2012-03-08 14:43:21 -06: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
|
|
|
|
void tp_init(); //initialise the heating
|
|
|
|
void manage_heater(); //it is critical that this is called periodically.
|
|
|
|
|
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 09:05:11 -05:00
|
|
|
// low level conversion routines
|
|
|
|
// do not use these routines and variables outside of temperature.cpp
|
2012-12-09 16:00:06 -06:00
|
|
|
extern int target_temperature[EXTRUDERS];
|
|
|
|
extern float current_temperature[EXTRUDERS];
|
2013-10-12 08:41:23 -05:00
|
|
|
#ifdef SHOW_TEMP_ADC_VALUES
|
|
|
|
extern int current_temperature_raw[EXTRUDERS];
|
|
|
|
extern int current_temperature_bed_raw;
|
|
|
|
#endif
|
2012-12-09 16:00:06 -06:00
|
|
|
extern int target_temperature_bed;
|
|
|
|
extern float current_temperature_bed;
|
2013-06-06 17:49:25 -05:00
|
|
|
#ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
|
|
|
extern float redundant_temperature;
|
|
|
|
#endif
|
2012-03-08 14:43:21 -06:00
|
|
|
|
|
|
|
#ifdef PIDTEMP
|
2012-09-12 21:01:31 -05:00
|
|
|
extern float Kp,Ki,Kd,Kc;
|
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 09:05:11 -05:00
|
|
|
float scalePID_i(float i);
|
|
|
|
float scalePID_d(float d);
|
|
|
|
float unscalePID_i(float i);
|
|
|
|
float unscalePID_d(float d);
|
|
|
|
|
2012-03-08 14:43:21 -06:00
|
|
|
#endif
|
2012-09-12 21:01:31 -05:00
|
|
|
#ifdef PIDTEMPBED
|
|
|
|
extern float bedKp,bedKi,bedKd;
|
|
|
|
#endif
|
2012-03-08 14:43:21 -06: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 14:14:51 -05:00
|
|
|
|
|
|
|
#ifdef BABYSTEPPING
|
|
|
|
extern volatile int babystepsTodo[3];
|
|
|
|
#endif
|
|
|
|
|
2012-03-08 14:43:21 -06:00
|
|
|
//high level conversion routines, for use outside of temperature.cpp
|
|
|
|
//inline so that there is no performance decrease.
|
|
|
|
//deg=degreeCelsius
|
|
|
|
|
|
|
|
FORCE_INLINE float degHotend(uint8_t extruder) {
|
2012-12-09 16:00:06 -06:00
|
|
|
return current_temperature[extruder];
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
2013-10-12 08:41:23 -05:00
|
|
|
#ifdef SHOW_TEMP_ADC_VALUES
|
|
|
|
FORCE_INLINE float rawHotendTemp(uint8_t extruder) {
|
|
|
|
return current_temperature_raw[extruder];
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE float rawBedTemp() {
|
|
|
|
return current_temperature_bed_raw;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-03-08 14:43:21 -06:00
|
|
|
FORCE_INLINE float degBed() {
|
2012-12-09 16:00:06 -06:00
|
|
|
return current_temperature_bed;
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE float degTargetHotend(uint8_t extruder) {
|
2012-12-09 16:00:06 -06:00
|
|
|
return target_temperature[extruder];
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE float degTargetBed() {
|
2012-12-09 16:00:06 -06:00
|
|
|
return target_temperature_bed;
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
|
2012-12-09 16:00:06 -06:00
|
|
|
target_temperature[extruder] = celsius;
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE void setTargetBed(const float &celsius) {
|
2012-12-09 16:00:06 -06:00
|
|
|
target_temperature_bed = celsius;
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
|
2012-12-09 16:00:06 -06:00
|
|
|
return target_temperature[extruder] > current_temperature[extruder];
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isHeatingBed() {
|
2012-12-09 16:00:06 -06:00
|
|
|
return target_temperature_bed > current_temperature_bed;
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
|
2012-12-09 16:00:06 -06:00
|
|
|
return target_temperature[extruder] < current_temperature[extruder];
|
2012-03-08 14:43:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isCoolingBed() {
|
2012-12-09 16:00:06 -06:00
|
|
|
return target_temperature_bed < current_temperature_bed;
|
2012-03-08 14:43:21 -06: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
|
|
|
|
#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 07:51:32 -05:00
|
|
|
#else
|
|
|
|
#define setTargetHotend1(_celsius) do{}while(0)
|
2012-03-08 14:43:21 -06:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 2
|
|
|
|
#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 07:51:32 -05:00
|
|
|
#else
|
|
|
|
#define setTargetHotend2(_celsius) do{}while(0)
|
2012-03-08 14:43:21 -06:00
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 3
|
|
|
|
#error Invalid number of extruders
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int getHeaterPower(int heater);
|
|
|
|
void disable_heater();
|
|
|
|
void setWatch();
|
|
|
|
void updatePID();
|
|
|
|
|
|
|
|
FORCE_INLINE void autotempShutdown(){
|
|
|
|
#ifdef AUTOTEMP
|
|
|
|
if(autotemp_enabled)
|
|
|
|
{
|
|
|
|
autotemp_enabled=false;
|
2012-03-08 15:04:13 -06:00
|
|
|
if(degTargetHotend(active_extruder)>autotemp_min)
|
|
|
|
setTargetHotend(0,active_extruder);
|
2012-03-08 14:43:21 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-12 21:01:31 -05:00
|
|
|
void PID_autotune(float temp, int extruder, int ncycles);
|
2012-03-08 14:43:21 -06:00
|
|
|
|
|
|
|
#endif
|
2012-09-12 21:01:31 -05:00
|
|
|
|