|
|
|
@ -19,6 +19,7 @@ |
|
|
|
|
|
|
|
#include "msp_motor_leisai.h" |
|
|
|
#include "rd_time.h" |
|
|
|
#include "BHBF.h" |
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
* 外部变量说明 * |
|
|
|
@ -52,6 +53,7 @@ static int LeiSai_SetTargetPosition(Motor_Instance_t *pstMotor, int32_t iTargetP |
|
|
|
static int LeiSai_SetDO(Motor_Instance_t *pstMotor, uint8_t ucDoIndex, uint8_t ucState); |
|
|
|
static int LeiSai_ParseResponse(Motor_Instance_t *pstMotor, const uint8_t *pucData, uint32_t uiLen); |
|
|
|
static int32_t LeiSai_SpeedConvert(Motor_Instance_t *pstMotor, int32_t iSpeedE01Mmin); |
|
|
|
static int32_t LeiSai_SpeedConvertex(Motor_Instance_t *pstMotor, int32_t iSpeedCount); |
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
* 全局变量 * |
|
|
|
@ -76,6 +78,7 @@ const Motor_Protocol_t g_stLeiSaiProtocol = { |
|
|
|
.pfSetDO = LeiSai_SetDO, |
|
|
|
.pfParseResponse = LeiSai_ParseResponse, |
|
|
|
.pfSpeedConvert = LeiSai_SpeedConvert, |
|
|
|
.pfSpeedConvertex = LeiSai_SpeedConvertex, |
|
|
|
}; |
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
@ -393,12 +396,29 @@ static int LeiSai_ParseResponse(Motor_Instance_t *pstMotor, const uint8_t *pucDa |
|
|
|
{ |
|
|
|
case LEISAI_OD_FAULT_CODE: |
|
|
|
{ |
|
|
|
pstMotor->m_eState = MOTOR_STATE_ERROR; |
|
|
|
uint32_t uiFaultCode[2] = {0}; |
|
|
|
uiFaultCode[1] = (uint32_t)(pucData[4] |
|
|
|
| (pucData[5] << 8) |
|
|
|
| (pucData[6] << 16) |
|
|
|
| (pucData[7] << 24)); |
|
|
|
uiFaultCode[0] = pstMotor->m_stConfig.m_ucMotorID; |
|
|
|
if (uiFaultCode[1] != 0) |
|
|
|
{ |
|
|
|
pstMotor->m_eState = MOTOR_STATE_ERROR; |
|
|
|
} |
|
|
|
MsgCenter_SendTo(MODULE_NAME_CUSTOM, MOTOR_CMD_GET_FAULT_CODE, uiFaultCode, sizeof(uiFaultCode)); |
|
|
|
break; |
|
|
|
} |
|
|
|
case LEISAI_OD_VELOCITY_ACTUAL: |
|
|
|
{ |
|
|
|
|
|
|
|
int32_t iRealVelocity[2] = {0}; |
|
|
|
iRealVelocity[0] = (int32_t)(pucData[4] |
|
|
|
| (pucData[5] << 8) |
|
|
|
| (pucData[6] << 16) |
|
|
|
| (pucData[7] << 24)); |
|
|
|
iRealVelocity[1] = MotorMgr_SpeedConvertex(pstMotor, iRealVelocity[0]); |
|
|
|
iRealVelocity[0] = pstMotor->m_stConfig.m_ucMotorID; |
|
|
|
MsgCenter_SendTo(MODULE_NAME_CUSTOM, MOTOR_CMD_GET_SPEED, iRealVelocity, sizeof(iRealVelocity)); |
|
|
|
break; |
|
|
|
} |
|
|
|
default: |
|
|
|
@ -427,3 +447,19 @@ static int32_t LeiSai_SpeedConvert(Motor_Instance_t *pstMotor, int32_t iSpeedE01 |
|
|
|
|
|
|
|
return (int32_t)dPulsePerSec; |
|
|
|
} |
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
函 数 名 : LeiSai_SpeedConvertex |
|
|
|
功能描述 : 速度单位转换:脉冲/秒 -> m/min |
|
|
|
*****************************************************************************/ |
|
|
|
static int32_t LeiSai_SpeedConvertex(Motor_Instance_t *pstMotor, int32_t iSpeedCount) |
|
|
|
{ |
|
|
|
if (NULL == pstMotor) |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
double dPulsePerSec = iSpeedCount*60.0/pstMotor->m_stConfig.m_uiPulsePerRound/pstMotor->m_stConfig.m_uiReductionRatio* 3.14 * pstMotor->m_stConfig.m_fWheelDiameter; |
|
|
|
|
|
|
|
return (int32_t)dPulsePerSec; |
|
|
|
} |
|
|
|
|