ce15dcdcee78de7287b73015fa083632c7965fb1
[clinton/Smoothieware.git] / src / modules / tools / temperaturecontrol / TemperatureControl.h
1 /*
2 this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
3 smoothie 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.
4 smoothie 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.
5 you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef TEMPERATURECONTROL_H
9 #define TEMPERATURECONTROL_H
10
11 #include "Module.h"
12 #include "Pwm.h"
13 #include "TempSensor.h"
14 #include "TemperatureControlPublicAccess.h"
15
16 class TemperatureControl : public Module {
17
18 public:
19 TemperatureControl(uint16_t name, int index);
20 ~TemperatureControl();
21
22 void on_module_loaded();
23 void on_main_loop(void* argument);
24 void on_gcode_received(void* argument);
25 void on_second_tick(void* argument);
26 void on_get_public_data(void* argument);
27 void on_set_public_data(void* argument);
28 void on_halt(void* argument);
29
30 void set_desired_temperature(float desired_temperature);
31
32 float get_temperature();
33
34
35 friend class PID_Autotuner;
36
37 private:
38 void load_config();
39 uint32_t thermistor_read_tick(uint32_t dummy);
40 void pid_process(float);
41 void setPIDp(float p);
42 void setPIDi(float i);
43 void setPIDd(float d);
44
45 int pool_index;
46
47 float target_temperature;
48 float max_temp, min_temp;
49
50 float preset1;
51 float preset2;
52
53 TempSensor *sensor;
54 float i_max;
55 int o;
56 float last_reading;
57 float readings_per_second;
58 Pwm heater_pin;
59
60 std::string designator;
61
62
63 float hysteresis;
64 float iTerm;
65 float lastInput;
66 // PID settings
67 float p_factor;
68 float i_factor;
69 float d_factor;
70 float PIDdt;
71
72 enum RUNAWAY_TYPE {NOT_HEATING, HEATING_UP, COOLING_DOWN, TARGET_TEMPERATURE_REACHED};
73
74 // pack these to save memory
75 struct {
76 uint16_t name_checksum;
77 uint16_t set_m_code:10;
78 uint16_t set_and_wait_m_code:10;
79 uint16_t get_m_code:10;
80 RUNAWAY_TYPE runaway_state:3;
81 // Temperature runaway config options
82 uint8_t runaway_range:6; // max 63
83 uint16_t runaway_heating_timeout:7; // 1016 secs
84 uint16_t runaway_cooling_timeout:7; // 1016 secs
85 uint16_t runaway_timer:7;
86 uint8_t tick:3;
87 bool use_bangbang:1;
88 bool waiting:1;
89 bool temp_violated:1;
90 bool link_to_tool:1;
91 bool active:1;
92 bool readonly:1;
93 bool windup:1;
94 bool sensor_settings:1;
95 };
96 };
97
98 #endif