C语言
Qt Quick Ultralite 车载集群演示
/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/#ifndef DRIVETRAIN_H #define DRIVETRAIN_H #include <stdint.h> namespace Simulation { class Drivetrain { public: struct DriveData { float speed; float rpm; int gear; float odo; float range; float battery; float fuel; float coolantTemp; }; struct Config { static const int MAX_GEARS = 10; float maxSpeed; float maxRpm; float minRpm; float shiftUpAtRpm; float shiftDownAtRpm; float tireCircumference; // cm float diffRatio; int gearNum; float gearRatios[MAX_GEARS]; float batteryFillRatio; float batteryDrainRatio; float coolantHeatRatio; float coolantCooldownRatio; float optimalTemp; float maxTemp; float maxRange; }; Drivetrain(const Config &config); void update(uint32_t tick, float acceleration); void updateCruiseControl(uint32_t tick, float targetSpeed); void reset(); void resetOdo(float value = 0); void resetBattery(float value = 0); float getSpeed(float rpm, int gear) const; float getRpm(float speed, int gear) const; const DriveData &getDriveData() const { return _data; } private: float updateRpm(uint32_t tick, float acceleration); void updateGearShift(uint32_t tick, float prevRpm, float acceleration); void updateSpeed(); void applySpeedLimit(); void updateOdo(uint32_t tick); void updateRange(); void updateBattery(uint32_t tick, float acceleration); void updateFuelLevel(); void updateCoolantTemp(uint32_t tick, float acceleration); void shiftGear(int delta); DriveData _data; const Config _config; uint32_t _constSpeedTime; }; } // namespace Simulation #endif // DRIVETRAIN_H