From 692c8a031cd1bc64f7e052b58357d3cc80cdf765 Mon Sep 17 00:00:00 2001 From: Lizongdi <1210855344@qq.com> Date: Mon, 17 Aug 2026 14:49:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4optional=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E4=B8=8E=E8=80=81=E4=BB=A3=E7=A0=81=E9=87=8D?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RBcore/BHBF.c | 5 + RBcore/drv_interface.c | 58 +++--- RBcore/include/drv_interface.h | 16 +- motor/motor_example.c | 14 +- optional/CMakeLists.txt | 15 -- optional/msp_MK32.c | 170 ----------------- optional/msp_MK32.h | 109 ----------- optional/msp_TI5MOTOR.c | 211 ---------------------- optional/msp_TI5MOTOR.h | 122 ------------- project/paint_robot_new/paint_robot_new.c | 4 +- 10 files changed, 51 insertions(+), 673 deletions(-) delete mode 100644 optional/CMakeLists.txt delete mode 100644 optional/msp_MK32.c delete mode 100644 optional/msp_MK32.h delete mode 100644 optional/msp_TI5MOTOR.c delete mode 100644 optional/msp_TI5MOTOR.h diff --git a/RBcore/BHBF.c b/RBcore/BHBF.c index c0fb99e..679663f 100644 --- a/RBcore/BHBF.c +++ b/RBcore/BHBF.c @@ -57,6 +57,11 @@ static void RBcore_ModuleHandler(const Msg_t *pstMsg) switch (pstMsg->m_uiMsgID) { + case RBCORE_CMD_STOP_ALL: + { + //log_i("RBCORE_CMD_STOP_ALL"); + break; + } case RBCORE_CMD_MANUAL_FORWARD: { log_i("RBCORE_CMD_MANUAL_FORWARD"); diff --git a/RBcore/drv_interface.c b/RBcore/drv_interface.c index 27ffb5b..1084de2 100644 --- a/RBcore/drv_interface.c +++ b/RBcore/drv_interface.c @@ -37,16 +37,16 @@ extern TComCtrl *g_ptUartCtrl; /*----------------------------------------------* * 全局变量 * *----------------------------------------------*/ -TComCtrl *g_ptRS485_1; -TComCtrl *g_ptRS485_2; -TComCtrl *g_ptRS485_3; -TComCtrl *g_ptRS485_4; -TComCtrl *g_ptLTE_7S0; -TComCtrl *g_ptE28_SBUS; +TComCtrl *g_ptrs485_1; +TComCtrl *g_ptrs485_2; +TComCtrl *g_ptrs485_3; +TComCtrl *g_ptrs485_4; +TComCtrl *g_ptlte_7S0; +TComCtrl *g_ptSbus; TComCtrl *g_ptInterCall; -TComCtrl *g_ptFDCAN1; -TComCtrl *g_ptFDCAN2; +TComCtrl *g_ptCAN1; +TComCtrl *g_ptCAN2; /*----------------------------------------------* * 模块级变量 * *----------------------------------------------*/ @@ -62,7 +62,7 @@ TComCtrl *g_ptFDCAN2; int RS485_1_Send(char *_pBuffer, uint32_t _iSize) { HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, GPIO_PIN_SET); - TUartUserData *ptUartUserData = (TUartUserData *)g_ptRS485_1->m_pUserData; + TUartUserData *ptUartUserData = (TUartUserData *)g_ptrs485_1->m_pUserData; int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, GPIO_PIN_RESET); return iRet; @@ -70,7 +70,7 @@ int RS485_1_Send(char *_pBuffer, uint32_t _iSize) int LTE_7S0_Send(char *_pBuffer, uint32_t _iSize) { - TUartUserData *ptUartUserData = (TUartUserData *)g_ptLTE_7S0->m_pUserData; + TUartUserData *ptUartUserData = (TUartUserData *)g_ptlte_7S0->m_pUserData; int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); return iRet; } @@ -78,7 +78,7 @@ int LTE_7S0_Send(char *_pBuffer, uint32_t _iSize) int RS485_2_Send(char *_pBuffer, uint32_t _iSize) { HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin, GPIO_PIN_SET); - TUartUserData *ptUartUserData = (TUartUserData *)g_ptRS485_2->m_pUserData; + TUartUserData *ptUartUserData = (TUartUserData *)g_ptrs485_2->m_pUserData; int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin, GPIO_PIN_RESET); return iRet; @@ -93,7 +93,7 @@ int InterCall_Send(char *_pBuffer, uint32_t _iSize) int E28_SBUS_Send(char *_pBuffer, uint32_t _iSize) { - TUartUserData *ptUartUserData = (TUartUserData *)g_ptE28_SBUS->m_pUserData; + TUartUserData *ptUartUserData = (TUartUserData *)g_ptSbus->m_pUserData; int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); return iRet; } @@ -101,7 +101,7 @@ int E28_SBUS_Send(char *_pBuffer, uint32_t _iSize) int RS485_3_Send(char *_pBuffer, uint32_t _iSize) { HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port, RS485_3_DIR_Pin, GPIO_PIN_SET); - TUartUserData *ptUartUserData = (TUartUserData *)g_ptRS485_3->m_pUserData; + TUartUserData *ptUartUserData = (TUartUserData *)g_ptrs485_3->m_pUserData; int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port, RS485_3_DIR_Pin, GPIO_PIN_RESET); return iRet; @@ -110,7 +110,7 @@ int RS485_3_Send(char *_pBuffer, uint32_t _iSize) int RS485_4_Send(char *_pBuffer, uint32_t _iSize) { HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port, RS485_4_DIR_Pin, GPIO_PIN_SET); - TUartUserData *ptUartUserData = (TUartUserData *)g_ptRS485_4->m_pUserData; + TUartUserData *ptUartUserData = (TUartUserData *)g_ptrs485_4->m_pUserData; int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port, RS485_4_DIR_Pin, GPIO_PIN_RESET); return iRet; @@ -118,12 +118,12 @@ int RS485_4_Send(char *_pBuffer, uint32_t _iSize) int FDCAN1_Send(char *_pBuffer, uint32_t _iSize) { - return CAN_TX_FIFOQ(g_ptFDCAN1, _pBuffer, _iSize); + return CAN_TX_FIFOQ(g_ptCAN1, _pBuffer, _iSize); } int FDCAN2_Send(char *_pBuffer, uint32_t _iSize) { - return CAN_TX_FIFOQ(g_ptFDCAN2, _pBuffer, _iSize); + return CAN_TX_FIFOQ(g_ptCAN2, _pBuffer, _iSize); } #ifndef CONFIG_UART_IT_IDLEDMA @@ -131,18 +131,18 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) { - UART_RX_IRQHandler(g_ptRS485_1); + UART_RX_IRQHandler(g_ptrs485_1); } else if (huart->Instance == USART2) { - UART_RX_IRQHandler(g_ptLTE_7S0); + UART_RX_IRQHandler(g_ptlte_7S0); } else if (huart->Instance == USART3) { #ifdef USE_PRINT UART_RX_IRQHandler(g_ptUartCtrl); #else - UART_RX_IRQHandler(g_ptRS485_2); + UART_RX_IRQHandler(g_ptrs485_2); #endif } else if (huart->Instance == UART4) @@ -151,15 +151,15 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } else if (huart->Instance == UART5) { - UART_RX_IRQHandler(g_ptE28_SBUS); + UART_RX_IRQHandler(g_ptSbus); } else if (huart->Instance == USART6) { - UART_RX_IRQHandler(g_ptRS485_3); + UART_RX_IRQHandler(g_ptrs485_3); } else if (huart->Instance == UART7) { - UART_RX_IRQHandler(g_ptRS485_4); + UART_RX_IRQHandler(g_ptrs485_4); } } #endif @@ -204,22 +204,22 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { if (hfdcan->Instance == FDCAN1) { - CAN_RX_IRQHandler(g_ptFDCAN1); + CAN_RX_IRQHandler(g_ptCAN1); } else if (hfdcan->Instance == FDCAN2) { - CAN_RX_IRQHandler(g_ptFDCAN2); + CAN_RX_IRQHandler(g_ptCAN2); } } -void Read_RS485_1(void *argument) +void Read_Sbus(void *argument) { char pcBuffer[52] = {0}; while(1) { __disable_irq(); - rd_ComRead(g_ptRS485_1, pcBuffer, 25); + rd_ComRead(g_ptSbus, pcBuffer, 25); __enable_irq(); Rd_Delay(1); } @@ -235,10 +235,10 @@ void Drv_InterfaceInit(void) RBcore_Init(); Mlogic_Init(); - const osThreadAttr_t Read_RS485_1_attributes = { - .name = "RS485_1", + const osThreadAttr_t Read_Sbus_attributes = { + .name = "Sbus", .stack_size = 512, .priority = (osPriority_t) osPriorityHigh6, }; - (void)osThreadNew(Read_RS485_1, NULL, &Read_RS485_1_attributes); + (void)osThreadNew(Read_Sbus, NULL, &Read_Sbus_attributes); } diff --git a/RBcore/include/drv_interface.h b/RBcore/include/drv_interface.h index 510530d..5355109 100644 --- a/RBcore/include/drv_interface.h +++ b/RBcore/include/drv_interface.h @@ -75,16 +75,16 @@ extern "C"{ /*==============================================* * project-wide global variables * *----------------------------------------------*/ -extern TComCtrl *g_ptRS485_1; -extern TComCtrl *g_ptRS485_2; -extern TComCtrl *g_ptRS485_3; -extern TComCtrl *g_ptRS485_4; -extern TComCtrl *g_ptLTE_7S0; -extern TComCtrl *g_ptE28_SBUS; +extern TComCtrl *g_ptrs485_1; +extern TComCtrl *g_ptrs485_2; +extern TComCtrl *g_ptrs485_3; +extern TComCtrl *g_ptrs485_4; +extern TComCtrl *g_ptlte_7S0; +extern TComCtrl *g_ptSbus; extern TComCtrl *g_ptInterCall; -extern TComCtrl *g_ptFDCAN1; -extern TComCtrl *g_ptFDCAN2; +extern TComCtrl *g_ptCAN1; +extern TComCtrl *g_ptCAN2; /*==============================================* * routines' or functions' implementations * diff --git a/motor/motor_example.c b/motor/motor_example.c index e9400b7..87125c2 100644 --- a/motor/motor_example.c +++ b/motor/motor_example.c @@ -71,7 +71,7 @@ void MotorExample_LeiSai(void) }; // 3. 创建电机实例(使用雷赛协议) - Motor_Instance_t *pstLeftMotor = MotorMgr_Create(&stLeftConfig, g_ptFDCAN1, LeiSai_GetProtocol(), NULL); + Motor_Instance_t *pstLeftMotor = MotorMgr_Create(&stLeftConfig, g_ptCAN1, LeiSai_GetProtocol(), NULL); // 4. 配置右轮电机 Motor_Config_t stRightConfig = { @@ -80,7 +80,7 @@ void MotorExample_LeiSai(void) .m_uiReductionRatio = 70, .m_fWheelDiameter = 0.26f }; - Motor_Instance_t *pstRightMotor = MotorMgr_Create(&stRightConfig, g_ptFDCAN1, LeiSai_GetProtocol(), NULL); + Motor_Instance_t *pstRightMotor = MotorMgr_Create(&stRightConfig, g_ptCAN1, LeiSai_GetProtocol(), NULL); // 5. 复位并激活所有电机 if (pstLeftMotor != NULL) @@ -163,7 +163,7 @@ void MotorExample_MultiProtocol(void) // 使用雷赛协议的电机 Motor_Config_t stConfig1 = { .m_ucMotorID = 1 }; - Motor_Instance_t *pstMotor1 = MotorMgr_Create(&stConfig1, g_ptFDCAN1, LeiSai_GetProtocol(), NULL); + Motor_Instance_t *pstMotor1 = MotorMgr_Create(&stConfig1, g_ptCAN1, LeiSai_GetProtocol(), NULL); // 假设未来有其他协议 // Motor_Config_t stConfig2 = { .m_ucMotorID = 2 }; @@ -347,8 +347,8 @@ void MotorInit(void) { // 初始化FDCAN1,使用雷赛电机的回调 TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 8, 0); - g_ptFDCAN1 = rd_ComCreate(check_LeiSaiMotor, decode_LeiSaiMotor, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData); - CAN_IT_init(g_ptFDCAN1); + g_ptCAN1 = rd_ComCreate(check_LeiSaiMotor, decode_LeiSaiMotor, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData); + CAN_IT_init(g_ptCAN1); // 初始化电机管理模块 MotorMgr_Init(); @@ -360,7 +360,7 @@ void MotorInit(void) .m_uiReductionRatio = 70, .m_fWheelDiameter = 0.26f }; - g_apstMotors[0] = MotorMgr_Create(&stLeftMotorConfig, g_ptFDCAN1, LeiSai_GetProtocol(), NULL); + g_apstMotors[0] = MotorMgr_Create(&stLeftMotorConfig, g_ptCAN1, LeiSai_GetProtocol(), NULL); // 配置右轮电机 Motor_Config_t stRightMotorConfig = { @@ -369,7 +369,7 @@ void MotorInit(void) .m_uiReductionRatio = 70, .m_fWheelDiameter = 0.26f }; - g_apstMotors[1] = MotorMgr_Create(&stRightMotorConfig, g_ptFDCAN1, LeiSai_GetProtocol(), NULL); + g_apstMotors[1] = MotorMgr_Create(&stRightMotorConfig, g_ptCAN1, LeiSai_GetProtocol(), NULL); g_uiMotorModuleID = MsgCenter_Register(MODULE_NAME_MOTOR, Motor_ModuleHandler); diff --git a/optional/CMakeLists.txt b/optional/CMakeLists.txt deleted file mode 100644 index cd8acad..0000000 --- a/optional/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 3.10) - -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 RBcore) - target_link_libraries(optional PUBLIC RBcore) -else() - message(WARNING "[optional] Dependency 'RBcore' not found.") -endif() \ No newline at end of file diff --git a/optional/msp_MK32.c b/optional/msp_MK32.c deleted file mode 100644 index 16d0b67..0000000 --- a/optional/msp_MK32.c +++ /dev/null @@ -1,170 +0,0 @@ -/****************************************************************************** - - 版权所有 (C), 2018-2099, Radkil - - ****************************************************************************** - 文 件 名 : msp_MK32.c - 版 本 号 : 初稿 - 作 者 : radkil - 生成日期 : 2026年6月8日 - 最近修改 : - 功能描述 : MK32遥控器 - - 修改历史 : - 1.日 期 : 2026年6月8日 - 作 者 : radkil - 修改内容 : 创建文件 - -******************************************************************************/ -#include "msp_MK32.h" -#include "BHBF.h" -#include - - -/*----------------------------------------------* - * 外部变量说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 外部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 内部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 全局变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 模块级变量 * - *----------------------------------------------*/ -static SP_MSP_MK32_Button RB_MK32; - -/*----------------------------------------------* - * 常量定义 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 宏定义 * - *----------------------------------------------*/ - -static int check_MK32Data(char *_pBuffer, uint32_t _iSize) -{ - if (_pBuffer[0] != 0x0f) - { - return -1; - } - if (_pBuffer[24] != 0x0f) - { - return -1; - } - else - { - return 25; - } -} - -static void decode_MK32Data(const char *buf, uint32_t _iSize) -{ - int16_t CH[16]; - int Start_byte = -1; - - 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); - - int32_t* channel_ptrs[16] = - { - &RB_MK32.CH0_RY_H, &RB_MK32.CH1_RY_V, &RB_MK32.CH2_LY_V, &RB_MK32.CH3_LY_H, - &RB_MK32.CH4_SA, &RB_MK32.CH5_SB, &RB_MK32.CH6_SC, &RB_MK32.CH7_SD, - &RB_MK32.CH8_SE, &RB_MK32.CH9_SF, &RB_MK32.CH10_LD1, &RB_MK32.CH11_RD1, - &RB_MK32.CH12_S1, &RB_MK32.CH13_S2, &RB_MK32.CH14_LT, &RB_MK32.CH15_RT - }; - - // 按键数值转换:1050为中间值,272-1712 - for (int i = 0; i < 16; i++) - { - // 通过指针解引用赋值,完美替代原来的 RB_MK32[i + 1] - *channel_ptrs[i] = (int32_t)((CH[i] - 992) * 1.388889); - } - - // 【核心修改】:通过具体的成员名访问 IsOnline,替代原来的 RB_MK32[17] - if (buf[22] == 0) - { - RB_MK32.IsOnline = 1; - } - else - { - RB_MK32.IsOnline = 0; - } - RB_MK32.RxIndex++; -} - -void MK32_Init(void) -{ - TUartUserData *ptUartUserData = UART_userdata_init(5, 115200, 512); - g_ptE28_SBUS = rd_ComCreate(check_MK32Data, decode_MK32Data, E28_SBUS_Send, ptUartUserData->m_buf_size, ptUartUserData); - UART_IT_init(g_ptE28_SBUS); -} - -GF_CMD MK32_Task(int mode) -{ - int angle; - angle = atan2(RB_MK32.CH1_RY_V, RB_MK32.CH0_RY_H) * 180 / M_PI; - - if(RB_MK32.CH5_SB == 0) - { - // 前进 - if((angle >= 45) && (angle <= 135)) - { - if (0 == mode) return GF_CMD_MANUAL_FORWARD; - else return GF_CMD_AUTO_FORWARD; - } - // 后退 - else if((angle >= -135) && (angle < -45)) - { - return GF_CMD_MANUAL_BACKWARD; - } - else - { - return GF_CMD_STOP_ALL; - } - } - else - { - // 前进 - if((angle >= 45) && (angle <= 135)) - { - if (0 == mode) return GF_CMD_MANUAL_FORWARD; - else return GF_CMD_AUTO_FORWARD; - } - // 后退 - else if((angle >= -135) && (angle < -45)) - { - return GF_CMD_MANUAL_BACKWARD; - } - else - { - return GF_CMD_STOP_ALL; - } - } -} diff --git a/optional/msp_MK32.h b/optional/msp_MK32.h deleted file mode 100644 index ece783a..0000000 --- a/optional/msp_MK32.h +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** - - 版权所有 (C), 2018-2099, Radkil - - ****************************************************************************** - 文 件 名 : msp_MK32.h - 版 本 号 : 初稿 - 作 者 : radkil - 生成日期 : 2026年6月8日 - 最近修改 : - 功能描述 : msp_MK32.c 的头文件 - - 修改历史 : - 1.日 期 : 2026年6月8日 - 作 者 : radkil - 修改内容 : 创建文件 - -******************************************************************************/ - -/*----------------------------------------------* - * 外部变量说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 外部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 内部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 全局变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 模块级变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 常量定义 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 宏定义 * - *----------------------------------------------*/ - -#ifndef __MSP_MK32_H__ -#define __MSP_MK32_H__ - - -#ifdef __cplusplus -#if __cplusplus -extern "C"{ -#endif -#endif /* __cplusplus */ - - -/*==============================================* - * include header files * - *----------------------------------------------*/ -#include - - - -/*==============================================* - * constants or macros define * - *----------------------------------------------*/ -typedef struct _SP_MSP_MK32_Button -{ - int32_t RxIndex; - int32_t CH0_RY_H; - int32_t CH1_RY_V; - int32_t CH2_LY_V; - int32_t CH3_LY_H; - int32_t CH4_SA; - int32_t CH5_SB; - int32_t CH6_SC; - int32_t CH7_SD; - int32_t CH8_SE; - int32_t CH9_SF; - int32_t CH10_LD1; - int32_t CH11_RD1; - int32_t CH12_S1; - int32_t CH13_S2; - int32_t CH14_LT; - int32_t CH15_RT; - int32_t IsOnline; -} SP_MSP_MK32_Button; - - -/*==============================================* - * project-wide global variables * - *----------------------------------------------*/ - - - -/*==============================================* - * routines' or functions' implementations * - *----------------------------------------------*/ - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - - -#endif /* __MSP_MK32_H__ */ diff --git a/optional/msp_TI5MOTOR.c b/optional/msp_TI5MOTOR.c deleted file mode 100644 index 217f30c..0000000 --- a/optional/msp_TI5MOTOR.c +++ /dev/null @@ -1,211 +0,0 @@ -/****************************************************************************** - - 版权所有 (C), 2018-2099, Radkil - - ****************************************************************************** - 文 件 名 : msp_TI5MOTOR.c - 版 本 号 : 初稿 - 作 者 : radkil - 生成日期 : 2026年6月8日 - 最近修改 : - 功能描述 : TI5电机 - - 修改历史 : - 1.日 期 : 2026年6月8日 - 作 者 : radkil - 修改内容 : 创建文件 - -******************************************************************************/ -#include "msp_TI5MOTOR.h" -#include "BHBF.h" - -/*----------------------------------------------* - * 外部变量说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 外部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 内部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 全局变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 模块级变量 * - *----------------------------------------------*/ -static MotorParameters Motor[4]; -static int32_t Motor_ID_Errors[7] = { 0 }; -static CSP tempCSP; - -/*----------------------------------------------* - * 常量定义 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 宏定义 * - *----------------------------------------------*/ - -#define DF_MSP_Ti5Motor_StartID 0 - -static int CANSendCommand(uint8_t id, uint8_t command, int32_t *content) -{ - int len = (content != NULL) ? 5 : 1; - char buf[10] = {0}; - buf[0] = id; - buf[1] = command; - if (content != NULL) - { - RD_MEMCPY(&buf[2], content, 4); - } - return rd_ComWrite(g_ptFDCAN1, (char *)buf, len); -} - -static void Motor_ClearFault(uint8_t id) -{ - CANSendCommand(id, 0x0B, NULL); -} - -static void Motor_GetFaultState(uint8_t id) -{ - CANSendCommand(id, 0x0A, NULL); // set motor stop mode - -} - -static void GetCSPByCommand(uint8_t id) -{ - CANSendCommand(id, 0x41, NULL); -} - -static void Motor_SetVelocityModeAndTargetVelocity(uint8_t id, int32_t targetSpeed) -{ - CANSendCommand(id, 0x1d, &targetSpeed); //Motor_SetVelocityModeAndTargetVelocity -} - -static int check_TI5MOTOR(char *buffer, uint32_t length) -{ - TCANUserData *ptCANUserData = (TCANUserData *)g_ptFDCAN1->m_pUserData; - uint8_t ID_A_T = (uint8_t)ptCANUserData->m_canrx->Identifier; - int32_t Function_code = 0; - - if (ID_A_T >= DF_MSP_Ti5Motor_StartID - && ID_A_T < DF_MSP_Ti5Motor_StartID + 7) - { - (Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).RxIndex++; - } - - switch (Function_code) - { - case 3: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Run_Mode, - &buffer[1], length - 1); - break; - case 4: //ma - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Current, - &buffer[1], length - 1); - - break; - case 5: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Target_Current, - &buffer[1], length - 1); - - break; - case 6: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Velcity, - &buffer[1], length - 1); - - break; - case 7: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Target_Velcity, - &buffer[1], length - 1); - - break; - case 8: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Position, - &buffer[1], length - 1); - - break; - case 9: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Target_Position, - &buffer[1], length - 1); - break; - case 10: - - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).ERROR_Flag, - &buffer[1], length - 1); - - memcpy(&(Motor_ID_Errors[ID_A_T - DF_MSP_Ti5Motor_StartID]), - &buffer[1], length - 1); - break; - case 49: - memcpy( - &(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Temperature_Motor, - &buffer[1], length - 1); - break; - case 50: - memcpy(&(Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Temperature_PCB, - &buffer[1], length - 1); - break; - - case 65: - case 66: - case 67: - case 68: - //电流 MA - // case 65-68 均返回CSP - //tempCSP=&buffer[0]; - memcpy(&tempCSP, buffer, 8); - (Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Current = - tempCSP.Current;//单位为mA - (Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Velcity = - tempCSP.Velocity;//转化为度每秒公式:(返回值/100/减速比)*360 - (Motor[ID_A_T - DF_MSP_Ti5Motor_StartID]).Position = - tempCSP.Position;//转化为减速机角度公式:(返回值/65536/减速比)*360 - return 8; - default: - return -1; - } - return 1; -} - -static void decode_TI5MOTOR(const char *_pBuffer, uint32_t _iSize) -{ - return; -} - -void MoveWheel_Init(void) -{ - TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 8, 0); - g_ptFDCAN1 = rd_ComCreate(check_TI5MOTOR, decode_TI5MOTOR, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData); - CAN_IT_init(g_ptFDCAN1); - - for (int i = 1; i < 5; i++) - { - GetCSPByCommand(i); - Rd_Delay(4); - Motor_ClearFault(i); - Rd_Delay(4); - } -} - -void MoveWheel_Task(int32_t Target_Velcity[]) -{ - for (int i = 1; i < 5; i++) - { - Motor_ClearFault(i); - Rd_Delay(4); - Motor_GetFaultState(i); - Rd_Delay(4); - GetCSPByCommand(i); - Rd_Delay(4); - } - for (int i = 1; i < 5; i++) - { - Motor_SetVelocityModeAndTargetVelocity(i, Target_Velcity[i]); - Rd_Delay(4); - } -} diff --git a/optional/msp_TI5MOTOR.h b/optional/msp_TI5MOTOR.h deleted file mode 100644 index 195f931..0000000 --- a/optional/msp_TI5MOTOR.h +++ /dev/null @@ -1,122 +0,0 @@ -/****************************************************************************** - - 版权所有 (C), 2018-2099, Radkil - - ****************************************************************************** - 文 件 名 : msp_TI5MOTOR.h - 版 本 号 : 初稿 - 作 者 : radkil - 生成日期 : 2026年6月8日 - 最近修改 : - 功能描述 : msp_TI5MOTOR.c 的头文件 - - 修改历史 : - 1.日 期 : 2026年6月8日 - 作 者 : radkil - 修改内容 : 创建文件 - -******************************************************************************/ - -/*----------------------------------------------* - * 外部变量说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 外部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 内部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 全局变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 模块级变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 常量定义 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 宏定义 * - *----------------------------------------------*/ - -#ifndef __MSP_TI5MOTOR_H__ -#define __MSP_TI5MOTOR_H__ - - -#ifdef __cplusplus -#if __cplusplus -extern "C"{ -#endif -#endif /* __cplusplus */ - - -/*==============================================* - * include header files * - *----------------------------------------------*/ -#include - - - -/*==============================================* - * constants or macros define * - *----------------------------------------------*/ -typedef struct _MotorParameters { - int32_t MotorID; - int32_t RxIndex; - int32_t Run_Mode; - int32_t Current; - int32_t Target_Current; - int32_t Velcity; - int32_t Target_Velcity; - int32_t Position; - int32_t Target_Position; - int32_t ERROR_Flag; - int32_t Temperature_Motor; - int32_t Temperature_PCB; - int32_t AccTime; - int32_t DecTime; - int32_t EncoderOffset; /* 53 83 设置位置偏移 int32_t "设置偏移值和目标位置 -(目标位置=编码器位置 - 偏移值)" */ -} MotorParameters; - -#pragma pack (2) /*指定按2字节对齐*/ -typedef struct _CSP -{ - int16_t Current; - int16_t Velocity; - int32_t Position; -} CSP; - -typedef struct _TSP -{ - int32_t Torque; - int32_t Velocity; - int32_t Position; -} TSP; - -#pragma pack () /*取消指定对齐,恢复缺省对齐*/ - -/*==============================================* - * project-wide global variables * - *----------------------------------------------*/ - - - -/*==============================================* - * routines' or functions' implementations * - *----------------------------------------------*/ - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - - -#endif /* __MSP_TI5MOTOR_H__ */ diff --git a/project/paint_robot_new/paint_robot_new.c b/project/paint_robot_new/paint_robot_new.c index f1c16f2..5df1f91 100644 --- a/project/paint_robot_new/paint_robot_new.c +++ b/project/paint_robot_new/paint_robot_new.c @@ -119,8 +119,8 @@ static void decode_MK32Data(const char *buf, uint32_t _iSize) void MK32_Init(void) { TUartUserData *ptUartUserData = UART_userdata_init(5, 115200, 512); - g_ptE28_SBUS = rd_ComCreate(check_MK32Data, decode_MK32Data, E28_SBUS_Send, ptUartUserData->m_buf_size, ptUartUserData); - UART_IT_init(g_ptE28_SBUS); + g_ptSbus = rd_ComCreate(check_MK32Data, decode_MK32Data, E28_SBUS_Send, ptUartUserData->m_buf_size, ptUartUserData); + UART_IT_init(g_ptSbus); } void MK32_Task(void *argument)