Преглед изворни кода

去掉多余的fast_atan接口,统一使用fast_atan2

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin пре 2 година
родитељ
комит
348e2f135a

+ 1 - 1
Applications/foc/core/controller.c

@@ -228,7 +228,7 @@ static __INLINE void mot_contrl_update_phase_vol(mot_contrl_t *ctrl) {
 	ctrl->phase_v_ab.a *= mag_mul;
 	ctrl->phase_v_ab.b *= mag_mul;
 	/* 计算低通相位延时 */
-	float angle_rad = fast_atan_2(We_hz, PHASE_VOL_LPF_BAND);
+	float angle_rad = fast_atan2(We_hz, PHASE_VOL_LPF_BAND);
 	/* 延时半周期*/
 	angle_rad += (We_hz * 2 * M_PI * ctrl->foc.ts / 2);
 	norm_angle_rad(angle_rad);

+ 2 - 2
Applications/foc/core/ladrc_observer.c

@@ -76,7 +76,7 @@ float ladrc_observer_update(float va, float vb, float ia, float ib) {
 	
 	observer.Ebeta = observer.beta.z2 * (-observer.ld);
 
-	float angle = fast_atan_2(-observer.Ealpha, observer.Ebeta);
+	float angle = fast_atan2(-observer.Ealpha, observer.Ebeta);
 	UTILS_NAN_ZERO(angle);
 	norm_angle_rad(angle);
 
@@ -101,7 +101,7 @@ float ladrc_observer_update(float va, float vb, float ia, float ib) {
 	}
 	LowPass_Filter(observer.Vel_El, vel, observer.lpf_ceof);
 	/* 补偿ladrc相位延时,LADRC等效截止频率为Wo/2pi的两个低通滤波器串联 */
-	angle = fast_atan_2(observer.Vel_El, Wo) * 2.0f;
+	angle = fast_atan2(observer.Vel_El, Wo) * 2.0f;
 	/* 电压滞后一个控制周期,需要通过当前的电角速度对计算的角度进行补偿 */
 	observer.angle_out = observer.angle_atan + (angle + 0/*observer.Vel_El * observer.ts*/);
 	norm_angle_rad(observer.angle_out);

+ 2 - 2
Applications/foc/core/smo_observer.c

@@ -91,7 +91,7 @@ static void smo_arctan(void) {
 	float ealpha_in = -smo.est_eAlpha_Filted;
 	float ebeta_in  =  smo.est_eBeta_Filted;
 
-	float angle = fast_atan_2(ealpha_in, ebeta_in); //通过反正切获取电角度
+	float angle = fast_atan2(ealpha_in, ebeta_in); //通过反正切获取电角度
 	UTILS_NAN_ZERO(angle);
 	norm_angle_rad(angle);
 	float prev_angle = smo.est_angle;
@@ -113,7 +113,7 @@ static void smo_arctan(void) {
 	}
 	smo.est_rad_pers_filted = smo.est_rad_pers;
 	/*低通滤波有相位滞后,需要补偿,同时电流和电压滞后一个控制周期,需要通过当前的电角速度对计算的角度进行补偿 */
-	smo.est_angle_out = smo.est_angle + fast_atan_2(smo.est_rad_pers_filted, smo.lpf_wc) + smo.est_rad_pers_filted * smo.ts;
+	smo.est_angle_out = smo.est_angle + fast_atan2(smo.est_rad_pers_filted, smo.lpf_wc) + smo.est_rad_pers_filted * smo.ts;
 	norm_angle_rad(smo.est_angle_out);
 	smo.est_rpm = (30.0f * smo.est_rad_pers_filted/M_PI/smo.motor_poles);
 	if (smo.est_rpm > CONFIG_HW_MAX_MOTOR_RPM) {

+ 1 - 1
Applications/foc/motor/mot_params_ind.c

@@ -256,7 +256,7 @@ void mot_params_calc_inductance(void) {
 	sys_debug("vmag %f, %f\n", v_mag, Vdead * hj_samples*0.5f);
 	v_mag -= Vdead * hj_samples*0.5f;
 	
-	float z_angle = fast_atan_2(i_image, i_real) - fast_atan_2(v_image, v_real);
+	float z_angle = fast_atan2(i_image, i_real) - fast_atan2(v_image, v_real);
 	float s,c;
 	arm_sin_cos(pi_2_degree(z_angle), &s, &c);
 

+ 1 - 24
Applications/math/fast_math.h

@@ -106,7 +106,7 @@ static __INLINE s16 line_intp(s16 x, s16 x_l, s16 x_h, s16 y_l, s16 y_h) {
 /**
  * Fast atan2
  *
- * See http://www.dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization
+ * See based on https://math.stackexchange.com/a/1105038/81278
  *
  * @param y
  * y
@@ -118,29 +118,6 @@ static __INLINE s16 line_intp(s16 x, s16 x_l, s16 x_h, s16 y_l, s16 y_h) {
  * The angle in radians
  */
 static __INLINE float fast_atan2(float y, float x) {
-	float abs_y = fabsf(y) + 1e-20f; // kludge to prevent 0/0 condition
-	float angle;
-
-	if (x >= 0) {
-		float r = (x - abs_y) / (x + abs_y);
-		float rsq = r * r;
-		angle = ((0.1963f * rsq) - 0.9817f) * r + (M_PI / 4.0f);
-	} else {
-		float r = (x + abs_y) / (abs_y - x);
-		float rsq = r * r;
-		angle = ((0.1963f * rsq) - 0.9817f) * r + (3.0f * M_PI / 4.0f);
-	}
-
-	UTILS_NAN_ZERO(angle);
-
-	if (y < 0) {
-		return(-angle);
-	} else {
-		return(angle);
-	}
-}
-
-static __INLINE float fast_atan_2(float y, float x) {
     // a := min (|x|, |y|) / max (|x|, |y|)
     float abs_y = ABS(y);
     float abs_x = ABS(x);