Browse Source

电压转速,转速扭矩表中记录真实的map点个数

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin 2 years ago
parent
commit
d89f1ae2c6

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

@@ -415,7 +415,7 @@
 #endif
 
 #define DEBUG_PORT_UART2
-#define CONFIG_MOTOR_TORQUE_CONF "foc/motor/A1_motor_config.c"
+//#define CONFIG_MOTOR_TORQUE_CONF "foc/motor/A1_motor_config.c"
 
 //#define CONFIG_DQ_STEP_RESPONSE
 

+ 11 - 11
Applications/foc/motor/motor_param.c

@@ -124,11 +124,11 @@ static void motor_rpm_lookup(s16 rpm, vol_rpm_torque_map *map, rpm_torque_map **
 		*out_map1 = table;
         *out_maph = table + 1;
 		return;
-	}else if (rpm >= table[CONFIG_MAX_VEL_COUNT-1].rpm) {
-		*out_map1 = *out_maph = table + CONFIG_MAX_VEL_COUNT - 1;
+	}else if (rpm >= table[map->n - 1].rpm) {
+		*out_map1 = *out_maph = table + map->n - 1;
 		return;
 	}
-	for (int i = 1; i < CONFIG_MAX_VEL_COUNT; i++) {
+	for (int i = 1; i < map->n; i++) {
 		if (rpm <= table[i].rpm) {
 			*out_map1 = table + i - 1;
 			*out_maph = table + i;
@@ -142,11 +142,11 @@ static void motor_current_lookup(s16 torque, rpm_torque_map *map,  torque2dq_t**
 	if (torque <= table[0].torque) {
 		*currl = table;
         *currh = table + 1;
-	}else if (torque >= table[CONFIG_MAX_D_COUNT - 1].torque) {
-		*currl = table + CONFIG_MAX_D_COUNT - 2;
-        *currh = table + CONFIG_MAX_D_COUNT - 1;
+	}else if (torque >= table[map->n - 1].torque) {
+		*currl = table + map->n - 2;
+        *currh = table + map->n - 1;
 	}
-	for (int i = 1; i < CONFIG_MAX_D_COUNT; i++) {
+	for (int i = 1; i < map->n; i++) {
 		if (torque <= table[i].torque) {
 			*currl = table + i - 1;
 			*currh = table + i;
@@ -219,15 +219,15 @@ s16 motor_torque_ext_char_curve(s16 rpm, s16 vdc) {
 	/* 获取低电压对应当前转速的最大扭矩 */
 	motor_rpm_lookup(vel, vmapl, &rmapl, &rmaph);
     _DEBUG("vol %d -> rpm %d : %d\n", vmapl->vol, rmapl->rpm, rmaph->rpm);
-	s16 max_t1 = rmapl->dqmap[CONFIG_MAX_D_COUNT-1].torque;
-	s16 max_t2 = rmaph->dqmap[CONFIG_MAX_D_COUNT-1].torque;
+	s16 max_t1 = rmapl->dqmap[rmapl->n - 1].torque;
+	s16 max_t2 = rmaph->dqmap[rmaph->n-1].torque;
 	s16 low_vel_max_t = line_intp(vel, rmapl->rpm, rmaph->rpm, max_t1, max_t2);
 
 	/* 获取高电压对应当前转速的最大扭矩 */
 	motor_rpm_lookup(vel, vmaph, &rmapl, &rmaph);
     _DEBUG("vol %d -> rpm %d : %d\n", vmaph->vol, rmapl->rpm, rmaph->rpm);
-	max_t1 = rmapl->dqmap[CONFIG_MAX_D_COUNT-1].torque;
-	max_t2 = rmaph->dqmap[CONFIG_MAX_D_COUNT-1].torque;
+	max_t1 = rmapl->dqmap[rmapl->n-1].torque;
+	max_t2 = rmaph->dqmap[rmaph->n-1].torque;
 	s16 high_vel_max_t = line_intp(vel, rmaph->rpm, rmaph->rpm, max_t1, max_t2);
 
 	/* 对两个电压的扭矩插值,获取最终的最大扭矩 */

+ 2 - 0
Applications/foc/motor/motor_param.h

@@ -33,12 +33,14 @@ typedef struct {
 /* 转速对应的d轴电流 */
 typedef struct {
 	s16 rpm;
+	u8  n;
 	torque2dq_t dqmap[CONFIG_MAX_D_COUNT];
 }rpm_torque_map;
 
 /* 电压、转速对应的d轴电流 */
 typedef struct {
 	s16 vol;
+	u8  n;
 	rpm_torque_map rpm_torque[CONFIG_MAX_VEL_COUNT];
 }vol_rpm_torque_map;