From 2247badaa6e174dbcbc73275e88eeebfa68bbf96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C3=A1kona?= Date: Fri, 10 Apr 2020 23:49:22 +0200 Subject: [PATCH] coding style improvements according to ticket #595. --- src/FDM/YASim/ElectricEngine.cpp | 11 ++++++----- src/FDM/YASim/ElectricEngine.hpp | 13 ++++++++----- src/FDM/YASim/FGFDM.cpp | 9 ++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/FDM/YASim/ElectricEngine.cpp b/src/FDM/YASim/ElectricEngine.cpp index 9a3e06149..6258ae10a 100644 --- a/src/FDM/YASim/ElectricEngine.cpp +++ b/src/FDM/YASim/ElectricEngine.cpp @@ -2,6 +2,7 @@ // Based on original patch from Ian Dall // Date: Wed Jan 11 22:35:24 2012 +1030 // #595 Support for electric motors in YASim (patch provided) +// Improved by ThunderFly s.r.o. //////////////////////////////////////////////////////// #include "Atmosphere.hpp" @@ -9,14 +10,14 @@ #include "ElectricEngine.hpp" namespace yasim { -// explain parameters! -ElectricEngine::ElectricEngine(float V, float Kv, float Rm) : +// idealized DC electric motor model +ElectricEngine::ElectricEngine(float voltage, float Kv, float Rm) : _Rm(Rm) { _running = false; - _omega0 = V * Kv; - _K = 1/Kv; - _torque0 = _K * _K * _omega0 / _Rm; + _omega0 = voltage * Kv; // calculate RPM of unloaded motor + _K = 1/Kv; // calculate reciprocal value of motor velocity constant + _torque0 = _K * _K * _omega0 / _Rm; // rough estimate of full load torque valid for DC electric motor invalid for BLDC } void ElectricEngine::calc(float pressure, float temp, float omega) diff --git a/src/FDM/YASim/ElectricEngine.hpp b/src/FDM/YASim/ElectricEngine.hpp index d704137ed..018f7b170 100644 --- a/src/FDM/YASim/ElectricEngine.hpp +++ b/src/FDM/YASim/ElectricEngine.hpp @@ -1,6 +1,7 @@ // Based on original patch from Ian Dall // Date: Wed Jan 11 22:35:24 2012 +1030 // #595 Support for electric motors in YASim (patch provided) +// Improved by ThunderFly s.r.o. //////////////////////////////////////////////////////// #ifndef _ELECTRICENGINE_HPP @@ -15,8 +16,10 @@ public: virtual ElectricEngine* isElectricEngine() { return this; } // Initializes an engine from known "takeoff" parameters. - // explain parameters: physical meaning? which dimensions (volts, meters, kilogram...)? - ElectricEngine(float V, float Kv, float Rm); + // voltage - power supply voltage applied to the motor in volts + // Kv - electric motor velocity constant in RPM/1V + // Rm - engine winding resistance in Ohms + ElectricEngine(float voltage, float Kv, float Rm); virtual void calc(float pressure, float temp, float speed); virtual void stabilize() { return; }; @@ -30,11 +33,11 @@ private: float _omega0 {0}; // Reference engine speed float _minThrottle {0.05f}; // minimum throttle [0:1] float _K {0}; // _K = Eb/omega = tau/Ia - float _Rm {1}; + float _Rm {1}; // engine windig resistence // Runtime state/output: - float _torque {0}; - float _torque0 {1}; + float _torque {0}; // actual torque of the motor + float _torque0 {1}; // nominal operating torque }; }; // namespace yasim diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index a8e5783a9..3440dd1aa 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -799,11 +799,10 @@ void FGFDM::parseTurbineEngine(const XMLAttributes* a) void FGFDM::parseElectricEngine(const XMLAttributes* a) { - //Kv is expected to be given as RPM in XML - float Kv = attrf(a, "Kv") * RPM2RAD; - float V = attrf(a, "V"); - float Rm = attrf(a, "Rm"); - ElectricEngine* eng = new ElectricEngine(V, Kv, Rm); + float Kv = attrf(a, "Kv") * RPM2RAD; //Kv is expected to be given as RPM per volt in XML + float voltage = attrf(a, "voltage"); // voltage applied at the motor windings in volts + float Rm = attrf(a, "Rm"); // winding resistance in Ohms + ElectricEngine* eng = new ElectricEngine(voltage, Kv, Rm); ((PropEngine*)_currObj)->setEngine(eng); }