|
|
|
@ -81,34 +81,6 @@ static void Motor_ModuleHandler(const Msg_t *pstMsg) |
|
|
|
memset(g_aiMotorSpeed, 0, sizeof(g_aiMotorSpeed)); |
|
|
|
break; |
|
|
|
} |
|
|
|
case MOTOR_CMD_SET_HOME: |
|
|
|
{ |
|
|
|
log_i("Not Support [%d]", pstMsg->m_uiMsgID); |
|
|
|
break; |
|
|
|
} |
|
|
|
case MOTOR_CMD_GET_STATUS: |
|
|
|
{ |
|
|
|
// 回复状态给请求者
|
|
|
|
Motor_StatusData_t stStatus; |
|
|
|
for (int i = 0; i < 2; i++) |
|
|
|
{ |
|
|
|
if (g_apstMotors[i] != NULL) |
|
|
|
{ |
|
|
|
const Motor_Data_t *pstData = MotorMgr_GetData(g_apstMotors[i]); |
|
|
|
if (pstData != NULL) |
|
|
|
{ |
|
|
|
stStatus.m_ucMotorIndex = i; |
|
|
|
stStatus.m_iPosition = pstData->m_iRealPosition; |
|
|
|
stStatus.m_iVelocity = pstData->m_iRealVelocity; |
|
|
|
stStatus.m_uiFaultCode = pstData->m_uiFaultCode; |
|
|
|
|
|
|
|
// 回复给请求者
|
|
|
|
MsgCenter_SendTo(MODULE_NAME_RBCORE, 0x10, &stStatus, sizeof(stStatus)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -118,21 +90,12 @@ static void Motor_ModuleHandler(const Msg_t *pstMsg) |
|
|
|
// 雷赛响应ID范围:0x581 - 0x5FF (0x580 + MotorID)
|
|
|
|
static int check_LeiSaiMotor(char *_pBuffer, uint32_t _iSize) |
|
|
|
{ |
|
|
|
if (NULL == _pBuffer || _iSize < 4) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
TCANUserData *ptCANUserData = (TCANUserData *)g_ptCAN1->m_pUserData; |
|
|
|
uint32_t iCANId = (uint32_t)ptCANUserData->m_canrx->Identifier; |
|
|
|
|
|
|
|
// 从buffer中提取CAN ID(前4字节)
|
|
|
|
uint32_t uiFrameID = (uint32_t)(_pBuffer[0] & 0xFF) |
|
|
|
| ((_pBuffer[1] & 0xFF) << 8) |
|
|
|
| ((_pBuffer[2] & 0xFF) << 16) |
|
|
|
| ((_pBuffer[3] & 0xFF) << 24); |
|
|
|
|
|
|
|
// 雷赛响应ID范围:0x581 - 0x5FF
|
|
|
|
if (uiFrameID >= 0x581 && uiFrameID <= 0x5FF) |
|
|
|
if (iCANId >= 0x581 && iCANId <= 0x5FF) |
|
|
|
{ |
|
|
|
return 8 + 4; // 数据长度8 + CAN ID长度4
|
|
|
|
return _iSize; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
@ -141,22 +104,14 @@ static int check_LeiSaiMotor(char *_pBuffer, uint32_t _iSize) |
|
|
|
// 雷赛电机CAN响应解码函数
|
|
|
|
static void decode_LeiSaiMotor(const char *_pBuffer, uint32_t _iSize) |
|
|
|
{ |
|
|
|
if (NULL == _pBuffer || _iSize < 12) // 4字节CAN ID + 8字节数据
|
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 从buffer中提取CAN ID
|
|
|
|
uint32_t uiFrameID = (uint32_t)(_pBuffer[0] & 0xFF) |
|
|
|
| ((_pBuffer[1] & 0xFF) << 8) |
|
|
|
| ((_pBuffer[2] & 0xFF) << 16) |
|
|
|
| ((_pBuffer[3] & 0xFF) << 24); |
|
|
|
TCANUserData *ptCANUserData = (TCANUserData *)g_ptCAN1->m_pUserData; |
|
|
|
uint32_t iCANId = (uint32_t)ptCANUserData->m_canrx->Identifier; |
|
|
|
|
|
|
|
// 提取电机ID (0x580 + MotorID)
|
|
|
|
uint8_t ucMotorID = (uint8_t)(uiFrameID - 0x580); |
|
|
|
uint8_t ucMotorID = (uint8_t)(iCANId - 0x580); |
|
|
|
|
|
|
|
// 调用电机管理模块解析响应
|
|
|
|
MotorMgr_ParseResponse(ucMotorID, (const uint8_t *)&_pBuffer[4], 8); |
|
|
|
MotorMgr_ParseResponse(ucMotorID, (const uint8_t *)_pBuffer, _iSize); |
|
|
|
} |
|
|
|
|
|
|
|
void MotorTask(void *argument) |
|
|
|
@ -224,7 +179,5 @@ void MotorTask(void *argument) |
|
|
|
MotorMgr_SetTargetSpeed(g_apstMotors[i], g_aiMotorSpeed[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Rd_Delay(2); // 2ms周期
|
|
|
|
} |
|
|
|
} |
|
|
|
|