Browse Source

temp

master
Lizongdi 3 days ago
parent
commit
2790f6042f
  1. 46
      RBcore/drv_interface.c
  2. 70
      RBcore/ground_manger.c
  3. 120
      project/paint_robot_new/paint_robot_new.c

46
RBcore/drv_interface.c

@ -44,6 +44,7 @@ TComCtrl *g_ptrs485_4;
TComCtrl *g_ptlte_7S0; TComCtrl *g_ptlte_7S0;
TComCtrl *g_ptSbus; TComCtrl *g_ptSbus;
TComCtrl *g_ptInterCall; TComCtrl *g_ptInterCall;
TComCtrl *g_ptlpuart;
TComCtrl *g_ptCAN1; TComCtrl *g_ptCAN1;
TComCtrl *g_ptCAN2; TComCtrl *g_ptCAN2;
@ -116,6 +117,13 @@ int RS485_4_Send(char *_pBuffer, uint32_t _iSize)
return iRet; return iRet;
} }
int LPUART_PV_Send(char *_pBuffer, uint32_t _iSize)
{
TUartUserData *ptUartUserData = (TUartUserData *)g_ptlpuart->m_pUserData;
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
return iRet;
}
int FDCAN1_Send(char *_pBuffer, uint32_t _iSize) int FDCAN1_Send(char *_pBuffer, uint32_t _iSize)
{ {
return CAN_TX_FIFOQ(g_ptCAN1, _pBuffer, _iSize); return CAN_TX_FIFOQ(g_ptCAN1, _pBuffer, _iSize);
@ -161,6 +169,10 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{ {
UART_RX_IRQHandler(g_ptrs485_4); UART_RX_IRQHandler(g_ptrs485_4);
} }
else if (huart->Instance == LPUART1)
{
UART_RX_IRQHandler(g_ptlpuart);
}
} }
#endif #endif
@ -212,33 +224,55 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
} }
} }
void Read_Sbus(void *argument) void Read_MK32(void *argument)
{ {
char pcBuffer[52] = {0}; char pcBuffer[52] = {0};
char pcBuffer2[52] = {0};
while(1) while(1)
{ {
__disable_irq(); __disable_irq();
rd_ComRead(g_ptSbus, pcBuffer, 25); rd_ComRead(g_ptSbus, pcBuffer, 25);
rd_ComRead(g_ptlpuart, pcBuffer2, 25);
__enable_irq(); __enable_irq();
Rd_Delay(1); Rd_Delay(1);
} }
} }
extern void MotorInit(void); extern void MotorInit(void);
extern void Mlogic_Init(void); 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 void decode_PV(const char *buf, uint32_t _iSize);
void Send_PV(void *argument);
void ground_manger_init(void);
void Drv_InterfaceInit(void) void Drv_InterfaceInit(void)
{ {
MsgCenter_Init(); MsgCenter_Init();
ground_manger_init();
MotorInit(); MotorInit();
RBcore_Init(); RBcore_Init();
Mlogic_Init();
const osThreadAttr_t Read_Sbus_attributes = { TUartUserData *ptSbus = UART_userdata_init(5, -1, 512);
.name = "Sbus", 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 = 512, .stack_size = 512,
.priority = (osPriority_t) osPriorityHigh6, .priority = (osPriority_t) osPriorityHigh6,
}; };
(void)osThreadNew(Read_Sbus, NULL, &Read_Sbus_attributes); (void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes);
TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512);
g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData);
UART_IT_init(g_ptlpuart);
const osThreadAttr_t Send_PV_attributes = {
.name = "Send_PV",
.stack_size = 512,
.priority = (osPriority_t) osPriorityHigh4,
};
(void)osThreadNew(Send_PV, NULL, &Send_PV_attributes);
} }

70
RBcore/ground_manger.c

