![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dd
Dependencies: BufferedSerial FastAnalogIn FastPWM mbed SHT75
controlt.cpp
- Committer:
- sbh9428
- Date:
- 2016-02-22
- Revision:
- 1:5c42ec7f1aeb
- Parent:
- 0:9bfc4aea91e2
- Child:
- 2:4c51394fb35b
File content as of revision 1:5c42ec7f1aeb:
/* * controlt.cpp * * Created on: 2016. 2. 19. * Author: sbh9428 */ #include "controlt.h" control_t::control_t() { // TODO Auto-generated constructor stub } control_t::control_t(temp_sensor_t* _temp_sensor, peltier_t* _peltier) { log_count=0; target_temp=15; P_value=0; I_value=0; D_value=0; temp_sensor=_temp_sensor; peltier=_peltier; } control_t::~control_t() { // TODO Auto-generated destructor stub } float control_t::get_temp() { return temp_sensor->get_temp(); } void control_t::control_PWM(float PWM) { peltier->set_PWM(PWM); } void control_t::control_temp() { PWM_value+=calc_P(); PWM_value+=calc_I(); PWM_value+=calc_D(); if(PWM_value>1) { PWM_value=1; } if(PWM_value<-1) { PWM_value=-1; } peltier->set_PWM(PWM_value); } void control_t::set_mode(int _mode) { mode=_mode; } void control_t::set_PWM_value(float _PWM_value) { PWM_value=_PWM_value; } void control_t::set_target_temp(float _target_temp) { target_temp=_target_temp; } void control_t::set_P_value(float _P_value) { P_value=_P_value; } void control_t::set_I_value(float _I_value) { I_value=_I_value; } void control_t::set_D_value(float _D_value) { D_value=_D_value; } void control_t::refresh_PWM() { write_log(); if(mode==0) { PWM_value=0; control_PWM(0); } else if(mode==1) { } else if(mode==2) { control_temp(); } } int control_t::get_mode() { return mode; } float control_t::get_target_temp() { return target_temp; } float control_t::get_P_value() { return P_value; } float control_t::get_I_value() { return I_value; } float control_t::get_D_value() { return D_value; } float control_t::get_PWM_value() { return PWM_value; } float control_t::calc_P() { return (target_temp-temp_sensor->get_temp())*P_value; } float control_t::calc_I() { float data=0; for(int i=0;i<10;i++) { data+=temp_log[i]; } return data*I_value; } float control_t::calc_D() { return -(temp_log[log_count]-temp_log[(log_count-1)%10])*D_value; } void control_t::write_log() { log_count++; log_count=log_count%10; temp_log[log_count]=temp_sensor->get_temp(); }