Michael Spencer / Smoothie

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Revision:
2:1df0b61d3b5a
Parent:
0:31e91bb0ef3c
--- a/modules/tools/temperaturecontrol/TemperatureControl.h	Sat Mar 01 02:37:29 2014 +0000
+++ b/modules/tools/temperaturecontrol/TemperatureControl.h	Fri Feb 28 18:52:52 2014 -0800
@@ -1,77 +1,106 @@
-/*  
+/*
       this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
       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.
       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.
-      you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>. 
+      you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef temperaturecontrol_h
 #define temperaturecontrol_h
 
 #include "libs/Pin.h"
+#include "Pwm.h"
 #include <math.h>
 
-#define UNDEFINED -1
+#include "RingBuffer.h"
 
-#define thermistor_checksum                41045
-#define r0_checksum                        5538
-#define readings_per_second_checksum       18645 
-#define t0_checksum                        6564
-#define beta_checksum                      1181
-#define vadc_checksum                      10911
-#define vcc_checksum                       36157
-#define r1_checksum                        5795
-#define r2_checksum                        6052
-#define temperature_control_checksum       44054
-#define thermistor_pin_checksum            1788 
-#define heater_pin_checksum                35619 
+#define QUEUE_LEN 8
+
+class TemperatureControlPool;
 
 class TemperatureControl : public Module {
+
     public:
-        TemperatureControl();
         TemperatureControl(uint16_t name);
-        
-        virtual void on_module_loaded();
-        virtual void on_main_loop(void* argument);
-        virtual void on_gcode_execute(void* argument);
-        virtual void on_config_reload(void* argument);
-        void set_desired_temperature(double desired_temperature);
-        double get_temperature();
-        double adc_value_to_temperature(double adc_value);
-        double temperature_to_adc_value(double temperature);
+
+        void on_module_loaded();
+        void on_main_loop(void* argument);
+        void on_gcode_execute(void* argument);
+        void on_gcode_received(void* argument);
+        void on_config_reload(void* argument);
+        void on_second_tick(void* argument);
+        void on_get_public_data(void* argument);
+        void on_set_public_data(void* argument);
+
+        void set_desired_temperature(float desired_temperature);
+        float get_temperature();
+        float adc_value_to_temperature(int adc_value);
         uint32_t thermistor_read_tick(uint32_t dummy);
-        double new_thermistor_reading();
-        double average_adc_reading();
-        
-        double    desired_adc_value;
-        double    tail_adc_value;
-        double    head_adc_value;
+        int new_thermistor_reading();
+
+
+        int pool_index;
+        TemperatureControlPool *pool;
+        friend class PID_Autotuner;
+
+    private:
+        void pid_process(float);
+
+        float target_temperature;
+
+        float preset1;
+        float preset2;
 
         // Thermistor computation settings
-        double r0;
-        double t0;
-        double r1;
-        double r2;
-        double beta;
-        double vadc;
-        double vcc;
-        double k;
-        double vs;
-        double rs;
-        
-        double acceleration_factor;
-        double readings_per_second;
+        float r0;
+        float t0;
+        int r1;
+        int r2;
+        float beta;
+        float j;
+        float k;
+
 
-        RingBuffer<double,16> queue;  // Queue of Blocks
-        int error_count;
+        // PID runtime
+        float i_max;
+
+        int o;
+
+        float last_reading;
+
+        float acceleration_factor;
+        float readings_per_second;
+
+        RingBuffer<uint16_t,QUEUE_LEN> queue;  // Queue of readings
+        uint16_t median_buffer[QUEUE_LEN];
+        int running_total;
 
         uint16_t name_checksum;
 
-        Pin* thermistor_pin;
-        Pin* heater_pin;
-    
+        Pin  thermistor_pin;
+        Pwm  heater_pin;
+
         bool waiting;
+        bool min_temp_violated;
 
+        uint16_t set_m_code;
+        uint16_t set_and_wait_m_code;
+        uint16_t get_m_code;
+
+        string designator;
+
+
+        void setPIDp(float p);
+        void setPIDi(float i);
+        void setPIDd(float d);
+
+        float iTerm;
+        float lastInput;
+        // PID settings
+        float p_factor;
+        float i_factor;
+        float d_factor;
+        float PIDdt;
 };
 
 #endif