瀏覽代碼

扭矩表的电压个数,通过vol_n表示,最大5个最小1个

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin 2 年之前
父節點
當前提交
f031d6c296
共有 1 個文件被更改,包括 13 次插入8 次删除
  1. 13 8
      Applications/foc/motor/motor_param.c

+ 13 - 8
Applications/foc/motor/motor_param.c

@@ -98,18 +98,23 @@ int motor_map_torque_max_count(void) {
 #ifdef MOT_HAVE_MAPS
 
 vol_rpm_torque_map vol_rpm_curr_map[CONFIG_MAX_VOL_COUNT];
-
+u8 vol_n = CONFIG_MAX_VOL_COUNT;
 static void motor_vol_lookup(s16 vol, vol_rpm_torque_map *table, vol_rpm_torque_map **out_mapl, vol_rpm_torque_map **out_maph) {
+	if (vol_n == 1) {
+		*out_mapl = table;
+        *out_maph = table;
+		return;
+	}
 	if (vol <= table[0].vol) {
 		*out_mapl = table;
         *out_maph = table + 1;
 		return;
-	}else if (vol >= table[CONFIG_MAX_VOL_COUNT-1].vol){
-		*out_mapl = table + CONFIG_MAX_VOL_COUNT - 2;
-        *out_maph = table + CONFIG_MAX_VOL_COUNT - 1;
+	}else if (vol >= table[vol_n - 1].vol){
+		*out_mapl = table + vol_n - 2;
+        *out_maph = table + vol_n - 1;
 		return;
 	}
-	for (int i = 1; i < CONFIG_MAX_VOL_COUNT; i++) {
+	for (int i = 1; i < vol_n; i++) {
 		if ((vol <= table[i].vol)) {
 			*out_mapl = table + i - 1;
 			*out_maph = table + i;
@@ -220,14 +225,14 @@ 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[rmapl->n - 1].torque;
-	s16 max_t2 = rmaph->dqmap[rmaph->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[rmapl->n-1].torque;
-	max_t2 = rmaph->dqmap[rmaph->n-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);
 
 	/* 对两个电压的扭矩插值,获取最终的最大扭矩 */