IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> ROS机器人操作系统——如何将ROS与STM32连接(十六) -> 正文阅读

[嵌入式]ROS机器人操作系统——如何将ROS与STM32连接(十六)

ROS机器人操作系统


前言

前面学习了ROS的基本操作,仅仅只使用这个操作系统并没有什么用处,还需要讲他与硬件相结合从而控制机器人的运动。`

一、两种控制器的功能

在这里插入图片描述
ROS主控采用的Jetson nano B01 STM32主控用的是F407,通过Jetson 驱动雷达采集信息,然后串口像STM32发送相关的运动指令,串口接收到后执行相应的动作。
在这里插入图片描述

二、硬件连接

硬件连接很简单用的是平衡小车之家的ROS STM32控制板,其内置电平转换芯片,只需用一根USB数据线连接起来即可。
在这里插入图片描述
在这里插入图片描述
构造函数和析构函数是类的另一种操作,首先获取STM32数据也就是获取陀螺仪数据,然后计算出四元素,将相关信息发送给STM32

turn_on_robot::~turn_on_robot()
{
  //Sends the stop motion command to the lower machine before the turn_on_robot object ends
  //瀵硅薄turn_on_robot缁撴潫鍓嶅悜涓嬩綅鏈哄彂閫佸仠姝㈣繍鍔ㄥ懡浠?
  Send_Data.tx[0]=FRAME_HEADER;
  Send_Data.tx[1] = 0;  
  Send_Data.tx[2] = 0; 

  //The target velocity of the X-axis of the robot //鏈哄櫒浜篨杞寸殑鐩爣绾块熷害 
  Send_Data.tx[4] = 0;     
  Send_Data.tx[3] = 0;  

  //The target velocity of the Y-axis of the robot //鏈哄櫒浜篩杞寸殑鐩爣绾块熷害 
  Send_Data.tx[6] = 0;
  Send_Data.tx[5] = 0;  

  //The target velocity of the Z-axis of the robot //鏈哄櫒浜篫杞寸殑鐩爣瑙掗熷害 
  Send_Data.tx[8] = 0;  
  Send_Data.tx[7] = 0;    
  Send_Data.tx[9]=Check_Sum(9,SEND_DATA_CHECK); //Check the bits for the Check_Sum function //鏍¢獙浣嶏紝瑙勫垯鍙傝Check_Sum鍑芥暟
  Send_Data.tx[10]=FRAME_TAIL; 
  try
  {
    Stm32_Serial.write(Send_Data.tx,sizeof (Send_Data.tx)); //Send data to the serial port //鍚戜覆鍙e彂鏁版嵁  
  }
  catch (serial::IOException& e)   
  {
    ROS_ERROR_STREAM("Unable to send data through serial port"); //If sending data fails, an error message is printed //濡傛灉鍙戦佹暟鎹け璐?鎵撳嵃閿欒淇℃伅
  }
  Stm32_Serial.close(); //Close the serial port //鍏抽棴涓插彛  
  ROS_INFO_STREAM("Shutting down"); //Prompt message //鎻愮ず淇℃伅
}

uart.c

#include "usartx.h"
SEND_DATA Send_Data;
RECEIVE_DATA Receive_Data;
extern int Time_count;

/**************************************************************************
Function: Usartx3, Usartx1 and CAN send data task 
Input   : none
Output  : none
oˉêy1|?ü£o′??ú3?¢′??ú1?¢′??ú5?¢CAN·¢?íêy?Yè???
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
void data_task(void *pvParameters)
{
	 u32 lastWakeTime = getSysTickCnt();
	
   while(1)
    {	
			//The task is run at 20hz
			//′?è???ò?20Hzμ??μ?ê??DD
			vTaskDelayUntil(&lastWakeTime, F2T(RATE_20_HZ));
			//Assign the data to be sent
			//??òa??DD·¢?íμ?êy?Y??DD?3?μ
			data_transition(); 
			USART1_SEND();     //Serial port 1 sends data //′??ú1·¢?íêy?Y
			USART3_SEND();     //Serial port 3 (ROS) sends data  //′??ú3(ROS)·¢?íêy?Y
			USART5_SEND();     //Serial port 5 sends data //′??ú5·¢?íêy?Y
			CAN_SEND();        //CAN send data //CAN·¢?íêy?Y	
			
		}
}
/**************************************************************************
Function: The data sent by the serial port is assigned
Input   : none
Output  : none
oˉêy1|?ü£o′??ú·¢?íμ?êy?Y??DD?3?μ
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
void data_transition(void)
{
	Send_Data.Sensor_Str.Frame_Header = FRAME_HEADER; //Frame_header //??í·
	Send_Data.Sensor_Str.Frame_Tail = FRAME_TAIL;     //Frame_tail //???2
	
	//According to different vehicle types, different kinematics algorithms were selected to carry out the forward kinematics solution, 
	//and the three-axis velocity was obtained from each wheel velocity
	//?ù?Y2?í?3μDí????2?í????ˉ?§??·¨??DD???ˉ?§?y?a£?′ó?÷3μ???ù?è?ó3?èy?á?ù?è
	switch(Car_Mode)
	{	
		case Mec_Car:      
			Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/4)*1000;
	    Send_Data.Sensor_Str.Y_speed = ((MOTOR_A.Encoder-MOTOR_B.Encoder+MOTOR_C.Encoder-MOTOR_D.Encoder)/4)*1000; 
	    Send_Data.Sensor_Str.Z_speed = ((-MOTOR_A.Encoder-MOTOR_B.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/4/(Axle_spacing+Wheel_spacing))*1000;         
		  break; 
		
    case Omni_Car:      
			Send_Data.Sensor_Str.X_speed = ((MOTOR_C.Encoder-MOTOR_B.Encoder)/2/X_PARAMETER)*1000; 
	    Send_Data.Sensor_Str.Y_speed = ((MOTOR_A.Encoder*2-MOTOR_B.Encoder-MOTOR_C.Encoder)/3)*1000; 
	    Send_Data.Sensor_Str.Z_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder+MOTOR_C.Encoder)/3/Omni_turn_radiaus)*1000;      
		  break; 
    
		case Akm_Car:  
			Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder)/2)*1000; 
			Send_Data.Sensor_Str.Y_speed = 0;
			Send_Data.Sensor_Str.Z_speed = ((MOTOR_B.Encoder-MOTOR_A.Encoder)/Wheel_spacing)*1000;
		  break; 
		
		case Diff_Car: 
			Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder)/2)*1000; 
			Send_Data.Sensor_Str.Y_speed = 0;
			Send_Data.Sensor_Str.Z_speed = ((MOTOR_B.Encoder-MOTOR_A.Encoder)/Wheel_spacing)*1000;
			break; 
		
		case FourWheel_Car:
      Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/4)*1000; 
	    Send_Data.Sensor_Str.Y_speed = 0;
	    Send_Data.Sensor_Str.Z_speed = ((-MOTOR_B.Encoder-MOTOR_A.Encoder+MOTOR_C.Encoder+MOTOR_D.Encoder)/2/(Axle_spacing+Wheel_spacing))*1000;
		 break; 
		
		case Tank_Car:   
			Send_Data.Sensor_Str.X_speed = ((MOTOR_A.Encoder+MOTOR_B.Encoder)/2)*1000; 
			Send_Data.Sensor_Str.Y_speed = 0;
			Send_Data.Sensor_Str.Z_speed = ((MOTOR_B.Encoder-MOTOR_A.Encoder)/(Wheel_spacing)*1000);
			break; 
	}
	
	//The acceleration of the triaxial acceleration //?ó?ù?è??èy?á?ó?ù?è
	Send_Data.Sensor_Str.Accelerometer.X_data= accel[1]; //The accelerometer Y-axis is converted to the ros coordinate X axis //?ó?ù?è??Y?á×a??μ?ROS×?±êX?á
	Send_Data.Sensor_Str.Accelerometer.Y_data=-accel[0]; //The accelerometer X-axis is converted to the ros coordinate y axis //?ó?ù?è??X?á×a??μ?ROS×?±êY?á
	Send_Data.Sensor_Str.Accelerometer.Z_data= accel[2]; //The accelerometer Z-axis is converted to the ros coordinate Z axis //?ó?ù?è??Z?á×a??μ?ROS×?±êZ?á
	
	//The Angle velocity of the triaxial velocity //???ù?è??èy?á???ù?è
	Send_Data.Sensor_Str.Gyroscope.X_data= gyro[1]; //The Y-axis is converted to the ros coordinate X axis //???ù?è??Y?á×a??μ?ROS×?±êX?á
	Send_Data.Sensor_Str.Gyroscope.Y_data=-gyro[0]; //The X-axis is converted to the ros coordinate y axis //???ù?è??X?á×a??μ?ROS×?±êY?á
	if(Flag_Stop==0) 
		//If the motor control bit makes energy state, the z-axis velocity is sent normall
	  //è?1?μ??ú??????ê1?ü×′ì?£????′?y3£·¢?íZ?á???ù?è
		Send_Data.Sensor_Str.Gyroscope.Z_data=gyro[2];  
	else  
		//If the robot is static (motor control dislocation), the z-axis is 0
    //è?1??ú?÷è?ê??2?1μ?£¨μ??ú??????ê§?ü£?£????′·¢?íμ?Z?á???ù?è?a0		
		Send_Data.Sensor_Str.Gyroscope.Z_data=0;        
	
	//Battery voltage (this is a thousand times larger floating point number, which will be reduced by a thousand times as well as receiving the data).
	//μ?3?μ??1(?aà?????μ?êy·?′óò??§±?′?ê?£??àó|μ??ú?óê????ú?óê?μ?êy?Yoóò2?á??D?ò??§±?)
	Send_Data.Sensor_Str.Power_Voltage = Voltage*1000; 
	
	Send_Data.buffer[0]=Send_Data.Sensor_Str.Frame_Header; //Frame_heade //??í·
  Send_Data.buffer[1]=Flag_Stop; //Car software loss marker //D?3μèí?tê§?ü±ê????
	
	//The three-axis speed of / / car is split into two eight digit Numbers
	//D?3μèy?á?ù?è,?÷?á??2e·??aá???8??êy?Y?ù·¢?í
	Send_Data.buffer[2]=Send_Data.Sensor_Str.X_speed >>8; 
	Send_Data.buffer[3]=Send_Data.Sensor_Str.X_speed ;    
	Send_Data.buffer[4]=Send_Data.Sensor_Str.Y_speed>>8;  
	Send_Data.buffer[5]=Send_Data.Sensor_Str.Y_speed;     
	Send_Data.buffer[6]=Send_Data.Sensor_Str.Z_speed >>8; 
	Send_Data.buffer[7]=Send_Data.Sensor_Str.Z_speed ;    
	
	//The acceleration of the triaxial axis of / / imu accelerometer is divided into two eight digit reams
	//IMU?ó?ù?è??èy?á?ó?ù?è,?÷?á??2e·??aá???8??êy?Y?ù·¢?í
	Send_Data.buffer[8]=Send_Data.Sensor_Str.Accelerometer.X_data>>8; 
	Send_Data.buffer[9]=Send_Data.Sensor_Str.Accelerometer.X_data;   
	Send_Data.buffer[10]=Send_Data.Sensor_Str.Accelerometer.Y_data>>8;
	Send_Data.buffer[11]=Send_Data.Sensor_Str.Accelerometer.Y_data;
	Send_Data.buffer[12]=Send_Data.Sensor_Str.Accelerometer.Z_data>>8;
	Send_Data.buffer[13]=Send_Data.Sensor_Str.Accelerometer.Z_data;
	
	//The axis of the triaxial velocity of the / /imu is divided into two eight digits
	//IMU???ù?è??èy?á???ù?è,?÷?á??2e·??aá???8??êy?Y?ù·¢?í
	Send_Data.buffer[14]=Send_Data.Sensor_Str.Gyroscope.X_data>>8;
	Send_Data.buffer[15]=Send_Data.Sensor_Str.Gyroscope.X_data;
	Send_Data.buffer[16]=Send_Data.Sensor_Str.Gyroscope.Y_data>>8;
	Send_Data.buffer[17]=Send_Data.Sensor_Str.Gyroscope.Y_data;
	Send_Data.buffer[18]=Send_Data.Sensor_Str.Gyroscope.Z_data>>8;
	Send_Data.buffer[19]=Send_Data.Sensor_Str.Gyroscope.Z_data;
	
	//Battery voltage, split into two 8 digit Numbers
	//μ?3?μ??1,2e·??aá???8??êy?Y·¢?í
	Send_Data.buffer[20]=Send_Data.Sensor_Str.Power_Voltage >>8; 
	Send_Data.buffer[21]=Send_Data.Sensor_Str.Power_Voltage; 

  //Data check digit calculation, Pattern 1 is a data check
  //êy?YD£?é??????£??£ê?1ê?·¢?íêy?YD£?é
	Send_Data.buffer[22]=Check_Sum(22,1); 
	
	Send_Data.buffer[23]=Send_Data.Sensor_Str.Frame_Tail; //Frame_tail //???2
}
/**************************************************************************
Function: Serial port 1 sends data
Input   : none
Output  : none
oˉêy1|?ü£o′??ú1·¢?íêy?Y
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
void USART1_SEND(void)
{
  unsigned char i = 0;	
	
	for(i=0; i<24; i++)
	{
		usart1_send(Send_Data.buffer[i]);
	}	 
}
/**************************************************************************
Function: Serial port 3 sends data
Input   : none
Output  : none
oˉêy1|?ü£o′??ú3·¢?íêy?Y
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
void USART3_SEND(void)
{
  unsigned char i = 0;	
	for(i=0; i<24; i++)
	{
		usart3_send(Send_Data.buffer[i]);
	}	 
}
/**************************************************************************
Function: Serial port 5 sends data
Input   : none
Output  : none
oˉêy1|?ü£o′??ú5·¢?íêy?Y
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
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
oˉêy1|?ü£oCAN·¢?íêy?Y
è??ú2?êy£o?T
·μ ?? ?μ£o?T
**************************************************************************/
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
oˉêy1|?ü£o′??ú13?ê??ˉ
è??ú2?êy£o?T
·μ ?? ?μ£o?T
**************************************************************************/
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 //ê1?üGPIOê±?ó
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //Enable the Usart clock //ê1?ü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 //?′ó?í?íìê?3?
	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í¨μàê1?ü
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	
  //Initialize the VIC register with the specified parameters 
	//?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷	
	NVIC_Init(&NVIC_InitStructure);	
	
  //USART Initialization Settings 3?ê??ˉéè??
	USART_InitStructure.USART_BaudRate = bound; //Port rate //′??ú2¨ì??ê
	USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×?3¤?a8??êy?Y??ê?
	USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //ò???í£?1??
	USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //?T????D£?é??
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //?Tó2?têy?Yá÷????
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//Sending and receiving mode //ê?·¢?£ê?
	USART_Init(USART1, &USART_InitStructure); //Initialize serial port 1 //3?ê??ˉ′??ú1
	
	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //?a??′??ú?óêü?D??
	USART_Cmd(USART1, ENABLE);                     //Enable serial port 1 //ê1?ü′??ú1
}
/**************************************************************************
Function: Serial port 2 initialization
Input   : none
Output  : none
oˉêy1|?ü£o′??ú23?ê??ˉ
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
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  //ê1?üAFIOê±?ó
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);	 //Enable the gpio clock  //ê1?üGPIOê±?ó
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //Enable the Usart clock //ê1?üUSARTê±?ó
	GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);        //Pin remapping          //òy????ó3é?

	//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	//?′ó?í?íìê?3?
	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í¨μàê1?ü	
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  //Initialize the VIC register with the specified parameters 
	//?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷		
	NVIC_Init(&NVIC_InitStructure);	
	
	//USART Initialization Settings 3?ê??ˉéè??
	USART_InitStructure.USART_BaudRate = bound; //Port rate //′??ú2¨ì??ê
	USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×?3¤?a8??êy?Y??ê?
	USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //ò???í£?1
	USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //?T????D£?é??
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //?Tó2?têy?Yá÷????
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//Sending and receiving mode //ê?·¢?£ê?
	USART_Init(USART2, &USART_InitStructure);      //Initialize serial port 2 //3?ê??ˉ′??ú2
	
	USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //?a??′??ú?óêü?D??
	USART_Cmd(USART2, ENABLE);                     //Enable serial port 2 //ê1?ü′??ú2 
}
/**************************************************************************
Function: Serial port 3 initialization
Input   : none
Output  : none
oˉêy1|?ü£o′??ú33?ê??ˉ
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
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  //ê1?üAFIOê±?ó
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);	 //Enable the gpio clock  //ê1?üGPIOê±?ó
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //Enable the Usart clock //ê1?üUSARTê±?ó
	GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE); //Pin remapping          //òy????ó3é?
	
	//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	//?′ó?í?íìê?3?
  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í¨μàê1?ü	
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	
  //Initialize the VIC register with the specified parameters 
	//?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷		
	NVIC_Init(&NVIC_InitStructure);
	
  //USART Initialization Settings 3?ê??ˉéè??
	USART_InitStructure.USART_BaudRate = bound; //Port rate //′??ú2¨ì??ê
	USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×?3¤?a8??êy?Y??ê?
	USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //ò???í£?1
	USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //?T????D£?é??
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //?Tó2?têy?Yá÷????
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//Sending and receiving mode //ê?·¢?£ê?
  USART_Init(USART3, &USART_InitStructure);      //Initialize serial port 3 //3?ê??ˉ′??ú3
	
  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //?a??′??ú?óêü?D??
  USART_Cmd(USART3, ENABLE);                     //Enable serial port 3 //ê1?ü′??ú3 
}

/**************************************************************************
Function: Serial port 5 initialization
Input   : none
Output  : none
oˉêy1|?ü£o′??ú53?ê??ˉ
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
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  //ê1?üAFIOê±?ó
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);	 //Enable the gpio clock  //ê1?üGPIOê±?ó
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //Enable the Usart clock //ê1?ü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	//?′ó?í?íìê?3?
  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í¨μàê1?ü	
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	
  //Initialize the VIC register with the specified parameters 
	//?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷		
	NVIC_Init(&NVIC_InitStructure);
	
  //USART Initialization Settings 3?ê??ˉéè??
	USART_InitStructure.USART_BaudRate = bound; //Port rate //′??ú2¨ì??ê
	USART_InitStructure.USART_WordLength = USART_WordLength_8b; //The word length is 8 bit data format //×?3¤?a8??êy?Y??ê?
	USART_InitStructure.USART_StopBits = USART_StopBits_1; //A stop bit //ò???í£?1
	USART_InitStructure.USART_Parity = USART_Parity_No; //Prosaic parity bits //?T????D£?é??
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //No hardware data flow control //?Tó2?têy?Yá÷????
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;	//Sending and receiving mode //ê?·¢?£ê?
  USART_Init(UART5, &USART_InitStructure);      //Initialize serial port 5 //3?ê??ˉ′??ú5
	
  USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); //Open the serial port to accept interrupts //?a??′??ú?óêü?D??
  USART_Cmd(UART5, ENABLE);                     //Enable serial port 5 //ê1?ü′??ú5 
}
/**************************************************************************
Function: Serial port 1 receives interrupted
Input   : none
Output  : none
oˉêy1|?ü£o′??ú1?óê??D??
è??ú2?êy£o?T
·μ ?? ?μ£o?T
**************************************************************************/
int USART1_IRQHandler(void)
{	
	if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //Check if data is received //?D??ê?·??óê?μ?êy?Y
	{
		u8 Usart_Receive;
		static u8 Count;
		static u8 rxbuf[11];
		int check=0,error=1,i;
		
		Usart_Receive = USART_ReceiveData(USART1); //Read the data //?áè?êy?Y
		if(Time_count<CONTROL_DELAY)
			// Data is not processed until 10 seconds after startup
		  //?a?ú10???°2?′|àíêy?Y
			return 0;	
			
		//Fill the array with serial data
		//′??úêy?Yì?è?êy×é
    rxbuf[Count]=Usart_Receive;  
		
		//Ensure that the first data in the array is FRAME_HEADER
		//è·±£êy×éμúò???êy?Y?aFRAME_HEADER
    if(Usart_Receive == FRAME_HEADER||Count>0) 
			Count++; 
		else 
			Count=0;
		
		if (Count == 11) //Verify the length of the packet //?é?¤êy?Y°üμ?3¤?è
		{   
				Count=0; //Prepare for the serial port data to be refill into the array //?a′??úêy?Y??D?ì?è?êy×é×?×?±?
				if(rxbuf[10] == FRAME_TAIL) //Verify the frame tail of the packet //?é?¤êy?Y°üμ????2
				{			
					for(i=0; i<9; i++)
					{
						//XOR bit check, used to detect data error
						//òì?ò??D£?é£?ó?óú?ì2aêy?Yê?·?3?′í
						check=rxbuf[i]^check; 
					}
					if(check==rxbuf[9]) 
						//XOR bit check successful
					  //òì?ò??D£?é3é1|
					  error=0; 
					
					if(error==0)	 
				  {		
						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
						//′ó′??úêy?Y?óèy?á??±ê?ù?è£?·???8??oíμí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
oˉêy1|?ü£o′??ú2?óê??D??
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
int USART2_IRQHandler(void)
{	
	int Usart_Receive;
	if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //Check if data is received //?D??ê?·??óê?μ?êy?Y
	{	      
		static u8 Flag_PID,i,j,Receive[50],Last_Usart_Receive;
		static float Data;
				
		Usart_Receive=USART2->DR; //Read the data //?áè?êy?Y
		
		if(Deviation_Count<CONTROL_DELAY)
			// Data is not processed until 10 seconds after startup
		  //?a?ú10???°2?′|àíêy?Y
		  return 0;	

		if(Usart_Receive==0x41&&Last_Usart_Receive==0x41&&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
			//?a?ú10????oó£?°′??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_Receive==0x4B) 
			//Enter the APP steering control interface
		  //??è?APP×a?ò????????
			Turn_Flag=1;  
	  else	if(Usart_Receive==0x49||Usart_Receive==0x4A) 
      // Enter the APP direction control interface		
			//??è?APP·??ò????????	
			Turn_Flag=0;	
		
		if(Turn_Flag==0) 
		{
			//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×a?ò?????????üá?
			if     (Usart_Receive==0x43) Flag_Left=0,Flag_Right=1; //Right rotation //óò×?×a
			else if(Usart_Receive==0x47) Flag_Left=1,Flag_Right=0; //Left rotation  //×ó×?×a
			else                         Flag_Left=0,Flag_Right=0;
			if     (Usart_Receive==0x41||Usart_Receive==0x45) Flag_Direction=Usart_Receive-0x40;
			else  Flag_Direction=0;
		}
		if(Usart_Receive==0x58)  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_Receive==0x7B) Flag_PID=1;   //The start bit of the APP parameter instruction //APP2?êy??á??eê???
	 if(Usart_Receive==0x7D) Flag_PID=2;   //The APP parameter instruction stops the bit    //APP2?êy??á?í£?1??

	 if(Flag_PID==1) //Collect data //2é?ˉêy?Y
	 {
		Receive[i]=Usart_Receive;
		i++;
	 }
	 if(Flag_PID==2) //Analyze the data //·???êy?Y
	 {
			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			
      //?à1?±ê??????á?			
			Flag_PID=0;
			i=0;
			j=0;
			Data=0;
			memset(Receive, 0, sizeof(u8)*50); //Clear the array to zero//êy×é??á?
	 }
   if(RC_Velocity<0)   RC_Velocity=0; 	 
  }
  return 0;	
}
/**************************************************************************
Function: Serial port 3 receives interrupted
Input   : none
Output  : none
oˉêy1|?ü£o′??ú3?óê??D??
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
int USART3_IRQHandler(void)
{	
	static u8 Count=0;
	u8 Usart_Receive;

	if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //Check if data is received //?D??ê?·??óê?μ?êy?Y
	{
		Usart_Receive = USART_ReceiveData(USART3);//Read the data //?áè?êy?Y
		if(Time_count<CONTROL_DELAY)
			// Data is not processed until 10 seconds after startup
		  //?a?ú10???°2?′|àíêy?Y
		  return 0;	
		
		//Fill the array with serial data
		//′??úêy?Yì?è?êy×é
    Receive_Data.buffer[Count]=Usart_Receive;
		
		// Ensure that the first data in the array is FRAME_HEADER
		//è·±£êy×éμúò???êy?Y?aFRAME_HEADER
		if(Usart_Receive == FRAME_HEADER||Count>0) 
			Count++; 
		else 
			Count=0;
		
		if (Count == 11) //Verify the length of the packet //?é?¤êy?Y°üμ?3¤?è
		{   
				Count=0; //Prepare for the serial port data to be refill into the array //?a′??úêy?Y??D?ì?è?êy×é×?×?±?
				if(Receive_Data.buffer[10] == FRAME_TAIL) //Verify the frame tail of the packet //?é?¤êy?Y°üμ????2
				{
					//Data exclusionary or bit check calculation, mode 0 is sent data check
					//êy?Yòì?ò??D£?é????£??£ê?0ê?·¢?íêy?YD£?é
					if(Receive_Data.buffer[9] ==Check_Sum(9,0))	 
				  {		
						float Vz;
						//All modes flag position 0, USART3 control mode
            //?ùóD?£ê?±ê??????0£??aUsart3?????£ê?						
						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
						//′ó′??úêy?Y?óèy?á??±ê?ù?è£? μ¥??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
oˉêy1|?ü£o′??ú5?óê??D??
è??ú2?êy£o?T
·μ??  ?μ£o?T
**************************************************************************/
int UART5_IRQHandler(void)
{	
	static u8 Count=0;
	u8 Usart_Receive;

	if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) //Check if data is received //?D??ê?·??óê?μ?êy?Y
	{
		Usart_Receive = USART_ReceiveData(UART5);//Read the data //?áè?êy?Y
		if(Time_count<CONTROL_DELAY)
			// Data is not processed until 10 seconds after startup
		  //?a?ú10???°2?′|àíêy?Y
		  return 0;	
		
		//Fill the array with serial data
		//′??úêy?Yì?è?êy×é
    Receive_Data.buffer[Count]=Usart_Receive;
		
		// Ensure that the first data in the array is FRAME_HEADER
		//è·±£êy×éμúò???êy?Y?aFRAME_HEADER
		if(Usart_Receive == FRAME_HEADER||Count>0) 
			Count++; 
		else 
			Count=0;
		
		if (Count == 11) //Verify the length of the packet //?é?¤êy?Y°üμ?3¤?è
		{   
				Count=0; //Prepare for the serial port data to be refill into the array //?a′??úêy?Y??D?ì?è?êy×é×?×?±?
				if(Receive_Data.buffer[10] == FRAME_TAIL) //Verify the frame tail of the packet //?é?¤êy?Y°üμ????2
				{
					//Data exclusionary or bit check calculation, mode 0 is sent data check
					//êy?Yòì?ò??D£?é????£??£ê?0ê?·¢?íêy?YD£?é
					if(Receive_Data.buffer[9] ==Check_Sum(9,0))	 
				  {		
						float Vz;
						//All modes flag position 0, USART5 control mode
            //?ùóD?£ê?±ê??????0£??aUsart5?????£ê?						
						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
						//′ó′??úêy?Y?óèy?á??±ê?ù?è£? μ¥??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
oˉêy1|?ü£o??é????ú·¢1yà′??±ê?°???ù?èVx?¢??±ê???ù?èVz£?×a???a°¢???üD?3μμ?óò?°??×a??
è??ú2?êy£o??±ê?°???ù?èVx?¢??±ê???ù?èVz£?μ¥??£om/s£?rad/s
·μ??  ?μ£o°¢???üD?3μμ?óò?°??×a??£?μ¥??£orad
**************************************************************************/
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
	//°¢???üD?3μDèòaéè??×?D?×aí?°???
	//è?1???±ê?ù?èòa?óμ?×aí?°???D?óú×?D?×aí?°???£?
	//?áμ???D?3μ???ˉ?|2áá|′ó′óìá??£?????ó°?ì????D§1?
	Min_Turn_Radius=MINI_AKM_MIN_TURN_RADIUS;
	
	if(Vz!=0 && Vx!=0)
	{
		//If the target speed requires a turn radius less than the minimum turn radius
		//è?1???±ê?ù?èòa?óμ?×aí?°???D?óú×?D?×aí?°???
		if(float_abs(Vx/Vz)<=Min_Turn_Radius)
		{
			//Reduce the target angular velocity and increase the turning radius to the minimum turning radius in conjunction with the forward speed
			//?μμí??±ê???ù?è£???o??°???ù?è£?ìá??×aí?°???μ?×?D?×aí?°???
			if(Vz>0)
				Vz= float_abs(Vx)/(Min_Turn_Radius);
			else	
				Vz=-float_abs(Vx)/(Min_Turn_Radius);	
		}		
		R=Vx/Vz;
		//AngleL=atan(Axle_spacing/(R-0.5*Wheel_spacing));
		AngleR=atan(Axle_spacing/(R+0.5*Wheel_spacing));
	}
	else
	{
		AngleR=0;
	}
	
	return AngleR;
}
/**************************************************************************
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
oˉêy1|?ü£o??é????ú·¢1yà′μ???8??oíμí8??êy?Y??o?3éò???shortDíêy?Yoó£??ù×?μ¥???1?-????
è??ú2?êy£o??8??£?μí8??
·μ??  ?μ£o?ú?÷è?X/Y/Z?áμ???±ê?ù?è
**************************************************************************/
float XYZ_Target_Speed_transition(u8 High,u8 Low)
{
	//Data conversion intermediate variable
	//êy?Y×a??μ??D??±?á?
	short transition; 
	
	//????8??oíμí8????o?3éò???16??μ?shortDíêy?Y
	//The high 8 and low 8 bits are integrated into a 16-bit short data
	transition=((High<<8)+Low); 
	return 
		transition/1000+(transition%1000)*0.001; //Unit conversion, mm/s->m/s //μ¥??×a??, mm/s->m/s						
}
/**************************************************************************
Function: Serial port 1 sends data
Input   : The data to send
Output  : none
oˉêy1|?ü£o′??ú1·¢?íêy?Y
è??ú2?êy£oòa·¢?íμ?êy?Y
·μ??  ?μ£o?T
**************************************************************************/
void usart1_send(u8 data)
{
	USART1->DR = data;
	while((USART1->SR&0x40)==0);	
}
/**************************************************************************
Function: Serial port 2 sends data
Input   : The data to send
Output  : none
oˉêy1|?ü£o′??ú2·¢?íêy?Y
è??ú2?êy£oòa·¢?íμ?êy?Y
·μ??  ?μ£o?T
**************************************************************************/
void usart2_send(u8 data)
{
	USART2->DR = data;
	while((USART2->SR&0x40)==0);	
}
/**************************************************************************
Function: Serial port 3 sends data
Input   : The data to send
Output  : none
oˉêy1|?ü£o′??ú3·¢?íêy?Y
è??ú2?êy£oòa·¢?íμ?êy?Y
·μ??  ?μ£o?T
**************************************************************************/
void usart3_send(u8 data)
{
	USART3->DR = data;
	while((USART3->SR&0x40)==0);	
}
/**************************************************************************
Function: Serial port 5 sends data
Input   : The data to send
Output  : none
oˉêy1|?ü£o′??ú5·¢?íêy?Y
è??ú2?êy£oòa·¢?íμ?êy?Y
·μ??  ?μ£o?T
**************************************************************************/
void usart5_send(u8 data)
{
	UART5->DR = data;
	while((UART5->SR&0x40)==0);	
}

/**************************************************************************
Function: Calculates the check bits of data to be sent/received
Input   : Count_Number: The first few digits of a check; Mode: 0-Verify the received data, 1-Validate the sent data
Output  : Check result
oˉêy1|?ü£o????òa·¢?í/?óê?μ?êy?YD£?é?á1?
è??ú2?êy£oCount_Number£oD£?éμ??°????êy£?Mode£o0-???óê?êy?Y??DDD£?é£?1-??·¢?íêy?Y??DDD£?é
·μ??  ?μ£oD£?é?á1?
**************************************************************************/
u8 Check_Sum(unsigned char Count_Number,unsigned char Mode)
{
	unsigned char check_sum=0,k;
	
	//Validate the data to be sent
	//??òa·¢?íμ?êy?Y??DDD£?é
	if(Mode==1)
	for(k=0;k<Count_Number;k++)
	{
	check_sum=check_sum^Send_Data.buffer[k];
	}
	
	//Verify the data received
	//???óê?μ?μ?êy?Y??DDD£?é
	if(Mode==0)
	for(k=0;k<Count_Number;k++)
	{
	check_sum=check_sum^Receive_Data.buffer[k];
	}
	return check_sum;
}

总结

代码里的内容不难看懂,STM32用了FreeRTOS操作系统,ROS就是c++文件。

  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2022-03-16 22:35:59  更:2022-03-16 22:36:02 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 6:27:27-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码