ROS机器人操作系统——如何将ROS与STM32连接(十六)_ros移植stm32

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Golang全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注go)
img

正文

}
/**************************************************************************
Function: Serial port 5 sends data
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú5·¢ËÍÊý¾Ý
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
void USART5_SEND(void)
{
unsigned char i = 0;
for(i=0; i<24; i++)
{
usart5_send(Send_Data.buffer[i]);
}
}
/**************************************************************************
Function: CAN sends data
Input : none
Output : none
º¯Êý¹¦ÄÜ£ºCAN·¢ËÍÊý¾Ý
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
**************************************************************************/
void CAN_SEND(void)
{
u8 CAN_SENT[8],i;

for(i=0;i<8;i++)
{
CAN_SENT[i]=Send_Data.buffer[i];
}
CAN1_Send_Num(0x101,CAN_SENT);

for(i=0;i<8;i++)
{
CAN_SENT[i]=Send_Data.buffer[i+8];
}
CAN1_Send_Num(0x102,CAN_SENT);

for(i=0;i<8;i++)
{
CAN_SENT[i]=Send_Data.buffer[i+16];
}
CAN1_Send_Num(0x103,CAN_SENT);
}
/**************************************************************************
Function: Serial port 1 initialization
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú1³õʼ»¯
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
**************************************************************************/
void uart1_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //Enable the gpio clock //ʹÄÜGPIOʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //Enable the Usart clock //ʹÄÜUSARTʱÖÓ

//USART_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //Reuse push-pull output //¸´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOA, &GPIO_InitStructure);

//USART_RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //Float input //¸¡¿ÕÊäÈë
GPIO_Init(GPIOA, &GPIO_InitStructure);

//UsartNVIC configuration //UsartNVICÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
//Preempt priority //ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
//Subpriority //×ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//Enable the IRQ channel //IRQͨµÀʹÄÜ
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//Initialize the VIC register with the specified parameters
//¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
NVIC_Init(&NVIC_InitStructure);

