|
|
@ -30,26 +30,40 @@ void WaterCoolingTemperatureControlModule::initialize(int32_t id, config_t* cfg, |
|
|
|
|
|
|
|
m_pidmodule.initialize(&cfg->pid_cfg); |
|
|
|
m_thread.init("WaterCoolingTemperatureControlModule"); |
|
|
|
m_cfg = *cfg; |
|
|
|
m_cfg = *cfg; |
|
|
|
m_target_temperature = 25; |
|
|
|
m_temperature_sensor_mutex.init(); |
|
|
|
|
|
|
|
m_fan_ctrl->stop(); |
|
|
|
m_pelter_ctrl->stop(); |
|
|
|
m_pump_ctrl->stop(); |
|
|
|
module_clear_error(); |
|
|
|
ZLOGI(TAG, "WaterCoolingTemperatureControlModule initialized..."); |
|
|
|
} |
|
|
|
int32_t WaterCoolingTemperatureControlModule::getid(int32_t* id) { |
|
|
|
*id = m_id; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_clear_error() { return 0; } |
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_clear_error() { |
|
|
|
m_com_reg.module_errorcode = 0; |
|
|
|
m_com_reg.module_errorbitflag0 = 0; |
|
|
|
m_fan_ctrl->clearError(); |
|
|
|
m_pelter_ctrl->clearError(); |
|
|
|
m_pump_ctrl->clearError(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void WaterCoolingTemperatureControlModule::createDefaultConfig(config_t* cfg) { |
|
|
|
cfg->fanlevel = 90; |
|
|
|
cfg->min_fanlevel = 30; |
|
|
|
cfg->pumplevel = 100; |
|
|
|
cfg->pid_cfg.kp = 9; |
|
|
|
cfg->pid_cfg.ki = 0.600; |
|
|
|
cfg->pid_cfg.kp = 10; |
|
|
|
cfg->pid_cfg.ki = 0.5; |
|
|
|
cfg->pid_cfg.kd = 0; |
|
|
|
cfg->pid_cfg.max_output = 90; |
|
|
|
cfg->pid_cfg.min_output = -90; |
|
|
|
cfg->pid_cfg.max_integral = 100; |
|
|
|
cfg->pid_cfg.min_integral = -100; |
|
|
|
cfg->pid_cfg.max_output = 100; |
|
|
|
cfg->pid_cfg.min_output = -100; |
|
|
|
cfg->pid_cfg.max_integral = 200; |
|
|
|
cfg->pid_cfg.min_integral = -200; |
|
|
|
cfg->pidcompute_periodms = 1000; |
|
|
|
} |
|
|
|
|
|
|
@ -120,7 +134,17 @@ int32_t WaterCoolingTemperatureControlModule::do_action(int32_t actioncode) { |
|
|
|
|
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_factory_reset() { return 0; } |
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_flush_cfg() { return 0; } |
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_active_cfg() { return 0; } |
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_active_cfg() { |
|
|
|
// m_pidmodule
|
|
|
|
m_pidmodule.update_kp(m_cfg.pid_cfg.kp); |
|
|
|
m_pidmodule.update_kd(m_cfg.pid_cfg.kd); |
|
|
|
m_pidmodule.update_ki(m_cfg.pid_cfg.ki); |
|
|
|
m_pidmodule.update_max_output(m_cfg.pid_cfg.max_output); |
|
|
|
m_pidmodule.update_min_output(m_cfg.pid_cfg.min_output); |
|
|
|
m_pidmodule.update_max_integral(m_cfg.pid_cfg.max_integral); |
|
|
|
m_pidmodule.update_min_integral(m_cfg.pid_cfg.min_integral); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t WaterCoolingTemperatureControlModule::module_start() { |
|
|
|
m_thread.stop(); |
|
|
@ -148,32 +172,41 @@ void WaterCoolingTemperatureControlModule::workloop() { |
|
|
|
|
|
|
|
pump_start(m_cfg.pumplevel); |
|
|
|
fan_start(m_cfg.fanlevel); |
|
|
|
|
|
|
|
int32_t i = 0; |
|
|
|
uint32_t startticket = zos_get_tick(); |
|
|
|
while (!m_thread.getExitFlag()) { |
|
|
|
if (checkdevice() != 0) { |
|
|
|
ZLOGE(TAG, "somedevice is not working, stop the module"); |
|
|
|
break; |
|
|
|
if (zos_haspassedms(startticket) > 1000) { |
|
|
|
if (checkdevice() != 0) { |
|
|
|
ZLOGE(TAG, "somedevice is not working, stop the module"); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// m_thread.sleep(m_cfg.pidcompute_periodms);
|
|
|
|
m_thread.sleep(100); |
|
|
|
m_thread.sleep(m_cfg.pidcompute_periodms); |
|
|
|
|
|
|
|
// float val = read_pid_temperature();
|
|
|
|
float val = read_pid_temperature(); |
|
|
|
|
|
|
|
// float error = m_target_temperature - val;
|
|
|
|
// float out = 0;
|
|
|
|
// m_pidmodule.compute(error, &out);
|
|
|
|
float error = m_target_temperature - val; |
|
|
|
float out = 0; |
|
|
|
m_pidmodule.compute(error, &out); |
|
|
|
|
|
|
|
if (m_enable_log) { |
|
|
|
// ZLOGI(TAG, "temperature: %.2f %.2f integral_err:%.2f out:%d", m_target_temperature, val, m_pidmodule.get_integral_err(), (int32_t)out);
|
|
|
|
ZLOGI(TAG, "temperature: %.2f", read_pid_temperature()); |
|
|
|
ZLOGI(TAG, "temperature: %.2f %.2f integral_err:%.2f out:%d", m_target_temperature, val, m_pidmodule.get_integral_err(), (int32_t)out); |
|
|
|
} |
|
|
|
|
|
|
|
// peltier_set_power_level(out);
|
|
|
|
peltier_set_power_level(out); |
|
|
|
i++; |
|
|
|
if (i % 10 == 0) { |
|
|
|
int32_t fanspeed = out * 2; |
|
|
|
if (fanspeed > 100) fanspeed = 100; |
|
|
|
if (fanspeed < m_cfg.min_fanlevel) fanspeed = m_cfg.min_fanlevel; |
|
|
|
fan_start(fanspeed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pump_stop(); |
|
|
|
fan_stop(); |
|
|
|
peltier_set_power_level(0); |
|
|
|
} |
|
|
|
|
|
|
|
#define BIT(x, n) ((x >> n) & 0x01)
|
|
|
@ -181,8 +214,11 @@ void WaterCoolingTemperatureControlModule::workloop() { |
|
|
|
int32_t WaterCoolingTemperatureControlModule::checkdevice() { |
|
|
|
m_com_reg.module_errorbitflag0 = geterrorbitflag0(); |
|
|
|
if (m_com_reg.module_errorbitflag0 != 0) { |
|
|
|
ZLOGE(TAG, "checkdevice errorbitflag0:%d %d %d", //
|
|
|
|
BIT(m_com_reg.module_errorbitflag0, 0), BIT(m_com_reg.module_errorbitflag0, 1), BIT(m_com_reg.module_errorbitflag0, 2)); |
|
|
|
ZLOGE(TAG, "checkdevice errorbitflag0:%d %d %d %d", //
|
|
|
|
BIT(m_com_reg.module_errorbitflag0, 0), //
|
|
|
|
BIT(m_com_reg.module_errorbitflag0, 1), //
|
|
|
|
BIT(m_com_reg.module_errorbitflag0, 2), //
|
|
|
|
BIT(m_com_reg.module_errorbitflag0, 3)); |
|
|
|
m_pelter_ctrl->dumpErrorInfo(); |
|
|
|
m_com_reg.module_errorcode = err::khwardware_error; |
|
|
|
return 1; |
|
|
@ -195,13 +231,26 @@ int32_t WaterCoolingTemperatureControlModule::checkdevice() { |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
float WaterCoolingTemperatureControlModule::read_pid_temperature() { |
|
|
|
zlock_guard lock(m_temperature_sensor_mutex); |
|
|
|
ZITemperatureSensor* sensor = m_temperature_sensor[m_hardwared_config.temp_fb_index]; |
|
|
|
float val = sensor->getTemperature(); |
|
|
|
if (sensor->isError()) { |
|
|
|
ZLOGW(TAG, "get temperature fail %s", sensor->errorInfo()); |
|
|
|
return 0; |
|
|
|
float val[3] = {0}; |
|
|
|
for (int32_t i = 0; i < 3; i++) { |
|
|
|
val[i] = sensor->getTemperature(); |
|
|
|
osDelay(10); |
|
|
|
} |
|
|
|
// ¶ÔζȽøÐÐÅÅÐò
|
|
|
|
for (int32_t i = 0; i < 3; i++) { |
|
|
|
for (int32_t j = i + 1; j < 3; j++) { |
|
|
|
if (val[i] > val[j]) { |
|
|
|
float tmp = val[i]; |
|
|
|
val[i] = val[j]; |
|
|
|
val[j] = tmp; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return val; |
|
|
|
|
|
|
|
float retval = val[1]; |
|
|
|
return retval; |
|
|
|
} |
|
|
|
|
|
|
|
void WaterCoolingTemperatureControlModule::pump_start(int32_t pump_speed) { |
|
|
@ -230,7 +279,7 @@ void WaterCoolingTemperatureControlModule::fan_stop() { |
|
|
|
} |
|
|
|
|
|
|
|
void WaterCoolingTemperatureControlModule::peltier_set_power_level(int32_t level) { |
|
|
|
ZLOGI(TAG, "peltier_set_power_level %d", level); |
|
|
|
// ZLOGI(TAG, "peltier_set_power_level %d", level);
|
|
|
|
m_pelter_ctrl->setSpeed(level); |
|
|
|
// for (int32_t i = 0; i < m_peltier_ctrl_num; i++) {
|
|
|
|
// m_peltier_ctrl[i]->move(level);
|
|
|
@ -261,10 +310,13 @@ int32_t WaterCoolingTemperatureControlModule::geterrorbitflag0() { |
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
*/ |
|
|
|
ZITemperatureSensor* sensor = m_temperature_sensor[m_hardwared_config.temp_fb_index]; |
|
|
|
|
|
|
|
int32_t errorbitflag = 0; |
|
|
|
errorbitflag |= m_fan_ctrl->isError() << 0; |
|
|
|
errorbitflag |= m_pump_ctrl->isError() << 1; |
|
|
|
errorbitflag |= m_pelter_ctrl->isError() << 2; |
|
|
|
errorbitflag |= sensor->isError() << 3; |
|
|
|
|
|
|
|
// if (m_fanTable[1]) errorbitflag |= m_fanTable[1]->isError() << 1;
|
|
|
|
// if (m_fanTable[2]) errorbitflag |= m_fanTable[2]->isError() << 2;
|
|
|
@ -278,6 +330,7 @@ int32_t WaterCoolingTemperatureControlModule::geterrorbitflag0() { |
|
|
|
} |
|
|
|
|
|
|
|
float WaterCoolingTemperatureControlModule::getTemperatureSensorVal(int32_t index) { |
|
|
|
zlock_guard lock(m_temperature_sensor_mutex); |
|
|
|
if (index < 0 || index >= m_n_temperature_sensor) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|