| 1 | // |
| 2 | // Based on original patch from Ian Dall <[email protected]> |
| 3 | // Date: Wed Jan 11 22:35:24 2012 +1030 |
| 4 | // #595 Support for electric motors in YASim (patch provided) |
| 5 | // Improved by ThunderFly s.r.o. <[email protected]> |
| 6 | //////////////////////////////////////////////////////// |
| 7 | |
| 8 | #include "Atmosphere.hpp" |
| 9 | #include "Math.hpp" |
| 10 | #include "ElectricEngine.hpp" |
| 11 | namespace yasim { |
| 12 | |
| 13 | // idealized DC electric motor model |
| 14 | ElectricEngine::ElectricEngine(float voltage, float Kv, float Rm) : |
| 15 | _Rm(Rm) |
| 16 | { |
| 17 | _running = false; |
| 18 | _omega0 = voltage * Kv; // calculate RPM of unloaded motor |
| 19 | _K = 1/Kv; // calculate reciprocal value of motor velocity constant |
| 20 | _torque0 = _K * _K * _omega0 / _Rm; // rough estimate of full load torque valid for DC electric motor invalid for BLDC |
| 21 | } |
| 22 | |
| 23 | void ElectricEngine::calc(float pressure, float temp, float omega) |
| 24 | { |
| 25 | _running = (_throttle > _minThrottle); |
| 26 | // There are a huge variety of electronic speed controls and there |
| 27 | // is nothing to say that there isn't feedback to provide |
| 28 | // essentially an arbitrary relationship between throttle and |
| 29 | // omega. However, below is essentially equivalent to an idealised |
| 30 | // DC motor where the throttle controls the terminal voltage. PWM |
| 31 | // controllers in conjunction with the inductance of the windings |
| 32 | // should approximate this. |
| 33 | if (_running) { |
| 34 | _torque = ((_throttle - _minThrottle) / (1 - _minThrottle) - omega / _omega0) * _torque0; |
| 35 | } |
| 36 | else { |
| 37 | _torque = 0; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | }; // namespace yasim |