|
|
|
@ -129,21 +129,6 @@ static int LeiSai_SendSDO(Motor_Instance_t *pstMotor, uint8_t ucCmd, |
|
|
|
return rd_ComIDSend(pstMotor->m_ptCAN, uiFrameID, (char *)aucData, 8); |
|
|
|
} |
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
函 数 名 : LeiSai_UpdateDistance |
|
|
|
功能描述 : 更新距离计算 |
|
|
|
*****************************************************************************/ |
|
|
|
static void LeiSai_UpdateDistance(Motor_Instance_t *pstMotor) |
|
|
|
{ |
|
|
|
double dCircleLength = 3.14 * pstMotor->m_stConfig.m_fWheelDiameter; |
|
|
|
double dDeltaCounts = pstMotor->m_stData.m_iRealPosition - pstMotor->m_stData.m_iStartMeasurePos; |
|
|
|
|
|
|
|
pstMotor->m_stData.m_dRealDistance = (dDeltaCounts / pstMotor->m_stConfig.m_uiPulsePerRound |
|
|
|
/ pstMotor->m_stConfig.m_uiReductionRatio |
|
|
|
+ (double)pstMotor->m_stData.m_iRoundCount) |
|
|
|
* dCircleLength; |
|
|
|
} |
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
函 数 名 : LeiSai_Init |
|
|
|
功能描述 : 初始化电机 |
|
|
|
@ -406,65 +391,14 @@ static int LeiSai_ParseResponse(Motor_Instance_t *pstMotor, const uint8_t *pucDa |
|
|
|
|
|
|
|
switch (usFunctionCode) |
|
|
|
{ |
|
|
|
case LEISAI_OD_POSITION_ACTUAL: |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_iRealPosition = (int32_t)(pucData[4] |
|
|
|
| (pucData[5] << 8) |
|
|
|
| (pucData[6] << 16) |
|
|
|
| (pucData[7] << 24)); |
|
|
|
|
|
|
|
if (pstMotor->m_stData.m_ucStartMeasureFlag == 1) |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_ucStartMeasureFlag = 0; |
|
|
|
pstMotor->m_stData.m_iRoundCount = 0; |
|
|
|
pstMotor->m_stData.m_iStartMeasurePos = pstMotor->m_stData.m_iRealPosition; |
|
|
|
pstMotor->m_stData.m_iLastPosition = pstMotor->m_stData.m_iRealPosition; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (abs(pstMotor->m_stData.m_iRealPosition - pstMotor->m_stData.m_iLastPosition) >= 0x3FFFFFFF) |
|
|
|
{ |
|
|
|
if (pstMotor->m_stData.m_iRealPosition > 0) |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_iRoundCount -= 1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_iRoundCount += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pstMotor->m_stData.m_iLastPosition = pstMotor->m_stData.m_iRealPosition; |
|
|
|
LeiSai_UpdateDistance(pstMotor); |
|
|
|
break; |
|
|
|
} |
|
|
|
case LEISAI_OD_FAULT_CODE: |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_uiFaultCode = (uint32_t)(pucData[4] |
|
|
|
| (pucData[5] << 8) |
|
|
|
| (pucData[6] << 16) |
|
|
|
| (pucData[7] << 24)); |
|
|
|
if (pstMotor->m_stData.m_uiFaultCode != 0) |
|
|
|
{ |
|
|
|
pstMotor->m_eState = MOTOR_STATE_ERROR; |
|
|
|
} |
|
|
|
pstMotor->m_eState = MOTOR_STATE_ERROR; |
|
|
|
break; |
|
|
|
} |
|
|
|
case LEISAI_OD_VELOCITY_ACTUAL: |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_iRealVelocity = (int32_t)(pucData[4] |
|
|
|
| (pucData[5] << 8) |
|
|
|
| (pucData[6] << 16) |
|
|
|
| (pucData[7] << 24)); |
|
|
|
break; |
|
|
|
} |
|
|
|
case LEISAI_OD_TORQUE_ACTUAL: |
|
|
|
{ |
|
|
|
pstMotor->m_stData.m_iRealTorque = (int32_t)(pucData[4] |
|
|
|
| (pucData[5] << 8) |
|
|
|
| (pucData[6] << 16) |
|
|
|
| (pucData[7] << 24)); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
default: |
|
|
|
|