Quellcode durchsuchen

支持配置动态生成和动态设置

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui vor 2 Jahren
Ursprung
Commit
60aff97542

+ 5 - 3
Applications/autogen_config.h

@@ -1,4 +1,4 @@
-/* auto gen 2023/8/30 10:53:32*/
+/* auto gen 2023/8/30 19:10:01*/
 #ifndef _AUTOGEN_CONFIG_H__
 #ifndef _AUTOGEN_CONFIG_H__
 #define _AUTOGEN_CONFIG_H__
 #define _AUTOGEN_CONFIG_H__
 
 
@@ -11,10 +11,11 @@
 #define CONFIG_Motor_PLLBand  200
 #define CONFIG_Motor_PLLBand  200
 #define CONFIG_Motor_EpmPLL  400
 #define CONFIG_Motor_EpmPLL  400
 #define CONFIG_Motor_PosPLL  500
 #define CONFIG_Motor_PosPLL  500
-#define CONFIG_Motor_VelocityW  190
-#define CONFIG_Motor_VelocityC  145
+#define CONFIG_Motor_VehicleW  190
+#define CONFIG_Motor_WheelC  145
 #define CONFIG_Motor_GearRatio  6.25f
 #define CONFIG_Motor_GearRatio  6.25f
 #define CONFIG_Motor_MaxFwDCurr  100
 #define CONFIG_Motor_MaxFwDCurr  100
+#define CONFIG_Motor_MaxTorque  200
 #define CONFIG_Foc_MaxDCVol  110
 #define CONFIG_Foc_MaxDCVol  110
 #define CONFIG_Foc_MinDCVol  70
 #define CONFIG_Foc_MinDCVol  70
 #define CONFIG_Foc_MaxPhaseCurr  300
 #define CONFIG_Foc_MaxPhaseCurr  300
@@ -26,6 +27,7 @@
 #define CONFIG_Foc_MaxTorque  300
 #define CONFIG_Foc_MaxTorque  300
 #define CONFIG_Foc_MaxEbrkTorque  40
 #define CONFIG_Foc_MaxEbrkTorque  40
 #define CONFIG_Foc_MaxIDC  100
 #define CONFIG_Foc_MaxIDC  100
+#define CONFIG_Foc_MaxAutoHoldTorque  100
 #define CONFIG_Foc_ThroStartVol  0.85f
 #define CONFIG_Foc_ThroStartVol  0.85f
 #define CONFIG_Foc_ThroEndVol  4.15f
 #define CONFIG_Foc_ThroEndVol  4.15f
 #define CONFIG_Foc_ThroMinVol  0.4f
 #define CONFIG_Foc_ThroMinVol  0.4f

+ 6 - 6
Applications/bsp/at32/board_at_mc100_v1.h

@@ -7,15 +7,15 @@
 #endif
 #endif
 
 
 #define CONFIG_MOS_MAX_VOL 145.0F
 #define CONFIG_MOS_MAX_VOL 145.0F
-#define CONFIG_MAX_DC_VOL 110.0F
+#define CONFIG_HW_MAX_DC_VOLTAGE 110.0F
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_MIN_DC_VOL   (36.0f)
 #define CONFIG_MIN_DC_VOL   (36.0f)
 
 
-#define CONFIG_MAX_VBUS_CURRENT 200.0f
-#define CONFIG_MAX_MOT_RPM      9000.0f
-#define CONFIG_MAX_PHASE_CURR   500.0F
-#define CONFIG_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
-#define CONFIG_MAX_TORQUE       CONFIG_MAX_PHASE_CURR
+#define CONFIG_HW_MAX_DC_CURRENT 200.0f
+#define CONFIG_HW_MAX_MOTOR_RPM      9000.0f
+#define CONFIG_HW_MAX_PHASE_CURR   500.0F
+#define CONFIG_HW_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
+#define CONFIG_MAX_TORQUE       CONFIG_HW_MAX_PHASE_CURR
 #define CONFIG_MAX_LOCK_TORQUE  20
 #define CONFIG_MAX_LOCK_TORQUE  20
 
 
 //#define CONFIG_BEEP 
 //#define CONFIG_BEEP 

+ 6 - 6
Applications/bsp/at32/board_at_mc105_v3.h

@@ -7,16 +7,16 @@
 #endif
 #endif
 
 
 #define CONFIG_MOS_MAX_VOL 145.0F
 #define CONFIG_MOS_MAX_VOL 145.0F
-#define CONFIG_MAX_DC_VOL 110.0F
+#define CONFIG_HW_MAX_DC_VOLTAGE 110.0F
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_MIN_DC_VOL   (36.0f)
 #define CONFIG_MIN_DC_VOL   (36.0f)
 
 
-#define CONFIG_MAX_VBUS_CURRENT 200.0f
+#define CONFIG_HW_MAX_DC_CURRENT 200.0f
 #define CONFIG_MAX_CHRG_CURRENT (-100.0f)
 #define CONFIG_MAX_CHRG_CURRENT (-100.0f)
