Browse Source

删除optional模块,优化变量命名,不与老代码重复

master
Lizongdi 3 days ago
parent
commit
692c8a031c
  1. 5
      RBcore/BHBF.c
  2. 58
      RBcore/drv_interface.c
  3. 16
      RBcore/include/drv_interface.h
  4. 14
      motor/motor_example.c
  5. 15
      optional/CMakeLists.txt
  6. 170
      optional/msp_MK32.c
  7. 109
      optional/msp_MK32.h
  8. 211
      optional/msp_TI5MOTOR.c
  9. 122
      optional/msp_TI5MOTOR.h
  10. 4
      project/paint_robot_new/paint_robot_new.c

5
RBcore/BHBF.c

@ -57,6 +57,11 @@ static void RBcore_ModuleHandler(const Msg_t *pstMsg)
switch (pstMsg->m_uiMsgID) switch (pstMsg->m_uiMsgID)
{ {
case RBCORE_CMD_STOP_ALL:
{
//log_i("RBCORE_CMD_STOP_ALL");
break;
}
case RBCORE_CMD_MANUAL_FORWARD: case RBCORE_CMD_MANUAL_FORWARD:
{ {
log_i("RBCORE_CMD_MANUAL_FORWARD"); log_i("RBCORE_CMD_MANUAL_FORWARD");

58
RBcore/drv_interface.c

@ -37,16 +37,16 @@ extern TComCtrl *g_ptUartCtrl;
/*----------------------------------------------* /*----------------------------------------------*
* * * *
*----------------------------------------------*/ *----------------------------------------------*/
TComCtrl *g_ptRS485_1; TComCtrl *g_ptrs485_1;
TComCtrl *g_ptRS485_2; TComCtrl *g_ptrs485_2;
TComCtrl *g_ptRS485_3; TComCtrl *g_ptrs485_3;
TComCtrl *g_ptRS485_4; TComCtrl *g_ptrs485_4;
TComCtrl *g_ptLTE_7S0; TComCtrl *g_ptlte_7S0;
TComCtrl *g_ptE28_SBUS; TComCtrl *g_ptSbus;
TComCtrl *g_ptInterCall; TComCtrl *g_ptInterCall;
TComCtrl *g_ptFDCAN1; TComCtrl *g_ptCAN1;
TComCtrl *g_ptFDCAN2; TComCtrl *g_ptCAN2;
/*----------------------------------------------* /*----------------------------------------------*
* * * *
*----------------------------------------------*/ *----------------------------------------------*/
@ -62,7 +62,7 @@ TComCtrl *g_ptFDCAN2;
int RS485_1_Send(char *_pBuffer, uint32_t _iSize) int RS485_1_Send(char *_pBuffer, uint32_t _iSize)
{ {
HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, GPIO_PIN_SET); 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); 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); HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, GPIO_PIN_RESET);
return iRet; return iRet;
@ -70,7 +70,7 @@ int RS485_1_Send(char *_pBuffer, uint32_t _iSize)
int LTE_7S0_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); int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
return iRet; return iRet;
} }
@ -78,7 +78,7 @@ int LTE_7S0_Send(char *_pBuffer, uint32_t _iSize)
int RS485_2_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); 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); 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); HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin, GPIO_PIN_RESET);
return iRet; return iRet;
@ -93,7 +93,7 @@ int InterCall_Send(char *_pBuffer, uint32_t _iSize)
int E28_SBUS_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); int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
return iRet; return iRet;
} }
@ -101,7 +101,7 @@ int E28_SBUS_Send(char *_pBuffer, uint32_t _iSize)
int RS485_3_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); 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); 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); HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port, RS485_3_DIR_Pin, GPIO_PIN_RESET);
return iRet; return iRet;
@ -110,7 +110,7 @@ int RS485_3_Send(char *_pBuffer, uint32_t _iSize)
int RS485_4_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); 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); 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); HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port, RS485_4_DIR_Pin, GPIO_PIN_RESET);
return iRet; return iRet;
@ -118,12 +118,12 @@ int RS485_4_Send(char *_pBuffer, uint32_t _iSize)
int FDCAN1_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) 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 #ifndef CONFIG_UART_IT_IDLEDMA
@ -131,18 +131,18 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{ {
if (huart->Instance == USART1) if (huart->Instance == USART1)
{ {
UART_RX_IRQHandler(g_ptRS485_1); UART_RX_IRQHandler(g_ptrs485_1);
} }
else if (huart->Instance == USART2) else if (huart->Instance == USART2)
{ {
UART_RX_IRQHandler(g_ptLTE_7S0); UART_RX_IRQHandler(g_ptlte_7S0);
} }
else if (huart->Instance == USART3) else if (huart->Instance == USART3)
{ {
#ifdef USE_PRINT #ifdef USE_PRINT
UART_RX_IRQHandler(g_ptUartCtrl); UART_RX_IRQHandler(g_ptUartCtrl);
#else #else
UART_RX_IRQHandler(g_ptRS485_2); UART_RX_IRQHandler(g_ptrs485_2);
#endif #endif
} }
else if (huart->Instance == UART4) else if (huart->Instance == UART4)
@ -151,15 +151,15 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
} }
else if (huart->Instance == UART5) else if (huart->Instance == UART5)
{ {
UART_RX_IRQHandler(g_ptE28_SBUS); UART_RX_IRQHandler(g_ptSbus);
} }
else if (huart->Instance == USART6) else if (huart->Instance == USART6)
{ {
UART_RX_IRQHandler(g_ptRS485_3); UART_RX_IRQHandler(g_ptrs485_3);
} }
else if (huart->Instance == UART7) else if (huart->Instance == UART7)
{ {
UART_RX_IRQHandler(g_ptRS485_4); UART_RX_IRQHandler(g_ptrs485_4);
} }
} }
#endif #endif
@ -204,22 +204,22 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{ {
if (hfdcan->Instance == FDCAN1) if (hfdcan->Instance == FDCAN1)
{ {
CAN_RX_IRQHandler(g_ptFDCAN1); CAN_RX_IRQHandler(g_ptCAN1);
} }
else if (hfdcan->Instance == FDCAN2) 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}; char pcBuffer[52] = {0};
while(1) while(1)
{ {
__disable_irq(); __disable_irq();
rd_ComRead(g_ptRS485_1, pcBuffer, 25); rd_ComRead(g_ptSbus, pcBuffer, 25);
__enable_irq(); __enable_irq();
Rd_Delay(1); Rd_Delay(1);
} }
@ -235,10 +235,10 @@ void Drv_InterfaceInit(void)
RBcore_Init(); RBcore_Init();
Mlogic_Init(); Mlogic_Init();
const osThreadAttr_t Read_RS485_1_attributes = { const osThreadAttr_t Read_Sbus_attributes = {
.name = "RS485_1", .name = "Sbus",
.stack_size = 512, .stack_size = 512,
.priority = (osPriority_t) osPriorityHigh6, .priority = (osPriority_t) osPriorityHigh6,
}; };
(void)osThreadNew(Read_RS485_1, NULL, &Read_RS485_1_attributes); (void)osThreadNew(Read_Sbus, NULL, &Read_Sbus_attributes);
} }

