Browse Source

再次优化命令字

master
Lizongdi 22 hours ago
parent
commit
7551a32b13
  1. 17
      RBcore/BHBF.c
  2. 2
      RBcore/client_setting.c
  3. 22
      RBcore/include/BHBF.h
  4. 4
      motor/msp_motor_leisai.c
  5. 12
      project/paint_robot_new/paint_robot_new.c
  6. 2
      project/paint_robot_new/paint_robot_new_motors.c

17
RBcore/BHBF.c

@ -59,7 +59,7 @@ static void RBcore_ModuleHandler(const Msg_t *pstMsg)
static int aiMotorSpeed[2] = {0}; //0索引表示左,1索引表示右,多轮时到对应motor的MOTOR_CMD_SET_SPEED命令自行处理 static int aiMotorSpeed[2] = {0}; //0索引表示左,1索引表示右,多轮时到对应motor的MOTOR_CMD_SET_SPEED命令自行处理
switch (pstMsg->m_uiMsgID) switch (pstMsg->m_uiMsgID)
{ {
case RBCORE_CMD_STOP_ALL: case COMMON_CMD_STOP_ALL:
{ {
MsgCenter_SendTo(MODULE_NAME_MOTOR, pstMsg->m_uiMsgID, NULL, 0); MsgCenter_SendTo(MODULE_NAME_MOTOR, pstMsg->m_uiMsgID, NULL, 0);
break; break;
@ -102,6 +102,21 @@ static void RBcore_ModuleHandler(const Msg_t *pstMsg)
aiMotorSpeed[1] = -g_stCV.RightTurnSpeed; aiMotorSpeed[1] = -g_stCV.RightTurnSpeed;
MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_SET_SPEED, aiMotorSpeed, sizeof(aiMotorSpeed)); MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_SET_SPEED, aiMotorSpeed, sizeof(aiMotorSpeed));
} }
break;
}
case RBCORE_CMD_VERTICAL:
{
break;
}
case RBCORE_CMD_HORIZONTAL_LEFT:
{
break;
}
case RBCORE_CMD_HORIZONTAL_RIGHT:
{
break; break;
} }
case RBCORE_GET_VEHICLE_SPEED: case RBCORE_GET_VEHICLE_SPEED:

2
RBcore/client_setting.c