-#define CONFIG_MAX_MOT_RPM      9000.0f
-#define CONFIG_MAX_PHASE_CURR   500.0F
-#define CONFIG_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
-#define CONFIG_MAX_TORQUE       CONFIG_MAX_PHASE_CURR
+#define CONFIG_HW_MAX_MOTOR_RPM      9000.0f
+#define CONFIG_HW_MAX_PHASE_CURR   500.0F
+#define CONFIG_HW_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
+#define CONFIG_MAX_TORQUE       CONFIG_HW_MAX_PHASE_CURR
 #define CONFIG_MAX_LOCK_TORQUE  20
 #define CONFIG_MAX_LOCK_TORQUE  20
 #define CONFIG_MAX_ACTIVE_EMF   5000.0F
 #define CONFIG_MAX_ACTIVE_EMF   5000.0F
 
 

+ 6 - 6
Applications/bsp/gd32/board_mc100_v1.h

@@ -7,15 +7,15 @@
 #endif
 #endif
 
 
 #define CONFIG_MOS_MAX_VOL 145.0F
 #define CONFIG_MOS_MAX_VOL 145.0F
-#define CONFIG_MAX_DC_VOL 110.0F
+#define CONFIG_HW_MAX_DC_VOLTAGE 110.0F
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_MIN_DC_VOL   (36.0f)
 #define CONFIG_MIN_DC_VOL   (36.0f)
 
 
-#define CONFIG_MAX_VBUS_CURRENT 200.0f
-#define CONFIG_MAX_MOT_RPM      9000.0f
-#define CONFIG_MAX_PHASE_CURR   500.0F
-#define CONFIG_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
-#define CONFIG_MAX_TORQUE       CONFIG_MAX_PHASE_CURR
+#define CONFIG_HW_MAX_DC_CURRENT 200.0f
+#define CONFIG_HW_MAX_MOTOR_RPM      9000.0f
+#define CONFIG_HW_MAX_PHASE_CURR   500.0F
+#define CONFIG_HW_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
+#define CONFIG_MAX_TORQUE       CONFIG_HW_MAX_PHASE_CURR
 #define CONFIG_MAX_LOCK_TORQUE  20
 #define CONFIG_MAX_LOCK_TORQUE  20
 
 
 //#define CONFIG_BEEP 
 //#define CONFIG_BEEP 

+ 6 - 6
Applications/bsp/gd32/board_mc105_v3.h

@@ -7,16 +7,16 @@
 #endif
 #endif
 
 
 #define CONFIG_MOS_MAX_VOL 125.0F
 #define CONFIG_MOS_MAX_VOL 125.0F
-#define CONFIG_MAX_DC_VOL 110.0F
+#define CONFIG_HW_MAX_DC_VOLTAGE 110.0F
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_MIN_DC_VOL   (60.0f)
 #define CONFIG_MIN_DC_VOL   (60.0f)
 
 
-#define CONFIG_MAX_VBUS_CURRENT 250.0f
+#define CONFIG_HW_MAX_DC_CURRENT 250.0f
 #define CONFIG_MAX_CHRG_CURRENT (-100.0f)
 #define CONFIG_MAX_CHRG_CURRENT (-100.0f)
-#define CONFIG_MAX_MOT_RPM      9000.0f
-#define CONFIG_MAX_PHASE_CURR   500.0F
-#define CONFIG_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
-#define CONFIG_MAX_TORQUE       CONFIG_MAX_PHASE_CURR
+#define CONFIG_HW_MAX_MOTOR_RPM      9000.0f
+#define CONFIG_HW_MAX_PHASE_CURR   500.0F
+#define CONFIG_HW_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
+#define CONFIG_MAX_TORQUE       CONFIG_HW_MAX_PHASE_CURR
 #define CONFIG_MAX_LOCK_TORQUE  100
 #define CONFIG_MAX_LOCK_TORQUE  100
 #define CONFIG_MAX_ACTIVE_EMF   5000.0F
 #define CONFIG_MAX_ACTIVE_EMF   5000.0F
 //#define CONFIG_BEEP 
 //#define CONFIG_BEEP 

+ 5 - 5
Applications/bsp/gd32/board_yuanqu.h

@@ -7,14 +7,14 @@
 #endif
 #endif
 
 
 #define CONFIG_MOS_MAX_VOL 145.0F
 #define CONFIG_MOS_MAX_VOL 145.0F
-#define CONFIG_MAX_DC_VOL 120.0F
+#define CONFIG_HW_MAX_DC_VOLTAGE 120.0F
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_MIN_DC_VOL   (36.0f)
 #define CONFIG_MIN_DC_VOL   (36.0f)
 
 