16
RBcore/include/drv_interface.h

@ -75,16 +75,16 @@ extern "C"{
/*==============================================* /*==============================================*
* project-wide global variables * * project-wide global variables *
*----------------------------------------------*/ *----------------------------------------------*/
extern TComCtrl *g_ptRS485_1; extern TComCtrl *g_ptrs485_1;
extern TComCtrl *g_ptRS485_2; extern TComCtrl *g_ptrs485_2;
extern TComCtrl *g_ptRS485_3; extern TComCtrl *g_ptrs485_3;
extern TComCtrl *g_ptRS485_4; extern TComCtrl *g_ptrs485_4;
extern TComCtrl *g_ptLTE_7S0; extern TComCtrl *g_ptlte_7S0;
extern TComCtrl *g_ptE28_SBUS; extern TComCtrl *g_ptSbus;
extern TComCtrl *g_ptInterCall; extern TComCtrl *g_ptInterCall;
extern TComCtrl *g_ptFDCAN1; extern TComCtrl *g_ptCAN1;
extern TComCtrl *g_ptFDCAN2; extern TComCtrl *g_ptCAN2;
/*==============================================* /*==============================================*
* routines' or functions' implementations * * routines' or functions' implementations *

14
motor/motor_example.c

@ -71,7 +71,7 @@ void MotorExample_LeiSai(void)
}; };
// 3. 创建电机实例(使用雷赛协议) // 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. 配置右轮电机 // 4. 配置右轮电机
Motor_Config_t stRightConfig = { Motor_Config_t stRightConfig = {
@ -80,7 +80,7 @@ void MotorExample_LeiSai(void)
.m_uiReductionRatio = 70, .m_uiReductionRatio = 70,
.m_fWheelDiameter = 0.26f .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. 复位并激活所有电机 // 5. 复位并激活所有电机
if (pstLeftMotor != NULL) if (pstLeftMotor != NULL)
@ -163,7 +163,7 @@ void MotorExample_MultiProtocol(void)
// 使用雷赛协议的电机 // 使用雷赛协议的电机
Motor_Config_t stConfig1 = { .m_ucMotorID = 1 }; 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 }; // Motor_Config_t stConfig2 = { .m_ucMotorID = 2 };
@ -347,8 +347,8 @@ void MotorInit(void)
{ {
// 初始化FDCAN1,使用雷赛电机的回调 // 初始化FDCAN1,使用雷赛电机的回调
TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 8, 0); TCANUserData *ptCANUserData = CAN_userdata_init(&hfdcan1, 8, 0);
g_ptFDCAN1 = rd_ComCreate(check_LeiSaiMotor, decode_LeiSaiMotor, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData); g_ptCAN1 = rd_ComCreate(check_LeiSaiMotor, decode_LeiSaiMotor, FDCAN1_Send, CONFIG_UART_BUFFER_SIZE, ptCANUserData);
CAN_IT_init(g_ptFDCAN1); CAN_IT_init(g_ptCAN1);
// 初始化电机管理模块 // 初始化电机管理模块
MotorMgr_Init(); MotorMgr_Init();
@ -360,7 +360,7 @@ void MotorInit(void)
.m_uiReductionRatio = 70, .m_uiReductionRatio = 70,
.m_fWheelDiameter = 0.26f .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 = { Motor_Config_t stRightMotorConfig = {
@ -369,7 +369,7 @@ void MotorInit(void)
.m_uiReductionRatio = 70, .m_uiReductionRatio = 70,
.m_fWheelDiameter = 0.26f .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); g_uiMotorModuleID = MsgCenter_Register(MODULE_NAME_MOTOR, Motor_ModuleHandler);

15
optional/CMakeLists.txt

@ -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()

170
optional/msp_MK32.c

@ -1,170 +0,0 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: msp_MK32.c
: 稿
: radkil
: 202668
:
: MK32遥控器
:
1. : 202668
: radkil
:
******************************************************************************/
#include "msp_MK32.h"
#include "BHBF.h"
#include <math.h>
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
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;
}
}
}

