|
|
@@ -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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|