|
|
@@ -12,6 +12,10 @@ static torque_lut_t *_trq_tbl = NULL;
|
|
|
static torque_manager_t g_trq_mn;
|
|
|
void torque_init(void) {
|
|
|
_trq_tbl = nv_get_trq_tlb();
|
|
|
+ torque_reset();
|
|
|
+}
|
|
|
+
|
|
|
+void torque_reset(void) {
|
|
|
memset(&g_trq_mn, 0, sizeof(g_trq_mn));
|
|
|
}
|
|
|
|
|
|
@@ -46,29 +50,89 @@ void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-float throttle_to_speed(float f_throttle) {
|
|
|
-
|
|
|
+/* 获取油门开度 */
|
|
|
+static float throttle_ration(float f_throttle) {
|
|
|
if (f_throttle <= nv_get_foc_params()->n_minThroVol) {
|
|
|
return 0;
|
|
|
}
|
|
|
float delta = f_throttle - (nv_get_foc_params()->n_minThroVol);
|
|
|
|
|
|
- float ration = delta / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
|
|
|
+ int ration = (delta * 100.0f) / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
|
|
|
+
|
|
|
+ return ((float)ration)/100.0f;
|
|
|
+}
|
|
|
|
|
|
- return (PMSM_FOC_GetSpeedLimit() * ration);
|
|
|
+float throttle_to_speed(float f_throttle) {
|
|
|
+ return (PMSM_FOC_GetSpeedLimit() * throttle_ration(f_throttle));
|
|
|
}
|
|
|
|
|
|
float throttle_to_torque(float f_throttle) {
|
|
|
- if (f_throttle <= (nv_get_foc_params()->n_minThroVol)) {
|
|
|
- return 0;
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
- float delta = f_throttle - (nv_get_foc_params()->n_minThroVol);
|
|
|
|
|
|
- float ration = delta / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
|
|
|
- int torque = PMSM_FOC_GetTorqueLimit() * ration * 10.0f;
|
|
|
- return ((float)torque / 10.0f);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ 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(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;
|
|
|
+ g_trq_mn.accl = false;
|
|
|
+
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ PMSM_FOC_Set_Speed(speed_Ref);
|
|
|
}
|
|
|
|
|
|
+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);
|
|
|
+ }else if (run_mode == CTRL_MODE_CURRENT_BRK) {
|
|
|
+ if (!mc_throttle_released() || (mc_throttle_released() && (PMSM_FOC_GetSpeed() == 0.0f))) {
|
|
|
+ eCtrl_enable_eBrake(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
void torque_manager(u8 run_mode, float f_throttle) {
|
|
|
if ((g_trq_mn.count++ % 20) != 0) {
|
|
|
return;
|
|
|
@@ -92,5 +156,5 @@ void torque_manager(u8 run_mode, float f_throttle) {
|
|
|
eCtrl_enable_eBrake(false);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+} */
|
|
|
|