Browse Source

【待优化】MK32暂时解耦到控制器模块(控制器实例化方案暂时还没想好)

master
Lizongdi 21 hours ago
parent
commit
1a171ad0c8
  1. 2
      CMakeLists.txt
  2. 24
      RBcore/drv_interface.c
  3. 22
      controller/CMakeLists.txt
  4. 144
      controller/msp_MK32.c
  5. 113
      project/paint_robot_new/paint_robot_new_MK32.c

2
CMakeLists.txt

@ -122,7 +122,7 @@ add_module(lua lua OFF ON)
add_module(bspMCU bspMCU OFF OFF) add_module(bspMCU bspMCU OFF OFF)
add_module(RBcore RBcore OFF OFF) add_module(RBcore RBcore OFF OFF)
add_module(motor motor OFF OFF) add_module(motor motor OFF OFF)
add_module(optional optional OFF OFF) add_module(controller controller OFF OFF)
add_module(Spoolend project/Spoolend OFF OFF) add_module(Spoolend project/Spoolend OFF OFF)
add_module(paint_robot_new project/paint_robot_new OFF OFF) add_module(paint_robot_new project/paint_robot_new OFF OFF)
add_module(Spoolold project_old/Spoolold OFF OFF) add_module(Spoolold project_old/Spoolold OFF OFF)

24
RBcore/drv_interface.c

@ -226,16 +226,6 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
} }
} }
void Read_MK32(void *argument)
{
char pcBuffer[52] = {0};
while(1)
{
rd_ComRead(g_ptSbus, pcBuffer, 25);
}
}
void Read_PV(void *argument) void Read_PV(void *argument)
{ {
char pcBuffer[64] = {0}; char pcBuffer[64] = {0};
@ -257,8 +247,6 @@ void Read_motor(void *argument)
} }
extern void MotorTask(void *argument); extern void MotorTask(void *argument);
extern int check_MK32(char *_pBuffer, uint32_t _iSize);
extern void decode_MK32(const char *buf, uint32_t _iSize);
extern int check_PV(char *_pBuffer, uint32_t _iSize); extern int check_PV(char *_pBuffer, uint32_t _iSize);
extern void decode_PV(const char *buf, uint32_t _iSize); extern void decode_PV(const char *buf, uint32_t _iSize);
extern void ground_manger_init(void); extern void ground_manger_init(void);
@ -266,6 +254,7 @@ extern void Custom_Task(void *argument);
void SendIV_Init(void); void SendIV_Init(void);
void TL720D_Init(void); void TL720D_Init(void);
void RBcore_Init(void); void RBcore_Init(void);
void controller_init(void);
void Drv_InterfaceInit(void) void Drv_InterfaceInit(void)
{ {
@ -300,16 +289,7 @@ void Drv_InterfaceInit(void)
RBcore_Init(); RBcore_Init();
TUartUserData *ptSbus = UART_userdata_init(5, -1, 512); controller_init();
g_ptSbus = rd_ComCreate(check_MK32, decode_MK32, E28_SBUS_Send, ptSbus->m_buf_size, ptSbus);
UART_IT_init(g_ptSbus);
const osThreadAttr_t MK32_Task_attributes = {
.name = "Read_MK32",
.stack_size = 2048,
.priority = (osPriority_t) osPriorityRealtime1,
};
(void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes);
TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512); TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512);
g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData); g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData);

22
controller/CMakeLists.txt

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.10)
get_filename_component(TARGET_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
set(COMMON_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../library/CMakeLists.txt")
if(EXISTS ${COMMON_CMAKE_PATH})
include(${COMMON_CMAKE_PATH})
else()
message(FATAL_ERROR "Cannot find common build logic at ${COMMON_CMAKE_PATH}")
endif()
if(TARGET peripheral)
target_link_libraries(${TARGET_NAME} PUBLIC peripheral)
else()
message(FATAL_ERROR "[${TARGET_NAME}] Dependency 'peripheral' not found.")
endif()
if(TARGET RBcore)
target_link_libraries(${TARGET_NAME} PUBLIC RBcore)
else()
message(FATAL_ERROR "[${TARGET_NAME}] Dependency 'RBcore' not found.")
endif()

144
controller/msp_MK32.c

@ -0,0 +1,144 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: msp_MK32.c
: 稿
: radkil
: 2026910
:
: MK32驱动文件
:
1. : 2026910
: radkil
:
******************************************************************************/
#include "BHBF.h"
#include "msg_center.h"
#include "msp_MK32.pb.h"
#include "rd_time.h"
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
static SP_MSP_MK32_Button RB_MK32;
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
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;
}
void decode_MK32(const char *buf, uint32_t _iSize)
{
static uint32_t uiLastSendTick = 0;
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++;
uint32_t uiNowTick = Rd_GetTime();
if ((int32_t)(uiNowTick - uiLastSendTick) >= 50)
{
uiLastSendTick = uiNowTick;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_GET_MK32, (void *)&RB_MK32,
sizeof(RB_MK32));
}
}
void Read_MK32(void *argument)
{
char pcBuffer[52] = {0};
while (1)
{
rd_ComRead(g_ptSbus, pcBuffer, 25);
}
}
void controller_init(void)
{
TUartUserData *ptSbus = UART_userdata_init(5, -1, 512);
g_ptSbus = rd_ComCreate(check_MK32, decode_MK32, E28_SBUS_Send, ptSbus->m_buf_size, ptSbus);
UART_IT_init(g_ptSbus);
const osThreadAttr_t MK32_Task_attributes = {
.name = "Read_MK32",
.stack_size = 2048,
.priority = (osPriority_t) osPriorityRealtime1,
};
(void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes);
}

113
project/paint_robot_new/paint_robot_new_MK32.c

@ -1,113 +0,0 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: paint_robot_new_MK32.c
: 稿
: radkil
: 2026821
:
:
:
1. : 2026821
: radkil
:
******************************************************************************/
#include "BHBF.h"
#include "Protobuf/PSource/msp_MK32.pb.h"
#include "msg_center.h"
#include "rd_time.h"
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
static SP_MSP_MK32_Button RB_MK32;
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
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;
}
void decode_MK32(const char *buf, uint32_t _iSize)
{
static uint32_t uiLastSendTick = 0;
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++;
uint32_t uiNowTick = Rd_GetTime();
if ((int32_t)(uiNowTick - uiLastSendTick) >= 50)
{
uiLastSendTick = uiNowTick;
MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_GET_MK32, (void *)&RB_MK32, sizeof(RB_MK32));
}
}
Loading…
Cancel
Save