Преглед изворни кода

停止和重启的判断处理

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui пре 2 година
родитељ
комит
889b82ddd0
1 измењених фајлова са 17 додато и 15 уклоњено
  1. 17 15
      Applications/foc/motor/motor.c

+ 17 - 15
Applications/foc/motor/motor.c

@@ -1419,8 +1419,12 @@ static bool mc_can_stop_foc(void) {
 	if (motor.mode == CTRL_MODE_CURRENT) {
 		return false;
 	}
-	if (!motor.b_cruise && !motor.b_epm && motor.mode == CTRL_MODE_SPD && (motor.s_target_speed == MAX_S16 || motor.s_target_speed == 0)) {
-		return true;
+	if (!motor.b_cruise && !motor.b_epm && motor.mode == CTRL_MODE_SPD) {
+		if (motor.s_target_speed != MAX_S16 && motor.s_target_speed != 0) {
+			return false;
+		}else {
+			return true;
+		}
 	}
 	if (mc_throttle_released() && PMSM_FOC_GetSpeed() == 0.0f) {
 		if (!PMSM_FOC_AutoHoldding() && motor.epm_dir == EPM_Dir_None) {
@@ -1435,12 +1439,12 @@ static bool mc_can_stop_foc(void) {
 }
 
 static bool mc_can_restart_foc(void) {
-	bool can_start = (!PMSM_FOC_Is_Start()) && (!mc_throttle_released() || (motor.epm_dir != EPM_Dir_None)) && (!mc_critical_can_not_run());
+	bool can_start = (!mc_throttle_released() || (motor.epm_dir != EPM_Dir_None)) && (!mc_critical_can_not_run());
 	if (!foc_observer_is_encoder() && !foc_observer_sensorless_stable()){
-		can_start = false;
+		return false;
 	}
-	if (!motor.b_cruise && !motor.b_epm && motor.mode == CTRL_MODE_SPD && (motor.s_target_speed != MAX_S16 && motor.s_target_speed != 0)) {
-		can_start = true;
+	if ((motor.s_target_speed != MAX_S16 && motor.s_target_speed != 0) && (!mc_critical_can_not_run()) && motor.mode == CTRL_MODE_SPD) {
+		return true;
 	}
 	return can_start;
 }
@@ -1449,16 +1453,14 @@ static bool mc_can_restart_foc(void) {
 
 static void mc_motor_runstop(void) {
 	u32 mask;
-	if (mc_can_stop_foc()) {
-		if (PMSM_FOC_Is_Start()) {
-			mask = cpu_enter_critical();
-			PMSM_FOC_Stop();
-			pwm_disable_channel();
-			g_meas_foc.first = true;
-			cpu_exit_critical(mask);
-		}
+	if (PMSM_FOC_Is_Start() && mc_can_stop_foc()) {
+		mask = cpu_enter_critical();
+		PMSM_FOC_Stop();
+		pwm_disable_channel();
+		g_meas_foc.first = true;
+		cpu_exit_critical(mask);
 	}
-	if (mc_can_restart_foc()) {
+	if (!PMSM_FOC_Is_Start() && mc_can_restart_foc()) {
 		mask = cpu_enter_critical();
 		PMSM_FOC_Start(motor.mode);
 		mc_gear_vmode_changed();