@ -110,7 +110,7 @@ static void SendIV_ModuleHandler(const Msg_t *pstMsg)
switch (pstMsg->m_uiMsgID) switch (pstMsg->m_uiMsgID)
{ {
case CUSTOM_SET_IV: case SENDIV_SET_IV:
{ {
if (pstMsg->m_uiDataLen >= sizeof(IV)) if (pstMsg->m_uiDataLen >= sizeof(IV))
{ {

22
RBcore/include/BHBF.h

@ -73,13 +73,12 @@ extern "C"{
#define MODULE_NAME_SENDIV "sendiv" #define MODULE_NAME_SENDIV "sendiv"
typedef enum { typedef enum {
LUA_SHOW_INFO, COMMON_CMD_SHOW_INFO, // 终端信息展示
MOTOR_SET_SPEED, // 设置速度 COMMON_CMD_STOP_ALL, // 机器人停止
MOTOR_GET_SPEED, // 获取速度 MOTOR_START = 0x0100, // *电机命令开始*
MOTOR_GET_FAULT_CODE, // 获取错误码 MOTOR_SET_SPEED, // 设置速度
MOTOR_CMD_END = 0x0100, RBCORE_START = 0x0200, // *机器人共性命令开始*
RBCORE_CMD_STOP_ALL, // 机器人停止
RBCORE_CMD_MANUAL_FORWARD, // 机器人手动前进 RBCORE_CMD_MANUAL_FORWARD, // 机器人手动前进
RBCORE_CMD_MANUAL_BACKWARD, // 机器人手动后退 RBCORE_CMD_MANUAL_BACKWARD, // 机器人手动后退
RBCORE_CMD_MANUAL_TURNLEFT, // 机器人手动左转 RBCORE_CMD_MANUAL_TURNLEFT, // 机器人手动左转
@ -87,15 +86,18 @@ typedef enum {
RBCORE_CMD_VERTICAL, // 机器人竖直前进(带PID) RBCORE_CMD_VERTICAL, // 机器人竖直前进(带PID)
RBCORE_CMD_HORIZONTAL_LEFT, // 机器人水平向左(带PID) RBCORE_CMD_HORIZONTAL_LEFT, // 机器人水平向左(带PID)
RBCORE_CMD_HORIZONTAL_RIGHT, // 机器人水平向右(带PID) RBCORE_CMD_HORIZONTAL_RIGHT, // 机器人水平向右(带PID)
RBCORE_GET_VEHICLE_SPEED, // 获取机器人速度 RBCORE_GET_VEHICLE_SPEED, // 获取机器人速度(内部速度归一化)
RBCORE_CMD_END = 0x0200, CUSTOM_START = 0x0300, // *机器人特性命令开始*
CUSTOM_GET_PV, // 获取PV CUSTOM_GET_PV, // 获取PV
CUSTOM_SET_IV, // 设置IV
CUSTOM_GET_MK32, // 获取MK32 CUSTOM_GET_MK32, // 获取MK32
CUSTOM_GET_TL720D_ROLL, // 获取陀螺仪横滚角 CUSTOM_GET_TL720D_ROLL, // 获取陀螺仪横滚角
CUSTOM_GET_SPEED, // 获取速度(电机回码)
CUSTOM_GET_FAULT_CODE, // 获取错误码(电机回码)
CUSTOM_CMD_PAINTGUN, // 控制喷枪 CUSTOM_CMD_PAINTGUN, // 控制喷枪
CUSTOM_CMD_END = 0x0300, SENDIV_START = 0x0400, // *IV发送线程命令(一般低优先级事项也放到这)*
SENDIV_SET_IV, // 设置IV
} BHBF_Cmd_e; } BHBF_Cmd_e;
/*==============================================* /*==============================================*

4
motor/msp_motor_leisai.c

@ -406,7 +406,7 @@ static int LeiSai_ParseResponse(Motor_Instance_t *pstMotor, const uint8_t *pucDa
{ {
pstMotor->m_eState = MOTOR_STATE_ERROR; pstMotor->m_eState = MOTOR_STATE_ERROR;
} }
MsgCenter_SendTo(MODULE_NAME_CUSTOM, MOTOR_GET_FAULT_CODE, uiFaultCode, sizeof(uiFaultCode)); MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_GET_FAULT_CODE, uiFaultCode, sizeof(uiFaultCode));
break; break;
} }
case LEISAI_OD_VELOCITY_ACTUAL: case LEISAI_OD_VELOCITY_ACTUAL:
@ -418,7 +418,7 @@ static int LeiSai_ParseResponse(Motor_Instance_t *pstMotor, const uint8_t *pucDa
| (pucData[7] << 24)); | (pucData[7] << 24));
iRealVelocity[1] = MotorMgr_SpeedConvertex(pstMotor, iRealVelocity[0]); iRealVelocity[1] = MotorMgr_SpeedConvertex(pstMotor, iRealVelocity[0]);
iRealVelocity[0] = pstMotor->m_stConfig.m_ucMotorID; iRealVelocity[0] = pstMotor->m_stConfig.m_ucMotorID;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, MOTOR_GET_SPEED, iRealVelocity, sizeof(iRealVelocity)); MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_GET_SPEED, iRealVelocity, sizeof(iRealVelocity));
log_d("iRealVelocity[1] = %d", iRealVelocity[1]); log_d("iRealVelocity[1] = %d", iRealVelocity[1]);
break; break;
} }

12
project/paint_robot_new/paint_robot_new.c

@ -67,7 +67,7 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
switch (pstMsg->m_uiMsgID) switch (pstMsg->m_uiMsgID)
{ {
case MOTOR_GET_FAULT_CODE: case CUSTOM_GET_FAULT_CODE:
{ {
uint32_t uiFailtCode[2] = {0}; uint32_t uiFailtCode[2] = {0};
if (pstMsg->m_uiDataLen >= sizeof(uiFailtCode)) if (pstMsg->m_uiDataLen >= sizeof(uiFailtCode))
@ -76,7 +76,7 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
} }
break; break;
} }
case MOTOR_GET_SPEED: case CUSTOM_GET_SPEED:
{ {
int32_t iCurrentSpeed[2] = {0}; int32_t iCurrentSpeed[2] = {0};
if (pstMsg->m_uiDataLen >= sizeof(iCurrentSpeed)) if (pstMsg->m_uiDataLen >= sizeof(iCurrentSpeed))
@ -145,7 +145,7 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
if (abs(g_stMK32.CH2_LY_V) <= g_stCV.Joy_Sticker_Value_Allowance && abs(g_stMK32.CH3_LY_H) <= g_stCV.Joy_Sticker_Value_Allowance) if (abs(g_stMK32.CH2_LY_V) <= g_stCV.Joy_Sticker_Value_Allowance && abs(g_stMK32.CH3_LY_H) <= g_stCV.Joy_Sticker_Value_Allowance)
{ {
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0); MsgCenter_SendTo(MODULE_NAME_RBCORE, COMMON_CMD_STOP_ALL, NULL, 0);
break; break;
} }
@ -169,11 +169,11 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
} }
else else
{ {
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0); MsgCenter_SendTo(MODULE_NAME_RBCORE, COMMON_CMD_STOP_ALL, NULL, 0);
} }
break; break;
} }
case LUA_SHOW_INFO: case COMMON_CMD_SHOW_INFO:
{ {
lua_print("MK32 Info\nRxIndex:%d\tIsOnline:%d\n", g_stMK32.RxIndex, g_stMK32.IsOnline); lua_print("MK32 Info\nRxIndex:%d\tIsOnline:%d\n", g_stMK32.RxIndex, g_stMK32.IsOnline);
lua_print("CH0_RY_H\t%d\n", g_stMK32.CH0_RY_H); lua_print("CH0_RY_H\t%d\n", g_stMK32.CH0_RY_H);
@ -214,7 +214,7 @@ void Custom_Task(void *argument)
if ((int32_t)(uiNowTick - uiLastSendTick) >= IV_SEND_TIME) if ((int32_t)(uiNowTick - uiLastSendTick) >= IV_SEND_TIME)
{ {
uiLastSendTick = uiNowTick; uiLastSendTick = uiNowTick;
MsgCenter_SendTo(MODULE_NAME_SENDIV, CUSTOM_SET_IV, (void *)&g_stIV, sizeof(g_stIV)); MsgCenter_SendTo(MODULE_NAME_SENDIV, SENDIV_SET_IV, (void *)&g_stIV, sizeof(g_stIV));
} }
} }
} }

2
project/paint_robot_new/paint_robot_new_motors.c

@ -72,7 +72,7 @@ static void Motor_ModuleHandler(const Msg_t *pstMsg)
g_aiMotorSpeed[1] = MotorMgr_SpeedConvert(g_apstMotors[1], aiMotorSpeed[1]); g_aiMotorSpeed[1] = MotorMgr_SpeedConvert(g_apstMotors[1], aiMotorSpeed[1]);
break; break;
} }
case RBCORE_CMD_STOP_ALL: case COMMON_CMD_STOP_ALL:
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {

Loading…
Cancel
Save