diff --git a/conf/template/iddc.txt b/conf/template/iddc.txt index 2123cf27..014e9292 100644 --- a/conf/template/iddc.txt +++ b/conf/template/iddc.txt @@ -4,11 +4,10 @@ iddc0.rt_prio = 4 iddc0.en = fault0.en_out fault0.pos_error = 0 -pid0.enable = 0 +pid0.en = 0 hv0.en = iddc0.en_out hv0.cur_bw = iddc0.cur_bw hv0.cmd_mode = iddc0.cmd_mode -hv0.d_cmd = iddc0.d_cmd hv0.q_cmd = iddc0.q_cmd hv0.pos = iddc0.com_pos hv0.rev = iddc0.out_rev @@ -25,4 +24,6 @@ iddc0.pos_fb = fb_switch0.pos_fb iddc0.vel_fb = vel1.vel vel0.pos_in = fb_switch0.pos_fb -iddc0.vel_fb = vel1.vel \ No newline at end of file +iddc0.vel_fb = vel1.vel + +iddc0.test_cur = conf0.max_ac_cur \ No newline at end of file diff --git a/conf/template/idpmsm.txt b/conf/template/idpmsm.txt index cf07bcff..c7655efa 100644 --- a/conf/template/idpmsm.txt +++ b/conf/template/idpmsm.txt @@ -25,4 +25,6 @@ idpmsm0.pos_fb = fb_switch0.mot_abs_fb_no_offset idpmsm0.vel_fb = vel1.vel vel0.pos_in = fb_switch0.pos_fb -idpmsm0.vel_fb = vel1.vel \ No newline at end of file +idpmsm0.vel_fb = vel1.vel + +idpmsm0.test_cur = conf0.max_ac_cur \ No newline at end of file diff --git a/shared/comps/iddc.c b/shared/comps/iddc.c index d38d07b7..6a9d0d02 100644 --- a/shared/comps/iddc.c +++ b/shared/comps/iddc.c @@ -5,16 +5,13 @@ HAL_COMP(iddc); -HAL_PIN(d_cmd); HAL_PIN(q_cmd); HAL_PIN(com_pos); HAL_PIN(cmd_mode); HAL_PIN(en); HAL_PIN(en_out); -HAL_PIN(id_fb); HAL_PIN(iq_fb); -HAL_PIN(ud_fb); HAL_PIN(uq_fb); HAL_PIN(pos_fb); HAL_PIN(vel_fb); @@ -54,7 +51,7 @@ static void nrt_init(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { struct iddc_pin_ctx_t *pins = (struct iddc_pin_ctx_t *)pin_ptr; PIN(test_cur) = 4.0; PIN(test_vel) = 50.0; - PIN(ki) = 1.0; + PIN(ki) = 2.0; PIN(pi) = 1.0; PIN(vel_bw) = 20.0; PIN(cur_bw) = 1.0; @@ -78,14 +75,13 @@ static void nrt(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { case 10: // r PIN(state) = 1.1; PIN(timer) = 0.0; - PIN(d_cmd) = 0.0; PIN(q_cmd) = 0.0; PIN(com_pos) = 0.0; PIN(cmd_mode) = 0.0; printf("Measure r, l\n"); printf("block the rotor\n"); - printf("id0.state = 1.2 to start\n"); + printf("iddc0.state = 1.2 to start\n"); break; case 14: @@ -97,7 +93,6 @@ static void nrt(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { case 20: PIN(state) = 3.1; PIN(timer) = 0.0; - PIN(d_cmd) = 0.0; PIN(q_cmd) = 0.0; PIN(cur_sum) = 0.0; PIN(cmd_mode) = 0.0; @@ -106,7 +101,7 @@ static void nrt(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { printf("Measure torque constant\n"); printf("unblock the rotor\n"); printf("the motor will move\n"); - printf("id0.state = 2.2 to start\n"); + printf("iddc0.state = 2.2 to start\n"); break; case 23: @@ -135,9 +130,8 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(en_out) = 0.0; PIN(cmd_mode) = 0.0; PIN(timer) = 0.0; - PIN(d_cmd) = 0.0; PIN(q_cmd) = 0.0; - PIN(cur_bw) = 1.0; + PIN(cur_bw) = 10.0; if(PIN(en) > 0.0){ PIN(state) = 1.0; @@ -147,19 +141,17 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { case 12: // r PIN(en_out) = 1.0; PIN(cmd_mode) = 1.0; - PIN(cur_bw) = 1.0; - PIN(q_cmd) = 0.0; + PIN(cur_bw) = 10.0; PIN(com_pos) = 0.0; - PIN(d_cmd) = PIN(test_cur); + PIN(q_cmd) = PIN(test_cur); - PIN(r) = PIN(r) * 0.99 + PIN(ud_fb) / MAX(PIN(id_fb), 0.01) * 0.01; + PIN(r) = PIN(r) * 0.99 + PIN(uq_fb) / MAX(PIN(iq_fb), 0.01) * 0.01; PIN(timer) += period; if(PIN(timer) >= 2.0){ PIN(timer) = 0.0; PIN(state) = 1.3; - PIN(d_cmd) = 0.0; PIN(en_out) = 0.0; PIN(tmp0) = 0.0; PIN(tmp1) = 0.0; @@ -172,19 +164,18 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { case 13: // l PIN(en_out) = 1.0; PIN(cmd_mode) = 0.0; - PIN(q_cmd) = 0.0; - PIN(cur_bw) = 1.0; + PIN(cur_bw) = 10.0; - //PIN(l) = PIN(l) * 0.995 + ABS(PIN(ud_fb) - avg_test_volt / 2.0) / MAX(ABS(PIN(id_fb) - PIN(test_cur)), 0.001) * period * 0.005; - if(PIN(d_cmd) < PIN(avg_test_volt)){ - PIN(tmp0) = PIN(tmp0) * 0.99 + PIN(id_fb) * 0.01; - PIN(tmp1) = PIN(tmp1) * 0.99 + PIN(ud_fb) * 0.01; - PIN(d_cmd) = PIN(avg_test_volt) * 1.5; + //PIN(l) = PIN(l) * 0.995 + ABS(PIN(uq_fb) - avg_test_volt / 2.0) / MAX(ABS(PIN(iq_fb) - PIN(test_cur)), 0.001) * period * 0.005; + if(PIN(q_cmd) < PIN(avg_test_volt)){ + PIN(tmp0) = PIN(tmp0) * 0.99 + PIN(iq_fb) * 0.01; + PIN(tmp1) = PIN(tmp1) * 0.99 + PIN(uq_fb) * 0.01; + PIN(q_cmd) = PIN(avg_test_volt) * 1.5; } else{ - PIN(tmp2) = PIN(tmp2) * 0.99 + PIN(id_fb) * 0.01; - PIN(tmp3) = PIN(tmp3) * 0.99 + PIN(ud_fb) * 0.01; - PIN(d_cmd) = PIN(avg_test_volt) * 0.5; + PIN(tmp2) = PIN(tmp2) * 0.99 + PIN(iq_fb) * 0.01; + PIN(tmp3) = PIN(tmp3) * 0.99 + PIN(uq_fb) * 0.01; + PIN(q_cmd) = PIN(avg_test_volt) * 0.5; } PIN(timer) += period; @@ -192,7 +183,7 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(l) = ABS(PIN(tmp1) - PIN(tmp3)) / ABS(PIN(tmp0) - PIN(tmp2)) * period; PIN(timer) = 0.0; PIN(state) = 1.4; - PIN(d_cmd) = PIN(avg_test_volt); + PIN(q_cmd) = PIN(avg_test_volt); PIN(en_out) = 0.0; // PIN(tmp0) = 0.0; // PIN(tmp1) = 0.0; @@ -203,9 +194,10 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(en_out) = 1.0; PIN(cmd_mode) = 1.0; PIN(cur_bw) = 250.0; - PIN(d_cmd) = 0.0; float vel_error = PIN(test_vel) - ABS(PIN(vel_fb)); + vel_error = LIMIT(vel_error, PIN(test_vel) / 10.0); + PIN(cur_sum) += PIN(ki) * vel_error * period; PIN(q_cmd) = PIN(vel_bw) * period * vel_error + PIN(cur_sum); @@ -226,7 +218,6 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { PIN(timer) = 0.0; PIN(en_out) = 0.0; - PIN(d_cmd) = 0.0; PIN(q_cmd) = 0.0; PIN(cur_sum) = 0.0; PIN(cmd_mode) = 0.0; diff --git a/shared/comps/idm.c b/shared/comps/idm.c index f018c5fe..e63a851b 100644 --- a/shared/comps/idm.c +++ b/shared/comps/idm.c @@ -84,7 +84,7 @@ static void nrt(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { else{ printf("Measure friction, damping and inertia\n"); printf("the motor will move\n"); - printf("id0.state = 1.2 to start\n"); + printf("idm0.state = 1.2 to start\n"); } break; diff --git a/shared/comps/idpmsm.c b/shared/comps/idpmsm.c index 1297482a..cb9802e5 100644 --- a/shared/comps/idpmsm.c +++ b/shared/comps/idpmsm.c @@ -91,7 +91,7 @@ static void nrt(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { else{ printf("Measure r, l\n"); printf("the motor can move a bit\n"); - printf("id0.state = 1.2 to start\n"); + printf("idpmsm0.state = 1.2 to start\n"); } break; @@ -115,7 +115,7 @@ static void nrt(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { else{ printf("Measure com_offset, polepairs, out_rev\n"); printf("the motor will move\n"); - printf("id0.state = 2.2 to start\n"); + printf("idpmsm0.state = 2.2 to start\n"); } break;