Parcourir la source

加入扭矩过零点配置

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui il y a 2 ans
Parent
commit
6d7b887d99

+ 3 - 1
Applications/app/app.c

@@ -20,6 +20,7 @@
 #include "foc/limit.h"
 #include "foc/mc_error.h"
 #include "foc/mc_config.h"
+#include "foc/motor/throttle.h"
 
 #ifdef CONFIG_DQ_STEP_RESPONSE
 extern float target_d;
@@ -209,7 +210,8 @@ static u32 _app_plot_task(void * args) {
 	}else if (plot_type == 9) {
 		s16 thro_v = get_throttle_float() * 100.0f;
 		s16 thro2_v = get_throttle2_float() * 100.0f;
-		can_plot2(thro_v, thro2_v);
+		s16 sig = throttle_get_signal();
+		can_plot3(sig, thro_v, thro2_v);
 	}
 	return 20;
 }

+ 11 - 7
Applications/autogen_config.h

@@ -1,12 +1,12 @@
-/* auto gen 2023/9/2 14:57:59*/
+/* auto gen 2023/9/6 15:15:17*/
 #ifndef _AUTOGEN_CONFIG_H__
 #define _AUTOGEN_CONFIG_H__
 
 #define CONFIG_Version 1
-#define CONFIG_Motor_Poles  5
-#define CONFIG_Motor_Ld  4.5E-05f
-#define CONFIG_Motor_Lq  9.6E-05f
-#define CONFIG_Motor_Rs  0.008f
+#define CONFIG_Motor_Poles  4
+#define CONFIG_Motor_Ld  3.2E-05f
+#define CONFIG_Motor_Lq  7.3E-05f
+#define CONFIG_Motor_Rs  0.009f
 #define CONFIG_Motor_Flux  0.019f
 #define CONFIG_Motor_PLLBand  200
 #define CONFIG_Motor_EpmPLL  400
@@ -16,7 +16,7 @@
 #define CONFIG_Motor_GearRatio  6.25f
 #define CONFIG_Motor_MaxFwDCurr  100
 #define CONFIG_Motor_MaxTorque  200
-#define CONFIG_Motor_EncOffset  0
+#define CONFIG_Motor_EncOffset  -103
 #define CONFIG_Foc_MaxDCVol  110
 #define CONFIG_Foc_MinDCVol  70
 #define CONFIG_Foc_MaxPhaseCurr  300
@@ -33,7 +33,7 @@
 #define CONFIG_Foc_ThroEndVol  4.15f
 #define CONFIG_Foc_ThroMinVol  0.4f
 #define CONFIG_Foc_ThroMaxVol  4.6f
-#define CONFIG_Foc_CurrCtrlBandWith  200
+#define CONFIG_Foc_CurrCtrlBandWith  800
 #define CONFIG_Foc_ThroDecTime  10
 #define CONFIG_Foc_PID_VelLim_Kp 0.5f
 #define CONFIG_Foc_PID_VelLim_Ki 2.5f
@@ -211,4 +211,8 @@
 #define CONFIG_EnergyRecovery_Level8_Time 200
 #define CONFIG_EnergyRecovery_Level9_Torque 40
 #define CONFIG_EnergyRecovery_Level9_Time 200
+#define CONFIG_CrossZero_Low  1
+#define CONFIG_CrossZero_High  7
+#define CONFIG_CrossZero_MinStep  0.03f
+#define CONFIG_CrossZero_NorStep  5
 #endif /* _AUTOGEN_CONFIG_H__ */ 

+ 16 - 16
Applications/foc/core/PMSM_FOC_Core.c

@@ -626,41 +626,41 @@ u8 PMSM_FOC_CtrlMode(void) {
 	return gFoc_Ctrl.out.n_RunMode;
 }
 