109
optional/msp_MK32.h

@ -1,109 +0,0 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: msp_MK32.h
: 稿
: radkil
: 202668
:
: msp_MK32.c
:
1. : 202668
: radkil
:
******************************************************************************/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
#ifndef __MSP_MK32_H__
#define __MSP_MK32_H__
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
/*==============================================*
* include header files *
*----------------------------------------------*/
#include <stdint.h>
/*==============================================*
* 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__ */

211
optional/msp_TI5MOTOR.c

@ -1,211 +0,0 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: msp_TI5MOTOR.c
: 稿
: radkil
: 202668
:
: TI5电机
:
1. : 202668
: 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);
}
}

122
optional/msp_TI5MOTOR.h

@ -1,122 +0,0 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: msp_TI5MOTOR.h
: 稿
: radkil
: 202668
:
: msp_TI5MOTOR.c
:
1. : 202668
: radkil
:
******************************************************************************/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
#ifndef __MSP_TI5MOTOR_H__
#define __MSP_TI5MOTOR_H__
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
/*==============================================*
* include header files *
*----------------------------------------------*/
#include <stdint.h>
/*==============================================*
* 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__ */

4
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) void MK32_Init(void)
{ {
TUartUserData *ptUartUserData = UART_userdata_init(5, 115200, 512); 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); g_ptSbus = rd_ComCreate(check_MK32Data, decode_MK32Data, E28_SBUS_Send, ptUartUserData->m_buf_size, ptUartUserData);
UART_IT_init(g_ptE28_SBUS); UART_IT_init(g_ptSbus);
} }
void MK32_Task(void *argument) void MK32_Task(void *argument)

Loading…
Cancel
Save