-#define CONFIG_MAX_VBUS_CURRENT 200.0f
-#define CONFIG_MAX_MOT_RPM      9000.0f
-#define CONFIG_MAX_PHASE_CURR   400.0F
-#define CONFIG_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
+#define CONFIG_HW_MAX_DC_CURRENT 200.0f
+#define CONFIG_HW_MAX_MOTOR_RPM      9000.0f
+#define CONFIG_HW_MAX_PHASE_CURR   400.0F
+#define CONFIG_HW_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
 #define CONFIG_MAX_TORQUE       50.0F
 #define CONFIG_MAX_TORQUE       50.0F
 
 
 #define CONFIG_CURRENT_BANDWITH  1000.0f /* 电流环带宽 */
 #define CONFIG_CURRENT_BANDWITH  1000.0f /* 电流环带宽 */

+ 6 - 6
Applications/bsp/n32/board_n32_mc105_v3.h

@@ -2,15 +2,15 @@
 #define _BOARD_MC_V3_H__
 #define _BOARD_MC_V3_H__
 
 
 #define CONFIG_MOS_MAX_VOL 145.0F
 #define CONFIG_MOS_MAX_VOL 145.0F
-#define CONFIG_MAX_DC_VOL 110.0F
+#define CONFIG_HW_MAX_DC_VOLTAGE 110.0F
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_RATED_DC_VOL (96.0f)   /* 母线最大电压 V*/
 #define CONFIG_MIN_DC_VOL   (36.0f)
 #define CONFIG_MIN_DC_VOL   (36.0f)
 
 
-#define CONFIG_MAX_VBUS_CURRENT 120.0f
-#define CONFIG_MAX_MOT_RPM      9000.0f
-#define CONFIG_MAX_PHASE_CURR   500.0F
-#define CONFIG_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
-#define CONFIG_MAX_TORQUE       CONFIG_MAX_PHASE_CURR
+#define CONFIG_HW_MAX_DC_CURRENT 120.0f
+#define CONFIG_HW_MAX_MOTOR_RPM      9000.0f
+#define CONFIG_HW_MAX_PHASE_CURR   500.0F
+#define CONFIG_HW_MAX_PHASE_VOL    (CONFIG_MOS_MAX_VOL - 20.0F)
+#define CONFIG_MAX_TORQUE       CONFIG_HW_MAX_PHASE_CURR
 #define CONFIG_MAX_LOCK_TORQUE  20
 #define CONFIG_MAX_LOCK_TORQUE  20
 
 
 //#define CONFIG_BEEP 
 //#define CONFIG_BEEP 

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

