1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2024-12-20 15:42:18 +00:00
stmbl/shared/comps/pe.c

61 lines
1.2 KiB
C
Raw Permalink Normal View History

#include "pe_comp.h"
2017-09-06 00:01:26 +00:00
#include "commands.h"
#include "hal.h"
#include "math.h"
#include "defines.h"
#include "angle.h"
HAL_COMP(pe);
HAL_PIN(udc);
HAL_PIN(idc);
HAL_PIN(ud);
HAL_PIN(uq);
HAL_PIN(id);
HAL_PIN(iq);
HAL_PIN(torque);
HAL_PIN(vel);
HAL_PIN(r);
HAL_PIN(j);
HAL_PIN(cap);
HAL_PIN(e_el);
HAL_PIN(e_kin);
HAL_PIN(p_el_dc);
HAL_PIN(p_el_ac);
HAL_PIN(p_m);
HAL_PIN(p_t);
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 00:01:26 +00:00
// struct pe_ctx_t * ctx = (struct pe_ctx_t *)ctx_ptr;
2017-09-06 02:20:06 +00:00
struct pe_pin_ctx_t *pins = (struct pe_pin_ctx_t *)pin_ptr;
2017-09-06 00:01:26 +00:00
float udc = PIN(udc);
float vel = PIN(vel);
2017-09-06 02:20:06 +00:00
float id = PIN(id);
float iq = PIN(iq);
float t = PIN(torque);
2017-09-06 00:01:26 +00:00
2017-09-06 02:20:06 +00:00
PIN(e_el) = PIN(cap) * udc * udc / 2.0;
2017-09-06 00:01:26 +00:00
PIN(e_kin) = PIN(j) * vel * vel / 2.0;
PIN(p_el_dc) = udc * PIN(idc);
PIN(p_el_ac) = PIN(ud) * PIN(id) + PIN(ud) * PIN(id);
2017-09-06 02:20:06 +00:00
PIN(p_m) = t * vel;
PIN(p_t) = 3 / 2 * PIN(r) * (id * id + iq * iq);
2017-09-06 00:01:26 +00:00
}
hal_comp_t pe_comp_struct = {
2017-09-06 02:20:06 +00:00
.name = "pe",
.nrt = 0,
.rt = rt_func,
.frt = 0,
.nrt_init = 0,
.rt_start = 0,
.frt_start = 0,
.rt_stop = 0,
.frt_stop = 0,
.ctx_size = 0,
.pin_count = sizeof(struct pe_pin_ctx_t) / sizeof(struct hal_pin_inst_t),
2017-09-06 00:01:26 +00:00
};