Explorar o código

开电门未启动,学习转把最小启动电压

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

+ 5 - 4
Applications/foc/commands.h

@@ -108,10 +108,11 @@ typedef struct {
 	u16 vdc    :9;
 	u16 mot_ll :2; //motor temp limiter level
 	u16 mos_ll :2; //mos   temp limiter level
-	//16-47 bit
-	s16 idc;
-	//48-63 bit
-	s16 rpm;
+	u16 res    :3;
+	//31-63 bit
+	u32 idc    :11;// -1024 ~ +1023
+	u32 rpm    :14;
+	u32 thro_e :4 ;//throttle error bit mask
 }indicat_2A02_t;
 
 typedef struct {

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

@@ -78,6 +78,7 @@ typedef enum {
 typedef enum {
 	FOC_EV_MOT_Limit_L=FOC_CRIT_Err_Max + 1,
 	FOC_EV_MOS_Limit_L,
+	FOC_EV_THRO_START_V,
 }FOC_EVENT_R_t;
 
 #define FOC_Cri_Err_Mask(err) (1<<(err))

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

@@ -8,6 +8,7 @@
 #include "libs/logger.h"
 #include "prot/can_foc_msg.h"
 #include "foc/core/etcs.h"
+#include "foc/motor/throttle.h"
 
 static thro_torque_t _torque;
 
@@ -59,11 +60,11 @@ float thro_torque_gear_map(s16 rpm, u8 gear) {
 
 /* 获取油门开度 */
 static float thro_ration(float f_throttle) {
-	if (f_throttle <= nv_get_foc_params()->n_startThroVol) {
+	if (f_throttle <= throttle_start_vol()) {
 		return 0;
 	}
-	float delta = f_throttle - (nv_get_foc_params()->n_startThroVol);
-	int ration = (delta * 100.0f) / (nv_get_foc_params()->n_endThroVol - nv_get_foc_params()->n_startThroVol);	
+	float delta = f_throttle - throttle_start_vol();
+	int ration = (delta * 100.0f) / throttle_vol_range();
 	return ((float)ration)/100.0f;
 }
 
@@ -71,8 +72,8 @@ float thro_ration_to_voltage(float r) {
 	if (r == 0) {
 		return 0;
 	}
-	float vol = nv_get_foc_params()->n_startThroVol + r * (nv_get_foc_params()->n_endThroVol - nv_get_foc_params()->n_startThroVol);
-	return fclamp(vol, 0, nv_get_foc_params()->n_endThroVol);
+	float vol = throttle_start_vol() + r * throttle_vol_range();
+	return fclamp(vol, 0, throttle_end_vol());
 }
 
 float thro_get_ration(float f_thro) {

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

@@ -231,6 +231,7 @@ void mc_init(void) {
 	samples_init();
 	motor_encoder_init();
 	foc_command_init();
+	throttle_init();
 	thro_torque_init();
 	mc_detect_vbus_mode();
 	PMSM_FOC_CoreInit();
@@ -1437,7 +1438,7 @@ void Sched_MC_mTask(void) {
 
 	adc_vref_filter();
 
-	throttle_detect();
+	throttle_detect(motor.b_start);
 
 	F_all_Calc();
 

+ 42 - 5
Applications/foc/motor/throttle.c

@@ -5,8 +5,19 @@
 #include "libs/logger.h"
 #include "app/nv_storage.h"
 #include "foc/motor/throttle.h"
+#include "foc/mc_error.h"
 
 static u8 err_mask;
+static float _start_v, _end_v;
+static bool _auto_detect_sv = true;
+static bool _auto_detect_sv_cnt = 0;
+static float _auto_detect_sv_totle = 0;
+#define CONFIG_SAFE_INV_V   0.06f
+
+void throttle_init(void) {
+	_start_v = nv_get_foc_params()->n_startThroVol;
+	_end_v   = nv_get_foc_params()->n_endThroVol;
+}
 
 bool throttle1_is_error(void) {
 	if (err_mask & (THRO1_5V_ERR_BIT | THRO1_SIG_ERR_BIT)) {
@@ -34,13 +45,25 @@ bool throttle_is_all_error(void) {
 #endif
 }
 
+float throttle_start_vol(void) {
+	return _start_v;
+}
+
+float throttle_end_vol(void) {
+	return _end_v;
+}
+
+float throttle_vol_range(void) {
+	return (_end_v - _start_v);
+}
+
 float throttle_get_signal(void) {
 #if CONFIG_DAUL_THROTTLE==1
 	if (throttle1_is_error() && throttle2_is_error()) {
 		return 0.0f;
 	}else if (throttle1_is_error() && !throttle2_is_error()) {
 		float thr = get_thro2_5v_float() - get_throttle2_float();
-		return fclamp(thr, nv_get_foc_params()->n_startThroVol, nv_get_foc_params()->n_endThroVol);
+		return fclamp(thr, _start_v, _end_v);
 	}else if (!throttle1_is_error() && throttle2_is_error()) {
 		return get_throttle_float();
 	}else {
@@ -58,7 +81,7 @@ bool throttle_is_released(void) {
 	float signal = 0;
 	if (throttle1_is_error() && !throttle2_is_error()) {
 		float thr = get_thro2_5v_float() - get_throttle2_float();
-		signal = fclamp(thr, nv_get_foc_params()->n_startThroVol, nv_get_foc_params()->n_endThroVol);
+		signal = fclamp(thr, _start_v, _end_v);
 	}else if (!throttle1_is_error() && throttle2_is_error()) {
 		signal = get_throttle_float();
 	}else {
@@ -66,13 +89,13 @@ bool throttle_is_released(void) {
 		float thr2 = get_thro2_5v_float() - get_throttle2_float();
 		signal = (thr1+thr2)/2.0f;
 	}
-	return signal <= nv_get_foc_params()->n_startThroVol;
+	return signal <= _start_v;
 #else
-	return get_throttle_float() <= nv_get_foc_params()->n_startThroVol;
+	return get_throttle_float() <= _start_v;
 #endif
 }
 
-void throttle_detect(void) {
+void throttle_detect(bool ready) {
 	float thr_5v = get_thro_5v_float();
 	float thr_sig = get_throttle_float();
 	if (thr_sig <= nv_get_foc_params()->f_minThroVol || thr_sig >=nv_get_foc_params()->f_maxThroVol) {
@@ -97,4 +120,18 @@ void throttle_detect(void) {
 		}
 	}
 #endif
+	if (ready) {
+		_auto_detect_sv = false;
+	}else if (!throttle_is_all_error() && !ready && _auto_detect_sv) {
+		float v = throttle_get_signal();
+		if (v < _start_v) {
+			_auto_detect_sv_totle += v;
+			_auto_detect_sv_cnt ++;
+			if (_auto_detect_sv_cnt == 200) {
+				_start_v = _auto_detect_sv_totle / (float)_auto_detect_sv_cnt + CONFIG_SAFE_INV_V;
+				_auto_detect_sv = false;
+				mc_crit_err_add_s16(FOC_EV_THRO_START_V, (s16)(_start_v * 100.0f));
+			}
+		}
+	}
 }

+ 5 - 1
Applications/foc/motor/throttle.h

@@ -5,12 +5,16 @@
 #define	THRO1_SIG_ERR_BIT 0x04
 #define	THRO2_SIG_ERR_BIT 0x08
 
+void throttle_init(void);
 bool throttle_is_released(void);
 bool throttle_is_all_error(void);
 u8 throttle_get_errors(void);
 float throttle_get_signal(void);
-void throttle_detect(void);
+void throttle_detect(bool ready);
 bool throttle1_is_error(void);
 bool throttle2_is_error(void);
+float throttle_start_vol(void);
+float throttle_end_vol(void);
+float throttle_vol_range(void);
 #endif /* _THROTTLE_H__ */