diff --git a/project/paint_robot_new/paint_robot_new.c b/project/paint_robot_new/paint_robot_new.c index f229140..f5d29cd 100644 --- a/project/paint_robot_new/paint_robot_new.c +++ b/project/paint_robot_new/paint_robot_new.c @@ -67,6 +67,29 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg) switch (pstMsg->m_uiMsgID) { + case MOTOR_CMD_GET_FAULT_CODE: + { + uint32_t uiFailtCode[2] = {0}; + if (pstMsg->m_uiDataLen >= sizeof(uiFailtCode)) + { + RD_MEMCPY(uiFailtCode, pstMsg->m_aucData, sizeof(uiFailtCode)); + } + break; + } + case MOTOR_CMD_GET_SPEED: + { + int32_t iCurrentSpeed[2] = {0}; + if (pstMsg->m_uiDataLen >= sizeof(iCurrentSpeed)) + { + RD_MEMCPY(iCurrentSpeed, pstMsg->m_aucData, sizeof(iCurrentSpeed)); + if (1 == iCurrentSpeed[0]) + { + g_stIV.CurrentSpeed = iCurrentSpeed[1]; + log_i("g_stIV.CurrentSpeed = %d", g_stIV.CurrentSpeed); + } + } + break; + } case CUSTOM_GET_TL720D_ROLL: { if (pstMsg->m_uiDataLen >= sizeof(int32_t)) diff --git a/project/paint_robot_new/paint_robot_new_motors.c b/project/paint_robot_new/paint_robot_new_motors.c index 8cf75f8..3a76e3c 100644 --- a/project/paint_robot_new/paint_robot_new_motors.c +++ b/project/paint_robot_new/paint_robot_new_motors.c @@ -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周期 } }