2025年6月21-22日工作日志
一、主要工作内容
诊断函数封装与优化
初步完成了
EMERGENCY_AUXILIARY_PROPULSION
类的封装,统一管理主推进器的诊断逻辑和阈值配置。实现功能:
- 时序检查:封装
checkOutputTiming
和checkFeedbackTiming
,支持动态阈值配置。 - 状态诊断:完成RPM、电压、电流、温度等参数的解析与状态检查(如
checkRPMStatus
、checkVoltageStatus
)。 - 故障检测:封装补偿器液位、伸缩机构状态、接近开关等故障检测逻辑(如
checkFaultBits1Status
)。
- 时序检查:封装
新增功能:
支持通过
set/get
方法动态调整阈值(如setTimingThresholds
)。提供数据解析工具函数(如
parseRPM
、parseVoltage
)。#pragma once #include <cstdint> #include <string> #include <array> class MAIN_PROPULSION_CAN { public: // 阈值配置结构体 struct TimingThresholds { int64_t output_no_response; // 无输出阈值(微秒) int64_t output_too_fast; // 输出过快阈值(微秒) int64_t output_too_slow; // 输出过慢阈值(微秒) int64_t feedback_normal; // 反馈正常阈值(微秒) int64_t feedback_slow; // 反馈较慢阈值(微秒) int64_t feedback_no_response; // 无反馈阈值(微秒) }; struct RPMThresholds { int16_t min_rpm; // 最小转速 int16_t max_rpm; // 最大转速 bool allow_negative; // 是否允许负转速 }; struct VoltageThresholds { uint16_t min_voltage; // 最小电压值 (0V) uint16_t max_voltage; // 最大电压值 (根据实际系统设置) uint16_t high_voltage_threshold; // 高电压阈值 }; struct CurrentThresholds { uint16_t max_current; // 最大电流值 (255A) }; struct TemperatureThresholds { uint8_t max_motor_temp; // 电机最高温度 (150℃) uint8_t max_driver_temp; // 驱动器最高温度 (150℃) }; // 阈值设置 static void setTimingThresholds(const TimingThresholds& thresholds); static void setRPMThresholds(const RPMThresholds& thresholds); static void setVoltageThresholds(const VoltageThresholds& thresholds); static void setCurrentThresholds(const CurrentThresholds& thresholds); static void setTemperatureThresholds(const TemperatureThresholds& thresholds); // 阈值获取 static TimingThresholds getCurrentThresholds(); static RPMThresholds getCurrentRPMThresholds(); static VoltageThresholds getCurrentVoltageThresholds(); static CurrentThresholds getCurrentCurrentThresholds(); static TemperatureThresholds getCurrentTemperatureThresholds(); // 状态检查 static int checkOutputTiming(int64_t timeInterval); static int checkFeedbackTiming(int64_t timeBack); static bool checkRPM(int16_t rpm, std::string& message); static int checkRPMStatus(const uint8_t* data, size_t offset); // 数据解析 static int16_t parseRPM(const uint8_t* data, size_t offset); static uint16_t parseVoltage(const uint8_t data[], size_t offset); static uint8_t parseCurrent(const uint8_t data[], size_t offset); static uint8_t parseMotorTemperature(const uint8_t data[], size_t offset); static uint8_t parseDriverTemperature(const uint8_t data[], size_t offset); // 状态检查 static int checkVoltageStatus(const uint8_t data[], size_t offset); static int checkCurrentStatus(const uint8_t data[], size_t offset); static int checkMotorTempStatus(const uint8_t data[],size_t motor_temp_offset); static int checkDriverTempStatus(const uint8_t data[],size_t driver_temp_offset); //320223 // 状态反馈帧处理 static uint8_t parseCompensatorLevel(const uint8_t* data, size_t offset); static uint8_t parseExtensionStatus(const uint8_t* data, size_t offset); static uint8_t parseProximitySwitches(const uint8_t* data, size_t offset); static uint8_t parseFaultBits1(const uint8_t* data, size_t offset); static uint8_t parseFaultBits2(const uint8_t* data, size_t offset); // 状态检查 static int checkCompensatorLevelStatus(const uint8_t* data, size_t offset); static int checkExtensionStatus(const uint8_t* data, size_t offset); static int checkProximitySwitchesStatus(const uint8_t* data, size_t offset); static int checkFaultBits1Status(const uint8_t* data, size_t offset); static int checkFaultBits2Status(const uint8_t* data, size_t offset); private: static TimingThresholds currentTimingThresholds; static RPMThresholds currentRPMThresholds; static VoltageThresholds currentVoltageThresholds; static CurrentThresholds currentCurrentThresholds; static TemperatureThresholds currentTemperatureThresholds; };
辅助推进器与应急推进器封装
- 初步完成
EMERGENCY_AUXILIARY_PROPULSION_CAN
类的封装。 - 复用主推进器的诊断逻辑,调整部分阈值和状态检查规则(如应急推进器的RPM允许范围更广)。
- 初步完成
代码可移植性改进
- 将硬件相关参数(如CAN接口名称、缓冲区大小)通过常量定义集中管理。
- 使用标准C++库(如
<array>
、<chrono>
)替代平台特定代码。
二、代码修改示例(关键部分)
1. 诊断函数调用优化
// 原代码(分散调用)
Result_Buffer[i][packetIndex][8] = checkRPMStatus(g1_packet_buffer[i][packetIndex].data(), 26);
Result_Buffer[i][packetIndex][14] = checkVoltageStatus(g1_packet_buffer[i][packetIndex].data(), 30);
// 封装后(通过类方法调用)
Result_Buffer[i][packetIndex][8] = MAIN_PROPULSION_CAN::checkRPMStatus(data, offset);
Result_Buffer[i][packetIndex][14] = MAIN_PROPULSION_CAN::checkVoltageStatus(data, offset);
2. 阈值动态配置示例
// 动态调整主推进器RPM阈值
MAIN_PROPULSION_CAN::RPMThresholds rpmThresholds = {-3000, 3000, true};
MAIN_PROPULSION_CAN::setRPMThresholds(rpmThresholds);
三、存在问题与下一步计划
未验证内容
- 应急推进器封装代码(
EMERGENCY_AUXILIARY_PROPULSION_CAN
)尚未测试,可能存在阈值或解析逻辑错误。 - 多线程环境下阈值动态调整的线程安全性需验证。
- 应急推进器封装代码(
下一步任务
- 验证可行性:
- 搭建测试环境,模拟CAN数据输入,验证应急推进器诊断逻辑的正确性。
- 检查动态阈值修改是否实时生效。
- 性能测试:
- 评估高负载下缓冲区(
g_packet_buffer
)的处理延迟。
- 评估高负载下缓冲区(
- 日志增强:
- 在诊断函数中添加详细错误日志输出,便于问题追踪。
- 验证可行性:
四、其他备注
- 提交代码至Git仓库,分支:
feature/diagnostic-encapsulation
。 - 进一步验证可行性。
作者:wjj
联系方式:1816387198@qq.com
凡人修仙传:总会有办法的,他们世世代代生活在这里,毕竟凡人最擅长的就是坚强的活着。