Ver código fonte

解决骑行刹车或者释放转把概率出现掉速的问题

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 anos atrás
pai
commit
ad0d51ddaf

+ 4 - 4
Applications/app/app.c

@@ -147,7 +147,7 @@ static u32 _app_report_task(void *p) {
 		can_report_motparam(mot_params_get_est_flux(), FLUX_TYPE);
 	}
 
-	if (++loop % 10 == 0) {
+	if (++loop % 5 == 0) {
 		//sys_debug("rst 0x%x\n", get_mcu_reset_source());
 		sys_debug("Slow: %d - %d\n", g_meas_MCTask.intval_time, g_meas_MCTask.exec_time);
 		sys_debug("Fast: %d - %d, err: %d-%d-%d\n", g_meas_foc.intval_time, g_meas_foc.exec_time, g_meas_foc.intval_hi_err, g_meas_foc.intval_low_err, g_meas_foc.exec_max_error_time);
@@ -156,12 +156,12 @@ static u32 _app_report_task(void *p) {
 		//sys_debug("throttle %f\n", get_throttle_float());
 		//sys_debug("ADC Vref %f, %f\n", get_adc_vref(), adc_5vref_compesion());
 		//sys_debug("dead time %d\n", get_deadtime());
-		//thro_torque_log();
+		thro_torque_log();
 		//sys_debug("_>%f, %f, %f\n", ladrc_observer_get()->ld, ladrc_observer_get()->lq, ladrc_observer_get()->poles);
-		encoder_log();
+		//encoder_log();
 		//motor_debug();
 		//sample_log();
-		PMSM_FOC_LogDebug();
+		//PMSM_FOC_LogDebug();
 		//F_debug();
 		//eCtrl_debug_log();
 		//sys_debug("enc err %d, %d\n", foc_observer_enc_errcount(), foc_observer_sensorless_stable());

+ 5 - 0
Applications/foc/core/PMSM_FOC_Core.h

@@ -72,6 +72,11 @@ typedef enum {
 	FOC_CRIT_Err_Max = 32,
 }FOC_CritiCal_Ebit_t;
 
+typedef enum {
+	FOC_EV_MOT_Limit_L=FOC_CRIT_Err_Max + 1,
+	FOC_EV_MOS_Limit_L,
+}FOC_EVENT_R_t;
+
 #define FOC_Cri_Err_Mask(err) (1<<(err))
 
 typedef struct {

+ 16 - 7
Applications/foc/core/thro_torque.c

@@ -187,30 +187,35 @@ 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);
 
 	float thro_r = thro_ration(_torque.thro_filted);
-	u8    n_gear = mc_get_internal_gear();
+	_torque.gear = mc_get_internal_gear();
 
 	if (thro_r > _torque.thro_ration) {
 		if (!_torque.accl) {
 			_torque.thro_ration_last = _torque.thro_ration;
-			_torque.torque_real = PMSM_FOC_Get()->in.s_targetTorque;
+			_torque.torque_real = _torque.torque_req;
 			if (_torque.torque_real < 0) { //电子刹车的时候,扭矩可能为负
 				_torque.torque_real = 0;
 			}
+			acc_r = thro_r;
+			acc_r_last = _torque.thro_ration_last;
+			acc_trq = _torque.torque_real;
 		}
-		_torque.gear = n_gear;
 		_torque.accl = true;
 	}else if (thro_r < _torque.thro_ration) {
 		if (_torque.accl) {
 			_torque.thro_ration_last = _torque.thro_ration;
-			_torque.torque_real = PMSM_FOC_Get()->in.s_targetTorque;
+			_torque.torque_real = _torque.torque_req;
+			dec_r = thro_r;
+			dec_r_last = _torque.thro_ration_last;
+			dec_trq = _torque.torque_real;
 		}
-		_torque.gear = n_gear;
 		_torque.accl = false;
 	}
 
@@ -234,10 +239,12 @@ void thro_torque_process(u8 run_mode, float f_throttle) {
 		}
 
 		if (eCtrl_get_FinalTorque() < 0.0001f && vel < CONFIG_MIN_RPM_EXIT_EBRAKE) {
-			eCtrl_enable_eBrake(false);	
+			eCtrl_enable_eBrake(false);
+			thro_torque_reset();
 		}
 		if (!mc_throttle_released() || (mc_throttle_released() && (vel == 0.0f))) {
 			eCtrl_enable_eBrake(false);
+			thro_torque_reset();
 		}
 	}
 }
@@ -253,4 +260,6 @@ 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", acc_r, acc_r_last, acc_trq);
+	sys_debug("dec:%f,%f,%f", dec_r, dec_r_last, dec_trq);
 }

+ 4 - 0
Applications/foc/limit.c

@@ -123,6 +123,8 @@ static u16 _motor_limit(void) {
 			lim_value = (u16)(((float)gear->n_max_trq * curr_value) / 100.0f);
 			mc_set_motor_lim_level(i + 1);
 			return lim_value;
+		}else {
+			mc_set_motor_lim_level(0);
 		}
 	}
 	
@@ -163,6 +165,8 @@ static u16 _mos_limit(void) {
 			lim_value = (u16)(((float)gear->n_max_trq * curr_value) / 100.0f);
 			mc_set_mos_lim_level(i + 1);
 			return lim_value;
+		}else {
+			mc_set_mos_lim_level(0);
 		}
 	}
 	

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

@@ -372,10 +372,16 @@ bool mc_stop(void) {
 }
 
 void mc_set_mos_lim_level(u8 l) {
+	if (motor.mos_lim != l) {
+		mc_crit_err_add(FOC_EV_MOS_Limit_L, l, get_mos_temp());
+	}
 	motor.mos_lim = l;
 }
 
 void mc_set_motor_lim_level(u8 l) {
+	if (motor.motor_lim != l) {
+		mc_crit_err_add(FOC_EV_MOT_Limit_L, l, get_motor_temp());
+	}
 	motor.motor_lim = l;
 }