2020-09-23 18:59:59 +00:00
|
|
|
#include "iit_comp.h"
|
2017-07-01 01:18:08 +00:00
|
|
|
#include "commands.h"
|
|
|
|
#include "hal.h"
|
|
|
|
#include "math.h"
|
|
|
|
#include "defines.h"
|
|
|
|
|
2017-07-01 03:21:03 +00:00
|
|
|
HAL_COMP(iit);
|
2017-07-01 01:18:08 +00:00
|
|
|
|
2018-09-16 16:21:57 +00:00
|
|
|
// conf
|
|
|
|
HAL_PIN(amb_temp);
|
|
|
|
HAL_PIN(high_temp);
|
|
|
|
HAL_PIN(max_temp);
|
|
|
|
HAL_PIN(max_cur);
|
|
|
|
HAL_PIN(cur_boost);
|
|
|
|
HAL_PIN(max_time);
|
|
|
|
|
|
|
|
// out
|
|
|
|
HAL_PIN(temp);
|
|
|
|
// in
|
|
|
|
HAL_PIN(cur);
|
2017-07-01 01:18:08 +00:00
|
|
|
|
2017-09-06 02:20:06 +00:00
|
|
|
struct iit_ctx_t {
|
2018-09-16 16:21:57 +00:00
|
|
|
float e;
|
2017-07-01 01:18:08 +00:00
|
|
|
};
|
|
|
|
|
2019-04-29 20:08:54 +00:00
|
|
|
static void nrt_init(void *ctx_ptr, hal_pin_inst_t *pin_ptr) {
|
2017-09-06 02:20:06 +00:00
|
|
|
struct iit_ctx_t *ctx = (struct iit_ctx_t *)ctx_ptr;
|
|
|
|
struct iit_pin_ctx_t *pins = (struct iit_pin_ctx_t *)pin_ptr;
|
2018-09-16 16:21:57 +00:00
|
|
|
PIN(amb_temp) = 30.0;
|
|
|
|
PIN(high_temp) = 80.0;
|
|
|
|
PIN(max_temp) = 100.0;
|
|
|
|
PIN(max_time) = 10.0;
|
|
|
|
PIN(cur_boost) = 3.0;
|
|
|
|
ctx->e = 0.0;
|
2017-07-01 01:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 20:08:54 +00:00
|
|
|
static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) {
|
2017-09-06 02:20:06 +00:00
|
|
|
struct iit_ctx_t *ctx = (struct iit_ctx_t *)ctx_ptr;
|
|
|
|
struct iit_pin_ctx_t *pins = (struct iit_pin_ctx_t *)pin_ptr;
|
|
|
|
|
2018-09-16 16:21:57 +00:00
|
|
|
float cur_n = PIN(max_cur) / MAX(PIN(cur_boost), 1.0);
|
2018-09-16 16:49:53 +00:00
|
|
|
float max_e = PIN(max_cur) * PIN(max_cur) * MAX(PIN(max_time), 0.1);
|
2017-09-06 02:20:06 +00:00
|
|
|
|
2018-09-16 16:21:57 +00:00
|
|
|
float temp = ctx->e / max_e * PIN(max_temp) + PIN(amb_temp);
|
2017-09-06 02:20:06 +00:00
|
|
|
|
2018-09-16 16:21:57 +00:00
|
|
|
float pin = PIN(cur) * PIN(cur);
|
|
|
|
float pout = (temp - PIN(amb_temp)) * cur_n * cur_n / (PIN(high_temp) - PIN(amb_temp));
|
2017-09-06 02:20:06 +00:00
|
|
|
|
2018-09-16 16:21:57 +00:00
|
|
|
ctx->e += (pin - pout) * period;
|
2017-09-06 02:20:06 +00:00
|
|
|
|
2018-09-16 16:21:57 +00:00
|
|
|
PIN(temp) = temp;
|
2017-07-01 01:18:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-01 03:21:03 +00:00
|
|
|
hal_comp_t iit_comp_struct = {
|
2018-09-16 16:21:57 +00:00
|
|
|
.name = "iit",
|
|
|
|
.nrt = 0,
|
|
|
|
.rt = rt_func,
|
|
|
|
.frt = 0,
|
|
|
|
.nrt_init = nrt_init,
|
|
|
|
.rt_start = 0,
|
|
|
|
.frt_start = 0,
|
|
|
|
.rt_stop = 0,
|
|
|
|
.frt_stop = 0,
|
|
|
|
.ctx_size = sizeof(struct iit_ctx_t),
|
|
|
|
.pin_count = sizeof(struct iit_pin_ctx_t) / sizeof(struct hal_pin_inst_t),
|
2017-07-01 01:18:08 +00:00
|
|
|
};
|