改一下,向左是CW - 0, 向右是CCW - 1
This commit is contained in:
@@ -30,8 +30,8 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
MOTOR_DIR_CWW = 0, /* 向左移动 (Counter Clockwise) */
|
MOTOR_DIR_CW = 0, /* 向左移动 (Clockwise) */
|
||||||
MOTOR_DIR_CW = 1 /* 向右移动 (Clockwise) */
|
MOTOR_DIR_CCW = 1 /* 向右移动 (Counter Clockwise) */
|
||||||
} Motor_DirectionTypeDef;
|
} Motor_DirectionTypeDef;
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
@@ -73,7 +73,7 @@ uint8_t Machine_IsAtLimit(void);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 设置步进电机方向
|
* @brief 设置步进电机方向
|
||||||
* @param dir: 方向 (MOTOR_DIR_CWW: 向左, MOTOR_DIR_CW: 向右)
|
* @param dir: 方向 (MOTOR_DIR_CW: 向左, MOTOR_DIR_CCW: 向右)
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Machine_SetDirection(Motor_DirectionTypeDef dir);
|
void Machine_SetDirection(Motor_DirectionTypeDef dir);
|
||||||
|
|||||||
@@ -164,8 +164,8 @@ uint8_t Machine_IsAtLimit(void)
|
|||||||
/**
|
/**
|
||||||
* @brief 设置步进电机方向
|
* @brief 设置步进电机方向
|
||||||
* @param dir: 方向
|
* @param dir: 方向
|
||||||
* MOTOR_DIR_CWW (0): 向左移动 (CWW - Counter Clockwise)
|
* MOTOR_DIR_CW (0): 向左移动 (CW - Clockwise)
|
||||||
* MOTOR_DIR_CW (1): 向右移动 (CW - Clockwise)
|
* MOTOR_DIR_CCW (1): 向右移动 (CCW - Counter Clockwise)
|
||||||
* @note PD7为0表示向左,1表示向右
|
* @note PD7为0表示向左,1表示向右
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
@@ -174,7 +174,8 @@ void Machine_SetDirection(Motor_DirectionTypeDef dir)
|
|||||||
GPIO_PinState pinState;
|
GPIO_PinState pinState;
|
||||||
|
|
||||||
/* 根据方向设置PD7引脚状态 */
|
/* 根据方向设置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);
|
HAL_GPIO_WritePin(MOTOR_DIR_PIN_PORT, MOTOR_DIR_PIN, pinState);
|
||||||
@@ -212,8 +213,8 @@ uint8_t Machine_MoveToOrigin(void)
|
|||||||
{
|
{
|
||||||
uint32_t stepCount = 0;
|
uint32_t stepCount = 0;
|
||||||
|
|
||||||
/* 设置方向为向左(CWW) */
|
/* 设置方向为向左(CW) */
|
||||||
Machine_SetDirection(MOTOR_DIR_CWW);
|
Machine_SetDirection(MOTOR_DIR_CW);
|
||||||
DelayUs(STEP_DELAY_US);
|
DelayUs(STEP_DELAY_US);
|
||||||
|
|
||||||
/* 如果已经在原点,直接返回 */
|
/* 如果已经在原点,直接返回 */
|
||||||
@@ -276,7 +277,7 @@ uint8_t Machine_MoveToMaterial1(void)
|
|||||||
steps = Machine_MmToSteps(DISTANCE_TO_MATERIAL1);
|
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);
|
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);
|
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);
|
steps = Machine_MmToSteps(DISTANCE_TO_MATERIAL4);
|
||||||
|
|
||||||
/* 向右移动 */
|
/* 向右移动 */
|
||||||
return Machine_MoveSteps(MOTOR_DIR_CW, steps);
|
return Machine_MoveSteps(MOTOR_DIR_CCW, steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|||||||
Reference in New Issue
Block a user