1358 lines
61 KiB
C
1358 lines
61 KiB
C
#ifndef _INTERFACE_H_
|
||
#define _INTERFACE_H_
|
||
|
||
#include "stdint.h"
|
||
|
||
#include "app/app_config.h" // 假设包含基础配置和宏定义
|
||
#include "irq.h"
|
||
#include "interface_config.h"
|
||
#include <udelay/udelay.h>
|
||
|
||
|
||
|
||
#pragma pack(1)//数据结构一个字节对齐
|
||
|
||
|
||
#define REQUEST_READ_ID un_request_frame.bit_data.request_id//读取ID
|
||
#define REQUEST_HEADER_ID un_request_frame.bit_data.frame_header//帧头
|
||
|
||
|
||
#define FAULT 0
|
||
#define NORMAL 1
|
||
|
||
#define MAX_RECEIVED_DATA_SIZE 1024
|
||
|
||
//-----CAN----------------------------------------------------------------
|
||
// 接收电机控制器输入
|
||
typedef struct _StrMotorInput
|
||
{
|
||
//-----接收数据0x101或者0x201----------------------------------------------
|
||
unsigned int speed : 16; // 转速 偏移量 -30000
|
||
unsigned int bus_voltage : 16; // 母线电压 系数 0.1 偏移量 -3000
|
||
unsigned int torque : 16; // 扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
|
||
unsigned int fault_code : 8; // 故障码
|
||
unsigned int heartbeat : 8; // 心跳
|
||
|
||
} StrMotorInput;
|
||
typedef union _UnMotorInput
|
||
{
|
||
StrMotorInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrMotorInput)]; // 通过结构体类型确定大小
|
||
} UnMotorInput;
|
||
|
||
|
||
|
||
// 接收电机控制器输入
|
||
typedef struct _StrCanDebugOutput
|
||
{
|
||
uint8_t speed;
|
||
uint8_t desired_speed;
|
||
uint8_t curvature;
|
||
uint8_t desired_curvature;
|
||
uint16_t set_left_out;
|
||
uint16_t set_right_out;
|
||
} StrCanDebugOutput;
|
||
|
||
typedef union _UnCanDebugOutput
|
||
{
|
||
StrCanDebugOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrCanDebugOutput)]; // 通过结构体类型确定大小
|
||
} UnCanDebugOutput;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
typedef struct _StrMotorTempInput
|
||
{
|
||
//-----接收数据0x103或者0x104----------------------------------------------
|
||
unsigned int controller_temp : 8; // 控制器温度 偏移量 -40
|
||
unsigned int motor_temp : 8; // 电机温度 偏移量 -40
|
||
unsigned int motor_max_torque: 16; // 电机最大扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
|
||
unsigned int reserved_1 : 8; // 保留1
|
||
unsigned int reserved_2 : 8; // 保留2
|
||
unsigned int reserved_3 : 8; // 保留3
|
||
unsigned int heartbeat2 : 8; // 心跳
|
||
|
||
} StrMotorTempInput;
|
||
|
||
typedef union _UnMotorTempInput
|
||
{
|
||
StrMotorTempInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrMotorInput)]; // 通过结构体类型确定大小
|
||
} UnMotorTempInput;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 接收BMS输入
|
||
typedef struct _StrBmsInput
|
||
{
|
||
//----接收0x100----------------------------------
|
||
// 多字节数据,高位在前,低位在后
|
||
unsigned int bus_voltage : 16; // 母线电压 单位为10mV
|
||
unsigned int bus_current : 16; // 母线电流 单位为10mA
|
||
unsigned int remainder_capacity : 16; // 剩余容量 单位为10mAh 充电为正,放电为负
|
||
unsigned int crc1 : 16; //crc
|
||
//----接收0x101----------------------------------
|
||
// 多字节数据,高位在前,低位在后
|
||
unsigned int full_capacity : 16; // 充满容量 单位为10mAh
|
||
unsigned int Discharge_times : 16; // 放电循环次数 单位为1次
|
||
unsigned int soc : 16; // soc 1%
|
||
unsigned int crc2 : 16; //crc
|
||
} StrBmsInput;
|
||
|
||
typedef union _UnBmsInput
|
||
{
|
||
StrBmsInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrBmsInput)]; // 通过结构体类型确定大小
|
||
} UnBmsInput;
|
||
|
||
|
||
// 接收温度模块输入
|
||
typedef struct _StrTempModuleInput
|
||
{
|
||
//-----接收数据0x301,302----------------------------------------------
|
||
// 多字节数据,高位在前,低位在后
|
||
unsigned int channel_1 : 16; // 通道1 温度传感器 系数为0.1 有符号 正数表示正温度,负数表示负温度
|
||
unsigned int channel_2 : 16; // 通道2
|
||
unsigned int channel_3 : 16; // 通道3
|
||
unsigned int channel_4 : 16; // 通道4
|
||
unsigned int channel_5 : 16; // 通道5
|
||
unsigned int channel_6 : 16; // 通道6
|
||
unsigned int channel_7 : 16; // 通道7
|
||
unsigned int channel_8 : 16; // 通道8
|
||
} StrTempModuleInput;
|
||
|
||
typedef union _UnTempModuleInput
|
||
{
|
||
StrTempModuleInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrTempModuleInput)]; // 通过结构体类型确定大小
|
||
} UnTempModuleInput;
|
||
|
||
|
||
|
||
|
||
//-----以太网-------------------------------------------------------------
|
||
// 接收自主计算机自动输入
|
||
typedef struct _StrAutoComputerInput
|
||
{
|
||
// 多字节数据,高位在前,低位在后
|
||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0001
|
||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||
unsigned int heartbeat : 8; // 心跳 按帧累加
|
||
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
|
||
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
|
||
unsigned int latitude : 32; // 纬度 系数10^-7,431234567表示43.1234567度
|
||
unsigned int longitude : 32; // 经度 系数10^-7,431234567表示43.1234567度
|
||
unsigned int altitude : 32; // 高度 单位mm
|
||
unsigned int heading : 16; // 航向 车辆航向,35999表示359.99度
|
||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||
} StrAutoComputerInput;
|
||
|
||
typedef union _UnAutoComputerInput
|
||
{
|
||
StrAutoComputerInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrAutoComputerInput)]; // 通过结构体类型确定大小
|
||
} UnAutoComputerInput;
|
||
|
||
|
||
|
||
|
||
|
||
// 接收自主计算机手动输入
|
||
|
||
typedef struct _StrManualComputerInput
|
||
{
|
||
// 手动控制数据 高位在前,低位在后
|
||
unsigned int frame_header : 16; // 帧头 固定值0xFFBB
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0011
|
||
unsigned int frame_length : 8; // 帧长 固定值0x0B
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int set_speed : 16; // 期望速度 系数0.01,正为前进,负为后退 单位m/s
|
||
unsigned int set_curvature : 16; // 期望曲率 系数0.0001,正为左转,负为右转
|
||
unsigned int reserved : 8; // 保留 同时按下LB+Y时发0xFF,松开发0,同时按下LT+Y时发0x10,松开发0
|
||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||
} StrManualComputerInput;
|
||
|
||
typedef union _UnManualComputerInput
|
||
{
|
||
StrManualComputerInput bit_data; // 使用定义的结构体变量名
|
||
unsigned int arr[sizeof(StrManualComputerInput)]; // 通过结构体类型确定大小
|
||
} UnManualComputerInput;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 接收请求帧
|
||
typedef struct _StrRequestFrame
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 固定值0x0080
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0029
|
||
unsigned int frame_length : 16; // 帧长 固定值10
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int request_id : 16; // 请求帧ID 请求ID 0-FFFF,FFFF表示全部帧
|
||
unsigned int crc : 8; // CRC 按字节累加之和 取低8位
|
||
} StrRequestFrame;
|
||
|
||
typedef union _UnRequestFrame
|
||
{
|
||
StrRequestFrame bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrRequestFrame)]; // 通过结构体类型确定大小
|
||
} UnRequestFrame;
|
||
|
||
|
||
// 接收遥控器输入
|
||
typedef struct _StrRemoteControlInput
|
||
{
|
||
//-----接收数据0x12000013----------------------------------------------
|
||
unsigned int speed : 16; // 速度
|
||
unsigned int curvature : 16; // 曲率
|
||
unsigned int reserve1 : 16; // 遥控轴
|
||
|
||
unsigned int switch_a : 1; // SwA
|
||
unsigned int switch_b : 2; // SwB 急停开关 1释放 0/2是急停
|
||
unsigned int switch_c : 2; // SwC 模式开关 1自动 0/2是手动
|
||
unsigned int switch_d : 1; // SwD 上电开关 先短按再长按
|
||
unsigned int reserve2 : 1; // 保留
|
||
unsigned int reserve3 : 1; // 保留
|
||
|
||
unsigned int enable : 8; // 使能
|
||
} StrRemoteControlInput;
|
||
|
||
typedef union _UnRemoteControlInput
|
||
{
|
||
StrRemoteControlInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrRemoteControlInput)]; // 通过结构体类型确定大小
|
||
} UnRemoteControlInput;
|
||
|
||
|
||
// 定义接收数据结构体
|
||
typedef struct {
|
||
uint8_t data[MAX_RECEIVED_DATA_SIZE];
|
||
uint32_t length;
|
||
} ReceivedDataStruct;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//-----IO口---------------------------------------------------------------
|
||
// 从IO口输入
|
||
|
||
//20250116 增加温度采集字节
|
||
typedef struct _StrSwSample
|
||
{
|
||
unsigned int emergency_stop_switch : 1; // 通道1,急停开关
|
||
unsigned int High_voltage_switch : 1; // 通道2,高压开关
|
||
unsigned int flg_wake_ecu : 1; // 通道3
|
||
unsigned int CH04 : 1; // 通道4
|
||
unsigned int CH05 : 1; // 通道5
|
||
unsigned int CH06 : 1; // 通道6
|
||
unsigned int CH07 : 1; // 通道7
|
||
unsigned int CH08 : 1; // 通道8
|
||
unsigned int CH09 : 1; // 通道9
|
||
unsigned int CH10 : 1; // 通道10
|
||
unsigned int CH11 : 1; // 通道11
|
||
unsigned int CH12 : 1; // 通道12
|
||
unsigned int CH13 : 1; // 通道13
|
||
unsigned int CH14 : 1; // 通道14
|
||
unsigned int CH15 : 1; // 通道15
|
||
unsigned int CH16 : 1; // 通道16
|
||
unsigned int CH17 : 1; // 通道17
|
||
unsigned int CH18 : 1; // 通道18
|
||
unsigned int CH19 : 1; // 通道19
|
||
unsigned int CH20 : 1; // 通道20
|
||
unsigned int CH21 : 1; // 通道21
|
||
unsigned int CH22 : 1; // 通道22
|
||
unsigned int CH23 : 1; // 通道23
|
||
unsigned int CH24 : 1; // 通道24
|
||
unsigned int CH25 : 1; // 通道25
|
||
unsigned int CH26 : 1; // 通道26
|
||
unsigned int CH27 : 1; // 通道27
|
||
unsigned int CH28 : 1; // 通道28
|
||
unsigned int CH29 : 1; // 通道29
|
||
unsigned int CH30 : 1; // 通道30
|
||
unsigned int CH31 : 1; // 通道31
|
||
unsigned int CH32 : 1; // 通道32
|
||
|
||
// unsigned int CH33 : 1; // 通道33
|
||
// unsigned int CH34 : 1; // 通道34
|
||
// unsigned int CH35 : 1; // 通道35
|
||
// unsigned int CH36 : 1; // 通道36
|
||
// unsigned int CH37 : 1; // 通道37
|
||
// unsigned int CH38 : 1; // 通道38
|
||
// unsigned int CH39 : 1; // 通道39
|
||
// unsigned int CH40 : 1; // 通道40
|
||
// unsigned int CH41 : 1; // 通道41
|
||
// unsigned int CH42 : 1; // 通道42
|
||
// unsigned int CH43 : 1; // 通道43
|
||
// unsigned int CH44 : 1; // 通道44
|
||
// unsigned int reserve : 4;
|
||
unsigned int temperature[2]; // 温度
|
||
|
||
} StrSwSample;
|
||
|
||
typedef union _UnSwSample
|
||
{
|
||
StrSwSample bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrSwSample)]; // 通过结构体类型确定大小
|
||
} UnSwSample;
|
||
|
||
|
||
//-----输出数据结构---------------------------------------------------------------
|
||
//-----CAN----------------------------------------------------------------
|
||
// 输出到电机控制器
|
||
typedef struct _StrMotorOutput
|
||
{
|
||
//-----发送数据0x201或者0x202----------------------------------------------
|
||
unsigned int mode : 8; // 模式 0x1恒速模式,0x2恒扭模式,其他无效
|
||
unsigned int gear : 8; // 档位 0x0空挡模式,0x1前进挡,0x2倒退档,其他无效
|
||
unsigned int set_torque : 16; // 给定扭矩 系数 0.01 偏移量 -300 实际物理量=数据×系数+偏移量
|
||
unsigned int set_rotation_speed : 16; // 给定转速 偏移量 -30000
|
||
unsigned int fault_code : 8; // 故障码
|
||
unsigned int heartbeat : 8; // 心跳
|
||
//-----发送数据0x401或者0x402----------------------------------------------
|
||
unsigned int feed_power : 16; // 馈电功率 单位为 W 最大为10KW
|
||
unsigned int discharge_power : 16; // 放电功率 单位为 W 最大为15kW
|
||
unsigned int reserve1 : 16; // 保留
|
||
unsigned int reserve2 : 16; // 保留
|
||
} StrMotorOutput;
|
||
|
||
typedef union _UnMotorOutput
|
||
{
|
||
StrMotorOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrMotorOutput)]; // 通过结构体类型确定大小
|
||
} UnMotorOutput;
|
||
|
||
|
||
// 输出到采集模块
|
||
typedef struct _StrGatherOutput
|
||
{
|
||
//----- Send Data 0x15000002 ----------------------------------------------
|
||
unsigned int sleep_duration : 16; // 休眠时间
|
||
unsigned int wakeup_interval : 16; // 唤醒时间
|
||
unsigned int vehicle_mode : 8; // 整车模式
|
||
unsigned int reserved1 : 8; // 保留1
|
||
unsigned int reserved2 : 8; // 保留2
|
||
unsigned int reserved3 : 8; // 保留3
|
||
} StrGatherOutput;
|
||
|
||
typedef union _UnGatherOutput
|
||
{
|
||
StrGatherOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrGatherOutput)]; // 通过结构体类型确定大小
|
||
} UnGatherOutput;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// canoe协议输出
|
||
typedef struct _StrSdoOutput
|
||
{
|
||
//-----发送数据0x601----------------------------------------------
|
||
unsigned int cmd : 8; // 命令
|
||
unsigned int object_index : 16; // 索引
|
||
unsigned int sub_index : 8; // 从索引
|
||
unsigned int data : 32; // 数据
|
||
} StrSdoOutput;
|
||
|
||
typedef union _UnSdoOutput
|
||
{
|
||
StrSdoOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
|
||
} UnSdoOutput;
|
||
|
||
|
||
|
||
// 超声波数据发送
|
||
typedef struct _StrUltrasonicOutput
|
||
{
|
||
//-----发送数据0x521----------------------------------------------
|
||
uint8_t node; // 节点
|
||
uint8_t function_code; // 功能码
|
||
uint16_t register_address; // 寄存器地址
|
||
uint16_t data; // 数据
|
||
uint16_t reserve;// 保留
|
||
} StrUltrasonicOutput;
|
||
|
||
typedef union _UnUltrasonicOutput
|
||
{
|
||
StrUltrasonicOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrUltrasonicOutput)]; // 通过结构体类型确定大小
|
||
} UnUltrasonicOutput;
|
||
|
||
|
||
// 超声波数据读取
|
||
typedef struct _StrUltrasonicIntput
|
||
{
|
||
//-----发送数据0x521----------------------------------------------
|
||
uint8_t node; // 节点
|
||
uint8_t function_code; // 功能码
|
||
uint8_t len; // 长度
|
||
uint16_t data; // 数据
|
||
uint8_t reserve1;// 保留
|
||
uint16_t reserve2;// 保留
|
||
} StrUltrasonicInput;
|
||
|
||
typedef union _UnUltrasonicInput
|
||
{
|
||
StrUltrasonicInput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrUltrasonicInput)]; // 通过结构体类型确定大小
|
||
} UnUltrasonicInput;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//typedef struct _StrMotorOutput
|
||
//{
|
||
////-----发送数据0x10F80807----------------------------------------------
|
||
// unsigned int gear : 2; // 0 表示空挡,1 表示前进,2 表示后退
|
||
// unsigned int can_gear : 1; // 0-无效 1-有效。无效时 BIT10 的挡位无效,以线路控制挡位为准
|
||
// unsigned int can_break : 1; // 0:不刹车,1-刹车(刹车时才能启动电子刹车)
|
||
// unsigned int reserve1 : 1; // 0-只有高速档 1-可以通过接线切换 123 档。
|
||
// unsigned int reserve2 : 1; // 0-无效 1-有效:线控防盗使能
|
||
// unsigned int reserve3 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve4 : 1; // 0-无效 1-有效:线控座桶使能
|
||
//
|
||
// unsigned int reserve5 : 1; // 0-无效 1-有效:线控边撑使能
|
||
// unsigned int reserve6 : 1; // 0-无效 1-有效:线控防盗使能
|
||
// unsigned int reserve7 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve8 : 1; // 0-无效 1-有效:线控座桶使能
|
||
// unsigned int reserve9 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve10 : 1; // 0-无效 1-有效:线控座桶使能
|
||
// unsigned int reserve11 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve12 : 1; // 0-无效 1-有效:线控座桶使能
|
||
//
|
||
// unsigned int reserve13 : 1; // 0-无效 1-有效:线控边撑使能
|
||
// unsigned int reserve14 : 1; // 0-无效 1-有效:线控防盗使能
|
||
// unsigned int reserve15 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve16 : 1; // 0-无效 1-有效:线控座桶使能
|
||
// unsigned int reserve17 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve18 : 1; // 0-无效 1-有效:线控座桶使能
|
||
// unsigned int motor_direction : 1; // 0 和 1 (静止空闲状态设置有效,在油门、 转矩、转速模式下允许设置,否则使用控制器 内部保存的参数控制电机方向)
|
||
// unsigned int Contactor : 1; // 0-断开 1-闭合,(部分控制器支持)
|
||
//
|
||
// unsigned int reserve19 : 1; // 0-无效 1-有效:线控边撑使能
|
||
// unsigned int reserve20 : 1; // 0-无效 1-有效:线控防盗使能
|
||
// unsigned int reserve21 : 1; // 0-无效 1-有效:线控巡航使能
|
||
// unsigned int reserve22 : 1; // 0-无效 1-有效:线控座桶使能
|
||
// unsigned int mode : 4; //0x0:转把控制,0x5:油门模式,0xA:转矩模式, 0xC:转速模式,其它无效停机。在这三种模式下,电机方向设置有效。只允许在停机状态下设置控制模式。
|
||
//
|
||
// unsigned int control_data1 : 16; // 油门-256~+256:(0~+256 表示最大油门,-256 表 示最大电子刹车力度。转矩 -256~10000,(正数 驱 动 扭 矩 0~1000.0Nm,负数表示刹车,-256 表示最大电子刹车力度)转速-256~12000,(正数表示转速 0~12000rpm, 负数表示刹车,-256 最大刹车力度)
|
||
// unsigned int control_data2 : 16; // 控制数据和上一个一样
|
||
//} StrMotorOutput;
|
||
//
|
||
//typedef union _UnMotorOutput
|
||
//{
|
||
// StrMotorOutput bit_data; // 使用定义的结构体变量名
|
||
// uint8_t arr[sizeof(StrMotorOutput)]; // 通过结构体类型确定大小
|
||
//} UnMotorOutput;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//电机控制器风扇左
|
||
//kgf1
|
||
//电机控制器风扇右
|
||
//kgf3
|
||
//预充
|
||
//kgf4
|
||
//高压压继电器
|
||
//kgf7,8
|
||
//低压继电器
|
||
//kgf11-12
|
||
//左前红灯
|
||
//kgf6
|
||
//左前黄灯
|
||
//kgf9
|
||
//左风扇
|
||
//kgf14
|
||
//右风扇
|
||
//kgf19
|
||
//电脑
|
||
//kgf 17-18
|
||
//交换机
|
||
//kgf 21-22
|
||
//右前红灯
|
||
//kgf24
|
||
//右前黄灯
|
||
//kgf25
|
||
//左后红灯
|
||
//kgf26
|
||
//左后黄灯
|
||
//kgf27
|
||
//右后红灯
|
||
//kgf29
|
||
//右后黄灯
|
||
//kgf30
|
||
|
||
|
||
// 输出到开关阀模块
|
||
typedef struct _StrInfCanKGFOutput
|
||
{
|
||
//----------主机发送命令字0x11000002 --------------------------------------------
|
||
unsigned int KGF01 : 1; // 通道1
|
||
unsigned int KGF02 : 1; // 通道2
|
||
unsigned int KGF03 : 1; // 通道3
|
||
unsigned int KGF04 : 1; // 通道4
|
||
unsigned int KGF05 : 1; // 通道5
|
||
unsigned int KGF06 : 1; // 通道6
|
||
unsigned int KGF07 : 1; // 通道7
|
||
unsigned int KGF08 : 1; // 通道8
|
||
unsigned int KGF09 : 1; // 通道9
|
||
unsigned int KGF10 : 1; // 通道10
|
||
unsigned int KGF11 : 1; // 通道11
|
||
unsigned int KGF12 : 1; // 通道12
|
||
unsigned int KGF13 : 1; // 通道13
|
||
unsigned int KGF14 : 1; // 通道14
|
||
unsigned int KGF15 : 1; // 通道15
|
||
unsigned int KGF16 : 1; // 通道16
|
||
|
||
unsigned int can_rx2 : 8; // 保留
|
||
unsigned int can_rx3 : 8; // 保留
|
||
unsigned int can_rx4 : 8; // 保留
|
||
unsigned int can_rx5 : 8; // 保留
|
||
unsigned int can_period_h : 8; // 发送周期高位
|
||
unsigned int can_period_l : 8; // 发送周期低位
|
||
|
||
//----------发送0x11000003 ---------------------------------------------------
|
||
unsigned int pwm_01 : 4; // PWM通道1
|
||
unsigned int pwm_02 : 4; // PWM通道2
|
||
unsigned int pwm_03 : 4; // PWM通道3
|
||
unsigned int pwm_04 : 4; // PWM通道4
|
||
unsigned int pwm_05 : 4; // PWM通道5
|
||
unsigned int pwm_06 : 4; // PWM通道6
|
||
unsigned int pwm_07 : 4; // PWM通道7
|
||
unsigned int pwm_08 : 4; // PWM通道8
|
||
unsigned int pwm_09 : 4; // PWM通道9
|
||
unsigned int pwm_10 : 4; // PWM通道10
|
||
unsigned int pwm_11 : 4; // PWM通道11
|
||
unsigned int pwm_12 : 4; // PWM通道12
|
||
unsigned int pwm_13 : 4; // PWM通道13
|
||
unsigned int pwm_14 : 4; // PWM通道14
|
||
unsigned int pwm_15 : 4; // PWM通道15
|
||
unsigned int pwm_16 : 4; // PWM通道16
|
||
} StrInfCanKGFOutput;
|
||
|
||
typedef union _UnInfCanKGFOutput
|
||
{
|
||
StrInfCanKGFOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrInfCanKGFOutput)]; // 通过结构体类型确定大小
|
||
} UnInfCanKGFOutput;
|
||
|
||
|
||
|
||
// 输出到H桥模块
|
||
typedef struct _StrHBridgeOutput
|
||
{
|
||
//----------主机发送命令字0x7F2 --------------------------------------------
|
||
unsigned int channel_01 : 1; // 通道1
|
||
unsigned int channel_02 : 1; // 通道2
|
||
unsigned int channel_03 : 1; // 通道3
|
||
unsigned int channel_04 : 1; // 通道4
|
||
unsigned int channel_05 : 1; // 通道5
|
||
unsigned int channel_06 : 1; // 通道6
|
||
unsigned int channel_07 : 1; // 通道7
|
||
unsigned int channel_08 : 1; // 通道8
|
||
unsigned int sleep_01 : 1; // 休眠1
|
||
unsigned int sleep_02 : 1; // 休眠2
|
||
unsigned int sleep_03 : 1; // 休眠3
|
||
unsigned int sleep_04 : 1; // 休眠4
|
||
unsigned int reserve_01 : 1; // 保留1
|
||
unsigned int reserve_02 : 1; // 保留2
|
||
unsigned int reserve_03 : 1; // 保留3
|
||
unsigned int reserve_04 : 1; // 保留4
|
||
|
||
unsigned int reserve_05 : 8; // 保留5
|
||
unsigned int reserve_06 : 8; // 保留6
|
||
unsigned int reserve_07 : 8; // 保留7
|
||
unsigned int reserve_08 : 8; // 保留8
|
||
unsigned int can_period_h : 8; // 发送周期高位
|
||
unsigned int can_period_l : 8; // 发送周期低位
|
||
|
||
//----------发送0x7F3 ---------------------------------------------------
|
||
unsigned int pwm_channel_01 : 4; // PWM通道1
|
||
unsigned int pwm_channel_02 : 4; // PWM通道2
|
||
unsigned int pwm_channel_03 : 4; // PWM通道3
|
||
unsigned int pwm_channel_04 : 4; // PWM通道4
|
||
unsigned int pwm_channel_05 : 4; // PWM通道5
|
||
unsigned int pwm_channel_06 : 4; // PWM通道6
|
||
unsigned int pwm_channel_07 : 4; // PWM通道7
|
||
unsigned int pwm_channel_08 : 4; // PWM通道8
|
||
unsigned int pwm_reserve_01 : 4; // 保留pwm1
|
||
unsigned int pwm_reserve_02 : 4; // 保留pwm2
|
||
unsigned int pwm_reserve_03 : 4; // 保留pwm3
|
||
unsigned int pwm_reserve_04 : 4; // 保留pwm4
|
||
unsigned int pwm_reserve_05 : 4; // 保留pwm5
|
||
unsigned int pwm_reserve_06 : 4; // 保留pwm6
|
||
unsigned int pwm_reserve_07 : 4; // 保留pwm7
|
||
unsigned int pwm_reserve_08 : 4; // 保留pwm8
|
||
} StrHBridgeOutput;
|
||
|
||
typedef union _UnHBridgeOutput
|
||
{
|
||
StrHBridgeOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrHBridgeOutput)]; // 通过结构体类型确定大小
|
||
} UnHBridgeOutput;
|
||
|
||
|
||
// 输出给导航仪
|
||
typedef struct _StrWheelSpeedOutput
|
||
{
|
||
//-----发送数据0x98----------------------------------------------
|
||
unsigned int left_front : 16; // 左前轮速
|
||
unsigned int right_front : 16; // 右前轮速
|
||
unsigned int left_rear : 16; // 左后轮速
|
||
unsigned int right_rear : 16; // 右后轮速
|
||
} StrWheelSpeedOutput;
|
||
|
||
typedef union _UnWheelSpeedOutput
|
||
{
|
||
StrWheelSpeedOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrWheelSpeedOutput)]; // 通过结构体类型确定大小
|
||
} UnWheelSpeedOutput;
|
||
|
||
|
||
// 输出给基站升降杆
|
||
typedef struct _StrLifterOutput
|
||
{
|
||
//-----发送数据0x6F2----------------------------------------------
|
||
unsigned int cmd : 8 ; // 上升命令
|
||
unsigned int reserve1 : 8 ; // 保留
|
||
unsigned int reserve2 : 16; // 保留
|
||
unsigned int reserve3 : 16; // 保留
|
||
unsigned int reserve4 : 16; // 保留
|
||
} StrLifterOutput;
|
||
|
||
typedef union _UnrLifterOutput
|
||
{
|
||
StrLifterOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrLifterOutput)]; // 通过结构体类型确定大小
|
||
} UnLifterOutput;
|
||
|
||
|
||
// CAN ID 解析(联合体形式,支持位域和32位直接访问)
|
||
typedef union _UnCanIdInfo
|
||
{
|
||
uint32_t raw; // 32位整型,直接读写整个CAN ID
|
||
struct
|
||
{
|
||
uint32_t motor_id : 8; // 0-7 bit (电机ID)
|
||
uint32_t data : 16; // 8-23 bit (数据字段)
|
||
uint32_t mode : 5; // 24-28 bit (模式)
|
||
uint32_t res : 3; // 29-31 bit (保留位)
|
||
} bits;
|
||
|
||
} UnCanIdInfo;
|
||
|
||
|
||
// 输出can数据
|
||
typedef struct _StrTxCanOutput
|
||
{
|
||
uint16_t index; // 索引(类似寄存器地址)
|
||
uint16_t object_index; // 子索引(通常为0x0000)
|
||
uint32_t data; // 数据字段
|
||
} StrTxCanOutput;
|
||
|
||
|
||
// CAN数据区联合体 (8字节,严格遵循图片协议,大端序数据)
|
||
typedef union _UnTxCanData {
|
||
StrTxCanOutput bit_data; // 结构化访问
|
||
uint8_t arr[sizeof(StrTxCanOutput)]; // 字节数组形式(用于原始数据读写)
|
||
} UnTxCanData;
|
||
|
||
|
||
// 接收CAN帧结构体
|
||
typedef struct _StrTxCanFrame
|
||
{
|
||
UnCanIdInfo tx_can_id; // 接收到的29位CAN ID
|
||
UnTxCanData tx_can_data; // 接收到的8字节数据区
|
||
} StrTxCanFrame;
|
||
|
||
|
||
|
||
// CAN ID 解析联合体 (29位扩展帧,严格遵循图片协议,小端序适配)
|
||
typedef union _UnRxCanIdInfo {
|
||
uint32_t raw; // 完整的32位值
|
||
|
||
struct {
|
||
// 注意:小端序下,位域布局从低位到高位(Bit0到Bit31)
|
||
// 编译器通常从低位开始分配位域
|
||
|
||
// 主机CAN_ID (Bit7~Bit0) - 8位 - 最低字节
|
||
uint32_t host_id : 8; // Bit7~0: 主机CAN_ID
|
||
|
||
// 电机状态与故障信息域 (Bit23~Bit8) - 16位
|
||
uint32_t motor_can_id : 8; // Bit15~8: 当前电机CAN ID
|
||
uint32_t undervoltage : 1; // Bit16: 欠压故障 (0无1有)
|
||
uint32_t overcurrent : 1; // Bit17: 过流 (0无1有)
|
||
uint32_t overtemperature : 1; // Bit18: 过温 (0无1有)
|
||
uint32_t mag_encoder_fault : 1; // Bit19: 磁编码故障 (0无1有)
|
||
uint32_t hall_fault : 1; // Bit20: HALL编码故障 (0无1有)
|
||
uint32_t uncalibrated : 1; // Bit21: 未标定 (0无1有)
|
||
uint32_t mode_state : 2; // Bit23~22: 模式状态 (0:Reset,1:Cali,2:Motor)
|
||
|
||
// 协议标识 (Bit28~Bit24) - 5位
|
||
uint32_t protocol_id : 5; // Bit28~24: 协议标识(图中为2)
|
||
|
||
// 保留位 (Bit31~29) - 3位(图片中未使用)
|
||
uint32_t reserved : 3; // Bit31~29: 保留位,应设置为0
|
||
} bits;
|
||
} UnRxCanIdInfo;
|
||
|
||
// 输出can数据
|
||
typedef struct _StrRxCanOutput
|
||
{
|
||
uint16_t current_angle; // Byte0~1: 当前角度 [0~65535]对应(-4π~4π)
|
||
uint16_t current_velocity; // Byte2~3: 当前角速度 [0~65535]对应(-15rad/s~15rad/s)
|
||
uint16_t current_torque; // Byte4~5: 当前力矩 [0~65535]对应(-120Nm~120Nm)
|
||
uint16_t temperature; // Byte6~7: 当前温度: Temp(摄氏度)*10
|
||
} StrRxCanOutput;
|
||
|
||
// CAN数据区联合体 (8字节,严格遵循图片协议,大端序数据)
|
||
typedef union _UnRxCanData
|
||
{
|
||
StrRxCanOutput bit_data; // 结构化访问
|
||
uint8_t arr[sizeof(StrRxCanOutput)]; // 字节数组形式(用于原始数据读写)
|
||
} UnRxCanData;
|
||
|
||
// 接收CAN帧结构体
|
||
typedef struct _StrRxCanFrame
|
||
{
|
||
UnRxCanIdInfo rx_can_id; // 接收到的29位CAN ID
|
||
UnRxCanData rx_can_data; // 接收到的8字节数据区
|
||
} StrRxCanFrame;
|
||
|
||
|
||
|
||
//-----以太网-------------------------------------------------------------
|
||
// 输出给自主计算机
|
||
typedef struct _StrComputerOutput
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 0xFFCC
|
||
unsigned int frame_type : 16; // 帧类型 0x0011
|
||
unsigned int frame_length : 8; // 帧长 0x000b,11
|
||
unsigned int accumulated : 8; // 累加值
|
||
unsigned int speed : 16; // 左侧轮速
|
||
unsigned int curvature : 16; // 右侧轮速
|
||
unsigned int crc : 8; // CRC
|
||
} StrComputerOutput;
|
||
|
||
typedef union _UnComputerOutput
|
||
{
|
||
StrComputerOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrComputerOutput)]; // 通过结构体类型确定大小
|
||
} UnComputerOutput;
|
||
|
||
|
||
|
||
|
||
// 车辆信息,输出给上位机
|
||
typedef struct _StrVehicleInfoOutput
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0020
|
||
unsigned int frame_length : 16; // 帧长 固定值41
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int desired_speed : 16; // 期望速度 系数0.01, 正为前进,负为后退 单位m/s
|
||
unsigned int desired_curvature : 16; // 期望曲率 系数0.0001,正为左转,负为右转
|
||
unsigned int set_left_speed : 16; // 设定左转速度 电机1设定转速 正为正传,负为反转
|
||
unsigned int set_right_speed : 16; // 设定右转速度 电机2设定转速 正为正传,负为反转
|
||
unsigned int longitude : 32; // 纬度 系数 1e-7 值域(-180°,180°)
|
||
unsigned int latitude : 32; // 经度 系数 1e-7 值域(-90°,90°)
|
||
unsigned int altitude : 32; // 高度
|
||
unsigned int heading_angle : 16; // 航向角 系数 0.01 值域(0-360°)
|
||
unsigned int speed : 16; // 当前车速 系数 0.01 正为前进,负为后退 单位m/s
|
||
unsigned int curvature : 16; // 当前曲率 系数 0.0001正为左转,负为右转
|
||
unsigned int battery_voltage : 16; // 电池电压 系数 0.1 单位V
|
||
unsigned int battery_soc : 16; // 电池SOC 系数 0.1 单位:%
|
||
unsigned int battery_current : 16; // 电池电流 系数 0.1 偏移量 -30000 单位A
|
||
unsigned int vehicle_fault_state : 8; // 整车故障状态 0 故障 1正常
|
||
unsigned int crc : 8; // CRC 按字节累加之和 取低8位
|
||
} StrVehicleInfoOutput;
|
||
|
||
typedef union _UnVehicleInfoOutput
|
||
{
|
||
StrVehicleInfoOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrVehicleInfoOutput)]; // 通过结构体类型确定大小
|
||
} UnVehicleInfoOutput;
|
||
|
||
|
||
// 电机状态信息,输出给上位机
|
||
typedef struct _StrMotorStatusOutput
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0021
|
||
unsigned int frame_length : 16; // 帧长 固定值30
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int left_wheel_speed : 16; // 当前左侧轮速 系数 1 偏移量 -30000 单位rad/min
|
||
unsigned int right_wheel_speed : 16; // 当前右侧轮速 系数 1 偏移量 -30000 单位rad/min
|
||
unsigned int left_torque : 16; // 左侧电机扭矩 系数 0.01 偏移量 -300 单位N/s
|
||
unsigned int right_torque : 16; // 右侧电机扭矩 系数 0.01 偏移量 -300 单位N/s
|
||
unsigned int left_fault_code : 8; // 左侧电机故障码
|
||
unsigned int right_fault_code : 8; // 右侧电机故障码
|
||
unsigned int left_torque_limit : 16; // 左侧电机扭矩限制 系数 0.01 偏移量 -300 单位N/s
|
||
unsigned int right_torque_limit : 16; // 右侧电机扭矩限制 系数 0.01 偏移量 -300 单位N/s
|
||
unsigned int left_power_in : 16; // 左侧电机馈电功率 系数 1 偏移量 0 单位W
|
||
unsigned int right_power_in : 16; // 右侧电机馈电功率 系数 1 偏移量 0 单位W
|
||
unsigned int left_power_out : 16; // 左侧电机放电功率 系数 1 偏移量 0 单位W
|
||
unsigned int right_power_out : 16; // 右侧电机放电功率 系数 1 偏移量 0 单位W
|
||
unsigned int left_voltage : 16; // 左侧电机电压 系数0.1 偏移量-3000 单位V
|
||
unsigned int right_voltage : 16; // 右侧电机电压 系数0.1 偏移量-3000 单位V
|
||
unsigned int checksum : 8; // 校验和 按字节累加之和 取低8位
|
||
} StrMotorStatusOutput;
|
||
|
||
typedef union _UnMotorStatusOutput
|
||
{
|
||
StrMotorStatusOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrMotorStatusOutput)]; // 通过结构体类型确定大小
|
||
} UnMotorStatusOutput;
|
||
|
||
|
||
|
||
|
||
// PID参数输出,输出给上位机
|
||
typedef struct _StrPIDOutput
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0022
|
||
unsigned int frame_length : 16; // 帧长 固定值56
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int rc_straight_p : 32; // 遥控直行P参数 系数 0.001
|
||
unsigned int rc_straight_i : 32; // 遥控直行I参数 系数 0.001
|
||
unsigned int rc_straight_d : 32; // 遥控直行D参数 系数 0.001
|
||
unsigned int auto_straight_p : 32; // 自主直行P参数 系数 0.001
|
||
unsigned int auto_straight_i : 32; // 自主直行I参数 系数 0.001
|
||
unsigned int auto_straight_d : 32; // 自主直行D参数 系数 0.001
|
||
unsigned int rc_turn_p : 32; // 遥控转弯P参数 系数 0.001
|
||
unsigned int rc_turn_i : 32; // 遥控转弯I参数 系数 0.001
|
||
unsigned int rc_turn_d : 32; // 遥控转弯D参数 系数 0.001
|
||
unsigned int auto_turn_p : 32; // 自主转弯P参数 系数 0.001
|
||
unsigned int auto_turn_i : 32; // 自主转弯I参数 系数 0.001
|
||
unsigned int auto_turn_d : 32; // 自主转弯D参数 系数 0.001
|
||
unsigned int checksum : 8; // 校验和 按字节累加之和 取低8位
|
||
} StrPIDOutput;
|
||
|
||
typedef union _UnPIDOutput
|
||
{
|
||
StrPIDOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrPIDOutput)]; // 通过结构体类型确定大小
|
||
} UnPIDOutput;
|
||
|
||
// 模拟信号输出,输出给上位机
|
||
typedef struct _StrAnalogSignalOutput
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0023
|
||
unsigned int frame_length : 16; // 帧长 固定值24
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int channel_1 : 16; // 通道1 温度传感器 系数为0.1 有符号 正数表示正温度,负数标表示负温度
|
||
unsigned int channel_2 : 16; // 通道2
|
||
unsigned int channel_3 : 16; // 通道3
|
||
unsigned int channel_4 : 16; // 通道4
|
||
unsigned int channel_5 : 16; // 通道5 温度传感器 系数为0.1 有符号 正数表示正温度,负数标表示负温度
|
||
unsigned int channel_6 : 16; // 通道6
|
||
unsigned int channel_7 : 16; // 通道7
|
||
unsigned int channel_8 : 16; // 通道8
|
||
unsigned int crc : 8 ; // 校验和 按字节累加之和 取低8位
|
||
|
||
} StrAnalogSignalOutput;
|
||
|
||
typedef union _UnAnalogSignalOutput
|
||
{
|
||
StrAnalogSignalOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrAnalogSignalOutput)]; // 通过结构体类型确定大小
|
||
} UnAnalogSignalOutput;
|
||
|
||
|
||
|
||
// 遥控器数据输出,给上位机
|
||
typedef struct _StrRemoteControlOutput
|
||
{
|
||
//--------------------------------------------------
|
||
unsigned int frame_header : 16; // 帧头 固定值0xAACC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0024
|
||
unsigned int frame_length : 16; // 帧长 固定值20
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
|
||
// RC6GS遥控原始数据
|
||
unsigned int speed : 16; // 速度 系数0.01,正为前进,负为后退 单位m/s
|
||
unsigned int curvature : 16; // 曲率 系数0.0001,正为左转,负为右转
|
||
unsigned int reserve_1 : 16; // 备用1
|
||
|
||
unsigned int switch_a : 1; // SwA
|
||
unsigned int switch_b : 2; // SwB 0和2刹车状态 1正常状态
|
||
unsigned int switch_c : 2; // SwC 0和2自主状态 1手动状态
|
||
unsigned int switch_d : 1; // SwD
|
||
unsigned int hv_relay_state : 1; // 高压继电机状态 0 断开, 1开启
|
||
unsigned int reserve_2 : 1; // 备用
|
||
unsigned int enable : 8; // 使能 1遥控数据有效,0无效
|
||
unsigned int accumulated_value : 16; // 接收累加值
|
||
unsigned int crc : 8; // 校验和 按字节累加之和 取低8位
|
||
} StrRemoteControlOutput;
|
||
|
||
typedef union _UnRemoteControlOutput
|
||
{
|
||
StrRemoteControlOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrRemoteControlOutput)]; // 通过结构体类型确定大小
|
||
} UnRemoteControlOutput;
|
||
|
||
|
||
|
||
// 手动控制数据,返回给请求者
|
||
typedef struct _StrManualControlOutput
|
||
{
|
||
//--------------------------------------------------
|
||
// 手动控制数据 高位在前,低位在后
|
||
unsigned int frame_header : 16; // 帧头 固定值0xFFBB
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0025
|
||
unsigned int frame_length : 8; // 帧长 固定值0x0C
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
|
||
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
|
||
unsigned int reserved : 8; // 保留
|
||
unsigned int crc_1 : 8 ; // CRC 按字节累加之和,溢出取低8位
|
||
unsigned int accumulated_value : 16; // 接收累加值
|
||
unsigned int crc_2 : 8 ; // CRC 按字节累加之和,溢出取低8位
|
||
} StrManualControlOutput;
|
||
|
||
typedef union _UnManualControlOutput
|
||
{
|
||
StrManualControlOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrManualControlOutput)]; // 通过结构体类型确定大小
|
||
} UnManualControlOutput;
|
||
|
||
|
||
|
||
|
||
// 自动控制数据输出,返回给请求者
|
||
typedef struct _StrAutoControlOutput
|
||
{
|
||
//--------------------------------------------------
|
||
// 自主计算机自动数据 高位在前,低位在后
|
||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||
unsigned int frame_type : 16; // 帧类型 固定值0x0026
|
||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||
unsigned int accumulated : 8; // 累加值 按帧累加
|
||
unsigned int set_speed : 16; // 设定速度 系数0.01,正为前进,负为后退 单位m/s
|
||
unsigned int set_curvature : 16; // 设定曲率 系数0.0001,正为左转,负为右转
|
||
unsigned int latitude : 32; // 纬度 系数10^-7,431234567表示43.1234567度
|
||
unsigned int longitude : 32; // 经度 系数10^-7,431234567表示43.1234567度
|
||
unsigned int altitude : 32; // 高度 单位mm
|
||
unsigned int heading : 16; // 航向 车辆航向,35999表示359.99度。
|
||
unsigned int accumulated_value : 16; // 累加值 按帧累加
|
||
unsigned int crc : 8 ; // CRC 总体累加CRC
|
||
} StrAutoControlOutput;
|
||
|
||
typedef union _UnAutoControlOutput
|
||
{
|
||
StrAutoControlOutput bit_data; // 使用定义的结构体变量名
|
||
unsigned char arr[sizeof(StrAutoControlOutput)]; // 通过结构体类型确定大小
|
||
} UnAutoControlOutput;
|
||
|
||
|
||
|
||
/* 云台数据流请求完整通信帧结构体 - CMD_ID 0x25 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为2
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x25
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=2)
|
||
uint8_t data_type; // 数据类型:1-姿态 2-激光测距 3-磁编码角度 4-电机电压
|
||
uint8_t data_freq; // 输出频率:0-关闭 1-2Hz 2-4Hz 3-5Hz 4-10Hz 5-20Hz 6-50Hz 7-100Hz
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} GimbalStreamRequestFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 云台数据流请求完整通信帧联合体 - CMD_ID 0x25 */
|
||
typedef union {
|
||
GimbalStreamRequestFrame frame; // 按结构体访问各字段
|
||
uint8_t data[12]; // 按字节数组访问(总长度:2+1+2+2+1+2+2 = 12字节)
|
||
} GimbalStreamRequestFrameUnion;
|
||
|
||
|
||
/* 手动变倍自动对焦数据结构体 - CMD_ID 0x05 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为1
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x05
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=1)
|
||
int8_t zoom; // 变倍控制:1-放大 0-停止缩放(松手后发送) -1-缩小
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} ManualZoomFocusFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 手动变倍自动对焦完整通信帧联合体 - CMD_ID 0x05 */
|
||
typedef union {
|
||
ManualZoomFocusFrame frame; // 按结构体访问各字段
|
||
uint8_t data[11]; // 按字节数组访问(总长度:2+1+2+2+1+1+2 = 11字节)
|
||
} ManualZoomFocusFrameUnion;
|
||
|
||
/* 拍照录像控制数据结构体 - CMD_ID 0x0C */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为1
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x0C
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=1)
|
||
uint8_t func_type; // 功能类型: 0-拍照 2-录像 3-5-运动模式 10-联动变倍等 3:运动模式: 锁定模式 4:运动模式: 跟随模式 5:运动模式: FPV 模式
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} PhotoVideoControlFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 拍照录像控制完整通信帧联合体 - CMD_ID 0x0C */
|
||
typedef union {
|
||
PhotoVideoControlFrame frame; // 按结构体访问各字段
|
||
uint8_t data[11]; // 按字节数组访问(总长度:2+1+2+2+1+1+2 = 11字节)
|
||
} PhotoVideoControlFrameUnion;
|
||
|
||
/* 设置激光测距状态数据结构体 - CMD_ID 0x32 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为1
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x32
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=1)
|
||
uint8_t laser_state; // 激光测距状态:1-开启 0-关闭
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} SetLaserRangingStatusFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 设置激光测距状态完整通信帧联合体 - CMD_ID 0x32 */
|
||
typedef union {
|
||
SetLaserRangingStatusFrame frame; // 按结构体访问各字段
|
||
uint8_t data[11]; // 按字节数组访问(总长度:2+1+2+2+1+1+2 = 11字节)
|
||
} SetLaserRangingStatusFrameUnion;
|
||
|
||
/* 设置AI追踪目标坐标信息流状态数据结构体 - CMD_ID 0x51 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为1
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x51
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=1)
|
||
uint8_t track_action; // AI追踪目标坐标信息流状态:1-打开输出 0-关闭输出
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} SetAiTrackTargetCoordinateStatusFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 设置AI追踪目标坐标信息流状态完整通信帧联合体 - CMD_ID 0x51 */
|
||
typedef union {
|
||
SetAiTrackTargetCoordinateStatusFrame frame; // 按结构体访问各字段
|
||
uint8_t data[11]; // 按字节数组访问(总长度:2+1+2+2+1+1+2 = 11字节)
|
||
} SetAiTrackTargetCoordinateUnion;
|
||
|
||
/* 设置AI追踪模式数据结构体 - CMD_ID 0x55 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为1
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x55
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=1)
|
||
uint8_t Ai_mode; // AI追踪模式:0-关闭 1-开启
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} SetAiTrackingModeFrame;
|
||
#pragma pack(pop)
|
||
|
||
|
||
/* 设置AI追踪目标坐标信息流状态完整通信帧联合体 - CMD_ID 0x55 */
|
||
typedef union {
|
||
SetAiTrackingModeFrame frame; // 按结构体访问各字段
|
||
uint8_t data[11]; // 按字节数组访问(总长度:2+1+2+2+1+1+2 = 11字节)
|
||
} SetAiTrackingModeFrameUnion;
|
||
|
||
|
||
|
||
/* 请求当前云台模式数据结构体 - CMD_ID 0x19 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为0(无数据域)
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x19
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=0,无数据)
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} RequestCurrentPodModeFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 请求当前云台模式完整通信帧联合体 - CMD_ID 0x19 */
|
||
typedef union {
|
||
RequestCurrentPodModeFrame frame; // 按结构体访问各字段
|
||
uint8_t data[10]; // 按字节数组访问(总长度:2+1+2+2+1+0+2 = 10字节)
|
||
} RequestCurrentPodModeFrameUnion;
|
||
|
||
|
||
/* 设置AI选择追踪目标数据结构体 - CMD_ID 0x56 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为9
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x56
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=9)
|
||
uint8_t track_action; // 追踪动作:1-追踪目标 0-取消追踪
|
||
uint16_t touch_lx; // 点选:x坐标,范围为视频流分辨率的宽大小;框选:方框左上顶点x坐标
|
||
uint16_t touch_ly; // 点选:y坐标,范围为视频流分辨率的高大小;框选:方框左上顶点y坐标
|
||
uint16_t touch_rx; // 点选:0;框选:方框右下顶点x坐标
|
||
uint16_t touch_ry; // 点选:0;框选:方框右下顶点y坐标
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} SetAiSelectTrackingTargetFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 设置AI选择追踪目标完整通信帧联合体 - CMD_ID 0x51 */
|
||
typedef union {
|
||
SetAiSelectTrackingTargetFrame frame; // 按结构体访问各字段
|
||
uint8_t data[19]; // 按字节数组访问(总长度:2+1+2+2+1+1+2+2+2+2+2 = 19字节)
|
||
} SetAiSelectTrackingTargetUnion;
|
||
|
||
|
||
/* 云台转向控制数据结构体 - CMD_ID 0x07 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为2
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x07
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=2)
|
||
int8_t turn_yaw; // 航向转向控制:-100~0~100,正负代表方向,数值越大转向速度越快;松手发0停止。向右滑动为0~100,向左滑动为0~-100
|
||
int8_t turn_pitch; // 俯仰转向控制:-100~0~100,正负代表方向,数值越大转向速度越快;松手发0停止。向上滑动为0~100,向下滑动为0~-100
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} PanTiltControlFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 云台转向控制完整通信帧联合体 - CMD_ID 0x07 */
|
||
typedef union {
|
||
PanTiltControlFrame frame; // 按结构体访问各字段
|
||
uint8_t data[12]; // 按字节数组访问(总长度:2+1+2+2+1+2+2 = 12字节)
|
||
} PanTiltControlFrameUnion;
|
||
|
||
|
||
/* 一键回中数据结构体 - CMD_ID 0x08 */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为1
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x08
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=1)
|
||
uint8_t center_pos; // 回中模式:1-一键回中,2-居中朝下,3-居中,4-朝下
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} CenterControlFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 一键回中完整通信帧联合体 - CMD_ID 0x08 */
|
||
typedef union {
|
||
CenterControlFrame frame; // 按结构体访问各字段
|
||
uint8_t data[11]; // 按字节数组访问(总长度:2+1+2+2+1+1+1+2 = 11字节)
|
||
} CenterControlUnion;
|
||
|
||
|
||
/* 设置云台姿态角度数据结构体 - CMD_ID 0x0E */
|
||
#pragma pack(push, 1)
|
||
typedef struct {
|
||
uint16_t STX; // 帧起始标志,固定为0x6655(低字节在前,实际存储为0x55 0x66)
|
||
uint8_t CTRL; // 控制位:bit0-need_ack(是否需要ack) bit1-ack_pack(是否为ack包) bit2-7-预留
|
||
uint16_t Data_len; // 数据域字节长度(低字节在前),此处固定为4
|
||
uint16_t SEQ; // 帧序列(0~65535),低字节在前
|
||
uint8_t CMD_ID; // 命令ID,此处固定为0x0E
|
||
// 以下为DATA域(对应偏移8开始,长度=Data_len=4)
|
||
int16_t yaw; // 目标偏航角度
|
||
int16_t pitch; // 目标俯仰角度
|
||
uint16_t CRC16; // 整个数据包的CRC16校验(低字节在前)
|
||
} SetGimbalPoseFrame;
|
||
#pragma pack(pop)
|
||
|
||
/* 设置云台姿态角度完整通信帧联合体 - CMD_ID 0x0E */
|
||
typedef union {
|
||
SetGimbalPoseFrame frame; // 按结构体访问各字段
|
||
uint8_t data[13]; // 按字节数组访问(总长度:2+1+2+2+1+2+2+2 = 13字节)
|
||
} SetGimbalPoseUnion;
|
||
|
||
|
||
//-----IO口---------------------------------------------------------------
|
||
// 电压信号输出,到遥控器
|
||
typedef struct _StrVoltageSignalOutput
|
||
{
|
||
unsigned int pwm_value : 16; // PWM值
|
||
} StrVoltageSignalOutput;
|
||
|
||
typedef union _UnVoltageSignalOutput
|
||
{
|
||
StrVoltageSignalOutput bit_data; // 使用定义的结构体变量名
|
||
uint8_t arr[sizeof(StrVoltageSignalOutput)]; // 通过结构体类型确定大小
|
||
} UnVoltageSignalOutput;
|
||
|
||
|
||
|
||
//外部数据结构声明
|
||
extern UnMotorInput un_motor_input1 ;//电机控制器1 左侧
|
||
extern UnMotorInput un_motor_input2 ;//电机控制器2 右侧
|
||
extern UnMotorInput un_motor_input3 ;//电机控制器1 左后侧
|
||
extern UnMotorInput un_motor_input4 ;//电机控制器2 右后侧
|
||
extern UnBmsInput un_bms_input ;//BMS接收数据
|
||
extern UnTempModuleInput un_temp_module_input;//温度采集模块
|
||
extern UnAutoComputerInput un_auto_computer_input;//自主计算机自动数据
|
||
extern UnManualComputerInput un_manual_computer_input;//自主计算机手动数据
|
||
|
||
extern UnUltrasonicInput un_ultrasonic_input1;//超声波传感器输入1
|
||
|
||
extern UnUltrasonicOutput un_ultrasonic_output1;//超声波传感器输出
|
||
|
||
|
||
|
||
extern UnMotorOutput un_motor_output1; //电机输出
|
||
extern UnMotorOutput un_motor_output2; //电机输出
|
||
extern UnMotorOutput un_motor_output3; //电机输出
|
||
extern UnMotorOutput un_motor_output4; //电机输出
|
||
extern UnMotorTempInput un_motor_temp1; //电机控制器1 温度
|
||
extern UnMotorTempInput un_motor_temp2; //电机控制器2 温度
|
||
extern UnMotorTempInput un_motor_temp3; //电机控制器3 左后侧
|
||
extern UnMotorTempInput un_motor_temp4; //电机控制器4 右后侧
|
||
|
||
|
||
extern UnInfCanKGFOutput un_inf_can_kgf_output1;
|
||
extern UnInfCanKGFOutput un_inf_can_kgf_output2;
|
||
extern UnHBridgeOutput un_h_bridge_output;
|
||
extern UnHBridgeOutput un_h_bridge_output1;//H桥输出
|
||
|
||
extern UnWheelSpeedOutput un_wheel_wpeed_output;
|
||
extern UnGatherOutput un_gather_output;//采集模块输出
|
||
|
||
|
||
//串口
|
||
extern UnRemoteControlInput un_remote_control_input; //遥控器输入
|
||
|
||
//IO口
|
||
extern UnSwSample un_sw_sample;
|
||
|
||
//以太网
|
||
extern UnRequestFrame un_request_frame; //请求帧
|
||
|
||
extern UnComputerOutput un_computer_output; //输出给自主计算机
|
||
|
||
//输出给上位机
|
||
extern UnVehicleInfoOutput un_vehicle_Info_output; // 车辆信息,输出给上位机
|
||
extern UnMotorStatusOutput un_motor_status_output; // 电机状态信息,输出给上位机
|
||
extern UnPIDOutput un_pid_output; // PID参数输出,输出给上位机
|
||
extern UnAnalogSignalOutput un_analog_signal_output; // 模拟信号输出,输出给上位机
|
||
extern UnRemoteControlOutput un_remote_control_output;// 遥控器数据输出,给上位机
|
||
extern UnManualControlOutput un_manual_control_output;// 手动控制数据,返回给请求者
|
||
extern UnAutoControlOutput un_auto_control_output; // 自动控制数据输出,返回给请求者
|
||
extern UnSdoOutput un_sdo_output ;//转向电机输出
|
||
|
||
|
||
//变量
|
||
extern uint8_t test_app[26];
|
||
|
||
extern ReceivedDataStruct mt11_received_data;
|
||
extern ReceivedDataStruct mt11_tx_data;
|
||
|
||
|
||
extern UnCanDebugOutput un_can_debug_output;//调试输出
|
||
|
||
//转台
|
||
extern GimbalStreamRequestFrameUnion gimbal_stream_request_output;//请求云台数据流
|
||
extern PhotoVideoControlFrameUnion photo_video_control_output ;//设置FPV模式
|
||
extern SetAiTrackingModeFrameUnion ai_track_mode_output ;//追踪模式
|
||
extern SetAiTrackTargetCoordinateUnion ai_track_coordinate_output ;//ai追踪信息流
|
||
|
||
extern RequestCurrentPodModeFrameUnion request_pod_mode_output ;//请求云台状态
|
||
extern SetAiSelectTrackingTargetUnion ai_select_track_target_output ;//设置ai追踪目标
|
||
extern PanTiltControlFrameUnion pan_tilt_control_output;//控制云台
|
||
|
||
extern CenterControlUnion center_control_output ;//一键回中控制输出
|
||
extern SetGimbalPoseUnion set_gimbal_pose_output ;//设置云台姿态角度控制输出
|
||
|
||
|
||
extern StrTxCanFrame un_sdo_output1 ;//电机1输出
|
||
extern StrTxCanFrame un_sdo_output2 ;//电机2输出
|
||
extern StrTxCanFrame un_sdo_output3 ;//电机3输出
|
||
extern StrTxCanFrame un_sdo_output4 ;//电机4输出
|
||
extern StrTxCanFrame un_sdo_output5 ;//电机5输出
|
||
|
||
extern StrTxCanFrame un_sdo_output6 ;//电机1使能
|
||
extern StrTxCanFrame un_sdo_output7 ;//电机2使能
|
||
|
||
extern StrRxCanFrame un_motor_pitch_input ;//俯仰电机输入
|
||
extern StrRxCanFrame un_motor_right_input ;//水平电机输入
|
||
|
||
//函数
|
||
void canSendAll(void *signal_id);
|
||
void ethernetSendAll(void *signal_id);
|
||
|
||
#pragma pack()
|
||
|
||
#endif /* _INTERFACE_H_ */
|