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