Ver código fonte

加入接口获取速度绝对值,多个地方需要判断绝对值的大小

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin 2 anos atrás
pai
commit
2f13e5d2ab
2 arquivos alterados com 12 adições e 7 exclusões
  1. 5 0
      Applications/foc/core/controller.h
  2. 7 7
      Applications/foc/motor/motor.c

+ 5 - 0
Applications/foc/core/controller.h

@@ -292,5 +292,10 @@ static __INLINE u32 mot_contrl_get_torque_acc_time(mot_contrl_t *ctrl) {
 	return ctrl->ramp_input_torque.time;
 }
 
+static __INLINE s16 mot_contrl_get_speed_abs(mot_contrl_t *ctrl) {
+	s16 speed = (s16)mot_contrl_get_speed(ctrl);
+	return ABS(speed);
+}
+
 #endif /* _CONTROLLER_H__ */
 

+ 7 - 7
Applications/foc/motor/motor.c

@@ -369,7 +369,7 @@ bool mc_start(u8 mode) {
 		mot_contrl_set_error(&motor.controller, FOC_Param_Err);
 		return false;
 	}
-	if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
+	if (mot_contrl_get_speed_abs(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
 		mot_contrl_set_error(&motor.controller, FOC_NowAllowed_With_Speed);
 		return false;
 	}
@@ -424,7 +424,7 @@ bool mc_stop(void) {
 		return false;
 	}
 
-	if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
+	if (mot_contrl_get_speed_abs(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
 		mot_contrl_set_error(&motor.controller, FOC_NowAllowed_With_Speed);
 		return false;
 	}
@@ -643,7 +643,7 @@ bool mc_set_ctrl_mode(u8 mode) {
 	if (mc_critical_can_not_run()) {
 		return false;
 	}
-	if ((mode == CTRL_MODE_OPEN) && (ABS(mot_contrl_get_speed(&motor.controller)) > CONFIG_ZERO_SPEED_RPM)) {
+	if ((mode == CTRL_MODE_OPEN) && (mot_contrl_get_speed_abs(&motor.controller) > CONFIG_ZERO_SPEED_RPM)) {
 		mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
 		return false;
 	}
@@ -1211,7 +1211,7 @@ static void motor_vbus_crit_check(s16 curr_vbus) {
 				mot_contrl_stop(&motor.controller);
 			}
 			if (mc_set_critical_error(FOC_CRIT_Vol_HW_Err)) {
-				if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
+				if (mot_contrl_get_speed_abs(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
 					mc_crit_err_add_s16(FOC_CRIT_Vol_HW_Err, curr_vbus);
 				}
 			}
@@ -1349,7 +1349,7 @@ static bool mc_run_stall_process(u8 run_mode) {
 			motor.runStall_time = 0;
 			motor.b_runStall = false; //转把释放,清除堵转标志
 		}else if (mot_contrl_get_current_vector(&motor.controller) >= CONFIG_STALL_MAX_CURRENT){
-			if (ABS(mot_contrl_get_speed(&motor.controller)) < 1.0f && (motor.runStall_time == 0)) {
+			if (mot_contrl_get_speed_abs(&motor.controller) < 1 && (motor.runStall_time == 0)) {
 				motor.runStall_time = get_tick_ms();
 				motor.runStall_pos = motor_encoder_get_position();
 			}
@@ -1460,7 +1460,7 @@ static void mc_process_brake_light(void) {
 static void mc_process_curise(void) {
 	static bool can_pause_resume = false;
 	if (motor.b_cruise) {
-		if (mot_contrl_get_speed(&motor.controller) < CONFIG_CRUISE_EXIT_RPM) {
+		if (mot_contrl_get_speed_abs(&motor.controller) < CONFIG_CRUISE_EXIT_RPM) {
 			mot_contrl_set_cruise(&motor.controller, false);
 			return;
 		}
@@ -1508,7 +1508,7 @@ static bool mc_can_stop_foc(void) {
 			return true;
 		}
 	}
-	if (mc_throttle_released() && ((mot_contrl_get_speed(&motor.controller)) == 0.0f)) {
+	if (mc_throttle_released() && ((mot_contrl_get_speed_abs(&motor.controller)) == 0)) {
 		if (!mot_contrl_is_auto_holdding(&motor.controller) && motor.epm_dir == EPM_Dir_None) {
 			return true;
 		}