|
|
@@ -57,9 +57,9 @@ static float throttle_ration(float f_throttle) {
|
|
|
}
|
|
|
float delta = f_throttle - (nv_get_foc_params()->n_minThroVol);
|
|
|
|
|
|
- int ration = (delta * 100.0f) / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
|
|
|
+ int ration = (delta * 1000.0f) / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
|
|
|
|
|
|
- return ((float)ration)/100.0f;
|
|
|
+ return ((float)ration)/1000.0f;
|
|
|
}
|
|
|
|
|
|
float throttle_to_speed(float f_throttle) {
|
|
|
@@ -70,62 +70,109 @@ float throttle_to_torque(float f_throttle) {
|
|
|
return PMSM_FOC_GetTorqueLimit() * throttle_ration(f_throttle);
|
|
|
}
|
|
|
|
|
|
-void torque_mode_process(float f_throttle) {
|
|
|
- float thro_curr = throttle_ration(f_throttle);
|
|
|
- float thro_prev = g_trq_mn.thro_prev;
|
|
|
- float trq_ref = throttle_to_torque(f_throttle);
|
|
|
+#define REAL_DQ_CEOF 1.1f
|
|
|
|
|
|
- if (mc_throttle_released()) {
|
|
|
- if ((eCtrl_get_FinalTorque() > 0.0f)) {
|
|
|
- eCtrl_enable_eBrake(true);
|
|
|
- float ref_now = min(PMSM_FOC_Get_Real_Torque() * 0.9f, eCtrl_get_RefTorque());
|
|
|
- eCtrl_reset_Torque(ref_now);
|
|
|
- PMSM_FOC_Set_Torque(0);
|
|
|
- g_trq_mn.accl = false;
|
|
|
- g_trq_mn.thro_prev = 0.0f;
|
|
|
- }
|
|
|
+#if 1
|
|
|
+void torque_mode_process(void) {
|
|
|
+ float ref_trq = PMSM_FOC_GetTorqueLimit() * g_trq_mn.thro_value;
|
|
|
+
|
|
|
+ if ((mc_throttle_released()) && eCtrl_enable_eBrake(true)) {
|
|
|
+ g_trq_mn.thro_value = 0;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (thro_curr > thro_prev) {
|
|
|
- if (PMSM_FOC_GetSpeed() == 0.0f) {
|
|
|
- g_trq_mn.accl_ref = MAX(eCtrl_get_FinalTorque(), trq_ref); //不能小于autohold产生的扭矩
|
|
|
- }else if (!g_trq_mn.accl){
|
|
|
- g_trq_mn.accl_ref = eCtrl_get_RefTorque();
|
|
|
- }
|
|
|
- if (g_trq_mn.accl_ref > PMSM_FOC_GetTorqueLimit()) {
|
|
|
- g_trq_mn.accl_ref = PMSM_FOC_GetTorqueLimit();
|
|
|
+ if (!mc_throttle_released()) {
|
|
|
+ if (PMSM_FOC_GetSpeed() <= 1.0f) {
|
|
|
+ ref_trq = MAX(eCtrl_get_FinalTorque() * REAL_DQ_CEOF, ref_trq );
|
|
|
}
|
|
|
- trq_ref = g_trq_mn.accl_ref + thro_curr * (PMSM_FOC_GetTorqueLimit() - g_trq_mn.accl_ref);
|
|
|
+ PMSM_FOC_Set_Torque(ref_trq );
|
|
|
+ }else if (mc_throttle_released() && eCtrl_get_FinalTorque() != 0){
|
|
|
+ float real_trq = PMSM_FOC_Get_Real_Torque();
|
|
|
+ float ref_now = min(real_trq, eCtrl_get_RefTorque());
|
|
|
+ eCtrl_reset_Torque(ref_now);
|
|
|
+ PMSM_FOC_Set_Torque(0);
|
|
|
+ g_trq_mn.thro_value = 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+#else
|
|
|
+void torque_mode_process(void) {
|
|
|
+ float thro_curr = g_trq_mn.thro_value;
|
|
|
+ float thro_prev = g_trq_mn.thro_prev;
|
|
|
+ float trq_ref = PMSM_FOC_GetTorqueLimit() * thro_curr;
|
|
|
|
|
|
- g_trq_mn.accl = true;
|
|
|
- }else if (thro_curr < thro_prev){
|
|
|
- if (g_trq_mn.accl) {
|
|
|
- g_trq_mn.accl_ref = min(PMSM_FOC_Get_Real_Torque() * 0.9f, eCtrl_get_RefTorque());
|
|
|
- eCtrl_reset_Torque(g_trq_mn.accl_ref);
|
|
|
- }
|
|
|
- trq_ref = thro_curr * g_trq_mn.accl_ref;
|
|
|
+ if ((thro_curr == 0.0f) && eCtrl_enable_eBrake(true)) {
|
|
|
+ g_trq_mn.thro_value = 0;
|
|
|
g_trq_mn.accl = false;
|
|
|
-
|
|
|
+ g_trq_mn.thro_prev = 0.0f;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ float real_trq = eCtrl_get_FinalTorque() * REAL_DQ_CEOF;
|
|
|
+ if (trq_ref > 0) {
|
|
|
+ if (PMSM_FOC_GetSpeed() <= 10.0f) {
|
|
|
+ g_trq_mn.accl_ref = MAX(real_trq, trq_ref); //不能小于autohold产生的扭矩
|
|
|
+ trq_ref = g_trq_mn.accl_ref;
|
|
|
+ }else {
|
|
|
+ if (thro_curr > thro_prev) {
|
|
|
+ if (!g_trq_mn.accl){
|
|
|
+ g_trq_mn.accl_ref = eCtrl_get_RefTorque();
|
|
|
+ }
|
|
|
+ if (g_trq_mn.accl_ref > PMSM_FOC_GetTorqueLimit()) {
|
|
|
+ g_trq_mn.accl_ref = PMSM_FOC_GetTorqueLimit();
|
|
|
+ }
|
|
|
+ trq_ref = g_trq_mn.accl_ref + thro_curr * (PMSM_FOC_GetTorqueLimit() - g_trq_mn.accl_ref);
|
|
|
+ g_trq_mn.accl = true;
|
|
|
+ }else if (thro_curr < thro_prev){
|
|
|
+ if (g_trq_mn.accl) {
|
|
|
+ g_trq_mn.accl_ref = min(real_trq, eCtrl_get_RefTorque());
|
|
|
+ eCtrl_reset_Torque(g_trq_mn.accl_ref);
|
|
|
+ }
|
|
|
+ trq_ref = thro_curr * g_trq_mn.accl_ref;
|
|
|
+ g_trq_mn.accl = false;
|
|
|
+ }else {
|
|
|
+ if (g_trq_mn.accl) {
|
|
|
+ trq_ref = g_trq_mn.accl_ref + thro_curr * (PMSM_FOC_GetTorqueLimit() - g_trq_mn.accl_ref);
|
|
|
+ }else {
|
|
|
+ trq_ref = thro_curr * g_trq_mn.accl_ref;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PMSM_FOC_Set_Torque(trq_ref);
|
|
|
+ }
|
|
|
+ else if (eCtrl_get_FinalTorque() != 0){
|
|
|
+ float ref_now = min(real_trq, eCtrl_get_RefTorque());
|
|
|
+ eCtrl_reset_Torque(ref_now);
|
|
|
+ PMSM_FOC_Set_Torque(0);
|
|
|
+ g_trq_mn.thro_value = 0;
|
|
|
}
|
|
|
- PMSM_FOC_Set_Torque(trq_ref);
|
|
|
g_trq_mn.thro_prev = thro_curr;
|
|
|
}
|
|
|
|
|
|
-void speed_mode_process(float f_throttle) {
|
|
|
- float speed_Ref = throttle_to_speed(f_throttle);
|
|
|
+#endif
|
|
|
+void speed_mode_process(void) {
|
|
|
+ float speed_Ref = g_trq_mn.spd_ref;
|
|
|
PMSM_FOC_Set_Speed(speed_Ref);
|
|
|
}
|
|
|
|
|
|
+#define THRO_REF_LP_CEOF 0.2f
|
|
|
+
|
|
|
void throttle_process(u8 run_mode, float f_throttle) {
|
|
|
- if ((g_trq_mn.count++ % 20) != 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
if (run_mode == CTRL_MODE_TRQ) {
|
|
|
- torque_mode_process(f_throttle);
|
|
|
- }else if (run_mode == CTRL_MODE_SPD) {
|
|
|
- speed_mode_process(f_throttle);
|
|
|
+ float thro_value = throttle_ration(f_throttle);
|
|
|
+ g_trq_mn.thro_value = LowPass_Filter(g_trq_mn.thro_value, thro_value, THRO_REF_LP_CEOF);
|
|
|
+ if ((g_trq_mn.count++ % 20) == 0) {
|
|
|
+ torque_mode_process();
|
|
|
+ }
|
|
|
+
}else if (run_mode == CTRL_MODE_SPD) {
|
|
|
+ float spd_ref = throttle_to_speed(f_throttle);
|
|
|
+ g_trq_mn.spd_ref = LowPass_Filter(g_trq_mn.spd_ref, spd_ref, THRO_REF_LP_CEOF);
|
|
|
+ if ((g_trq_mn.count++ % 20) == 0) {
|
|
|
+ speed_mode_process();
|
|
|
+ }
|
|
|
}else if (run_mode == CTRL_MODE_CURRENT_BRK) {
|
|
|
+ eCtrl_reset_Torque(0);
|
|
|
+ if (eCtrl_get_FinalCurrent() < 0.0001f && PMSM_FOC_GetSpeed() < CONFIG_MIN_RPM_EXIT_EBRAKE) {
|
|
|
+ eCtrl_enable_eBrake(false);
|
|
|
+ }
|
|
|
if (!mc_throttle_released() || (mc_throttle_released() && (PMSM_FOC_GetSpeed() == 0.0f))) {
|
|
|
eCtrl_enable_eBrake(false);
|
|
|
}
|