更新电机占空比最小值
This commit is contained in:
parent
8602e7bccf
commit
f759a1c198
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include "main.h"
|
||||
|
||||
// duty in [-100, 100]
|
||||
|
||||
void MOTOR_Start(void);
|
||||
void MOTOR_Slip(void);
|
||||
void MOTOR_Stop(void);
|
||||
|
|
|
@ -17,6 +17,8 @@ void MOTOR_Start(void)
|
|||
HAL_TIM_PWM_Start(MOTOR_TIM, MOTOR_R_CHAN);
|
||||
}
|
||||
|
||||
/// @brief 自由滑行
|
||||
/// @param
|
||||
void MOTOR_Slip(void)
|
||||
{
|
||||
HAL_GPIO_WritePin(L_FORWARD_GPIO_Port, L_FORWARD_Pin | L_BACKWARD_Pin | R_FORWARD_Pin | R_BACKWARD_Pin, GPIO_PIN_RESET);
|
||||
|
@ -24,6 +26,8 @@ void MOTOR_Slip(void)
|
|||
__HAL_TIM_SetCompare(MOTOR_TIM, MOTOR_R_CHAN, MAX_SPEED);
|
||||
}
|
||||
|
||||
/// @brief 刹车
|
||||
/// @param
|
||||
void MOTOR_Stop(void)
|
||||
{
|
||||
HAL_GPIO_WritePin(L_FORWARD_GPIO_Port, L_FORWARD_Pin | L_BACKWARD_Pin | R_FORWARD_Pin | R_BACKWARD_Pin, GPIO_PIN_RESET);
|
||||
|
@ -31,6 +35,10 @@ void MOTOR_Stop(void)
|
|||
__HAL_TIM_SetCompare(MOTOR_TIM, MOTOR_R_CHAN, 0);
|
||||
}
|
||||
|
||||
/// @brief 控制电机占空比
|
||||
|
||||
/// @param leftDuty 绝对值 20-100, 支持正负
|
||||
/// @param rightDuty 绝对值 20-100,支持正负
|
||||
void MOTOR_SetDuty(int8_t leftDuty, int8_t rightDuty)
|
||||
{
|
||||
leftDuty = preProcess(leftDuty, MOTOR_L);
|
||||
|
@ -47,13 +55,12 @@ void MOTOR_SetDuty(int8_t leftDuty, int8_t rightDuty)
|
|||
|
||||
int8_t preProcess(int8_t duty, uint8_t motor)
|
||||
{
|
||||
if (duty > 100)
|
||||
duty = 100;
|
||||
else if (duty < -100)
|
||||
duty = -100;
|
||||
|
||||
if (duty >= 0)
|
||||
{
|
||||
if (duty > 100)
|
||||
duty = 100;
|
||||
else if (duty < 20)
|
||||
duty = 20;
|
||||
if (motor & MOTOR_L)
|
||||
{
|
||||
HAL_GPIO_WritePin(L_FORWARD_GPIO_Port, L_FORWARD_Pin, GPIO_PIN_SET);
|
||||
|
@ -67,6 +74,10 @@ int8_t preProcess(int8_t duty, uint8_t motor)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (duty < -100)
|
||||
duty = -100;
|
||||
else if (duty > -20)
|
||||
duty = -20;
|
||||
if (motor & MOTOR_L)
|
||||
{
|
||||
HAL_GPIO_WritePin(L_FORWARD_GPIO_Port, L_FORWARD_Pin, GPIO_PIN_RESET);
|
||||
|
|
Loading…
Reference in New Issue
Block a user