diff --git a/Core/Inc/machine.h b/Core/Inc/machine.h index a768400..7c9c3fd 100644 --- a/Core/Inc/machine.h +++ b/Core/Inc/machine.h @@ -30,8 +30,8 @@ extern "C" { */ typedef enum { - MOTOR_DIR_CWW = 0, /* 向左移动 (Counter Clockwise) */ - MOTOR_DIR_CW = 1 /* 向右移动 (Clockwise) */ + MOTOR_DIR_CW = 0, /* 向左移动 (Clockwise) */ + MOTOR_DIR_CCW = 1 /* 向右移动 (Counter Clockwise) */ } Motor_DirectionTypeDef; /* Exported constants --------------------------------------------------------*/ @@ -73,7 +73,7 @@ uint8_t Machine_IsAtLimit(void); /** * @brief 设置步进电机方向 - * @param dir: 方向 (MOTOR_DIR_CWW: 向左, MOTOR_DIR_CW: 向右) + * @param dir: 方向 (MOTOR_DIR_CW: 向左, MOTOR_DIR_CCW: 向右) * @retval None */ void Machine_SetDirection(Motor_DirectionTypeDef dir); diff --git a/Core/Src/machine.c b/Core/Src/machine.c index 71bde7d..c7d462a 100644 --- a/Core/Src/machine.c +++ b/Core/Src/machine.c @@ -164,8 +164,8 @@ uint8_t Machine_IsAtLimit(void) /** * @brief 设置步进电机方向 * @param dir: 方向 - * MOTOR_DIR_CWW (0): 向左移动 (CWW - Counter Clockwise) - * MOTOR_DIR_CW (1): 向右移动 (CW - Clockwise) + * MOTOR_DIR_CW (0): 向左移动 (CW - Clockwise) + * MOTOR_DIR_CCW (1): 向右移动 (CCW - Counter Clockwise) * @note PD7为0表示向左,1表示向右 * @retval None */ @@ -174,7 +174,8 @@ void Machine_SetDirection(Motor_DirectionTypeDef dir) GPIO_PinState pinState; /* 根据方向设置PD7引脚状态 */ - pinState = (dir == MOTOR_DIR_CWW) ? GPIO_PIN_RESET : GPIO_PIN_SET; + /* CW(0) = 向左 = GPIO_PIN_RESET, CCW(1) = 向右 = GPIO_PIN_SET */ + pinState = (dir == MOTOR_DIR_CW) ? GPIO_PIN_RESET : GPIO_PIN_SET; /* 设置方向引脚 */ HAL_GPIO_WritePin(MOTOR_DIR_PIN_PORT, MOTOR_DIR_PIN, pinState); @@ -212,8 +213,8 @@ uint8_t Machine_MoveToOrigin(void) { uint32_t stepCount = 0; - /* 设置方向为向左(CWW) */ - Machine_SetDirection(MOTOR_DIR_CWW); + /* 设置方向为向左(CW) */ + Machine_SetDirection(MOTOR_DIR_CW); DelayUs(STEP_DELAY_US); /* 如果已经在原点,直接返回 */ @@ -276,7 +277,7 @@ uint8_t Machine_MoveToMaterial1(void) steps = Machine_MmToSteps(DISTANCE_TO_MATERIAL1); /* 向左移动 */ - return Machine_MoveSteps(MOTOR_DIR_CWW, steps); + return Machine_MoveSteps(MOTOR_DIR_CW, steps); } /** @@ -292,7 +293,7 @@ uint8_t Machine_MoveToMaterial2(void) steps = Machine_MmToSteps(DISTANCE_TO_MATERIAL2); /* 向左移动 */ - return Machine_MoveSteps(MOTOR_DIR_CWW, steps); + return Machine_MoveSteps(MOTOR_DIR_CW, steps); } /** @@ -308,7 +309,7 @@ uint8_t Machine_MoveToMaterial3(void) steps = Machine_MmToSteps(DISTANCE_TO_MATERIAL3); /* 向右移动 */ - return Machine_MoveSteps(MOTOR_DIR_CW, steps); + return Machine_MoveSteps(MOTOR_DIR_CCW, steps); } /** @@ -324,7 +325,7 @@ uint8_t Machine_MoveToMaterial4(void) steps = Machine_MmToSteps(DISTANCE_TO_MATERIAL4); /* 向右移动 */ - return Machine_MoveSteps(MOTOR_DIR_CW, steps); + return Machine_MoveSteps(MOTOR_DIR_CCW, steps); } /* USER CODE BEGIN 1 */