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.

187 lines
5.6 KiB

/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: paint_robot_new.c
: 稿
: radkil
: 2026714
:
:
:
1. : 2026714
: radkil
:
******************************************************************************/
#include "BHBF.h"
#include "msg_center.h"
#include "../Protobuf/PSource/msp_MK32.pb.h"
#include "../Protobuf/PSource/bsp_PV.pb.h"
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
2 days ago
static SP_MSP_MK32_Button RB_MK32;
static uint32_t g_uiCustomModuleID = 0;
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
4 days ago
int check_MK32(char *_pBuffer, uint32_t _iSize)
{
if (_iSize < 25) return 0; // 数据不足25字节,不读[24]不误判,等下一包
if (_pBuffer[0] != 0x0f) return -1;
if (_pBuffer[24] != 0x00) return -1;
return 25;
}
4 days ago
void decode_MK32(const char *buf, uint32_t _iSize)
{
int32_t CH[16];
int Start_byte = 0;
CH[0] = ((buf[Start_byte + 1] | buf[Start_byte + 2] << 8) & 0x07FF);
CH[1] = ((buf[Start_byte + 2] >> 3 | buf[Start_byte + 3] << 5) & 0x07FF);
CH[2] = ((buf[Start_byte + 3] >> 6 | buf[Start_byte + 4] << 2
| buf[Start_byte + 5] << 10) & 0x07FF);
CH[3] = ((buf[Start_byte + 5] >> 1 | buf[Start_byte + 6] << 7) & 0x07FF);
CH[4] = ((buf[Start_byte + 6] >> 4 | buf[Start_byte + 7] << 4) & 0x07FF);
CH[5] = ((buf[Start_byte + 7] >> 7 | buf[Start_byte + 8] << 1
| buf[Start_byte + 9] << 9) & 0x07FF);
CH[6] = ((buf[Start_byte + 9] >> 2 | buf[Start_byte + 10] << 6) & 0x07FF);
CH[7] = ((buf[Start_byte + 10] >> 5 | buf[Start_byte + 11] << 3) & 0x07FF);
CH[8] = ((buf[Start_byte + 12] | buf[Start_byte + 13] << 8) & 0x07FF);
CH[9] = ((buf[Start_byte + 13] >> 3 | buf[Start_byte + 14] << 5) & 0x07FF);
CH[10] = ((buf[Start_byte + 14] >> 6 | buf[Start_byte + 15] << 2
| buf[Start_byte + 16] << 10) & 0x07FF);
CH[11] = ((buf[Start_byte + 16] >> 1 | buf[Start_byte + 17] << 7) & 0x07FF);
CH[12] = ((buf[Start_byte + 17] >> 4 | buf[Start_byte + 18] << 4) & 0x07FF);
CH[13] = ((buf[Start_byte + 18] >> 7 | buf[Start_byte + 19] << 1
| buf[Start_byte + 20] << 9) & 0x07FF);
CH[14] = ((buf[Start_byte + 20] >> 2 | buf[Start_byte + 21] << 6) & 0x07FF);
CH[15] = ((buf[Start_byte + 21] >> 5 | buf[Start_byte + 22] << 3) & 0x07FF);
// 按键数值转换:1050为中间值,272-1712
for (int i = 0; i < 16; i++)
{
CH[i] = (int32_t)((CH[i] - 992) * 1.388889);
}
RD_MEMCPY(&(RB_MK32.CH0_RY_H), CH, sizeof(CH));
if (buf[23] == 0)
{
RB_MK32.IsOnline = 1;
}
else
{
RB_MK32.IsOnline = 0;
}
RB_MK32.RxIndex++;
4 days ago
int angle;
angle = atan2(RB_MK32.CH1_RY_V, RB_MK32.CH0_RY_H) * 180 / M_PI;
4 days ago
if(RB_MK32.CH5_SB == 0)
{
// 前进
if((angle >= 45) && (angle <= 135))
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0);
}
// 后退
else if((angle >= -135) && (angle < -45))
{
4 days ago
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0);
}
else
{
4 days ago
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0);
}
4 days ago
}
else
{
// 前进
if((angle >= 45) && (angle <= 135))
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0);
}
// 后退
else if((angle >= -135) && (angle < -45))
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0);
}
else
{
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0);
}
}
}
static void Custom_ModuleHandler(const Msg_t *pstMsg)
{
if (NULL == pstMsg)
{
return;
}
switch (pstMsg->m_uiMsgID)
{
case CUSTOM_GET_PV:
{
//log_i("RBCORE_CMD_STOP_ALL");
Motor_CmdData_t tMotor_CmdData_t = {0};
tMotor_CmdData_t.m_ucMotorIndex = 1;
tMotor_CmdData_t.m_iValue = (int32_t)pstMsg->m_aucData;
MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_CMD_SET_SPEED, (void *)&tMotor_CmdData_t, sizeof(Motor_CmdData_t));
break;
}
default:
break;
}
}
void Custom_Task(void *argument)
{
while(1)
{
MsgCenter_ProcessWait(g_uiCustomModuleID, 2);
}
}
void Custom_Init(void)
{
g_uiCustomModuleID = MsgCenter_Register(MODULE_NAME_CUSTOM, Custom_ModuleHandler);
const osThreadAttr_t Custom_attributes = {
.name = MODULE_NAME_CUSTOM,
.stack_size = 1024,
.priority = (osPriority_t) osPriorityRealtime,
};
(void)osThreadNew(Custom_Task, NULL, &Custom_attributes);
}