Просмотр исходного кода

用户设置的runtime限流,保存到motor结构体,挡位切换的母线电流不能超过用户的runtime设置

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 лет назад
Родитель
Сommit
62c5d5be49
2 измененных файлов с 9 добавлено и 1 удалено
  1. 6 1
      Applications/foc/motor/motor.c
  2. 3 0
      Applications/foc/motor/motor.h

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

@@ -43,6 +43,7 @@ static motor_t motor = {
 	.mode = CTRL_MODE_OPEN,
 	.mos_lim = 0,
 	.motor_lim = 0,
+	.idc_user_lim = IDC_USER_LIMIT_NONE,
 };
 static motor_err_t mc_error;
 
@@ -174,7 +175,7 @@ static void mc_gear_vmode_changed(void) {
 	
 	//sys_debug("limit %d-%d-%d, mode = %s\n", gears->n_max_speed, gears->n_max_idc, gears->n_max_trq, motor.b_is96Mode?"96V":"48V");
 	PMSM_FOC_SpeedLimit(gears->n_max_speed);
-	PMSM_FOC_DCCurrLimit(gears->n_max_idc);
+	PMSM_FOC_DCCurrLimit(min(gears->n_max_idc, motor.idc_user_lim));
 	PMSM_FOC_TorqueLimit(gears->n_max_trq);
 	eCtrl_set_accl_time((u16)gears->n_accl_time);
 }
@@ -411,6 +412,10 @@ bool mc_set_cruise_speed(bool rpm_abs, float target_rpm) {
 
 void mc_set_idc_limit(s16 limit) {
 	s16 g_limit = mc_get_gear_idc_limit();
+	if (g_limit == motor.idc_user_lim) {
+		return;
+	}
+	motor.idc_user_lim = g_limit;
 	limit = min(g_limit, limit);
 	PMSM_FOC_DCCurrLimit(limit);
 }

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

@@ -6,6 +6,8 @@
 #include "foc/motor/encoder.h"
 #include "app/nv_storage.h"
 
+#define IDC_USER_LIMIT_NONE ((s16)0x3fff)
+
 typedef struct {
 	bool running;
 	u32  start_ts;
@@ -45,6 +47,7 @@ typedef struct {
 	bool   b_wait_brk_release;
 	u8     mos_lim;
 	u8     motor_lim;
+	s16    idc_user_lim;
 	fan_t  fan[2];
 }motor_t;