@@ -17,7 +17,7 @@ void F_all_Calc(void) {
 	if (!_init) {
 	if (!_init) {
 		_init = true;
 		_init = true;
 		C = (float)mc_conf()->m.wheel_c / 100.0f;
 		C = (float)mc_conf()->m.wheel_c / 100.0f;
-		M = (float)mc_conf()->m.velocity_w;
+		M = (float)mc_conf()->m.vehicle_w;
 		gear_ratio = (float)mc_conf()->m.gear_ratio;
 		gear_ratio = (float)mc_conf()->m.gear_ratio;
 	}
 	}
 	float kmph = PMSM_FOC_GetSpeed() / gear_ratio * C * 60.0f / 1000.0f;
 	float kmph = PMSM_FOC_GetSpeed() / gear_ratio * C * 60.0f / 1000.0f;

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

@@ -214,13 +214,13 @@ void PMSM_FOC_CoreInit(void) {
 	memset(&gFoc_Ctrl.in, 0, sizeof(FOC_InP));
 	memset(&gFoc_Ctrl.in, 0, sizeof(FOC_InP));
 	memset(&gFoc_Ctrl.out, 0, sizeof(FOC_OutP));
 	memset(&gFoc_Ctrl.out, 0, sizeof(FOC_OutP));
 	
 	
-	gFoc_Ctrl.hwLim.s_iDCMax = CONFIG_MAX_VBUS_CURRENT;
-	gFoc_Ctrl.hwLim.s_motRPMMax = CONFIG_MAX_MOT_RPM;
-	gFoc_Ctrl.hwLim.s_PhaseCurrMax = CONFIG_MAX_PHASE_CURR;
-	gFoc_Ctrl.hwLim.s_PhaseVolMax = CONFIG_MAX_PHASE_VOL;
-	gFoc_Ctrl.hwLim.s_vDCMax      = CONFIG_MAX_DC_VOL;
-	gFoc_Ctrl.hwLim.s_torqueMax  = CONFIG_MAX_MOTOR_TORQUE;
-	gFoc_Ctrl.hwLim.s_FWDCurrMax = CONFIG_MAX_FW_D_CURR;
+	gFoc_Ctrl.hwLim.s_iDCMax = CONFIG_HW_MAX_DC_CURRENT;
+	gFoc_Ctrl.hwLim.s_motRPMMax = CONFIG_HW_MAX_MOTOR_RPM;
+	gFoc_Ctrl.hwLim.s_PhaseCurrMax = CONFIG_HW_MAX_PHASE_CURR;
+	gFoc_Ctrl.hwLim.s_PhaseVolMax = CONFIG_HW_MAX_PHASE_VOL;
+	gFoc_Ctrl.hwLim.s_vDCMax      = CONFIG_HW_MAX_DC_VOLTAGE;
+	gFoc_Ctrl.hwLim.s_torqueMax  = mc_conf()->m.max_torque; //电机的最大扭矩
+	gFoc_Ctrl.hwLim.s_FWDCurrMax = mc_conf()->m.max_fw_id;  //电池能支持的最大弱磁电流
 	if (!g_focinit) {
 	if (!g_focinit) {
 		PMSM_FOC_UserInit();
 		PMSM_FOC_UserInit();
 		PMSM_FOC_RT_LimInit();
 		PMSM_FOC_RT_LimInit();
@@ -957,7 +957,7 @@ static __INLINE void PMSM_FOC_idq_Assign(void) {
 /*called in media task */
 /*called in media task */
 void PMSM_FOC_idqCalc(void) {
 void PMSM_FOC_idqCalc(void) {
 	if (gFoc_Ctrl.in.b_AutoHold) {
 	if (gFoc_Ctrl.in.b_AutoHold) {
-		float hold_torque = min(gFoc_Ctrl.protLim.s_TorqueLim, CONFIG_MAX_LOCK_TORQUE);
+		float hold_torque = min(gFoc_Ctrl.protLim.s_TorqueLim, mc_conf()->c.max_autohold_torque);
 		gFoc_Ctrl.pi_lock.max = hold_torque;
 		gFoc_Ctrl.pi_lock.max = hold_torque;
 		gFoc_Ctrl.pi_lock.min = -hold_torque;
 		gFoc_Ctrl.pi_lock.min = -hold_torque;
 		float vel_count = motor_encoder_get_vel_count();
 		float vel_count = motor_encoder_get_vel_count();

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

@@ -30,8 +30,8 @@ void ladrc_observer_init(float Wo, float vel_min, float lpf_cut_off) {
 	observer.lq = mc_conf()->m.lq;
 	observer.lq = mc_conf()->m.lq;
 	observer.r = mc_conf()->m.rs;
 	observer.r = mc_conf()->m.rs;
 	observer.poles = mc_conf()->m.poles;
 	observer.poles = mc_conf()->m.poles;
-	observer.max_eVel = CONFIG_MAX_MOT_RPM/30.0f * M_PI * mc_conf()->m.poles;
-	observer.max_z1 = CONFIG_MAX_PHASE_CURR * 10.0f;
+	observer.max_eVel = CONFIG_HW_MAX_MOTOR_RPM/30.0f * M_PI * mc_conf()->m.poles;
+	observer.max_z1 = CONFIG_HW_MAX_PHASE_CURR * 10.0f;
 	observer.max_z2 = CONFIG_MAX_ACTIVE_EMF / observer.ld;
 	observer.max_z2 = CONFIG_MAX_ACTIVE_EMF / observer.ld;
 	observer.Vel_El = 0;
 	observer.Vel_El = 0;
 	observer.Vel_El_filter = 0;
 	observer.Vel_El_filter = 0;

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

@@ -16,7 +16,7 @@ void smo_observer_init(float pll_bandwith, float lpf_wc, float Ksmo, float Ksta)
 	smo.bandwith = pll_bandwith;
 	smo.bandwith = pll_bandwith;
 	smo.pll_kp = pll_bandwith * 2;
 	smo.pll_kp = pll_bandwith * 2;
 	smo.pll_ki = SQ(pll_bandwith);
 	smo.pll_ki = SQ(pll_bandwith);
-	smo.pll_max_rad_pers = CONFIG_MAX_MOT_RPM/30.0f * M_PI * mc_conf()->m.poles;
+	smo.pll_max_rad_pers = CONFIG_HW_MAX_MOTOR_RPM/30.0f * M_PI * mc_conf()->m.poles;
 	smo.lpf_wc = lpf_wc;
 	smo.lpf_wc = lpf_wc;
 	smo.lpf_ceof = (lpf_wc*smo.ts);
 	smo.lpf_ceof = (lpf_wc*smo.ts);
 	smo.Ksmo = Ksmo;
 	smo.Ksmo = Ksmo;
@@ -116,8 +116,8 @@ static void smo_arctan(void) {
 	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_atan_2(smo.est_rad_pers_filted, smo.lpf_wc) + smo.est_rad_pers_filted * smo.ts;
 	angle_clamp(smo.est_angle_out);
 	angle_clamp(smo.est_angle_out);
 	smo.est_rpm = (30.0f * smo.est_rad_pers_filted/M_PI/smo.motor_poles);
 	smo.est_rpm = (30.0f * smo.est_rad_pers_filted/M_PI/smo.motor_poles);
-	if (smo.est_rpm > CONFIG_MAX_MOT_RPM) {
-		smo.est_rpm = CONFIG_MAX_MOT_RPM;
+	if (smo.est_rpm > CONFIG_HW_MAX_MOTOR_RPM) {
+		smo.est_rpm = CONFIG_HW_MAX_MOTOR_RPM;
 	}else if (smo.est_rpm < 0) {
 	}else if (smo.est_rpm < 0) {
 		smo.est_rpm = 0;
 		smo.est_rpm = 0;
 	}
 	}
@@ -142,8 +142,8 @@ static void smo_pll(void) {
 	smo.est_rad_pers_filted = do_lpf(smo.est_rad_pers_filted, smo.est_rad_pers, smo.lpf_ceof); //对速度低通滤波
 	smo.est_rad_pers_filted = do_lpf(smo.est_rad_pers_filted, smo.est_rad_pers, smo.lpf_ceof); //对速度低通滤波
 	angle_clamp(smo.est_angle);
 	angle_clamp(smo.est_angle);
 	smo.est_rpm = (30.0f * smo.est_rad_pers_filted/M_PI/smo.motor_poles);
 	smo.est_rpm = (30.0f * smo.est_rad_pers_filted/M_PI/smo.motor_poles);
-	if (smo.est_rpm > CONFIG_MAX_MOT_RPM) {
-		smo.est_rpm = CONFIG_MAX_MOT_RPM;
+	if (smo.est_rpm > CONFIG_HW_MAX_MOTOR_RPM) {
+		smo.est_rpm = CONFIG_HW_MAX_MOTOR_RPM;
 	}else if (smo.est_rpm < 0) {
 	}else if (smo.est_rpm < 0) {
 		smo.est_rpm = 0;
 		smo.est_rpm = 0;
 	}
 	}

+ 6 - 6
Applications/foc/foc_config.h

@@ -22,28 +22,28 @@
 /* 电子刹车,动能回收,加速 */
 /* 电子刹车,动能回收,加速 */
 #define CONFIG_eCTRL_STEP_TS CONFIG_SPD_CTRL_MS     /* 斜率给定的step的时间值,单位 ms */
 #define CONFIG_eCTRL_STEP_TS CONFIG_SPD_CTRL_MS     /* 斜率给定的step的时间值,单位 ms */
 #define CONFIG_eCTRL_Brake_TIME 1500     /* 捏住刹车的时间,超过这个时间启动ebrake,单位 ms */
 #define CONFIG_eCTRL_Brake_TIME 1500     /* 捏住刹车的时间,超过这个时间启动ebrake,单位 ms */
-#define CONFIG_EBRK_RAMP_TIME 50
 #define CONFIG_AUTOHOLD_DETECT_TIME 2000
 #define CONFIG_AUTOHOLD_DETECT_TIME 2000
 
 
-#define CONFIG_CRUISE_RAMP_TIME 4000
+#define CONFIG_CRUISE_RAMP_TIME 4000 /* 定速巡航的时候给定加减速的斜波时间 */
 
 
-#define CONFIG_LIMIT_RAMP_TIME (6 * 1000)
+#define CONFIG_LIMIT_RAMP_TIME (6 * 1000) /* 过温、欠压保护的给定限流和限速的斜波时间 */
 
 
 #define CONFIG_SENSORLESS_RAMP_TIME (20 * 1000)
 #define CONFIG_SENSORLESS_RAMP_TIME (20 * 1000)
 
 
 #define CONFIG_MTPA_CALI_RAMP_TIME (10 * 1000)
 #define CONFIG_MTPA_CALI_RAMP_TIME (10 * 1000)
 
 
+/* 防止打齿,0扭矩上下的时候需要缓给定参数 */
 #define CONFIG_RAMP_SECOND_STEP (0.1F)
 #define CONFIG_RAMP_SECOND_STEP (0.1F)
-
 #define CONFIG_RAMP_FIRST_TARGET (1.0F)
 #define CONFIG_RAMP_FIRST_TARGET (1.0F)
 #define CONFIG_RAMP_SECOND_TARGET (5.0F * 1.5F)
 #define CONFIG_RAMP_SECOND_TARGET (5.0F * 1.5F)
-
 #define CONFIG_RAMP_CROSS_ZERO_STEP (0.1F)
 #define CONFIG_RAMP_CROSS_ZERO_STEP (0.1F)
 
 
-#define CURRENT_LOOP_RAMP_COUNT 15 //1ms 完成ramp给定
+/* dq轴电流环指令斜波 */
+#define CURRENT_LOOP_RAMP_COUNT 15 //15个控制周期 完成ramp给定
 
 
 #define CONFIG_CRUISE_ENABLE_ACCL 1 //定速巡航可以加速,油门回退,继续定速巡航
 #define CONFIG_CRUISE_ENABLE_ACCL 1 //定速巡航可以加速,油门回退,继续定速巡航
 
 
+/* 限速/速度环等情况下的最大负扭矩,一般给0,不产生拖拽感 */
 #define CONFIG_MAX_NEG_TORQUE 0.0F
 #define CONFIG_MAX_NEG_TORQUE 0.0F
 
 
 #define CONFIG_ENABLE_IAB_REC 1   // for phase current debug
 #define CONFIG_ENABLE_IAB_REC 1   // for phase current debug

+ 10 - 5
Applications/foc/mc_config.c

@@ -182,11 +182,11 @@ void mc_conf_default(void) {
 	conf.m.nor_pll_band = CONFIG_Motor_PLLBand;
 	conf.m.nor_pll_band = CONFIG_Motor_PLLBand;
 	conf.m.epm_pll_band = CONFIG_Motor_EpmPLL;
 	conf.m.epm_pll_band = CONFIG_Motor_EpmPLL;
 	conf.m.pos_pll_band = CONFIG_Motor_PosPLL;
 	conf.m.pos_pll_band = CONFIG_Motor_PosPLL;
-	conf.m.velocity_w = CONFIG_Motor_VelocityW;
-	conf.m.wheel_c = CONFIG_Motor_VelocityC;
+	conf.m.vehicle_w = CONFIG_Motor_VehicleW;
+	conf.m.wheel_c = CONFIG_Motor_WheelC;
 	conf.m.gear_ratio = CONFIG_Motor_GearRatio;
 	conf.m.gear_ratio = CONFIG_Motor_GearRatio;
 	conf.m.max_fw_id = CONFIG_Motor_MaxFwDCurr;
 	conf.m.max_fw_id = CONFIG_Motor_MaxFwDCurr;
-
+	conf.m.max_torque = CONFIG_Motor_MaxTorque;
 	conf.c.max_dc_vol = CONFIG_Foc_MaxDCVol;
 	conf.c.max_dc_vol = CONFIG_Foc_MaxDCVol;
 	conf.c.min_dc_vol = CONFIG_Foc_MinDCVol;
 	conf.c.min_dc_vol = CONFIG_Foc_MinDCVol;
 	conf.c.max_phase_curr = CONFIG_Foc_MaxPhaseCurr;
 	conf.c.max_phase_curr = CONFIG_Foc_MaxPhaseCurr;
@@ -204,6 +204,7 @@ void mc_conf_default(void) {
 	conf.c.thro_max_vol = CONFIG_Foc_ThroMaxVol;
 	conf.c.thro_max_vol = CONFIG_Foc_ThroMaxVol;
 	conf.c.thro_min_vol = CONFIG_Foc_ThroMinVol;
 	conf.c.thro_min_vol = CONFIG_Foc_ThroMinVol;
 	conf.c.thro_dec_time = CONFIG_Foc_ThroDecTime;
 	conf.c.thro_dec_time = CONFIG_Foc_ThroDecTime;
+	conf.c.max_autohold_torque = CONFIG_Foc_MaxAutoHoldTorque;
 
 
 	conf.c.pid[PID_IQ_ID].kp = (float)conf.c.dq_loop_bandwith * 2.0f * 3.14f * conf.m.ld;
 	conf.c.pid[PID_IQ_ID].kp = (float)conf.c.dq_loop_bandwith * 2.0f * 3.14f * conf.m.ld;
 	conf.c.pid[PID_IQ_ID].ki = conf.m.rs / conf.m.ld;
 	conf.c.pid[PID_IQ_ID].ki = conf.m.rs / conf.m.ld;
@@ -283,10 +284,11 @@ int mc_conf_decode_motor(u8 *buff) {
 	conf.m.nor_pll_band = (float)decode_u16(buff); buff += 2;
 	conf.m.nor_pll_band = (float)decode_u16(buff); buff += 2;
 	conf.m.epm_pll_band = (float)decode_u16(buff); buff += 2;
 	conf.m.epm_pll_band = (float)decode_u16(buff); buff += 2;
 	conf.m.pos_pll_band = (float)decode_u16(buff); buff += 2;
 	conf.m.pos_pll_band = (float)decode_u16(buff); buff += 2;
-	conf.m.velocity_w = decode_u16(buff);buff += 2;
+	conf.m.vehicle_w = decode_u16(buff);buff += 2;
 	conf.m.wheel_c = decode_u16(buff);buff += 2;
 	conf.m.wheel_c = decode_u16(buff);buff += 2;
 	conf.m.gear_ratio = decode_float(buff);buff += 4;
 	conf.m.gear_ratio = decode_float(buff);buff += 4;
 	conf.m.max_fw_id = decode_u16(buff); buff += 2;
 	conf.m.max_fw_id = decode_u16(buff); buff += 2;
+	conf.m.max_torque = decode_u16(buff); buff += 2;
 	return buff - ori;
 	return buff - ori;
 }
 }
 
 
@@ -300,10 +302,11 @@ int mc_conf_encode_motor(u8 *buff) {
 	encode_u16(buff, (u16)conf.m.nor_pll_band); buff += 2;
 	encode_u16(buff, (u16)conf.m.nor_pll_band); buff += 2;
 	encode_u16(buff, (u16)conf.m.epm_pll_band); buff += 2;
 	encode_u16(buff, (u16)conf.m.epm_pll_band); buff += 2;
 	encode_u16(buff, (u16)conf.m.pos_pll_band); buff += 2;
 	encode_u16(buff, (u16)conf.m.pos_pll_band); buff += 2;
-	encode_u16(buff, conf.m.velocity_w);buff += 2;
+	encode_u16(buff, conf.m.vehicle_w);buff += 2;
 	encode_u16(buff, conf.m.wheel_c);buff += 2;
 	encode_u16(buff, conf.m.wheel_c);buff += 2;
 	encode_float(buff, conf.m.gear_ratio);buff += 4;
 	encode_float(buff, conf.m.gear_ratio);buff += 4;
 	encode_u16(buff, conf.m.max_fw_id); buff += 2;
 	encode_u16(buff, conf.m.max_fw_id); buff += 2;
+	encode_u16(buff, conf.m.max_torque); buff += 2;
 	return buff - ori;
 	return buff - ori;
 }
 }
 
 
@@ -337,6 +340,7 @@ int mc_conf_decode_controler(u8 *buff) {
 	conf.c.max_epm_back_torque = decode_s16(buff);buff += 2;
 	conf.c.max_epm_back_torque = decode_s16(buff);buff += 2;
 	conf.c.max_ebrk_torque = decode_s16(buff);buff += 2;
 	conf.c.max_ebrk_torque = decode_s16(buff);buff += 2;
 	conf.c.max_idc = decode_s16(buff);buff += 2;
 	conf.c.max_idc = decode_s16(buff);buff += 2;
+	conf.c.max_autohold_torque = decode_s16(buff);buff += 2;
 	conf.c.dq_loop_bandwith = decode_s16(buff);buff += 2;
 	conf.c.dq_loop_bandwith = decode_s16(buff);buff += 2;
 	conf.c.thro_start_vol = decode_float(buff);buff += 4;
 	conf.c.thro_start_vol = decode_float(buff);buff += 4;
 	conf.c.thro_end_vol = decode_float(buff);buff += 4;
 	conf.c.thro_end_vol = decode_float(buff);buff += 4;
@@ -363,6 +367,7 @@ int mc_conf_encode_controler(u8 *buff) {
 	encode_s16(buff, conf.c.max_epm_back_torque);buff += 2;
 	encode_s16(buff, conf.c.max_epm_back_torque);buff += 2;
 	encode_s16(buff, conf.c.max_ebrk_torque);buff += 2;
 	encode_s16(buff, conf.c.max_ebrk_torque);buff += 2;
 	encode_s16(buff, conf.c.max_idc);buff += 2;
 	encode_s16(buff, conf.c.max_idc);buff += 2;
+	encode_s16(buff, conf.c.max_autohold_torque);buff += 2;
 	encode_s16(buff, conf.c.dq_loop_bandwith);buff += 2;
 	encode_s16(buff, conf.c.dq_loop_bandwith);buff += 2;
 	encode_float(buff, conf.c.thro_start_vol);buff += 4;
 	encode_float(buff, conf.c.thro_start_vol);buff += 4;
 	encode_float(buff, conf.c.thro_end_vol);buff += 4;
 	encode_float(buff, conf.c.thro_end_vol);buff += 4;

+ 3 - 1
Applications/foc/mc_config.h

@@ -29,10 +29,11 @@ typedef struct
 	float nor_pll_band;
 	float nor_pll_band;
 	float epm_pll_band;
 	float epm_pll_band;
 	float pos_pll_band;
 	float pos_pll_band;
-	int velocity_w;
+	int vehicle_w;
 	int wheel_c;
 	int wheel_c;
 	float gear_ratio;
 	float gear_ratio;
 	u16	max_fw_id;
 	u16	max_fw_id;
+	u16 max_torque;
 }motor_t;
 }motor_t;
 
 
 typedef struct {
 typedef struct {
@@ -53,6 +54,7 @@ typedef struct {
 	s16 max_epm_back_torque;
 	s16 max_epm_back_torque;
 	s16 max_ebrk_torque;
 	s16 max_ebrk_torque;
 	s16 max_idc;
 	s16 max_idc;
+	s16 max_autohold_torque;
 	s16 dq_loop_bandwith;
 	s16 dq_loop_bandwith;
 	float thro_start_vol;
 	float thro_start_vol;
 	float thro_end_vol;
 	float thro_end_vol;

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

@@ -1470,7 +1470,7 @@ void Sched_MC_mTask(void) {
 	/* 母线电流,实际采集的相电流矢量大小的计算 */
 	/* 母线电流,实际采集的相电流矢量大小的计算 */
 	PMSM_FOC_Calc_Current();
 	PMSM_FOC_Calc_Current();
 
 
-	if ((PMSM_FOC_GetVbusCurrent() > (CONFIG_MAX_VBUS_CURRENT * 1.1f)) || (PMSM_FOC_GetVbusCurrent() < CONFIG_MAX_CHRG_CURRENT)) {
+	if ((PMSM_FOC_GetVbusCurrent() > (CONFIG_HW_MAX_DC_CURRENT * 1.1f)) || (PMSM_FOC_GetVbusCurrent() < CONFIG_MAX_CHRG_CURRENT)) {
 		vbus_err_cnt ++;
 		vbus_err_cnt ++;
 		if (vbus_err_cnt >= 5) {
 		if (vbus_err_cnt >= 5) {
 			if (mc_set_critical_error(FOC_CRIT_IDC_OV)) {
 			if (mc_set_critical_error(FOC_CRIT_IDC_OV)) {

+ 2 - 1
Applications/foc/motor/motor_param.c

@@ -2,6 +2,7 @@
 #include "foc/motor/motor_param.h"
 #include "foc/motor/motor_param.h"
 #include "foc/core/PMSM_FOC_Core.h"
 #include "foc/core/PMSM_FOC_Core.h"
 #include "math/fast_math.h"
 #include "math/fast_math.h"
+#include "foc/mc_config.h"
 #include "libs/logger.h"
 #include "libs/logger.h"
 
 
 #if CONFIG_MOT_TYPE==MOTOR_BLUESHARK_A1
 #if CONFIG_MOT_TYPE==MOTOR_BLUESHARK_A1
@@ -42,7 +43,7 @@ s16 motor_max_torque_for_rpm(s16 rpm) {
 	}
 	}
 	return mot_map[map_size-1].torque;
 	return mot_map[map_size-1].torque;
 #else
 #else
-	return CONFIG_MAX_MOTOR_TORQUE;
+	return mc_conf()->m.max_torque;
 #endif
 #endif
 }
 }
 
 

+ 1 - 4
Applications/foc/motor/motor_param.h

@@ -104,7 +104,7 @@ float motor_get_ebreak_toruqe(float rpm);
 #define MOTOR_POLES  5
 #define MOTOR_POLES  5
 #define MOTOR_Flux (0.019f)
 #define MOTOR_Flux (0.019f)
 #define MOTOR_ENC_OFFSET 0.0F
 #define MOTOR_ENC_OFFSET 0.0F
-#define CONFIG_MAX_MOTOR_TORQUE 200.0F
+
 
 
 #define PI_VEL_LIM_KP 0.085F //0.13f
 #define PI_VEL_LIM_KP 0.085F //0.13f
 #define PI_VEL_LIM_KI 2.5F
 #define PI_VEL_LIM_KI 2.5F
@@ -116,9 +116,6 @@ float motor_get_ebreak_toruqe(float rpm);
 
 
 #define MOTOR_NR 0x13
 #define MOTOR_NR 0x13
 
 
-#define CONFIG_CURRENT_BANDWITH  (200 * 2 * PI) /* 电流环带宽 */
-#define CONFIG_DEFAULT_PHASE_CURR_LIM 200
-#define CONFIG_MAX_FW_D_CURR     100.0F //d轴最大的退磁电流
 #define CONFIG_CURRENT_LOOP_DECOUPE    //电流环解耦
 #define CONFIG_CURRENT_LOOP_DECOUPE    //电流环解耦
 #define CONFIG_SENSORLESS_MAX_IDC 30
 #define CONFIG_SENSORLESS_MAX_IDC 30
 #define CONFIG_SENSORLESS_MAX_TORQUE 80
 #define CONFIG_SENSORLESS_MAX_TORQUE 80

+ 4 - 2
mc_config.yml

@@ -10,10 +10,11 @@ Motor:
   PLLBand: 200
   PLLBand: 200
   EpmPLL: 400
   EpmPLL: 400
   PosPLL: 500
   PosPLL: 500
-  VelocityW: 190  #kg
-  VelocityC: 145  #cm
+  VehicleW: 190  #kg
+  WheelC: 145  #cm
   GearRatio: 6.25 # 1:6.25
   GearRatio: 6.25 # 1:6.25
   MaxFwDCurr: 100
   MaxFwDCurr: 100
+  MaxTorque: 200 #根据控制方式不同,可能是相电流,可能是真实扭矩
 Foc:
 Foc:
   MaxDCVol: 110
   MaxDCVol: 110
   MinDCVol: 70
   MinDCVol: 70
@@ -26,6 +27,7 @@ Foc:
   MaxTorque: 300
   MaxTorque: 300
   MaxEbrkTorque: 40
   MaxEbrkTorque: 40
   MaxIDC: 100
   MaxIDC: 100
+  MaxAutoHoldTorque: 100
   ThroStartVol: 0.85
   ThroStartVol: 0.85
   ThroEndVol: 4.15
   ThroEndVol: 4.15
   ThroMinVol: 0.4
   ThroMinVol: 0.4