فهرست منبع

dq轴电流分配查表,如果表不存在,使用id=0的控制策略

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 سال پیش
والد
کامیت
f3ea0ae12e

+ 13 - 0
Applications/app/nv_storage.c

@@ -164,6 +164,19 @@ void nv_set_ebrake_current(float phase_curr, float dc_curr) {
 	foc_params.s_iDCeBrkLim = dc_curr;
 }
 
+torque_lut_t *nv_get_trq_tlb(void) {
+	torque_lut_t *tbl = (torque_lut_t *)fmc_get_addr(trq_Tbl_idx);
+	if (tbl->magic != 0x5AA5) {
+		return NULL;
+	}
+	u16 crc = crc16_get((u8 *)tbl, sizeof(torque_lut_t) - 2);
+	if (crc != tbl->crc16) {
+		return NULL;
+	}
+	return tbl;
+}
+
+
 void nv_storage_init(void) {
 	nv_read_motor_params();
 	nv_read_foc_params();

+ 7 - 1
Applications/app/nv_storage.h

@@ -42,10 +42,12 @@ typedef struct {
 
 #define MAX_TRQ_POINTS 60
 #define MAX_SPD_POINTS 100
-
+#define TBL_TRQ_INTVAL 1
+#define TBL_SPD_INTVAL 100
 typedef struct {
 	s16  d[MAX_TRQ_POINTS][MAX_SPD_POINTS];
 	s16  q[MAX_TRQ_POINTS][MAX_SPD_POINTS];
+	u16  magic;
 	u16  crc16;
 }torque_lut_t;
 
@@ -56,6 +58,9 @@ typedef struct {
 #define focParam_idx_0 (motorParam_idx_0 + 2)
 #define focParam_idx_1 (motorParam_idx_0 + 3)
 
+#define trq_Tbl_idx (focParam_idx_1 + 1)
+#define trq_Tbl_size (30)
+
 void nv_storage_init(void);
 motor_params_t *nv_get_motor_params(void);
 foc_params_t *nv_get_foc_params(void);
@@ -70,6 +75,7 @@ void nv_get_pid(u8 id, pid_conf_t *pid);
 void nv_set_hwbrake_mode(u8 mode);
 void nv_set_throttle_vol(float min, float max);
 void nv_set_ebrake_current(float phase_curr, float dc_curr);
+torque_lut_t *nv_get_trq_tlb(void);
 
 #endif /* _NV_Storage_H__ */
 

+ 1 - 1
Applications/bsp/board_mc_v1.h

@@ -26,7 +26,7 @@
 #define CONFIG_UNDER_VOL_DC_CURR 15.0F
 #define CONFIG_MAX_FW_D_CURR     100.0F //d轴最大的退磁电流
 
-#define CONFIG_CURR_LP_CUT_FREQ (2000.0F)
+#define CONFIG_CURR_LP_CUT_FREQ (3000.0F)
 
 #define CONFIG_CURR_LP_PARAM (CONFIG_CURR_LP_CUT_FREQ*2*3.14F/(float)FOC_PWM_FS)
 

+ 5 - 0
Applications/bsp/fmc_flash.c

@@ -107,6 +107,11 @@ static void _fmc_read_data(uint32_t addr, uint8_t *data, int len){
 	}
 }
 
+uint32_t fmc_get_addr(int page) {
+	return 0x08000000 + (_flash_capatity() - one_page_size * page);
+}
+
+
 static void _fmc_write_data(uint32_t addr, uint8_t *data, int len){
 	fmc_unlock();
 	fmc_flag_clear(FMC_FLAG_PGERR | FMC_FLAG_WPERR | FMC_FLAG_END);

+ 1 - 0
Applications/bsp/fmc_flash.h

@@ -9,6 +9,7 @@ void fmc_write_data(int index, uint8_t *data, int len);
 void fmc_read_data(int index, uint8_t *data, int len);
 void fmc_write_magic(uint32_t magic);
 uint32_t fmc_read_magic(void);
+uint32_t fmc_get_addr(int page);
 
 #endif /* _FMC_FLASH_H__ */
 

+ 32 - 4
Applications/foc/core/torque.c

@@ -3,17 +3,45 @@
 #include "foc/motor/motor.h"
 #include "foc/core/e_ctrl.h"
 #include "foc/core/PMSM_FOC_Core.h"
-
+#include "app/nv_storage.h"
 /*
 通过查表获取对应扭矩和速度时的Id和IQ的分配
 */
-void torque_init(void) {
+static torque_lut_t *_trq_tbl = NULL;
 
+void torque_init(void) {
+	_trq_tbl = nv_get_trq_tlb();
 }
 
 void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
-	dq_out->d = 0;
-	dq_out->q = torque;
+	if ((_trq_tbl == NULL) || (torque < 0 || rpm < 0)) {
+		dq_out->d = 0;
+		dq_out->q = torque;
+		return;
+	}
+	int trq_idx = (int)torque / TBL_TRQ_INTVAL;
+	int rpm_idx = (int)rpm / TBL_SPD_INTVAL;
+	if (trq_idx >= MAX_TRQ_POINTS) {
+		trq_idx = MAX_TRQ_POINTS -1;
+	}
+	if (rpm_idx >= MAX_SPD_POINTS) {
+		rpm_idx = MAX_SPD_POINTS -1;
+	}
+	s16 d = _trq_tbl->d[trq_idx][rpm_idx];
+	s16 q = _trq_tbl->q[trq_idx][rpm_idx];
+	if (trq_idx < MAX_TRQ_POINTS - 1) {
+		trq_idx += 1;
+	}
+	if (rpm_idx < MAX_SPD_POINTS - 1) {
+		rpm_idx += 1;
+	}
+	s16 d_delta = _trq_tbl->d[trq_idx][rpm_idx] - d;
+	s16 q_delta = _trq_tbl->q[trq_idx][rpm_idx] - q;
+	float comp_ceof = 0.5f * ((torque - torque/TBL_TRQ_INTVAL*TBL_TRQ_INTVAL)/(float)TBL_TRQ_INTVAL + (rpm - rpm/TBL_SPD_INTVAL*TBL_SPD_INTVAL)/(float)TBL_SPD_INTVAL);
+
+	dq_out->d = d + d_delta * comp_ceof;
+	dq_out->q = q + q_delta * comp_ceof;
+
 }
 
 float speed_target_from_throttle(float f_throttle) {

+ 1 - 1
Applications/foc/foc_config.h

@@ -3,7 +3,7 @@
 
 #define CONFIG_DEFAULT_IDC_LIM 100
 #define CONFIG_DEFAULT_PHASE_CURR_LIM 300
-#define CONFIG_DEFAULT_RPM_LIM       3000
+#define CONFIG_DEFAULT_RPM_LIM       8000
 
 #define CONFIG_DEFAULT_EPM_PHASE_CURR 50
 #define CONFIG_DEFAULT_EPM_RPM        200

+ 4 - 4
Applications/foc/limit.c

@@ -3,10 +3,10 @@
 #include "foc/samples.h"
 
 static limter_t motor_temp_lim[] = {//电机过温限流,限制相电流
-	{.enter_pointer = 110, .exit_pointer = 100, .limit_value = 0},
-	{.enter_pointer = 100, .exit_pointer = 90, .limit_value = 40},
-	{.enter_pointer = 90, .exit_pointer = 80, .limit_value = 80},
-	{.enter_pointer = 80, .exit_pointer = 70, .limit_value = 100},
+	{.enter_pointer = 130, .exit_pointer = 120, .limit_value = 0},
+	{.enter_pointer = 120, .exit_pointer = 110, .limit_value = 90},
+	{.enter_pointer = 110, .exit_pointer = 100, .limit_value = 120},
+	{.enter_pointer = 100, .exit_pointer = 90, .limit_value = 130},
 }; 
 static limter_t mos_temp_lim[] = { //mos过温限流,限制相电流
 	{.enter_pointer = 120, .exit_pointer = 110, .limit_value = 0},

+ 3 - 0
Applications/foc/motor/motor.c

@@ -18,6 +18,7 @@
 #include "foc/motor/motor_param.h"
 #include "foc/core/torque.h"
 #include "app/nv_storage.h"
+#include "foc/core/torque.h"
 
 static bool mc_is_hwbrake(void);
 static void _pwm_brake_timer_handler(shark_timer_t *);
@@ -77,6 +78,7 @@ void mc_init(void) {
 	samples_init();
 	motor_encoder_init();
 	foc_command_init();
+	torque_init();
 	PMSM_FOC_CoreInit();
 	mc_gpio_init();
 	MC_Check_MosVbusThrottle();
@@ -512,6 +514,7 @@ static bool mc_run_stall_process(u8 run_mode) {
 			if (!mc_throttle_released()) {
 				return true;
 			}
+			motor.runStall_time = 0;
 			motor.b_runStall = false; //转把释放,清除堵转标志
 		}else if ((ABS(PMSM_FOC_GetSpeed()) < 1.0f) && (PMSM_FOC_Get()->out.s_RealIdq.q >= CONFIG_STALL_MAX_CURRENT)){
 			if (motor.runStall_time == 0) {