|
|
|
@ -43,6 +43,7 @@ |
|
|
|
static Motor_Instance_t *g_apstMotors[MOTOR_INSTANCE_MAX] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; |
|
|
|
static uint32_t g_uiMotorModuleID = 0; |
|
|
|
static int g_aiMotorSpeed[MOTOR_INSTANCE_MAX] = {0}; |
|
|
|
static int g_isMotorInit = -1; // -1表示还在等待遥控器初始化完毕,0表示可以进行电机初始化,1表示电机初始化完毕,运行电机主循环
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
* 常量定义 * |
|
|
|
@ -72,6 +73,11 @@ static void Motor_ModuleHandler(const Msg_t *pstMsg) |
|
|
|
g_aiMotorSpeed[1] = MotorMgr_SpeedConvert(g_apstMotors[1], aiMotorSpeed[1]); |
|
|
|
break; |
|
|
|
} |
|
|
|
case MOTOR_POWER_ENABLE: |
|
|
|
{ |
|
|
|
g_isMotorInit = 0; |
|
|
|
break; |
|
|
|
} |
|
|
|
case MOTOR_POWER_DISABLE: |
|
|
|
{ |
|
|
|
HAL_GPIO_WritePin(OUT_0_GPIO_Port, OUT_0_Pin, 1); |
|
|
|
@ -125,7 +131,14 @@ static void decode_LeiSaiMotor(const char *_pBuffer, uint32_t _iSize) |
|
|
|
|
|
|
|
void MotorTask(void *argument) |
|
|
|
{ |
|
|
|
// 此时消息中心还未就绪,直接调用HAL库接口给电机上电
|
|
|
|
g_uiMotorModuleID = MsgCenter_Register(MODULE_NAME_MOTOR, Motor_ModuleHandler); |
|
|
|
while(1) |
|
|
|
{ |
|
|
|
// 处理消息
|
|
|
|
MsgCenter_ProcessWait(g_uiMotorModuleID, 2); |
|
|
|
|
|
|
|
if (0 == g_isMotorInit) |
|
|
|
{ |
|
|
|
HAL_GPIO_WritePin(OUT_0_GPIO_Port, OUT_0_Pin, 0); |
|
|
|
// 初始化FDCAN1,使用雷赛电机的回调
|
|
|
|
TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 32, 0); |
|
|
|
@ -153,8 +166,6 @@ void MotorTask(void *argument) |
|
|
|
}; |
|
|
|
g_apstMotors[1] = MotorMgr_Create(&stRightMotorConfig, g_ptCAN1, LeiSai_GetProtocol(), NULL); |
|
|
|
|
|
|
|
g_uiMotorModuleID = MsgCenter_Register(MODULE_NAME_MOTOR, Motor_ModuleHandler); |
|
|
|
|
|
|
|
MotorMgr_ResetAll(g_apstMotors[0]); |
|
|
|
Rd_Delay(500); |
|
|
|
MotorMgr_ResetAll(g_apstMotors[1]); |
|
|
|
@ -173,8 +184,9 @@ void MotorTask(void *argument) |
|
|
|
MotorMgr_SetHome(g_apstMotors[1]); |
|
|
|
MotorMgr_SpeedModeInit(g_apstMotors[0]); |
|
|
|
MotorMgr_SpeedModeInit(g_apstMotors[1]); |
|
|
|
|
|
|
|
while(1) |
|
|
|
g_isMotorInit = 1; |
|
|
|
} |
|
|
|
else if (g_isMotorInit > 0) |
|
|
|
{ |
|
|
|
static int LS_Motor_Config_Count = 0; |
|
|
|
if (LS_Motor_Config_Count <= 200) |
|
|
|
@ -185,8 +197,6 @@ void MotorTask(void *argument) |
|
|
|
MotorMgr_SetWatchdog(g_apstMotors[1], 1000); |
|
|
|
Rd_Delay(4); |
|
|
|
} |
|
|
|
// 处理消息
|
|
|
|
MsgCenter_ProcessWait(g_uiMotorModuleID, 2); |
|
|
|
MotorMgr_RequestPosition(g_apstMotors[0]); |
|
|
|
Rd_Delay(4); |
|
|
|
MotorMgr_RequestPosition(g_apstMotors[1]); |
|
|
|
@ -204,4 +214,5 @@ void MotorTask(void *argument) |
|
|
|
MotorMgr_SetTargetSpeed(g_apstMotors[1], g_aiMotorSpeed[1]); |
|
|
|
Rd_Delay(4); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|