增加转台
This commit is contained in:
252
interface.h
252
interface.h
@@ -59,14 +59,6 @@ typedef union _UnCanDebugOutput
|
||||
} UnCanDebugOutput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct _StrMotorTempInput
|
||||
{
|
||||
//-----接收数据0x103或者0x104----------------------------------------------
|
||||
@@ -86,31 +78,15 @@ typedef union _UnMotorTempInput
|
||||
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
|
||||
//-----接收BMS数据----------------------------------------------
|
||||
uint16_t bus_voltage; // 总电压 系数 0.1V/bit
|
||||
uint16_t bus_current; // 电流 系数 0.1A/bit 偏移量 -30000
|
||||
uint16_t soc; // SOC 系数 0.1%/bit
|
||||
uint8_t Life; // 生命周期 范围 0~255
|
||||
uint8_t Reserve; // 保留位
|
||||
} StrBmsInput;
|
||||
|
||||
typedef union _UnBmsInput
|
||||
@@ -169,9 +145,6 @@ typedef union _UnAutoComputerInput
|
||||
} UnAutoComputerInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收自主计算机手动输入
|
||||
|
||||
typedef struct _StrManualComputerInput
|
||||
@@ -193,14 +166,6 @@ typedef union _UnManualComputerInput
|
||||
unsigned int arr[sizeof(StrManualComputerInput) / sizeof(unsigned int)]; // 通过结构体类型确定大小
|
||||
} UnManualComputerInput;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 接收请求帧
|
||||
typedef struct _StrRequestFrame
|
||||
{
|
||||
@@ -236,6 +201,11 @@ typedef struct _StrRemoteControlInput
|
||||
unsigned int reserve3 : 1; // 保留
|
||||
|
||||
unsigned int enable : 8; // 使能
|
||||
|
||||
uint16_t y_axis;
|
||||
uint16_t x_axis;
|
||||
uint16_t reserve4;
|
||||
uint16_t reserve5;
|
||||
} StrRemoteControlInput;
|
||||
|
||||
typedef union _UnRemoteControlInput
|
||||
@@ -244,6 +214,14 @@ typedef union _UnRemoteControlInput
|
||||
uint8_t arr[sizeof(StrRemoteControlInput)]; // 通过结构体类型确定大小
|
||||
} UnRemoteControlInput;
|
||||
|
||||
// 磁编
|
||||
typedef struct _StrMagneticEncoder
|
||||
{
|
||||
uint8_t ip[4]; // IPv4
|
||||
uint16_t port; // 端口
|
||||
uint8_t magnetic_data; // 协议类型(1A)
|
||||
} StrMagneticEncoder;
|
||||
|
||||
|
||||
//-----IO口---------------------------------------------------------------
|
||||
// 从IO口输入
|
||||
@@ -664,6 +642,103 @@ typedef union _UnrLifterOutput
|
||||
} 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
|
||||
@@ -895,6 +970,57 @@ typedef union _UnAutoControlOutput
|
||||
} UnAutoControlOutput;
|
||||
|
||||
|
||||
// 接收转台指令输入
|
||||
typedef struct _StrComputerTurnableInput
|
||||
{
|
||||
// 多字节数据,高位在前,低位在后
|
||||
unsigned int frame_header : 16; // 帧头 固定值0xFFCC
|
||||
unsigned int frame_type : 16; // 帧类型 固定值0x0001
|
||||
unsigned int frame_length : 8; // 帧长 固定值0x19
|
||||
unsigned int heartbeat : 8; // 心跳 按帧累加
|
||||
|
||||
// --- 坐标数据部分 ---
|
||||
int32_t position_x; // X轴坐标
|
||||
int32_t position_y; // Y轴坐标
|
||||
int32_t position_z; // Z轴坐标
|
||||
|
||||
unsigned int crc : 8; // CRC 按字节累加之和,溢出取低8位
|
||||
} StrComputerTurnableInput;
|
||||
|
||||
typedef union _UnComputerTurnableInput
|
||||
{
|
||||
StrComputerTurnableInput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrComputerTurnableInput)]; // 通过结构体类型确定大小
|
||||
} UnComputerTurnableInput;
|
||||
|
||||
|
||||
|
||||
// 编码器数据帧结构体(针对0x1A命令的响应)
|
||||
typedef struct _StrEncoderData {
|
||||
//--------------------------------------------------
|
||||
// 编码器数据帧 - 对应 0x1A 命令的响应格式(10字节)
|
||||
unsigned int cf : 8; // 命令识别符 固定值0x1A
|
||||
unsigned int sf : 8; // 编码器状态 1byte
|
||||
unsigned int abs_value : 24; // 角度数据 3byte LSB(重命名:abs_value)
|
||||
unsigned int enid : 8; // 编码器ID 1byte
|
||||
unsigned int abm : 24; // 圈数数据 3byte LSB
|
||||
unsigned int almc : 8; // 编码器故障 1byte
|
||||
unsigned int crc : 8; // CRC校验 多项式x^8+1
|
||||
} StrEncoderData;
|
||||
|
||||
// 联合体定义,便于字节数组访问
|
||||
typedef union _UnEncoderData {
|
||||
StrEncoderData bit_data; // 位域方式访问
|
||||
unsigned char arr[sizeof(StrEncoderData)]; // 字节数组方式访问
|
||||
} UnEncoderData;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -914,10 +1040,11 @@ typedef union _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 StrRxCanFrame un_motor_input1 ;//电机控制器1 左侧
|
||||
extern StrRxCanFrame un_motor_input2 ;//电机控制器2 右侧
|
||||
extern StrRxCanFrame un_motor_input3 ;//电机控制器1 左后侧
|
||||
extern StrRxCanFrame un_motor_input4 ;//电机控制器2 右后侧
|
||||
|
||||
extern UnBmsInput un_bms_input ;//BMS接收数据
|
||||
extern UnTempModuleInput un_temp_module_input;//温度采集模块
|
||||
extern UnAutoComputerInput un_auto_computer_input;//自主计算机自动数据
|
||||
@@ -929,10 +1056,18 @@ 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 StrTxCanFrame un_motor_output1; //电机输出
|
||||
extern StrTxCanFrame un_motor_output2; //电机输出
|
||||
extern StrTxCanFrame un_motor_output3; //电机输出
|
||||
extern StrTxCanFrame un_motor_output4; //电机输出
|
||||
|
||||
|
||||
extern StrTxCanFrame un_motor_output5 ;//电机输出
|
||||
extern StrTxCanFrame un_motor_output6 ;//电机输出
|
||||
extern StrTxCanFrame un_motor_output7 ;//电机输出
|
||||
extern StrTxCanFrame un_motor_output8 ;//电机输出
|
||||
|
||||
|
||||
extern UnMotorTempInput un_motor_temp1; //电机控制器1 温度
|
||||
extern UnMotorTempInput un_motor_temp2; //电机控制器2 温度
|
||||
extern UnMotorTempInput un_motor_temp3; //电机控制器3 左后侧
|
||||
@@ -958,6 +1093,11 @@ extern UnSwSample un_sw_sample;
|
||||
extern UnRequestFrame un_request_frame; //请求帧
|
||||
|
||||
extern UnComputerOutput un_computer_output; //输出给自主计算机
|
||||
extern UnComputerTurnableInput un_computer_turnable_Input ;//转台以太网输入
|
||||
|
||||
extern UnEncoderData un_encoder_data_input ;
|
||||
|
||||
extern StrMagneticEncoder str_magnetic_encoder ;//编码器请求
|
||||
|
||||
//输出给上位机
|
||||
extern UnVehicleInfoOutput un_vehicle_Info_output; // 车辆信息,输出给上位机
|
||||
@@ -969,6 +1109,20 @@ extern UnManualControlOutput un_manual_control_output;// 手动控制数
|
||||
extern UnAutoControlOutput un_auto_control_output; // 自动控制数据输出,返回给请求者
|
||||
extern UnSdoOutput un_sdo_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_motor_output5 ;//电机1输出
|
||||
extern StrTxCanFrame un_motor_output6 ;//电机2输出
|
||||
extern StrTxCanFrame un_motor_output7 ;//电机3输出
|
||||
extern StrTxCanFrame un_motor_output8 ;//电机4输出
|
||||
|
||||
extern StrRxCanFrame un_pitch_intput ;//电机输入
|
||||
extern StrRxCanFrame un_right_intput ;//电机输入
|
||||
|
||||
|
||||
//变量
|
||||
extern uint8_t test_app[26];
|
||||
|
||||
Reference in New Issue
Block a user