|
@@ -84,6 +84,7 @@ bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#if 0
|
|
|
void mot_contrl_enable_hfi(mot_contrl_t *ctrl, bool enable) {
|
|
void mot_contrl_enable_hfi(mot_contrl_t *ctrl, bool enable) {
|
|
|
hfi_t *hfi = &ctrl->hfi;
|
|
hfi_t *hfi = &ctrl->hfi;
|
|
|
if (enable) {
|
|
if (enable) {
|
|
@@ -98,7 +99,28 @@ void mot_contrl_enable_hfi(mot_contrl_t *ctrl, bool enable) {
|
|
|
}
|
|
}
|
|
|
ctrl->b_hfi = enable;
|
|
ctrl->b_hfi = enable;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+#else
|
|
|
|
|
+#define HFI_PLL_BAND 100.0F
|
|
|
|
|
+void mot_contrl_enable_hfi(mot_contrl_t *ctrl, bool enable) {
|
|
|
|
|
+ hfi_t *hfi = &ctrl->hfi;
|
|
|
|
|
+ if (enable) {
|
|
|
|
|
+ PI_Controller_Reset(&hfi->pi, 0);
|
|
|
|
|
+ hfi->elec_vel = 0;//ctrl->foc.mot_vel_radusPers;
|
|
|
|
|
+ hfi->angle_deg = 0;//ctrl->foc.in.mot_angle;
|
|
|
|
|
+ hfi->rad_integrator = 0;//degree_2_pi(hfi->angle_deg);
|
|
|
|
|
+ hfi->v_inj = 15.0f;
|
|
|
|
|
+ hfi->pi.ts = ctrl->foc.ts;
|
|
|
|
|
+ hfi->pi.kp = 2 * HFI_PLL_BAND;
|
|
|
|
|
+ hfi->pi.ki = SQ(HFI_PLL_BAND);
|
|
|
|
|
+ hfi->pi.kd = 0;
|
|
|
|
|
+ hfi->pi.max = 2000.0f/30*M_PI*mc_conf()->m.poles;
|
|
|
|
|
+ hfi->pi.min = -hfi->pi.max;
|
|
|
|
|
+ hfi->sign = -1;
|
|
|
|
|
+ hfi->rpm_vel = 0;//ctrl->foc.in.mot_velocity;
|
|
|
|
|
+ }
|
|
|
|
|
+ ctrl->b_hfi = enable;
|
|
|
|
|
+}
|
|
|
|
|
+#endif
|
|
|
bool mot_contrl_request_mode(mot_contrl_t *ctrl, u8 mode) {
|
|
bool mot_contrl_request_mode(mot_contrl_t *ctrl, u8 mode) {
|
|
|
if (mode > CTRL_MODE_EBRAKE) {
|
|
if (mode > CTRL_MODE_EBRAKE) {
|
|
|
mot_contrl_set_error(ctrl, FOC_Param_Err);
|
|
mot_contrl_set_error(ctrl, FOC_Param_Err);
|
|
@@ -229,7 +251,8 @@ static __INLINE void phase_curr_unbal_check(mot_contrl_t *ctrl) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#define HFI_DEBUG_ON 1
|
|
|
|
|
|
|
+#define HFI_DEBUG_ON 0
|
|
|
|
|
+#if 0
|
|
|
static void mot_contrl_hfi_alpha_beta(mot_contrl_t *ctrl) {
|
|
static void mot_contrl_hfi_alpha_beta(mot_contrl_t *ctrl) {
|
|
|
hfi_t *hfi = &ctrl->hfi;
|
|
hfi_t *hfi = &ctrl->hfi;
|
|
|
float sin, cos;
|
|
float sin, cos;
|
|
@@ -260,7 +283,56 @@ static void mot_contrl_hfi_alpha_beta(mot_contrl_t *ctrl) {
|
|
|
}
|
|
}
|
|
|
hfi->b_sample = !hfi->b_sample;
|
|
hfi->b_sample = !hfi->b_sample;
|
|
|
}
|
|
}
|
|
|
|
|
+#else
|
|
|
|
|
+static __INLINE void hfi_pll_run(hfi_t *hfi, float alpha, float beta) {
|
|
|
|
|
+ float mag = NORM2_f(alpha, beta) + 1e-10f;
|
|
|
|
|
+ alpha /= mag;
|
|
|
|
|
+ beta /= mag;
|
|
|
|
|
+ float sin, cos;
|
|
|
|
|
+ arm_sin_cos(hfi->angle_deg, &sin, &cos);
|
|
|
|
|
+ float err = alpha * sin - beta * cos;
|
|
|
|
|
+ hfi->elec_vel = PI_Controller_Run(&hfi->pi, err);
|
|
|
|
|
+ hfi->rad_integrator += hfi->elec_vel * hfi->pi.ts;
|
|
|
|
|
+ norm_angle_rad(hfi->rad_integrator);
|
|
|
|
|
+ hfi->angle_deg = pi_2_degree(hfi->rad_integrator);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+static void mot_contrl_hfi_alpha_beta(mot_contrl_t *ctrl) {
|
|
|
|
|
+ hfi_t *hfi = &ctrl->hfi;
|
|
|
|
|
+ float sin, cos;
|
|
|
|
|
+ float sign = hfi->sign;
|
|
|
|
|
+#if HFI_DEBUG_ON
|
|
|
|
|
+ arm_sin_cos(hfi->angle_deg, &sin, &cos);
|
|
|
|
|
+#else
|
|
|
|
|
+ sin = ctrl->foc.sin;
|
|
|
|
|
+ cos = ctrl->foc.cos;
|
|
|
|
|
+#endif
|
|
|
|
|
+ if (hfi->sign > 0) {
|
|
|
|
|
+ hfi->sign = -1;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ hfi->sign = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ float hi_alpha = (ctrl->foc.in.curr_ab.a - hfi->sample_prev.a) * 0.5f * sign;
|
|
|
|
|
+ float hi_beta = (ctrl->foc.in.curr_ab.b - hfi->sample_prev.b) * 0.5f * sign;
|
|
|
|
|
+
|
|
|
|
|
+ float alpha = (ctrl->foc.in.curr_ab.a + hfi->sample_prev.a) * 0.5f;
|
|
|
|
|
+ float beta = (ctrl->foc.in.curr_ab.b + hfi->sample_prev.b) * 0.5f;
|
|
|
|
|
+
|
|
|
|
|
+ hfi_pll_run(hfi, hi_alpha, hi_beta);
|
|
|
|
|
+
|
|
|
|
|
+ hfi->v_alpha_inj = hfi->v_inj * cos * hfi->sign;
|
|
|
|
|
+ hfi->v_beta_inj = hfi->v_inj * sin * hfi->sign;
|
|
|
|
|
+ hfi->sample_prev.a = ctrl->foc.in.curr_ab.a;
|
|
|
|
|
+ hfi->sample_prev.b = ctrl->foc.in.curr_ab.b;
|
|
|
|
|
+
|
|
|
|
|
+ ctrl->foc.in.curr_ab.a = alpha;
|
|
|
|
|
+ ctrl->foc.in.curr_ab.b = beta;
|
|
|
|
|
+
|
|
|
|
|
+ hfi->rpm_vel = LowPass_Filter(hfi->rpm_vel, (hfi->elec_vel/M_PI*30/mc_conf()->m.poles) ,0.005f);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#endif
|
|
|
bool mot_contrl_update(mot_contrl_t *ctrl) {
|
|
bool mot_contrl_update(mot_contrl_t *ctrl) {
|
|
|
foc_t *foc = &ctrl->foc;
|
|
foc_t *foc = &ctrl->foc;
|
|
|
|
|
|