Explorar o código

转把信号采集统一在throttle.c 中处理(1ms sched task),转把低通滤波 200 rad/s bandwith

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=2) %!d(string=hai) anos
pai
achega
919f71237a

+ 4 - 23
Applications/foc/core/thro_torque.c

@@ -59,7 +59,7 @@ float thro_torque_gear_map(s16 rpm, u8 gear) {
 }
 }
 
 
 /* 获取油门开度 */
 /* 获取油门开度 */
-static float thro_ration(float f_throttle) {
+float get_throttle_ration(float f_throttle) {
 	if (f_throttle <= throttle_start_vol()) {
 	if (f_throttle <= throttle_start_vol()) {
 		return 0;
 		return 0;
 	}
 	}
@@ -76,10 +76,6 @@ float thro_ration_to_voltage(float r) {
 	return fclamp(vol, 0, throttle_end_vol());
 	return fclamp(vol, 0, throttle_end_vol());
 }
 }
 
 
-float thro_get_ration(float f_thro) {
-	return thro_ration(f_thro);
-}
-
 static float _thro_torque_for_accelerate(float ration) {
 static float _thro_torque_for_accelerate(float ration) {
 	float max_torque = thro_torque_gear_map((s16)_torque.spd_filted, _torque.gear);
 	float max_torque = thro_torque_gear_map((s16)_torque.spd_filted, _torque.gear);
 	float thro_torque = max_torque * ration;
 	float thro_torque = max_torque * ration;
@@ -189,27 +185,12 @@ static void thro_torque_request(void) {
 	}
 	}
 }
 }
 
 
-#define THRO_REF_LP_CEOF 0.2f
-static void thro_torque_filter(float f_throttle) {
-	if (mc_throttle_released()){
-		thro_torque_reset();
-	}else {
-		LowPass_Filter(_torque.thro_filted, f_throttle, THRO_REF_LP_CEOF);
-	}
-	float curr_rpm = PMSM_FOC_GetSpeed();
-	if (curr_rpm == 0) {
-		_torque.spd_filted = 0;
-	}else {
-		LowPass_Filter(_torque.spd_filted, curr_rpm, 0.01f);
-	}
-}
-
+#define THRO_RPM_LP_CEOF 0.01f
 void thro_torque_process(u8 run_mode, float f_throttle) {
 void thro_torque_process(u8 run_mode, float f_throttle) {
 
 
-	thro_torque_filter(f_throttle);
-
-	float thro_r = thro_ration(_torque.thro_filted);
+	float thro_r = get_throttle_ration(f_throttle);
 	_torque.gear = mc_get_internal_gear();
 	_torque.gear = mc_get_internal_gear();
+	LowPass_Filter(_torque.spd_filted, PMSM_FOC_GetSpeed(), THRO_RPM_LP_CEOF);
 
 
 	if (thro_r > _torque.thro_ration) {
 	if (thro_r > _torque.thro_ration) {
 		if (!_torque.accl) {
 		if (!_torque.accl) {

+ 1 - 1
Applications/foc/core/thro_torque.h

@@ -20,6 +20,6 @@ float thro_ration_to_voltage(float r);
 void thro_torque_process(u8 run_mode, float f_throttle);
 void thro_torque_process(u8 run_mode, float f_throttle);
 float get_user_request_torque(void);
 float get_user_request_torque(void);
 float thro_torque_gear_map(s16 rpm, u8 gear);
 float thro_torque_gear_map(s16 rpm, u8 gear);
-float thro_get_ration(float f_thro);
+float get_throttle_ration(float f_thro);
 #endif /* _THRO_TORQUE_H__ */
 #endif /* _THRO_TORQUE_H__ */
 
 

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

@@ -1339,7 +1339,7 @@ static void mc_process_epm_move(void) {
 		target_vel = -mc_conf()->c.max_epm_back_rpm;
 		target_vel = -mc_conf()->c.max_epm_back_rpm;
 		target_trq = mc_conf()->c.max_epm_back_torque;
 		target_trq = mc_conf()->c.max_epm_back_torque;
 	}else if (!motor.b_epm_cmd_move) {
 	}else if (!motor.b_epm_cmd_move) {
-		target_vel = thro_get_ration(throttle_get_signal()) * 2.0f * (float)target_vel;
+		target_vel = get_throttle_ration(throttle_get_signal()) * 2.0f * (float)target_vel;
 		step = 0.07f;
 		step = 0.07f;
 	}
 	}
 	step_towards(&motor.f_epm_vel, target_vel, step);
 	step_towards(&motor.f_epm_vel, target_vel, step);

+ 6 - 2
Applications/foc/motor/throttle.c

@@ -114,8 +114,12 @@ void throttle_force_detect(void) {
 }
 }
 
 
 void throttle_detect(bool ready) {
 void throttle_detect(bool ready) {
-	float thr_5v = get_thro_5v_float();
-	float thr_sig = get_throttle_float();
+	float thr_5v, thr_sig;
+
+	sample_throttle();
+
+	thr_5v = get_thro_5v_float();
+	thr_sig = get_throttle_float();
 	if (thr_sig <= mc_conf()->c.thro_min_vol || thr_sig >= mc_conf()->c.thro_max_vol) {
 	if (thr_sig <= mc_conf()->c.thro_min_vol || thr_sig >= mc_conf()->c.thro_max_vol) {
 		err_mask |= THRO1_SIG_ERR_BIT;
 		err_mask |= THRO1_SIG_ERR_BIT;
 	}
 	}

+ 2 - 4
Applications/foc/samples.c

@@ -54,11 +54,11 @@ void samples_init(void){
 #ifdef THROTTLE_CHAN
 #ifdef THROTTLE_CHAN
 	_throttle[0].value = (float)adc_get_throttle() * THROTTLE_VOL_CEOF;
 	_throttle[0].value = (float)adc_get_throttle() * THROTTLE_VOL_CEOF;
 	_throttle[0].filted_value = _throttle[0].value;
 	_throttle[0].filted_value = _throttle[0].value;
-	_throttle[0].lowpass = (0.01f);
+	_throttle[0].lowpass = (0.2f); //200 rad/s bandwith, sample s in 1ms task
 #ifdef THROTTLE2_CHAN
 #ifdef THROTTLE2_CHAN
 	_throttle[1].value = (float)adc_get_throttle2() * THROTTLE_VOL_CEOF;
 	_throttle[1].value = (float)adc_get_throttle2() * THROTTLE_VOL_CEOF;
 	_throttle[1].filted_value = _throttle[1].value;
 	_throttle[1].filted_value = _throttle[1].value;
-	_throttle[1].lowpass = (0.01f);
+	_throttle[1].lowpass = (0.2f);
 #endif
 #endif
 	sample_throttle();
 	sample_throttle();
 #endif
 #endif
@@ -178,8 +178,6 @@ float get_thro2_5v_float(void) {
 static u32 sample_task(void *param) {
 static u32 sample_task(void *param) {
 	sample_vbus();
 	sample_vbus();
 	sample_ibus();
 	sample_ibus();
-	sample_throttle();
-	//sample_uvw_phase();
 	sample_motor_temp();
 	sample_motor_temp();
 	sample_mos_temp();
 	sample_mos_temp();
 	sample_vref();
 	sample_vref();