@ -0,0 +1,70 @@
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: ground_manger.c
: 稿
: radkil
: 2026817
:
:
:
1. : 2026817
: radkil
:
******************************************************************************/
#include "BHBF.h"
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
void Send_ground(void *argument)
{
while(1)
{
Rd_Delay(1);
}
}
void ground_manger_init(void)
{
TUartUserData *ptUartUserData = UART_userdata_init(7, -1, 512);
g_ptrs485_4 = rd_ComCreate(NULL, NULL, RS485_4_Send, ptUartUserData->m_buf_size, ptUartUserData);
UART_IT_init(g_ptrs485_4);
const osThreadAttr_t Send_ground_attributes = {
.name = "Send_ground",
.stack_size = 512,
.priority = (osPriority_t) osPriorityRealtime2,
};
(void)osThreadNew(Send_ground, NULL, &Send_ground_attributes);
}

120
project/paint_robot_new/paint_robot_new.c

@ -31,6 +31,7 @@
* * * *
*----------------------------------------------*/ *----------------------------------------------*/
static MSP_MK32_Button RB_MK32; static MSP_MK32_Button RB_MK32;
static int RB_Mode = 0; //0表示手动,1表示自动
/*----------------------------------------------* /*----------------------------------------------*
* * * *
*----------------------------------------------*/ *----------------------------------------------*/
@ -47,7 +48,7 @@ static MSP_MK32_Button RB_MK32;
* * * *
*----------------------------------------------*/ *----------------------------------------------*/
static int check_MK32Data(char *_pBuffer, uint32_t _iSize) int check_MK32(char *_pBuffer, uint32_t _iSize)
{ {
if (_pBuffer[0] != 0x0f) if (_pBuffer[0] != 0x0f)
{ {
@ -63,7 +64,7 @@ static int check_MK32Data(char *_pBuffer, uint32_t _iSize)
} }
} }
static void decode_MK32Data(const char *buf, uint32_t _iSize) void decode_MK32(const char *buf, uint32_t _iSize)
{ {
int16_t CH[16]; int16_t CH[16];
int Start_byte = -1; int Start_byte = -1;
@ -114,66 +115,79 @@ static void decode_MK32Data(const char *buf, uint32_t _iSize)
RB_MK32.IsOnline = 0; RB_MK32.IsOnline = 0;
} }
RB_MK32.RxIndex++; RB_MK32.RxIndex++;
}
void MK32_Init(void) int angle;
{ angle = atan2(RB_MK32.CH1_RY_V, RB_MK32.CH0_RY_H) * 180 / M_PI;
TUartUserData *ptUartUserData = UART_userdata_init(5, 115200, 512);
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)
{
while(1)
{
int angle;
angle = atan2(RB_MK32.CH1_RY_V, RB_MK32.CH0_RY_H) * 180 / M_PI;
if(RB_MK32.CH5_SB == 0) 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))
{ {
// 前进 MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0);
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);
}
} }
else else
{ {
// 前进 MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0);
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);
}
} }
Rd_Delay(1); }
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);
}
}
Rd_Delay(1);
}
int check_PV(char *_pBuffer, uint32_t _iSize)
{
if (_iSize < 4) return -1;
if (_pBuffer[0] != 0x55) return -1;
if (_pBuffer[1] != 0x55) return -1;
uint16_t crc_check = ((_pBuffer[_iSize - 1] << 8) | _pBuffer[_iSize - 2]);
uint16_t crc_check1 = Rd_modbusCRC16(_pBuffer, _iSize - 2);
if (crc_check == crc_check1)
{
return _iSize - 2;
}
else
{
return -1;
} }
} }
void Mlogic_Init(void) void decode_PV(const char *buf, uint32_t _iSize)
{
RB_Mode = 0;
// Motor_CmdData_t tMotor_CmdData_t = {0};
// tMotor_CmdData_t.m_ucMotorIndex = 1;
// tMotor_CmdData_t.m_iValue = 10;
// MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_CMD_SET_SPEED, (void *)&tMotor_CmdData_t, sizeof(Motor_CmdData_t));
}
void Send_PV(void *argument)
{ {
const osThreadAttr_t logic_attributes = { while(1)
.name = "main_logic", {
.stack_size = 1024,
.priority = (osPriority_t) osPriorityRealtime2, Rd_Delay(1);
}; }
(void)osThreadNew(MK32_Task, NULL, &logic_attributes);
} }

Loading…
Cancel
Save