Browse Source

1.增加电机看门狗2.增加前进时界面不可控逻辑3.修复推SB时仍使用手动速度

paint_robot_new-v1.5
Lizongdi 2 weeks ago
parent
commit
64ea45148c
  1. 1
      RBcore/BHBF.c
  2. 1
      RBcore/include/BHBF.h
  3. 78
      project/paint_robot_new/paint_robot_new.c
  4. 35
      project/paint_robot_new/paint_robot_new_motors.c

1
RBcore/BHBF.c

@ -68,6 +68,7 @@ static void RBcore_ModuleHandler(const Msg_t *pstMsg)
case RBCORE_CMD_STOP_ALL:
{
MsgCenter_SendTo(MODULE_NAME_MOTOR, COMMON_CMD_STOP_ALL, NULL, 0);
MsgCenter_SendTo(MODULE_NAME_CUSTOM, COMMON_CMD_STOP_ALL, NULL, 0);
break;
}
case RBCORE_GET_TL720D_ROLL:

1
RBcore/include/BHBF.h

@ -78,7 +78,6 @@ typedef enum {
MOTOR_START = 0x0100, // *电机命令开始*
MOTOR_SET_SPEED, // 设置速度
MOTOR_POWER_DISABLE, // 电机失电
MOTOR_POWER_ENABLE, // 电机上电
RBCORE_START = 0x0200, // *机器人共性命令开始*
RBCORE_CMD_STOP_ALL, // 此命令统一调用机器人各个模块的COMMON_CMD_STOP_ALL

78
project/paint_robot_new/paint_robot_new.c

@ -183,6 +183,11 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
}
break;
}
case COMMON_CMD_STOP_ALL:
{
HAL_GPIO_WritePin(OUT_1_GPIO_Port, OUT_1_Pin, 1);
break;
}
case CUSTOM_CMD_PAINTGUN:
{
int paintstate = -1;
@ -218,16 +223,45 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
g_stIV.RobotMoveSpeed = iVehicleSpeed;
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_GET_VEHICLE_SPEED, (void *)&iVehicleSpeed, sizeof(int));
// 开关喷枪
if (g_stMK32.CH6_SC == -1000)
// 按键处于默认位置安卓界面可控
if ((fabs(g_stMK32.CH2_LY_V) <= 200) && (fabs(g_stMK32.CH3_LY_H) <= 200)
&& (fabs(g_stMK32.CH0_RY_H) <= 200) && (fabs(g_stMK32.CH1_RY_V) <= 200)
&& (g_stMK32.CH4_SA ==0) && (g_stMK32.CH5_SB == 0)
&& (g_stMK32.CH6_SC != -1000) )
{
int paintstate = 0;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_CMD_PAINTGUN, &paintstate, sizeof(int));
g_stIV.IsWorking = 0;
}
else
{
int paintstate = 1;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_CMD_PAINTGUN, &paintstate, sizeof(int));
g_stIV.IsWorking = 1;
}
// 开关喷枪
if (g_stPV.RunMode == 1)
{
if (g_stMK32.CH6_SC == -1000)
{
int paintstate = 0;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_CMD_PAINTGUN, &paintstate, sizeof(int));
}
else
{
int paintstate = 1;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_CMD_PAINTGUN, &paintstate, sizeof(int));
}
}
else if(g_stPV.RunMode == 2 || g_stPV.RunMode == 3)
{
static int CH13_S2_Value = 0;
if (g_stMK32.CH13_S2 != CH13_S2_Value)
{
if(g_stIV.CurrentSpeed != 0)
{
int paintstate = 0;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_CMD_PAINTGUN, &paintstate, sizeof(int));
}
}
CH13_S2_Value = g_stMK32.CH13_S2;
}
int iTargetAngle = 0;
@ -271,12 +305,36 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
// 自动巡航
if (g_stMK32.CH5_SB == -1000)
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0);
if (g_stPV.RunMode == 1)
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0);
}
else if (g_stPV.RunMode == 2 || g_stPV.RunMode == 3)
{
BHBF_straight_drive_Cmd stCmd = {
.m_iMode = 1,
.m_iAngle = g_stCV.RobotUpAngleValue + g_stPV.Vertical_Calibration,
.m_iTime = -1
};
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STRAIGHT_DRIVE, &stCmd, sizeof(stCmd));
}
break;
}
else if(g_stMK32.CH5_SB == 1000)
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0);
if (g_stPV.RunMode == 1)
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0);
}
else if (g_stPV.RunMode == 2 || g_stPV.RunMode == 3)
{
BHBF_straight_drive_Cmd stCmd = {
.m_iMode = -1,
.m_iAngle = g_stCV.RobotUpAngleValue + g_stPV.Vertical_Calibration,
.m_iTime = -1
};
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STRAIGHT_DRIVE, &stCmd, sizeof(stCmd));
}
break;
}
@ -297,7 +355,7 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0);
}
else
else if (g_stPV.RunMode == 2 || g_stPV.RunMode == 3)
{
BHBF_straight_drive_Cmd stCmd = {
.m_iMode = 1,
@ -313,7 +371,7 @@ static void Custom_ModuleHandler(const Msg_t *pstMsg)
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0);
}
else
else if (g_stPV.RunMode == 2 || g_stPV.RunMode == 3)
{
BHBF_straight_drive_Cmd stCmd = {
.m_iMode = -1,

35
project/paint_robot_new/paint_robot_new_motors.c

@ -72,11 +72,6 @@ static void Motor_ModuleHandler(const Msg_t *pstMsg)
g_aiMotorSpeed[1] = MotorMgr_SpeedConvert(g_apstMotors[1], aiMotorSpeed[1]);
break;
}
case MOTOR_POWER_ENABLE:
{
HAL_GPIO_WritePin(OUT_0_GPIO_Port, OUT_0_Pin, 0);
break;
}
case MOTOR_POWER_DISABLE:
{
HAL_GPIO_WritePin(OUT_0_GPIO_Port, OUT_0_Pin, 1);
@ -84,10 +79,6 @@ static void Motor_ModuleHandler(const Msg_t *pstMsg)
}
case COMMON_CMD_STOP_ALL:
{
for (int i = 0; i < 2; i++)
{
MotorMgr_SetTargetSpeed(g_apstMotors[i], 0);
}
memset(g_aiMotorSpeed, 0, sizeof(g_aiMotorSpeed));
break;
}
@ -177,24 +168,32 @@ void MotorTask(void *argument)
while(1)
{
static int LS_Motor_Config_Count = 0;
if (LS_Motor_Config_Count <= 200)
{
LS_Motor_Config_Count++;
MotorMgr_SetWatchdog(g_apstMotors[0], 1000);
Rd_Delay(4);
MotorMgr_SetWatchdog(g_apstMotors[1], 1000);
Rd_Delay(4);
}
// 处理消息
MsgCenter_ProcessWait(g_uiMotorModuleID, 2);
Rd_Delay(10);
MotorMgr_RequestPosition(g_apstMotors[0]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_RequestPosition(g_apstMotors[1]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_RequestFault(g_apstMotors[0]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_RequestFault(g_apstMotors[1]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_RequestVelocity(g_apstMotors[0]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_RequestVelocity(g_apstMotors[1]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_SetTargetSpeed(g_apstMotors[0], g_aiMotorSpeed[0]);
Rd_Delay(10);
Rd_Delay(4);
MotorMgr_SetTargetSpeed(g_apstMotors[1], g_aiMotorSpeed[1]);
Rd_Delay(10);
Rd_Delay(4);
}
}

Loading…
Cancel
Save