Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TemperatureControl.h Source File

TemperatureControl.h

00001 /*
00002       this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
00003       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.
00004       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.
00005       you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>.
00006 */
00007 
00008 #ifndef temperaturecontrol_h
00009 #define temperaturecontrol_h
00010 
00011 #include "libs/Pin.h"
00012 #include "Pwm.h"
00013 #include <math.h>
00014 
00015 #include "RingBuffer.h"
00016 
00017 #define QUEUE_LEN 8
00018 
00019 class TemperatureControlPool;
00020 
00021 class TemperatureControl : public Module {
00022 
00023     public:
00024         TemperatureControl(uint16_t name);
00025 
00026         void on_module_loaded();
00027         void on_main_loop(void* argument);
00028         void on_gcode_execute(void* argument);
00029         void on_gcode_received(void* argument);
00030         void on_config_reload(void* argument);
00031         void on_second_tick(void* argument);
00032         void on_get_public_data(void* argument);
00033         void on_set_public_data(void* argument);
00034 
00035         void set_desired_temperature(float desired_temperature);
00036         float get_temperature();
00037         float adc_value_to_temperature(int adc_value);
00038         uint32_t thermistor_read_tick(uint32_t dummy);
00039         int new_thermistor_reading();
00040 
00041 
00042         int pool_index;
00043         TemperatureControlPool *pool;
00044         friend class PID_Autotuner;
00045 
00046     private:
00047         void pid_process(float);
00048 
00049         float target_temperature;
00050 
00051         float preset1;
00052         float preset2;
00053 
00054         // Thermistor computation settings
00055         float r0;
00056         float t0;
00057         int r1;
00058         int r2;
00059         float beta;
00060         float j;
00061         float k;
00062 
00063 
00064         // PID runtime
00065         float i_max;
00066 
00067         int o;
00068 
00069         float last_reading;
00070 
00071         float acceleration_factor;
00072         float readings_per_second;
00073 
00074         RingBuffer<uint16_t,QUEUE_LEN> queue;  // Queue of readings
00075         uint16_t median_buffer[QUEUE_LEN];
00076         int running_total;
00077 
00078         uint16_t name_checksum;
00079 
00080         Pin  thermistor_pin;
00081         Pwm  heater_pin;
00082 
00083         bool waiting;
00084         bool min_temp_violated;
00085 
00086         uint16_t set_m_code;
00087         uint16_t set_and_wait_m_code;
00088         uint16_t get_m_code;
00089 
00090         string designator;
00091 
00092 
00093         void setPIDp(float p);
00094         void setPIDi(float i);
00095         void setPIDd(float d);
00096 
00097         float iTerm;
00098         float lastInput;
00099         // PID settings
00100         float p_factor;
00101         float i_factor;
00102         float d_factor;
00103         float PIDdt;
00104 };
00105 
00106 #endif