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

Merge branch 'running_test' into tcs_dev

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 лет назад
Родитель
Сommit
5a3155b5e2

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

@@ -783,7 +783,7 @@ static void crosszero_step_towards(float *value, float target) {
 	float high_ramp_torque = CONFIG_RAMP_SECOND_TARGET;
 	if (target > 0) {
 		if (v_now < -RAMPE_1) {
-			step_towards(value, -RAMPE_1, NORMAL_STEP);
+			step_towards(value, -RAMPE_1 + 0.001f, NORMAL_STEP);
 			cross_zero = true;
 		}else if (v_now >= -RAMPE_1 && v_now <= high_ramp_torque) {
 			step_towards(value, target, 0.03f);
@@ -791,7 +791,7 @@ static void crosszero_step_towards(float *value, float target) {
 		}
 	}else if (target == 0) {
 		if (v_now > high_ramp_torque) {
-			step_towards(value, high_ramp_torque, NORMAL_STEP);
+			step_towards(value, high_ramp_torque - 0.001f, NORMAL_STEP);
 			cross_zero = true;
 		}else if (v_now >= RAMPE_1 && v_now <= high_ramp_torque) {
 			step_towards(value, target, 0.03f);
@@ -799,7 +799,7 @@ static void crosszero_step_towards(float *value, float target) {
 		}
 	}else {
 		if (v_now > high_ramp_torque) {
-			step_towards(value, high_ramp_torque, NORMAL_STEP);
+			step_towards(value, high_ramp_torque - 0.001f, NORMAL_STEP);
 			cross_zero = true;
 		}else if (v_now >= -RAMPE_1 && v_now <= high_ramp_torque) {
 			step_towards(value, target, 0.03f);

+ 5 - 15
Applications/foc/core/thro_torque.c

@@ -95,15 +95,14 @@ static float _thro_torque_for_accelerate(float ration) {
 	}
 	/*
 	   直接获取油门开度对应的加速扭矩thro_torque 不小于间接计算得到的 acc_torque
-	   如果差值在正负5以上,需要step 补偿
 	*/
 	float torque_acc_ = thro_torque - acc_torque;
 	float step = 0.0f;
-	if (ABS(torque_acc_) < 5) {
-		torque_acc_ = 0;
-	}else {
-		float acc_t = mc_get_gear_config()->accl_time;
+	if (torque_acc_ > 0) {
+		float acc_t = mc_get_gear_config()->n_accl_time;
 		step = torque_acc_ / (acc_t + 0.00001f);
+	}else {
+		torque_acc_ = 0;
 	}
 	step_towards(&_torque.torque_acc_, torque_acc_, step);
 	return (acc_torque + _torque.torque_acc_);
@@ -204,8 +203,7 @@ static void thro_torque_filter(float f_throttle) {
 		LowPass_Filter(_torque.spd_filted, curr_rpm, 0.01f);
 	}
 }
-static float acc_r, acc_r_last, acc_trq;
-static float dec_r, dec_r_last, dec_trq;
+
 void thro_torque_process(u8 run_mode, float f_throttle) {
 
 	thro_torque_filter(f_throttle);
@@ -221,9 +219,6 @@ void thro_torque_process(u8 run_mode, float f_throttle) {
 				_torque.torque_real = 0;
 			}
 			_torque.torque_acc_ = 0;
-			acc_r = thro_r;
-			acc_r_last = _torque.thro_ration_last;
-			acc_trq = _torque.torque_real;
 		}
 		_torque.accl = true;
 	}else if (thro_r < _torque.thro_ration) {
@@ -233,9 +228,6 @@ void thro_torque_process(u8 run_mode, float f_throttle) {
 			if (_torque.torque_real < 0) { //电子刹车的时候,扭矩可能为负
 				_torque.torque_real = 0;
 			}
-			dec_r = thro_r;
-			dec_r_last = _torque.thro_ration_last;
-			dec_trq = _torque.torque_real;
 		}
 		_torque.accl = false;
 	}
@@ -281,6 +273,4 @@ float get_user_request_torque(void) {
 void thro_torque_log(void) {
 	sys_debug("accl %d, real %f, req %f\n", _torque.accl, _torque.torque_real, _torque.torque_req);
 	sys_debug("ration %f - %f - %f - %d\n", _torque.thro_ration, _torque.thro_ration_last, thro_torque_for_accelerate(), _torque.gear);
-	sys_debug("acc:%f,%f,%f\n", acc_r, acc_r_last, acc_trq);
-	sys_debug("dec:%f,%f,%f\n", dec_r, dec_r_last, dec_trq);
 }

+ 5 - 5
Applications/foc/limit.c

@@ -115,8 +115,8 @@ static u16 _motor_limit(void) {
 		lim_value = _temp_limiter(temp, lim);
 		if (lim_value != HW_LIMIT_NONE) {
 			if (lim_value == 0) {
-				if (mc_set_critical_error(FOC_CRIT_MOTOR_TEMP_Lim)) {
-					mc_crit_err_add_s16(FOC_CRIT_MOTOR_TEMP_Lim, temp);
+				if (mc_set_critical_error(FOC_CRIT_MOTOR_TEMP_Err)) {
+					mc_crit_err_add(FOC_CRIT_MOTOR_TEMP_Err, temp, (s16)PMSM_FOC_GetSpeed());
 				}
 			}else if (_can_recovery){
 				mc_clr_critical_error(FOC_CRIT_MOTOR_TEMP_Lim);
@@ -172,8 +172,8 @@ static u16 _mos_limit(void) {
 		lim_value = _temp_limiter(temp, lim);
 		if (lim_value != HW_LIMIT_NONE) {
 			if (lim_value == 0) {
-				if (mc_set_critical_error(FOC_CRIT_MOS_TEMP_Lim)) {
-					mc_crit_err_add_s16(FOC_CRIT_MOS_TEMP_Lim, temp);
+				if (mc_set_critical_error(FOC_CRIT_MOS_TEMP_Err)) {
+					mc_crit_err_add(FOC_CRIT_MOS_TEMP_Err, temp, (s16)PMSM_FOC_GetSpeed());
 				}
 			}else if (_can_recovery){
 				mc_clr_critical_error(FOC_CRIT_MOS_TEMP_Lim);
@@ -238,7 +238,7 @@ u16 vbus_under_vol_limit(void) {
 		if (lim_value != HW_LIMIT_NONE) {
 			if (mc_set_critical_error(FOC_CRIT_UN_Vol_Err)) {
 				if (PMSM_FOC_GetSpeed() > CONFIG_ZERO_SPEED_RPM) {
-					mc_crit_err_add_s16(FOC_CRIT_UN_Vol_Err, vol);
+					mc_crit_err_add(FOC_CRIT_UN_Vol_Err, vol, (s16)PMSM_FOC_GetSpeed());
 				}
 			}
 			return lim_value;

+ 2 - 2
Applications/foc/mc_error.c

@@ -85,7 +85,7 @@ void mc_err_block_save(void) {
 }
 
 int mc_crit_err_get(s16 offset, u8 *buff, int len) {
-	int count = len / sizeof(err_node_t);
+	int count = (len - 1) / sizeof(err_node_t);
 	int index = offset;
 	u8 *p_remain = buff++;
 	if (_e_nv->count == ERR_MAX_SIZE) {
@@ -110,7 +110,7 @@ int mc_crit_err_get(s16 offset, u8 *buff, int len) {
 
 
 int mc_err_runtime_get(s16 offset, u8 *buff, int len) {
-	int count = len / sizeof(runtime_node_t);
+	int count = (len - 1) / sizeof(runtime_node_t);
 	int index = offset;
 	u8 *p_remain = buff++;
 	if (_r_nv->count == RUNTIME_MAX_SIZE) {