应急推进器和辅助推进器诊断函数封装

2025年6月21-22日工作日志


一、主要工作内容

  1. 诊断函数封装与优化

    • 初步完成了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;
        };
  2. 辅助推进器与应急推进器封装

    • 初步完成EMERGENCY_AUXILIARY_PROPULSION_CAN类的封装。
    • 复用主推进器的诊断逻辑,调整部分阈值和状态检查规则(如应急推进器的RPM允许范围更广)。
  3. 代码可移植性改进

    • 将硬件相关参数(如CAN接口名称、缓冲区大小)通过常量定义集中管理。
    • 使用标准C++库(如<array>、<chrono>)替代平台特定代码。

二、代码修改示例(关键部分)

1. 诊断函数调用优化
cpp 复制代码
// 原代码(分散调用)
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. 阈值动态配置示例
cpp 复制代码
// 动态调整主推进器RPM阈值
MAIN_PROPULSION_CAN::RPMThresholds rpmThresholds = {-3000, 3000, true};
MAIN_PROPULSION_CAN::setRPMThresholds(rpmThresholds);

三、存在问题与下一步计划

  1. 未验证内容

    • 应急推进器封装代码(EMERGENCY_AUXILIARY_PROPULSION_CAN)尚未测试,可能存在阈值或解析逻辑错误。
    • 多线程环境下阈值动态调整的线程安全性需验证。
  2. 下一步任务

    • 验证可行性 :
      • 搭建测试环境,模拟CAN数据输入,验证应急推进器诊断逻辑的正确性。
      • 检查动态阈值修改是否实时生效。
    • 性能测试 :
      • 评估高负载下缓冲区(g_packet_buffer)的处理延迟。
    • 日志增强 :
      • 在诊断函数中添加详细错误日志输出,便于问题追踪。

四、其他备注

  • 提交代码至Git仓库,分支:feature/diagnostic-encapsulation。
  • 进一步验证可行性。

作者 :wjj
联系方式:1816387198@qq.com


凡人修仙传:总会有办法的,他们世世代代生活在这里,毕竟凡人最擅长的就是坚强的活着。


相关推荐
倒头就睡的小比特4 天前
算法竞赛C++常用的STL
c++·算法
weilx12344 天前
C++笔记-文件IO-<fcntl.h>
c++
Winlifes4 天前
我给 Codex 做了一个 Git 面板:分支树、提交历史和工作区操作
git
Smileyqp沛沛4 天前
前端?C++ ?较大差异基础罗列
c++·基础·前端转c++
C语言小火车4 天前
C/C++ 为什么需要编译器?
开发语言·c++
旖旎夜光4 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
吞下星星的少年·-·4 天前
C++ 萌新语法入门篇
c++·算法比赛
霍霍的袁4 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
another heaven4 天前
【算法/C++ MD5算法能否逆解码?原理、C++实现与同类哈希算法对比】
c++·算法·哈希算法
程序猿编码4 天前
告别改源码适配模型:纯 C++ 可配置 LLM 推理引擎,全格式全结构兼容
c++·大模型·llm·推理引擎