Files
cyy_mac 93ca37e36c 完善阿克曼控制与高速串口遥测
- 校正舵机中位、转向符号和阿克曼后轮差速模型\n- 增加航向角速度辅助及遥控通道调试开关\n- 将速度环提升至 200Hz,并按实际 dt 计算 PI 积分\n- 将 IMU 启动校准缩短为 2 秒\n- 为 USART3 增加 DMA 发送和 MCU 采样时间戳
2026-08-12 18:51:48 +08:00

102 lines
3.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __USRATX_H
#define __USRATX_H
#include "stdio.h"
#include "sys.h"
#include "system.h"
#define DATA_STK_SIZE 512
#define DATA_TASK_PRIO 4
#define FRAME_HEADER 0X7B //Frame_header //֡ͷ
#define FRAME_TAIL 0X7D //Frame_tail //֡β
//Frame grew 24 -> 44: appended session_id(4) + two 64-bit sample
//timestamps(8+8) before the checksum/tail. Bytes 0..21 keep the legacy
//layout so old parsers stay compatible; new fields live in the tail.
//֡<><D6A1> 24 -> 44<34><34><EFBFBD><EFBFBD>У<EFBFBD><D0A3>/֡βǰ׷<C7B0><D7B7><EFBFBD><EFBFBD> session_id(4) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 64λ<34><CEBB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>(8+8)<29><>
//<2F>ֽ<EFBFBD> 0..21 <20><><EFBFBD>ֽ<EFBFBD>ϲ<EFBFBD><CFB2>֣<EFBFBD><D6A3>¾ֽ<C2BE><D6BD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD>
#define SEND_DATA_SIZE 44
#define RECEIVE_DATA_SIZE 11
/*****A structure for storing triaxial data of a gyroscope accelerometer*****/
/*****<2A><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC>ٶȼ<D9B6><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĽṹ<C4BD><E1B9B9>*********************************/
typedef struct __Mpu6050_Data_
{
short X_data; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
short Y_data; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
short Z_data; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
}Mpu6050_Data;
/*******The structure of the serial port sending data************/
/*******<2A><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĽṹ<C4BD><E1B9B9>*************************************/
typedef struct _SEND_DATA_
{
unsigned char buffer[SEND_DATA_SIZE];
struct _Sensor_Str_
{
unsigned char Frame_Header; //1<><31><EFBFBD>ֽ<EFBFBD>
short X_speed; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
short Y_speed; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
short Z_speed; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
short Power_Voltage; //2 bytes //2<><32><EFBFBD>ֽ<EFBFBD>
Mpu6050_Data Accelerometer; //6 bytes //6<><36><EFBFBD>ֽ<EFBFBD>
Mpu6050_Data Gyroscope; //6 bytes //6<><36><EFBFBD>ֽ<EFBFBD>
unsigned int Session_Id; //4 bytes: MCU boot session ID //<2F><>MCU<43><55><EFBFBD><EFBFBD><EFBFBD>ỰID
unsigned long long Speed_Time_us; //8 bytes: encoder sample time //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
unsigned long long Imu_Time_us; //8 bytes: IMU sample time //IMU<4D><55><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
unsigned char Frame_Tail; //1 bytes //1<><31><EFBFBD>ֽ<EFBFBD>
}Sensor_Str;
}SEND_DATA;
typedef struct _RECEIVE_DATA_
{
unsigned char buffer[RECEIVE_DATA_SIZE];
struct _Control_Str_
{
unsigned char Frame_Header; //1 bytes //1<><31><EFBFBD>ֽ<EFBFBD>
float X_speed; //4 bytes //4<><34><EFBFBD>ֽ<EFBFBD>
float Y_speed; //4 bytes //4<><34><EFBFBD>ֽ<EFBFBD>
float Z_speed; //4 bytes //4<><34><EFBFBD>ֽ<EFBFBD>
unsigned char Frame_Tail; //1 bytes //1<><31><EFBFBD>ֽ<EFBFBD>
}Control_Str;
}RECEIVE_DATA;
//Sample timestamps captured at acquisition time by their owning tasks, and
//the per-boot session ID. Read by data_transition() when packing the frame.
//<2F>ɸ<EFBFBD><C9B8>Բɼ<D4B2><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>лỰID<49><44>
//<2F><> data_transition() <20><><EFBFBD>֡ʱ<D6A1><CAB1>ȡ<EFBFBD><C8A1>
extern volatile unsigned long long g_speed_sample_time_us;
extern volatile unsigned long long g_imu_sample_time_us;
extern volatile unsigned int g_session_id;
void data_task(void *pvParameters);
void data_transition(void);
void USART1_SEND(void);
void USART3_SEND(void);
void USART5_SEND(void);
void CAN_SEND(void);
void uart1_init(u32 bound);
void uart2_init(u32 bound);
void uart3_init(u32 bound);
void uart3_dma_tx_init(void);
void uart5_init(u32 bound);
int USART1_IRQHandler(void);
int USART2_IRQHandler(void);
int USART3_IRQHandler(void);
int UART5_IRQHandler(void);
float Vz_to_Akm_Angle(float Vx, float Vz);
float XYZ_Target_Speed_transition(u8 High,u8 Low);
void usart1_send(u8 data);
void usart2_send(u8 data);
void usart3_send(u8 data);
void usart5_send(u8 data);
u8 Check_Sum(unsigned char Count_Number,unsigned char Mode);
#endif