修改WDT以及增加转台
This commit is contained in:
218
interface.h
218
interface.h
@@ -195,7 +195,28 @@ typedef union _UnManualComputerInput
|
||||
} UnManualComputerInput;
|
||||
|
||||
|
||||
// 接收转台指令输入
|
||||
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;
|
||||
|
||||
|
||||
|
||||
@@ -237,6 +258,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
|
||||
@@ -359,26 +385,172 @@ typedef union _UnGatherOutput
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// canoe协议输出
|
||||
typedef struct _StrSdoOutput
|
||||
// CAN ID 解析(联合体形式,支持位域和32位直接访问)
|
||||
typedef union _UnCanIdInfo
|
||||
{
|
||||
//-----发送数据0x601----------------------------------------------
|
||||
unsigned int cmd : 8; // 命令
|
||||
unsigned int object_index : 16; // 索引
|
||||
unsigned int sub_index : 8; // 从索引
|
||||
unsigned int data : 32; // 数据
|
||||
} StrSdoOutput;
|
||||
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;
|
||||
|
||||
typedef union _UnSdoOutput
|
||||
} UnCanIdInfo;
|
||||
|
||||
|
||||
// 输出can数据
|
||||
typedef struct _StrTxCanOutput
|
||||
{
|
||||
StrSdoOutput bit_data; // 使用定义的结构体变量名
|
||||
uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
|
||||
} UnSdoOutput;
|
||||
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 解析(联合体形式,支持位域和32位直接访问)
|
||||
//typedef union _UnCanIdInfo
|
||||
//{
|
||||
// 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;
|
||||
// uint32_t raw; // 32位整型,直接读写整个CAN ID
|
||||
//} UnCanIdInfo;
|
||||
//
|
||||
//// CANoe协议输出(主结构体)
|
||||
//typedef struct _StrSdoOutput
|
||||
//{
|
||||
// uint16_t index; // 索引(类似寄存器地址)
|
||||
// uint16_t object_index; // 子索引(通常为0x0000)
|
||||
// uint32_t data; // 数据字段
|
||||
// UnCanIdInfo rx_can_id; // CAN ID(联合体形式)
|
||||
//} StrSdoOutput;
|
||||
//
|
||||
//// 主联合体(支持结构体和字节数组访问)
|
||||
//typedef union _UnSdoOutput
|
||||
//{
|
||||
// StrSdoIntput bit_data; // 结构化访问
|
||||
// uint8_t arr[sizeof(StrSdoIntput)]; // 字节数组形式(用于原始数据读写)
|
||||
//} UnSdoIntput;
|
||||
|
||||
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//// ID 解析输出
|
||||
//typedef struct _StrCanIdInfo
|
||||
//{
|
||||
////-----发送数据0x601----------------------------------------------
|
||||
// uint32_t motor_id:8;
|
||||
// uint32_t data:16;
|
||||
// uint32_t mode:5;
|
||||
// uint32_t res:3;
|
||||
//} StrCanIdInfo;
|
||||
//
|
||||
//
|
||||
//
|
||||
//// canoe协议输出
|
||||
//typedef struct _StrSdoOutput
|
||||
//{
|
||||
////-----发送数据0x601----------------------------------------------
|
||||
// uint16_t index; //索引,类似寄存器地址
|
||||
// uint16_t object_index; // 从索引 为0x0000
|
||||
// uint32_t data; // 数据
|
||||
// StrCanIdInfo rx_can_id;
|
||||
//} StrSdoOutput;
|
||||
//
|
||||
//typedef union _UnSdoOutput
|
||||
//{
|
||||
// StrSdoOutput bit_data; // 使用定义的结构体变量名
|
||||
// uint8_t arr[sizeof(StrSdoOutput)]; // 通过结构体类型确定大小
|
||||
//} UnSdoOutput;
|
||||
|
||||
|
||||
// 超声波数据发送
|
||||
typedef struct _StrUltrasonicOutput
|
||||
@@ -925,6 +1097,17 @@ extern UnTempModuleInput un_temp_module_input;//温度采集模块
|
||||
extern UnAutoComputerInput un_auto_computer_input;//自主计算机自动数据
|
||||
extern UnManualComputerInput un_manual_computer_input;//自主计算机手动数据
|
||||
|
||||
extern StrTxCanFrame un_sdo_output1 ;//电机1输出
|
||||
extern StrTxCanFrame un_sdo_output2 ;//电机2输出
|
||||
extern StrTxCanFrame un_sdo_output3 ;//电机3输出
|
||||
extern StrTxCanFrame un_sdo_output4 ;//电机3速度输出
|
||||
extern StrTxCanFrame un_sdo_output5 ;//电机使能输出
|
||||
|
||||
extern StrRxCanFrame un_pitch_intput ;//电机输入
|
||||
extern StrRxCanFrame un_right_intput ;//电机输入
|
||||
extern StrRxCanFrame un_turn_intput ;//电机输入
|
||||
|
||||
|
||||
extern UnUltrasonicInput un_ultrasonic_input1;//超声波传感器输入1
|
||||
|
||||
extern UnUltrasonicOutput un_ultrasonic_output1;//超声波传感器输出
|
||||
@@ -958,6 +1141,8 @@ extern UnRequestFrame un_request_frame; //请求帧
|
||||
|
||||
extern UnComputerOutput un_computer_output; //输出给自主计算机
|
||||
|
||||
extern UnComputerTurnableInput un_computer_turnable_Input ;//转台以太网输入
|
||||
|
||||
//输出给上位机
|
||||
extern UnVehicleInfoOutput un_vehicle_Info_output; // 车辆信息,输出给上位机
|
||||
extern UnMotorStatusOutput un_motor_status_output; // 电机状态信息,输出给上位机
|
||||
@@ -966,7 +1151,6 @@ 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 ;//转向电机输出
|
||||
|
||||
|
||||
//变量
|
||||
@@ -978,6 +1162,8 @@ extern UnCanDebugOutput un_can_debug_output;//调试输出
|
||||
//函数
|
||||
void canSendAll(void *signal_id);
|
||||
void ethernetSendAll(void *signal_id);
|
||||
float constrain(float value, float min_val, float max_val);
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user