|
|
@@ -1,6 +1,7 @@
|
|
|
#include "foc/core/torque.h"
|
|
|
#include "foc/foc_config.h"
|
|
|
#include "foc/motor/motor.h"
|
|
|
+#include "foc/motor/motor_param.h"
|
|
|
#include "foc/core/e_ctrl.h"
|
|
|
#include "foc/core/PMSM_FOC_Core.h"
|
|
|
#include "app/nv_storage.h"
|
|
|
@@ -72,62 +73,54 @@ float throttle_to_torque(float f_throttle) {
|
|
|
return PMSM_FOC_GetTorqueLimit() * throttle_ration(f_throttle);
|
|
|
}
|
|
|
|
|
|
-/* 软件设置油门开度,调试使用 */
|
|
|
-void throttle_set_ration(float r) {
|
|
|
- g_trq_mn.thro_value = r;
|
|
|
-}
|
|
|
-
|
|
|
#define REAL_DQ_CEOF 0.9f
|
|
|
#define FINAL_DQ_CEFO 1.1F
|
|
|
|
|
|
-void torque_mode_process(void) {
|
|
|
- float ref_trq = PMSM_FOC_GetTorqueLimit() * g_trq_mn.thro_value;
|
|
|
+void request_torque(float thro_ration) {
|
|
|
+ float curr_rpm = PMSM_FOC_GetSpeed();
|
|
|
+ if (curr_rpm == 0) {
|
|
|
+ g_trq_mn.spd_filted = 0;
|
|
|
+ }else {
|
|
|
+ LowPass_Filter(g_trq_mn.spd_filted, curr_rpm, 0.5f);
|
|
|
+ }
|
|
|
+ float trq_map = (float)get_max_torque_for_rpm((s16)g_trq_mn.spd_filted);
|
|
|
+ float trq_lim = PMSM_FOC_GetTorqueLimit();
|
|
|
+ float max_trq = min(trq_map, trq_lim);
|
|
|
+ float ref_trq = max_trq * thro_ration;
|
|
|
if ((mc_throttle_released()) && eCtrl_enable_eBrake(true)) {
|
|
|
- g_trq_mn.thro_value = 0;
|
|
|
- g_trq_mn.torque_prev = 0;
|
|
|
- g_trq_mn.torque_base = 0;
|
|
|
+ g_trq_mn.thro_ration = 0;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!mc_throttle_released()) {
|
|
|
- if (PMSM_FOC_GetSpeed() <= CONFIG_ZERO_SPEED_RPM) {
|
|
|
+ if (curr_rpm <= CONFIG_ZERO_SPEED_RPM) {
|
|
|
ref_trq = MAX(eCtrl_get_FinalTorque() * FINAL_DQ_CEFO, ref_trq );
|
|
|
- g_trq_mn.torque_base = ref_trq;
|
|
|
}
|
|
|
PMSM_FOC_Set_Torque(ref_trq );
|
|
|
- g_trq_mn.torque_prev = ref_trq;
|
|
|
}else if (mc_throttle_released() && eCtrl_get_FinalTorque() != 0){
|
|
|
float real_trq = PMSM_FOC_Get_Real_Torque() * REAL_DQ_CEOF;
|
|
|
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;
|
|
|
- g_trq_mn.torque_prev = 0;
|
|
|
- g_trq_mn.torque_base = 0;
|
|
|
+ g_trq_mn.thro_ration = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void speed_mode_process(void) {
|
|
|
- float speed_Ref = g_trq_mn.spd_ref;
|
|
|
+void request_speed(float thro_ration) {
|
|
|
+ float speed_Ref = PMSM_FOC_GetSpeedLimit() * thro_ration;
|
|
|
PMSM_FOC_Set_Speed(speed_Ref);
|
|
|
}
|
|
|
|
|
|
#define THRO_REF_LP_CEOF 0.2f
|
|
|
|
|
|
void throttle_process(u8 run_mode, float f_throttle) {
|
|
|
+ float thro_value = throttle_ration(f_throttle);
|
|
|
+ g_trq_mn.thro_ration = LowPass_Filter(g_trq_mn.thro_ration, thro_value, THRO_REF_LP_CEOF);
|
|
|
+
|
|
|
if (run_mode == CTRL_MODE_TRQ) {
|
|
|
- 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();
|
|
|
- }
|
|
|
-
|
|
|
+ request_torque(g_trq_mn.thro_ration);
|
|
|
}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();
|
|
|
- }
|
|
|
+ request_speed(g_trq_mn.thro_ration);
|
|
|
}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) {
|