98 lines
2.0 KiB
C
98 lines
2.0 KiB
C
#include "mw_motor.h"
|
|
#include "bsp_motor.h"
|
|
#include <stdint.h>
|
|
|
|
/*************************************************************************************
|
|
* @brief 驱动器左轮转动
|
|
* @param[in/out] Speed【参数注释】
|
|
*
|
|
* @warning 【不可重入,阻塞等警告】
|
|
* @note 【重大修改】
|
|
*************************************************************************************/
|
|
void mw_SetMotorSpeed_Left(int8_t Speed)
|
|
{
|
|
if (Speed >0)
|
|
{
|
|
bsp_AIN1_ON();
|
|
bsp_AIN2_OFF();
|
|
bsp_changeLeftMotorSpeed(Speed);
|
|
}
|
|
else if(Speed==0)
|
|
{
|
|
bsp_AIN1_ON();
|
|
bsp_AIN2_ON();
|
|
bsp_changeLeftMotorSpeed(Speed);
|
|
}
|
|
else
|
|
{
|
|
bsp_AIN1_OFF();
|
|
bsp_AIN2_ON();
|
|
bsp_changeLeftMotorSpeed(-Speed);
|
|
}
|
|
}
|
|
/*************************************************************************************
|
|
* @brief 驱动器右轮转动
|
|
* @param[in/out] Speed【参数注释】
|
|
*
|
|
* @warning 【不可重入,阻塞等警告】
|
|
* @note 【重大修改】
|
|
*************************************************************************************/
|
|
void mw_SetMotorSpeed_Right(int8_t Speed)
|
|
{
|
|
if (Speed >0)
|
|
{
|
|
bsp_BIN1_ON();
|
|
bsp_BIN2_OFF();
|
|
bsp_changeRightMotorSpeed(Speed);
|
|
}
|
|
else if(Speed==0)
|
|
{
|
|
bsp_BIN1_ON();
|
|
bsp_BIN2_ON();
|
|
bsp_changeRightMotorSpeed(Speed);
|
|
}
|
|
else
|
|
{
|
|
bsp_BIN1_OFF();
|
|
bsp_BIN2_ON();
|
|
bsp_changeRightMotorSpeed(-Speed);
|
|
}
|
|
}
|
|
|
|
void mw_motor_goAhead(int8_t speed)
|
|
{
|
|
mw_SetMotorSpeed_Left(speed);
|
|
mw_SetMotorSpeed_Right(-speed);
|
|
}
|
|
void mw_motor_goBack(int8_t speed)
|
|
{
|
|
mw_SetMotorSpeed_Left(-speed);
|
|
mw_SetMotorSpeed_Right(speed);
|
|
}
|
|
void mw_motor_turnLeft(int8_t speed)
|
|
{
|
|
mw_SetMotorSpeed_Left(speed);
|
|
mw_SetMotorSpeed_Right(0);
|
|
}
|
|
void mw_motor_turnRight(int8_t speed)
|
|
{
|
|
mw_SetMotorSpeed_Left(0);
|
|
mw_SetMotorSpeed_Right(-speed);
|
|
}
|
|
void mw_motor_selfLeft(int8_t speed)
|
|
{
|
|
mw_SetMotorSpeed_Left(-speed);
|
|
mw_SetMotorSpeed_Right(-speed);
|
|
}
|
|
void mw_motor_selfRight(int8_t speed)
|
|
{
|
|
mw_SetMotorSpeed_Left(speed);
|
|
mw_SetMotorSpeed_Right(speed);
|
|
}
|
|
void mw_motor_stop(void)
|
|
{
|
|
mw_SetMotorSpeed_Left(0);
|
|
mw_SetMotorSpeed_Right(0);
|
|
}
|
|
|