-#define RAMPE_1 CONFIG_RAMP_FIRST_TARGET
-#define NORMAL_STEP 3.0F
 static void crosszero_step_towards(float *value, float target) {
-	static float no_cro_step = NORMAL_STEP;
+	static float no_cro_step = CONFIG_CrossZero_NorStep;
 	float v_now = *value;
 	bool cross_zero = false;
-
-	float high_ramp_torque = CONFIG_RAMP_SECOND_TARGET;
+	float nor_step = mc_conf()->cz.normal_step;
+	float min_step = mc_conf()->cz.min_step;
+	float min_ramp_torque = mc_conf()->cz.low;
+	float high_ramp_torque = mc_conf()->cz.high;
 	if (target > 0) {
-		if (v_now < -RAMPE_1) {
-			step_towards(value, -RAMPE_1 + 0.001f, NORMAL_STEP);
+		if (v_now < -min_ramp_torque) {
+			step_towards(value, -min_ramp_torque + 0.001f, nor_step);
 			cross_zero = true;
-		}else if (v_now >= -RAMPE_1 && v_now <= high_ramp_torque) {
-			step_towards(value, target, 0.03f);
+		}else if (v_now >= -min_ramp_torque && v_now <= high_ramp_torque) {
+			step_towards(value, target, min_step);
 			cross_zero = true;
 		}
 	}else if (target == 0) {
 		if (v_now > high_ramp_torque) {
-			step_towards(value, high_ramp_torque - 0.001f, NORMAL_STEP);
+			step_towards(value, high_ramp_torque - 0.001f, nor_step);
 			cross_zero = true;
-		}else if (v_now >= RAMPE_1 && v_now <= high_ramp_torque) {
-			step_towards(value, target, 0.03f);
+		}else if (v_now >= min_ramp_torque && v_now <= high_ramp_torque) {
+			step_towards(value, target, min_step);
 			cross_zero = true;
 		}
 	}else {
 		if (v_now > high_ramp_torque) {
-			step_towards(value, high_ramp_torque - 0.001f, NORMAL_STEP);
+			step_towards(value, high_ramp_torque - 0.001f, nor_step);
 			cross_zero = true;
-		}else if (v_now >= -RAMPE_1 && v_now <= high_ramp_torque) {
-			step_towards(value, target, 0.03f);
+		}else if (v_now >= -min_ramp_torque && v_now <= high_ramp_torque) {
+			step_towards(value, target, min_step);
 			cross_zero = true;
 		}
 	}
 	if (!cross_zero) {
-		step_towards(&no_cro_step, NORMAL_STEP, 0.1f);
+		step_towards(&no_cro_step, nor_step, 0.1f);
 		step_towards(value, target, no_cro_step);
 	}else {
 		no_cro_step = 0.5f;

+ 21 - 0
Applications/foc/mc_config.c

@@ -418,6 +418,25 @@ int mc_conf_encode_setting(u8 *buff) {
 }
 
 
+int mc_conf_decode_cross_zero(u8 *buff) {
+	u8 *ori = buff;
+	conf.cz.low = (float)decode_s16(buff); buff += 2;
+	conf.cz.high = (float)decode_s16(buff); buff += 2;
+	conf.cz.min_step = decode_float(buff); buff += 4;
+	conf.cz.normal_step = (float)decode_s16(buff); buff += 2;
+	return buff - ori;
+}
+
+int mc_conf_encode_cross_zero(u8 *buff) {
+	u8 *ori = buff;
+	encode_s16(buff, (s16)conf.cz.low); buff += 2;
+	encode_s16(buff, (s16)conf.cz.high); buff += 2;
+	encode_float(buff, conf.cz.min_step); buff += 4;
+	encode_s16(buff, (s16)conf.cz.normal_step); buff += 2;
+	return buff - ori;
+}
+
+
 int mc_conf_decode_gear(gear_t *g , u8 *buff) {
 	u8 *ori = buff;
 	for (int i = 0; i < CONFIG_MAX_GEARS; i++) {
@@ -508,6 +527,7 @@ void mc_conf_decode_configs(void) {
 	buff += mc_conf_decode_limiter(conf.p_mos, CONFIG_TEMP_PROT_NUM, buff);
 	buff += mc_conf_decode_limiter(&conf.p_vol, 1, buff);
 	buff += mc_conf_decode_engreco(buff);
+	buff += mc_conf_decode_cross_zero(buff);
 }
 
 int mc_conf_encode_configs(u8 *buff) {
@@ -522,6 +542,7 @@ int mc_conf_encode_configs(u8 *buff) {
 	buff += mc_conf_encode_limiter(conf.p_mos, CONFIG_TEMP_PROT_NUM, buff);
 	buff += mc_conf_encode_limiter(&conf.p_vol, 1, buff);
 	buff += mc_conf_encode_engreco(buff);
+	buff += mc_conf_encode_cross_zero(buff);
 	return buff - ori;
 }
 

+ 8 - 0
Applications/foc/mc_config.h

@@ -91,6 +91,13 @@ typedef struct {
 	u16 time;
 }eng_reco_l_t;
 
+typedef struct {
+	float low;
+	float high;
+	float min_step;
+	float normal_step;
+}cross_zero_t;
+
 typedef struct {
 	u8 version;
 	motor_t m;
@@ -102,6 +109,7 @@ typedef struct {
 	limiter_t p_mos[CONFIG_TEMP_PROT_NUM];
 	limiter_t p_vol;
 	eng_reco_l_t e_r[CONFIG_EBRK_LVL_NUM];
+	cross_zero_t cz;
 	u16 crc;
 }mc_config;
 

+ 6 - 1
mc_config.yml

@@ -231,4 +231,9 @@ EnergyRecovery:  # Braking Energy Recovery
   - Torque: 55
     Time:   200  
   - Torque: 60
-    Time:   200     
+    Time:   200
+CrossZero: #扭矩过零处理
+  Low: 1
+  High: 7
+  MinStep: 0.03
+  NorStep: 5