|
|
|
/*
|
|
|
|
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"
|
|
|
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
|
|
#include "stepper.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// public functions
|
|
|
|
void tp_init(); //initialize the heating
|
|
|
|
void manage_heater(); //it is critical that this is called periodically.
|
|
|
|
|
|
|
|
#if ENABLED(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
12 years ago
|
|
|
// low level conversion routines
|
|
|
|
// do not use these routines and variables outside of temperature.cpp
|
|
|
|
extern int target_temperature[4];
|
|
|
|
extern float current_temperature[4];
|
|
|
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
|
|
|
extern int current_temperature_raw[4];
|
|
|
|
extern int current_temperature_bed_raw;
|
|
|
|
#endif
|
|
|
|
extern int target_temperature_bed;
|
|
|
|
extern float current_temperature_bed;
|
|
|
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
|
|
|
extern float redundant_temperature;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_CONTROLLERFAN
|
|
|
|
extern unsigned char soft_pwm_bed;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(PIDTEMP)
|
|
|
|
|
|
|
|
#if ENABLED(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
12 years ago
|
|
|
float scalePID_i(float i);
|
|
|
|
float scalePID_d(float d);
|
|
|
|
float unscalePID_i(float i);
|
|
|
|
float unscalePID_d(float d);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(PIDTEMPBED)
|
|
|
|
extern float bedKp, bedKi, bedKd;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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.
11 years ago
|
|
|
extern volatile int babystepsTodo[3];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//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) { return current_temperature[extruder]; }
|
|
|
|
FORCE_INLINE float degBed() { return current_temperature_bed; }
|
|
|
|
|
|
|
|
#if ENABLED(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
|
|
|
|
|
|
|
|
FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
|
|
|
|
FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
|
|
|
|
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
|
|
|
void start_watching_heater(int e = 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
|
|
|
|
target_temperature[extruder] = celsius;
|
|
|
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
|
|
|
start_watching_heater(extruder);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
FORCE_INLINE void setTargetBed(const float& celsius) { target_temperature_bed = celsius; }
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
#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);
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
HOTEND_ROUTINES(1);
|
|
|
|
#else
|
|
|
|
#define setTargetHotend1(c) do{}while(0)
|
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 2
|
|
|
|
HOTEND_ROUTINES(2);
|
|
|
|
#else
|
|
|
|
#define setTargetHotend2(c) do{}while(0)
|
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 3
|
|
|
|
HOTEND_ROUTINES(3);
|
|
|
|
#else
|
|
|
|
#define setTargetHotend3(c) do{}while(0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int getHeaterPower(int heater);
|
|
|
|
void disable_all_heaters();
|
|
|
|
void updatePID();
|
|
|
|
|
|
|
|
void PID_autotune(float temp, int extruder, int ncycles);
|
|
|
|
|
|
|
|
void setExtruderAutoFanState(int pin, bool state);
|
|
|
|
void checkExtruderAutoFans();
|
|
|
|
|
|
|
|
FORCE_INLINE void autotempShutdown() {
|
|
|
|
#if ENABLED(AUTOTEMP)
|
|
|
|
if (autotemp_enabled) {
|
|
|
|
autotemp_enabled = false;
|
|
|
|
if (degTargetHotend(active_extruder) > autotemp_min)
|
|
|
|
setTargetHotend(0, active_extruder);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TEMPERATURE_H
|