//USART Initialization Settings ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound; //Port rate //´®¿Ú²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×Ö³¤Îª8λÊý¾Ý¸ñʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //Ò»¸öֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //ÎÞÆæżУÑéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //ÊÕ·¢Ä£Ê½
USART_Init(USART1, &USART_InitStructure); //Initialize serial port 1 //³õʼ»¯´®¿Ú1

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //¿ªÆô´®¿Ú½ÓÊÜÖжÏ
USART_Cmd(USART1, ENABLE); //Enable serial port 1 //ʹÄÜ´®¿Ú1
}
/**************************************************************************
Function: Serial port 2 initialization
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú2³õʼ»¯
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
void uart2_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //Enable the AFIO clock //ʹÄÜAFIOʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); //Enable the gpio clock //ʹÄÜGPIOʱÖÓ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //Enable the Usart clock //ʹÄÜUSARTʱÖÓ
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); //Pin remapping //Òý½ÅÖØÓ³Éä

//USART_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //PD5
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //Reuse push-pull output //¸´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOD, &GPIO_InitStructure);

//USART_RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //PD6
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //Pull up input//ÉÏÀ­ÊäÈë
GPIO_Init(GPIOD, &GPIO_InitStructure);

//UsartNVIC configuration //UsartNVICÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
//Preempt priority //ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
//Subpriority //×ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//Enable the IRQ channel //IRQͨµÀʹÄÜ
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//Initialize the VIC register with the specified parameters
//¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
NVIC_Init(&NVIC_InitStructure);

//USART Initialization Settings ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound; //Port rate //´®¿Ú²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×Ö³¤Îª8λÊý¾Ý¸ñʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //Ò»¸öÍ£Ö¹
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //ÎÞÆæżУÑéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //ÊÕ·¢Ä£Ê½
USART_Init(USART2, &USART_InitStructure); //Initialize serial port 2 //³õʼ»¯´®¿Ú2

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //¿ªÆô´®¿Ú½ÓÊÜÖжÏ
USART_Cmd(USART2, ENABLE); //Enable serial port 2 //ʹÄÜ´®¿Ú2
}
/**************************************************************************
Function: Serial port 3 initialization
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú3³õʼ»¯
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
void uart3_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //Enable the AFIO clock //ʹÄÜAFIOʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //Enable the gpio clock //ʹÄÜGPIOʱÖÓ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //Enable the Usart clock //ʹÄÜUSARTʱÖÓ
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE); //Pin remapping //Òý½ÅÖØÓ³Éä

//USART_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //C10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //Reuse push-pull output //¸´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOC, &GPIO_InitStructure);

//USART_RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //PC11
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //Pull up input//ÉÏÀ­ÊäÈë
GPIO_Init(GPIOC, &GPIO_InitStructure);

//UsartNVIC configuration //UsartNVICÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
//Preempt priority //ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
//Preempt priority //ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//Enable the IRQ channel //IRQͨµÀʹÄÜ
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//Initialize the VIC register with the specified parameters
//¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
NVIC_Init(&NVIC_InitStructure);

//USART Initialization Settings ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound; //Port rate //´®¿Ú²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×Ö³¤Îª8λÊý¾Ý¸ñʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //Ò»¸öÍ£Ö¹
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //ÎÞÆæżУÑéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //ÊÕ·¢Ä£Ê½
USART_Init(USART3, &USART_InitStructure); //Initialize serial port 3 //³õʼ»¯´®¿Ú3

USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //¿ªÆô´®¿Ú½ÓÊÜÖжÏ
USART_Cmd(USART3, ENABLE); //Enable serial port 3 //ʹÄÜ´®¿Ú3
}

/**************************************************************************
Function: Serial port 5 initialization
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú5³õʼ»¯
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
void uart5_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //Enable the AFIO clock //ʹÄÜAFIOʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //Enable the gpio clock //ʹÄÜGPIOʱÖÓ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //Enable the Usart clock //ʹÄÜUSARTʱÖÓ

//USART_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //C12
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //Reuse push-pull output //¸´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOC, &GPIO_InitStructure);

//USART_RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PD2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //Pull up input//ÉÏÀ­ÊäÈë
GPIO_Init(GPIOD, &GPIO_InitStructure);

//UsartNVIC configuration //UsartNVICÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
//Preempt priority //ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
//Preempt priority //ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//Enable the IRQ channel //IRQͨµÀʹÄÜ
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//Initialize the VIC register with the specified parameters
//¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
NVIC_Init(&NVIC_InitStructure);

//USART Initialization Settings ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound; //Port rate //´®¿Ú²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×Ö³¤Îª8λÊý¾Ý¸ñʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //Ò»¸öÍ£Ö¹
USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //ÎÞÆæżУÑéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Sending and receiving mode //ÊÕ·¢Ä£Ê½
USART_Init(UART5, &USART_InitStructure); //Initialize serial port 5 //³õʼ»¯´®¿Ú5

USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //¿ªÆô´®¿Ú½ÓÊÜÖжÏ
USART_Cmd(UART5, ENABLE); //Enable serial port 5 //ʹÄÜ´®¿Ú5
}
/**************************************************************************
Function: Serial port 1 receives interrupted
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú1½ÓÊÕÖжÏ
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
**************************************************************************/
int USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //Check if data is received //ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý
{
u8 Usart_Receive;
static u8 Count;
static u8 rxbuf[11];
int check=0,error=1,i;

Usart_Receive = USART_ReceiveData(USART1); //Read the data //¶ÁÈ¡Êý¾Ý
if(Time_count<CONTROL_DELAY)
// Data is not processed until 10 seconds after startup
//¿ª»ú10ÃëÇ°²»´¦ÀíÊý¾Ý
return 0;

//Fill the array with serial data
//´®¿ÚÊý¾ÝÌîÈëÊý×é
rxbuf[Count]=Usart_Receive;

//Ensure that the first data in the array is FRAME_HEADER
//È·±£Êý×éµÚÒ»¸öÊý¾ÝΪFRAME_HEADER
if(Usart_Receive == FRAME_HEADER||Count>0)
Count++;
else
Count=0;

if (Count == 11) //Verify the length of the packet //ÑéÖ¤Êý¾Ý°üµÄ³¤¶È
{
Count=0; //Prepare for the serial port data to be refill into the array //Ϊ´®¿ÚÊý¾ÝÖØÐÂÌîÈëÊý×é×ö×¼±¸
if(rxbuf[10] == FRAME_TAIL) //Verify the frame tail of the packet //ÑéÖ¤Êý¾Ý°üµÄ֡β
{
for(i=0; i<9; i++)
{
//XOR bit check, used to detect data error
//Òì»òλУÑ飬ÓÃÓÚ¼ì²âÊý¾ÝÊÇ·ñ³ö´í
check=rxbuf[i]^check;
}
if(check==rxbuf[9])
//XOR bit check successful
//Òì»òλУÑé³É¹¦
error=0;

if(error0)
{
float Vz;
if(Usart1_ON_Flag
0)
{
//Serial port 1 controls flag position 1, other flag position 0
//´®¿Ú1¿ØÖƱê־λÖÃ1£¬ÆäËü±ê־λÖÃ0
Usart1_ON_Flag=1;
Usart5_ON_Flag=0;
APP_ON_Flag=0;
PS2_ON_Flag=0;
Remote_ON_Flag=0;
CAN_ON_Flag=0;
}

//Calculate the 3-axis target velocity from the serial data, which is divided into 8-bit high and 8-bit low units m/s
//´Ó´®¿ÚÊý¾ÝÇóÈýÖáÄ¿±êËٶȣ¬·Ö¸ß8λºÍµÍ8λ µ¥Î»m/s
Move_X=XYZ_Target_Speed_transition(rxbuf[3],rxbuf[4]);
Move_Y=XYZ_Target_Speed_transition(rxbuf[5],rxbuf[6]);
Vz =XYZ_Target_Speed_transition(rxbuf[7],rxbuf[8]);
if(Car_Mode==Akm_Car)
{
Move_Z=Vz_to_Akm_Angle(Move_X, Vz);
}
else
{
Move_Z=XYZ_Target_Speed_transition(rxbuf[7],rxbuf[8]);
}
}
}
}
}
return 0;
}
/**************************************************************************
Function: Refresh the OLED screen
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú2½ÓÊÕÖжÏ
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
int USART2_IRQHandler(void)
{
int Usart_Receive;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //Check if data is received //ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý
{
static u8 Flag_PID,i,j,Receive[50],Last_Usart_Receive;
static float Data;

Usart_Receive=USART2->DR; //Read the data //¶ÁÈ¡Êý¾Ý

if(Deviation_Count<CONTROL_DELAY)
// Data is not processed until 10 seconds after startup
//¿ª»ú10ÃëÇ°²»´¦ÀíÊý¾Ý
return 0;

if(Usart_Receive0x41&&Last_Usart_Receive0x41&&APP_ON_Flag==0)
//10 seconds after startup, press the forward button of APP to enter APP control mode
//The APP controls the flag position 1 and the other flag position 0
//¿ª»ú10ÃëÖ®ºó£¬°´ÏÂAPPµÄÇ°½ø¼ü½øÈëAPP¿ØÖÆģʽ
//APP¿ØÖƱê־λÖÃ1£¬ÆäËü±ê־λÖÃ0
PS2_ON_Flag=0,Remote_ON_Flag=0,APP_ON_Flag=1,CAN_ON_Flag=0,Usart1_ON_Flag=0, Usart5_ON_Flag=0;
Last_Usart_Receive=Usart_Receive;

if(Usart_Receive0x4B)
//Enter the APP steering control interface
//½øÈëAPPתÏò¿ØÖƽçÃæ
Turn_Flag=1;
else if(Usart_Receive
0x49||Usart_Receive==0x4A)
// Enter the APP direction control interface
//½øÈëAPP·½Ïò¿ØÖƽçÃæ
Turn_Flag=0;

if(Turn_Flag0)
{
//App rocker control interface command
//APPÒ¡¸Ë¿ØÖƽçÃæÃüÁî
if(Usart_Receive>=0x41&&Usart_Receive<=0x48)
{
Flag_Direction=Usart_Receive-0x40;
}
else if(Usart_Receive<=8)
{
Flag_Direction=Usart_Receive;
}
else Flag_Direction=0;
}
else if(Turn_Flag
1)
{
//APP steering control interface command
//APPתÏò¿ØÖƽçÃæÃüÁî
if (Usart_Receive0x43) Flag_Left=0,Flag_Right=1; //Right rotation //ÓÒ×Ôת
else if(Usart_Receive
0x47) Flag_Left=1,Flag_Right=0; //Left rotation //×ó×Ôת
else Flag_Left=0,Flag_Right=0;
if (Usart_Receive0x41||Usart_Receive0x45) Flag_Direction=Usart_Receive-0x40;
else Flag_Direction=0;
}
if(Usart_Receive0x58) RC_Velocity=RC_Velocity+100; //Accelerate the keys, +100mm/s //¼ÓËÙ°´¼ü£¬+100mm/s
if(Usart_Receive
0x59) RC_Velocity=RC_Velocity-100; //Slow down buttons, -100mm/s //¼õËÙ°´¼ü£¬-100mm/s

// The following is the communication with the APP debugging interface
//ÒÔÏÂÊÇÓëAPPµ÷ÊÔ½çÃæͨѶ
if(Usart_Receive0x7B) Flag_PID=1; //The start bit of the APP parameter instruction //APP²ÎÊýÖ¸ÁîÆðʼλ
if(Usart_Receive
0x7D) Flag_PID=2; //The APP parameter instruction stops the bit //APP²ÎÊýÖ¸Áîֹͣλ

if(Flag_PID1) //Collect data //²É¼¯Êý¾Ý
{
Receive[i]=Usart_Receive;
i++;
}
if(Flag_PID
2) //Analyze the data //·ÖÎöÊý¾Ý
{
if(Receive[3]==0x50) PID_Send=1;
else if(Receive[1]!=0x23)
{
for(j=i;j>=4;j–)
{
Data+=(Receive[j-1]-48)*pow(10,i-j);
}
switch(Receive[1])
{
case 0x30: RC_Velocity=Data;break;
case 0x31: Velocity_KP=Data;break;
case 0x32: Velocity_KI=Data;break;
case 0x33: break;
case 0x34: break;
case 0x35: break;
case 0x36: break;
case 0x37: break;
case 0x38: break;
}
}
//Relevant flag position is cleared
//Ïà¹Ø±ê־λÇåÁã
Flag_PID=0;
i=0;
j=0;
Data=0;
memset(Receive, 0, sizeof(u8)*50); //Clear the array to zero//Êý×éÇåÁã
}
if(RC_Velocity<0) RC_Velocity=0;
}
return 0;
}
/**************************************************************************
Function: Serial port 3 receives interrupted
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú3½ÓÊÕÖжÏ
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
int USART3_IRQHandler(void)
{
static u8 Count=0;
u8 Usart_Receive;

if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //Check if data is received //ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý
{
Usart_Receive = USART_ReceiveData(USART3);//Read the data //¶ÁÈ¡Êý¾Ý
if(Time_count<CONTROL_DELAY)
// Data is not processed until 10 seconds after startup
//¿ª»ú10ÃëÇ°²»´¦ÀíÊý¾Ý
return 0;

//Fill the array with serial data
//´®¿ÚÊý¾ÝÌîÈëÊý×é
Receive_Data.buffer[Count]=Usart_Receive;

// Ensure that the first data in the array is FRAME_HEADER
//È·±£Êý×éµÚÒ»¸öÊý¾ÝΪFRAME_HEADER
if(Usart_Receive == FRAME_HEADER||Count>0)
Count++;
else
Count=0;

if (Count == 11) //Verify the length of the packet //ÑéÖ¤Êý¾Ý°üµÄ³¤¶È
{
Count=0; //Prepare for the serial port data to be refill into the array //Ϊ´®¿ÚÊý¾ÝÖØÐÂÌîÈëÊý×é×ö×¼±¸
if(Receive_Data.buffer[10] == FRAME_TAIL) //Verify the frame tail of the packet //ÑéÖ¤Êý¾Ý°üµÄ֡β
{
//Data exclusionary or bit check calculation, mode 0 is sent data check
//Êý¾ÝÒì»òλУÑé¼ÆË㣬ģʽ0ÊÇ·¢ËÍÊý¾ÝУÑé
if(Receive_Data.buffer[9] ==Check_Sum(9,0))
{
float Vz;
//All modes flag position 0, USART3 control mode
//ËùÓÐģʽ±ê־λÖÃ0£¬ÎªUsart3¿ØÖÆģʽ
PS2_ON_Flag=0;
Remote_ON_Flag=0;
APP_ON_Flag=0;
CAN_ON_Flag=0;
Usart5_ON_Flag=0;
Usart1_ON_Flag=0;

//Calculate the target speed of three axis from serial data, unit m/s
//´Ó´®¿ÚÊý¾ÝÇóÈýÖáÄ¿±êËٶȣ¬ µ¥Î»m/s
Move_X=XYZ_Target_Speed_transition(Receive_Data.buffer[3],Receive_Data.buffer[4]);
Move_Y=XYZ_Target_Speed_transition(Receive_Data.buffer[5],Receive_Data.buffer[6]);
Vz =XYZ_Target_Speed_transition(Receive_Data.buffer[7],Receive_Data.buffer[8]);
if(Car_Mode==Akm_Car)
{
Move_Z=Vz_to_Akm_Angle(Move_X, Vz);
}
else
{
Move_Z=XYZ_Target_Speed_transition(Receive_Data.buffer[7],Receive_Data.buffer[8]);
}
}
}
}
}
return 0;
}

/**************************************************************************
Function: Serial port 5 receives interrupted
Input : none
Output : none
º¯Êý¹¦ÄÜ£º´®¿Ú5½ÓÊÕÖжÏ
Èë¿Ú²ÎÊý£ºÎÞ
·µ»Ø Öµ£ºÎÞ
**************************************************************************/
int UART5_IRQHandler(void)
{
static u8 Count=0;
u8 Usart_Receive;

if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) //Check if data is received //ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý
{
Usart_Receive = USART_ReceiveData(UART5);//Read the data //¶ÁÈ¡Êý¾Ý
if(Time_count<CONTROL_DELAY)
// Data is not processed until 10 seconds after startup
//¿ª»ú10ÃëÇ°²»´¦ÀíÊý¾Ý
return 0;

//Fill the array with serial data
//´®¿ÚÊý¾ÝÌîÈëÊý×é
Receive_Data.buffer[Count]=Usart_Receive;

// Ensure that the first data in the array is FRAME_HEADER
//È·±£Êý×éµÚÒ»¸öÊý¾ÝΪFRAME_HEADER
if(Usart_Receive == FRAME_HEADER||Count>0)
Count++;
else
Count=0;

if (Count == 11) //Verify the length of the packet //ÑéÖ¤Êý¾Ý°üµÄ³¤¶È
{
Count=0; //Prepare for the serial port data to be refill into the array //Ϊ´®¿ÚÊý¾ÝÖØÐÂÌîÈëÊý×é×ö×¼±¸
if(Receive_Data.buffer[10] == FRAME_TAIL) //Verify the frame tail of the packet //ÑéÖ¤Êý¾Ý°üµÄ֡β
{
//Data exclusionary or bit check calculation, mode 0 is sent data check
//Êý¾ÝÒì»òλУÑé¼ÆË㣬ģʽ0ÊÇ·¢ËÍÊý¾ÝУÑé
if(Receive_Data.buffer[9] ==Check_Sum(9,0))
{
float Vz;
//All modes flag position 0, USART5 control mode
//ËùÓÐģʽ±ê־λÖÃ0£¬ÎªUsart5¿ØÖÆģʽ
PS2_ON_Flag=0;
Remote_ON_Flag=0;
APP_ON_Flag=0;
CAN_ON_Flag=0;
Usart5_ON_Flag=1;
Usart1_ON_Flag=0;

//Calculate the target speed of three axis from serial data, unit m/s
//´Ó´®¿ÚÊý¾ÝÇóÈýÖáÄ¿±êËٶȣ¬ µ¥Î»m/s
Move_X=XYZ_Target_Speed_transition(Receive_Data.buffer[3],Receive_Data.buffer[4]);
Move_Y=XYZ_Target_Speed_transition(Receive_Data.buffer[5],Receive_Data.buffer[6]);
Vz =XYZ_Target_Speed_transition(Receive_Data.buffer[7],Receive_Data.buffer[8]);
if(Car_Mode==Akm_Car)
{
Move_Z=Vz_to_Akm_Angle(Move_X, Vz);
}
else
{
Move_Z=XYZ_Target_Speed_transition(Receive_Data.buffer[7],Receive_Data.buffer[8]);
}
}
}
}
}
return 0;
}
/**************************************************************************
Function: After the top 8 and low 8 figures are integrated into a short type data, the unit reduction is converted
Input : 8 bits high, 8 bits low
Output : The target velocity of the robot on the X/Y/Z axis
º¯Êý¹¦ÄÜ£º½«ÉÏλ»ú·¢¹ýÀ´Ä¿±êÇ°½øËÙ¶ÈVx¡¢Ä¿±ê½ÇËÙ¶ÈVz£¬×ª»»Îª°¢¿ËÂüС³µµÄÓÒÇ°ÂÖת½Ç
Èë¿Ú²ÎÊý£ºÄ¿±êÇ°½øËÙ¶ÈVx¡¢Ä¿±ê½ÇËÙ¶ÈVz£¬µ¥Î»£ºm/s£¬rad/s
·µ»Ø Öµ£º°¢¿ËÂüС³µµÄÓÒÇ°ÂÖת½Ç£¬µ¥Î»£ºrad
**************************************************************************/
float Vz_to_Akm_Angle(float Vx, float Vz)
{
float R, AngleR, Min_Turn_Radius;
//float AngleL;

//Ackermann car needs to set minimum turning radius
//If the target speed requires a turn radius less than the minimum turn radius,
//This will greatly improve the friction force of the car, which will seriously affect the control effect
//°¢¿ËÂüС³µÐèÒªÉèÖÃ×îСתÍä°ë¾¶
//Èç¹ûÄ¿±êËÙ¶ÈÒªÇóµÄתÍä°ë¾¶Ð¡ÓÚ×îСתÍä°ë¾¶£¬
//»áµ¼ÖÂС³µÔ˶¯Ä¦²ÁÁ¦´ó´óÌá¸ß£¬ÑÏÖØÓ°Ïì¿ØÖÆЧ¹û
Min_Turn_Radius=MINI_AKM_MIN_TURN_RADIUS;

if(Vz!=0 && Vx!=0)
{

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Go)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
us
//If the target speed requires a turn radius less than the minimum turn radius,
//This will greatly improve the friction force of the car, which will seriously affect the control effect
//°¢¿ËÂüС³µÐèÒªÉèÖÃ×îСתÍä°ë¾¶
//Èç¹ûÄ¿±êËÙ¶ÈÒªÇóµÄתÍä°ë¾¶Ð¡ÓÚ×îСתÍä°ë¾¶£¬
//»áµ¼ÖÂС³µÔ˶¯Ä¦²ÁÁ¦´ó´óÌá¸ß£¬ÑÏÖØÓ°Ïì¿ØÖÆЧ¹û
Min_Turn_Radius=MINI_AKM_MIN_TURN_RADIUS;

if(Vz!=0 && Vx!=0)
{

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Go)
[外链图片转存中…(img-A8z5fsRe-1713410981335)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值