You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.0 KiB

3 months ago
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: BHBF.c
3 months ago
: 稿
: radkil
: 202668
:
:
:
1. : 202668
: radkil
:
******************************************************************************/
#include "BHBF.h"
3 months ago
#include "common.h"
#include "msg_center.h"
3 months ago
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
static uint32_t g_uiRBcoreModuleID = 0;
3 months ago
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
static void RBcore_ModuleHandler(const Msg_t *pstMsg)
3 months ago
{
if (NULL == pstMsg)
{
return;
}
3 months ago
static int iSpeed = -1;
static int aiMotorSpeed[2] = {0}; //0索引表示左,1索引表示右,多轮时到对应motor的MOTOR_CMD_SET_SPEED命令自行处理
switch (pstMsg->m_uiMsgID)
{
case CMD_STOP_ALL:
{
MsgCenter_SendTo(MODULE_NAME_MOTOR, pstMsg->m_uiMsgID, NULL, 0);
break;
}
case RBCORE_CMD_MANUAL_FORWARD:
{
if (iSpeed >= 0)
{
aiMotorSpeed[0] = iSpeed;
aiMotorSpeed[1] = iSpeed;
12 hours ago
MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_SET_SPEED, aiMotorSpeed, sizeof(aiMotorSpeed));
}
break;
}
case RBCORE_CMD_MANUAL_BACKWARD:
{
if (iSpeed >= 0)
{
aiMotorSpeed[0] = -iSpeed;
aiMotorSpeed[1] = -iSpeed;
12 hours ago
MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_SET_SPEED, aiMotorSpeed, sizeof(aiMotorSpeed));
}
break;
}
case RBCORE_CMD_MANUAL_TURNLEFT:
{
if (g_stCV.LeftTurnSpeed > 0 && g_stCV.RightTurnSpeed > 0)
{
aiMotorSpeed[0] = -g_stCV.LeftTurnSpeed;
aiMotorSpeed[1] = g_stCV.RightTurnSpeed;
12 hours ago
MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_SET_SPEED, aiMotorSpeed, sizeof(aiMotorSpeed));
}
break;
}
case RBCORE_CMD_MANUAL_TURNRIGHT:
{
if (g_stCV.LeftTurnSpeed > 0 && g_stCV.RightTurnSpeed > 0)
{
aiMotorSpeed[0] = g_stCV.LeftTurnSpeed;
aiMotorSpeed[1] = -g_stCV.RightTurnSpeed;
12 hours ago
MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_SET_SPEED, aiMotorSpeed, sizeof(aiMotorSpeed));
}
break;
}
case RBCORE_GET_VEHICLE_SPEED:
{
if (pstMsg->m_uiDataLen >= sizeof(int))
{
RD_MEMCPY(&iSpeed, pstMsg->m_aucData, sizeof(int));
iSpeed *= 10;
}
break;
}
default:
break;
}
3 months ago
}
void RBcore_Task(void *argument)
3 months ago
{
while(1)
{
// 处理消息
MsgCenter_ProcessWait(g_uiRBcoreModuleID, 2);
3 months ago
}
}
void RBcore_Init(void)
3 months ago
{
g_uiRBcoreModuleID = MsgCenter_Register(MODULE_NAME_RBCORE, RBcore_ModuleHandler);
const osThreadAttr_t GF_Dispatch_attributes = {
.name = MODULE_NAME_RBCORE,
.stack_size = 2048,
.priority = (osPriority_t) osPriorityRealtime1,
};
(void)osThreadNew(RBcore_Task, NULL, &GF_Dispatch_attributes);
3 months ago
}