瀏覽代碼

能量回收启动先扭矩下降到0,再启动负扭矩

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin 2 年之前
父節點
當前提交
21902cf3a1
共有 3 個文件被更改,包括 16 次插入18 次删除
  1. 6 6
      Applications/foc/core/controller.c
  2. 1 1
      Applications/foc/core/controller.h
  3. 9 11
      Applications/foc/motor/motor.c

+ 6 - 6
Applications/foc/core/controller.c

@@ -127,8 +127,8 @@ u8 mot_contrl_mode(mot_contrl_t *ctrl) {
 			PI_Controller_Reset(&ctrl->pi_vel, ctrl->target_torque);
 		}else if ((preMode != ctrl->mode_running) && (ctrl->mode_running == CTRL_MODE_EBRAKE)) {
 			line_ramp_reset(&ctrl->ramp_input_torque, ctrl->target_torque);
-			line_ramp_set_time(&ctrl->ramp_input_torque, ctrl->ebrk_ramp_time);
-			line_ramp_set_target(&ctrl->ramp_input_torque, motor_get_ebreak_toruqe(ctrl->foc.in.mot_velocity));
+			line_ramp_set_time(&ctrl->ramp_input_torque, ctrl->torque_dec_time);
+			line_ramp_set_target(&ctrl->ramp_input_torque, 0);//先把扭矩快速减小到0
 		}else if ((preMode == CTRL_MODE_EBRAKE) && (ctrl->mode_running == CTRL_MODE_SPD)) {
 			PI_Controller_Reset(&ctrl->pi_vel, F_get_air());
 		}
@@ -573,7 +573,7 @@ float mot_contrl_get_ebrk_torque(mot_contrl_t *ctrl) {
 
 void mot_contrl_set_ebrk_time(mot_contrl_t *ctrl, u32 time) {
 	ctrl->ebrk_ramp_time = time;
-	if (ctrl->mode_running == CTRL_MODE_EBRAKE) {
+	if ((ctrl->mode_running == CTRL_MODE_EBRAKE) && (time != ctrl->ramp_input_torque.time_dec)) {
 		line_ramp_set_time(&ctrl->ramp_input_torque, time);
 		line_ramp_update(&ctrl->ramp_input_torque);
 	}
@@ -653,7 +653,7 @@ bool mot_contrl_set_torque(mot_contrl_t *ctrl, float torque) {
 	float torque_min = 0;
 	float torque_max = ctrl->userlim.torque;
 	if (ctrl->mode_running == CTRL_MODE_EBRAKE) {
-		torque_min = -ctrl->userlim.torque;
+		torque_min = -ctrl->userlim.ebrk_torque;
 		torque_max = 0;
 	}
 	torque = fclamp(torque, torque_min, torque_max);
@@ -713,7 +713,7 @@ static bool is_hw_brake_shutting_power(mot_contrl_t *ctrl) {
 	return (ctrl->b_hw_braker && mc_hwbrk_can_shutpower());
 }
 
-bool mot_contrl_energy_recovery(mot_contrl_t *ctrl, bool start) {
+bool mot_contrl_set_ebreak(mot_contrl_t *ctrl, bool start) {
 	bool enable = ctrl->b_ebrk_running;
 	if (mot_contrl_get_ebrk_torque(ctrl) == 0) {
 		enable = false;
@@ -739,7 +739,7 @@ void mot_contrl_set_hw_brake(mot_contrl_t *ctrl, bool hw_brake) {
 		ctrl->b_hw_braker = hw_brake;
 	}
 	if (is_hw_brake_shutting_power(ctrl)) {
-		if (!ctrl->b_ebrk_running && !mot_contrl_energy_recovery(ctrl, true)) {
+		if (!ctrl->b_ebrk_running && !mot_contrl_set_ebreak(ctrl, true)) {
 			line_ramp_reset(&ctrl->ramp_input_torque, 0);
 		}
 	}

+ 1 - 1
Applications/foc/core/controller.h

@@ -191,7 +191,7 @@ void mot_contrl_set_torque_acc_time(mot_contrl_t *ctrl, u32 acc);
 bool mot_contrl_set_torque(mot_contrl_t *ctrl, float torque);
 void mot_contrl_mtpa_calibrate(mot_contrl_t *ctrl, bool enable);
 void mot_contrl_set_autohold(mot_contrl_t *ctrl, bool lock);
-bool mot_contrl_energy_recovery(mot_contrl_t *ctrl, bool start);
+bool mot_contrl_set_ebreak(mot_contrl_t *ctrl, bool start);
 void mot_contrl_set_hw_brake(mot_contrl_t *ctrl, bool hw_brake);
 void mot_contrl_calc_current(mot_contrl_t *ctrl);
 void mot_contrl_get_pid(mot_contrl_t *ctrl, u8 id, float *kp, float *ki, float *kd);

+ 9 - 11
Applications/foc/motor/motor.c

@@ -1562,7 +1562,7 @@ static void mc_process_throttle_torque(float vol) {
 			return;
 		}
 #endif
-		if (mot_contrl_energy_recovery(&motor.controller, true)) {
+		if (mot_contrl_set_ebreak(&motor.controller, true)) {
 			return;
 		}
 	}
@@ -1575,18 +1575,16 @@ static void mc_process_throttle_torque(float vol) {
 			mot_contrl_set_target_vel(&motor.controller, vel_ref);
 		}
 	}else if (motor.controller.mode_running == CTRL_MODE_EBRAKE){
+		/* 等待输入扭矩先减小到0 */
+		if (line_ramp_get_interp(&motor.controller.ramp_input_torque) >= 0.001f) {
+			return;
+		}
+		mot_contrl_set_ebrk_time(&motor.controller, motor.controller.ebrk_ramp_time);
 		float vel = mot_contrl_get_speed(&motor.controller);
 		float ebrk_trq = motor_get_ebreak_toruqe(vel);
-			
-		if (ebrk_trq >= -mot_contrl_get_ebrk_torque(&motor.controller)/2){
-			mot_contrl_set_ebrk_time(&motor.controller, 1);
-		}
-		if (ebrk_trq != 0) {
-			mot_contrl_set_torque(&motor.controller, ebrk_trq);
-		}	
-		if ((mot_contrl_get_final_torque(&motor.controller) < 0.0001f && vel < CONFIG_MIN_RPM_EXIT_EBRAKE) ||
-			(!mc_throttle_released() || (mc_throttle_released() && (vel == 0.0f)))) {
-			mot_contrl_energy_recovery(&motor.controller, false);
+		mot_contrl_set_torque(&motor.controller, ebrk_trq);
+		if ((vel < CONFIG_MIN_RPM_EXIT_EBRAKE) || (!mc_throttle_released() || (mc_throttle_released() && (vel == 0.0f)))) {
+			mot_contrl_set_ebreak(&motor.controller, false);
 			throttle_torque_reset();
 		}
 	}