LCOV - code coverage report
Current view: top level - src/microsim/engine - EngineParameters.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 0.0 % 124 0
Test Date: 2024-11-21 15:56:26 Functions: 0.0 % 7 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    EngineParameters.cpp
      15              : /// @author  Michele Segata
      16              : /// @date    4 Feb 2015
      17              : ///
      18              : /****************************************************************************/
      19              : 
      20              : #include <config.h>
      21              : 
      22              : #include <cmath>
      23              : #include <utils/geom/GeomHelper.h> // for M_PI
      24              : #include "EngineParameters.h"
      25              : 
      26              : 
      27            0 : EngineParameters::EngineParameters() : nGears(5), differentialRatio(3.714), wheelDiameter_m(0.94),
      28            0 :     mass_kg(1300), cAir(0.3), a_m2(2.7), rho_kgpm3(1.2), cr1(0.0136), cr2(5.18e-7),
      29            0 :     slope(0.), tiresFrictionCoefficient(0.7), engineEfficiency(0.8),
      30            0 :     massFactor(1.089), cylinders(4), dt(0.01), minRpm(1000), maxRpm(7000),
      31            0 :     brakesTau_s(0.2), tauEx_s(0.1), tauBurn_s(-1), fixedTauBurn(false) {
      32            0 :     id = "";
      33              :     //set default gear ratios
      34            0 :     gearRatios = new double[nGears];
      35            0 :     gearRatios[0] = 3.909;//4.5;
      36            0 :     gearRatios[1] = 2.238;//3.5;//2.6;
      37            0 :     gearRatios[2] = 1.520;//2.5;//1.5;
      38            0 :     gearRatios[3] = 1.156;//1.5;//1.0;
      39            0 :     gearRatios[4] = 0.971;//1.0;//0.8;
      40              :     //default engine mapping
      41            0 :     engineMapping.degree = 1;
      42            0 :     engineMapping.x[0] = -7.50084;
      43            0 :     engineMapping.x[1] = 0.02045;
      44              :     //default shifting rule
      45            0 :     shiftingRule.rpm = 6000;
      46            0 :     shiftingRule.deltaRpm = 100;
      47              :     //initialize precomputed coefficients
      48            0 :     computeCoefficients();
      49              : 
      50            0 : }
      51              : 
      52            0 : EngineParameters::EngineParameters(const EngineParameters& other) :
      53            0 :     nGears(other.nGears), differentialRatio(other.differentialRatio), wheelDiameter_m(other.wheelDiameter_m),
      54            0 :     mass_kg(other.mass_kg), cAir(other.cAir), a_m2(other.a_m2), rho_kgpm3(other.rho_kgpm3), cr1(other.cr1), cr2(other.cr2),
      55            0 :     slope(other.slope), tiresFrictionCoefficient(other.tiresFrictionCoefficient), engineEfficiency(other.engineEfficiency),
      56            0 :     massFactor(other.massFactor), cylinders(other.cylinders), dt(other.dt), minRpm(other.minRpm), maxRpm(other.maxRpm),
      57            0 :     brakesTau_s(other.brakesTau_s), tauEx_s(other.tauEx_s), tauBurn_s(other.tauBurn_s), fixedTauBurn(other.fixedTauBurn) {
      58            0 :     id = other.id;
      59            0 :     gearRatios = new double[nGears];
      60            0 :     for (int i = 0; i < nGears; i++) {
      61            0 :         gearRatios[i] = other.gearRatios[i];
      62              :     }
      63            0 :     engineMapping.degree = other.engineMapping.degree;
      64            0 :     for (int i = 0; i < engineMapping.degree; i++) {
      65            0 :         engineMapping.x[i] = other.engineMapping.x[i];
      66              :     }
      67            0 :     shiftingRule.rpm = other.shiftingRule.rpm;
      68            0 :     shiftingRule.deltaRpm = other.shiftingRule.deltaRpm;
      69            0 :     computeCoefficients();
      70            0 : }
      71            0 : EngineParameters& EngineParameters::operator =(const EngineParameters& other) {
      72            0 :     id = other.id;
      73            0 :     nGears = other.nGears;
      74            0 :     differentialRatio = other.differentialRatio;
      75            0 :     wheelDiameter_m = other.wheelDiameter_m;
      76            0 :     mass_kg = other.mass_kg;
      77            0 :     cAir = other.cAir;
      78            0 :     a_m2 = other.a_m2;
      79            0 :     rho_kgpm3 = other.rho_kgpm3;
      80            0 :     cr1 = other.cr1;
      81            0 :     cr2 = other.cr2;
      82            0 :     slope = other.slope;
      83            0 :     tiresFrictionCoefficient = other.tiresFrictionCoefficient;
      84            0 :     engineEfficiency = other.engineEfficiency;
      85            0 :     massFactor  = other.massFactor;
      86            0 :     cylinders = other.cylinders;
      87            0 :     dt = other.dt;
      88            0 :     minRpm = other.minRpm;
      89            0 :     maxRpm = other.maxRpm;
      90            0 :     delete [] gearRatios;
      91            0 :     gearRatios = new double[nGears];
      92            0 :     for (int i = 0; i < nGears; i++) {
      93            0 :         gearRatios[i] = other.gearRatios[i];
      94              :     }
      95            0 :     engineMapping.degree = other.engineMapping.degree;
      96            0 :     for (int i = 0; i < engineMapping.degree; i++) {
      97            0 :         engineMapping.x[i] = other.engineMapping.x[i];
      98              :     }
      99            0 :     shiftingRule.rpm = other.shiftingRule.rpm;
     100            0 :     shiftingRule.deltaRpm = other.shiftingRule.deltaRpm;
     101            0 :     brakesTau_s = other.brakesTau_s;
     102            0 :     tauBurn_s = other.tauBurn_s;
     103            0 :     tauEx_s = other.tauEx_s;
     104            0 :     fixedTauBurn = other.fixedTauBurn;
     105            0 :     computeCoefficients();
     106            0 :     return *this;
     107              : }
     108              : 
     109            0 : EngineParameters::~EngineParameters() {
     110            0 :     delete [] gearRatios;
     111            0 : }
     112              : 
     113            0 : void EngineParameters::computeCoefficients() {
     114            0 :     __airFrictionCoefficient = 0.5 * cAir * a_m2 * rho_kgpm3;
     115            0 :     __cr1 = mass_kg * massFactor * GRAVITY_MPS2 * cr1;
     116            0 :     __cr2 = mass_kg * massFactor * GRAVITY_MPS2 * cr2;
     117            0 :     __gravity = mass_kg * massFactor * GRAVITY_MPS2 * sin(slope / 180 * M_PI);
     118            0 :     __maxNoSlipAcceleration = tiresFrictionCoefficient * GRAVITY_MPS2 * cos(slope / 180 * M_PI);
     119            0 :     __rpmToSpeedCoefficient = wheelDiameter_m * M_PI / (differentialRatio * 60);
     120            0 :     __speedToRpmCoefficient = differentialRatio * 60 / (wheelDiameter_m * M_PI);
     121            0 :     __speedToThrustCoefficient = engineEfficiency * HP_TO_W;
     122            0 :     __maxAccelerationCoefficient = mass_kg * massFactor;
     123            0 :     __brakesAlpha = dt / (brakesTau_s + dt);
     124            0 :     __brakesOneMinusAlpha = 1 - __brakesAlpha;
     125            0 :     __engineTau1 = (420.0 * cylinders - 240.0) / (2.0 * cylinders);
     126            0 :     __engineTau2 = (120.0 * cylinders - 120.0) / cylinders;
     127            0 :     __engineTauDe_s = tauBurn_s + tauEx_s;
     128            0 : }
     129              : 
     130            0 : void EngineParameters::dumpParameters(std::ostream& out) {
     131            0 :     out << "ID: " << id.c_str() << std::endl;
     132              : 
     133            0 :     out << "Gearbox:\n";
     134            0 :     out << "\tGears number: " << (int)nGears << std::endl;
     135            0 :     for (int i = 0; i < nGears; i++) {
     136            0 :         out << std::setprecision(4) << "\tRatio of gear " << (i + 1) << ": " << gearRatios[i] << std::endl;
     137              :     }
     138            0 :     out << std::setprecision(4) << "\tFinal drive ratio: " << differentialRatio << std::endl;
     139              : 
     140            0 :     out << "Wheels:\n";
     141            0 :     out << std::setprecision(3) << "\tDiameter: " << wheelDiameter_m << " m\n";
     142            0 :     out << std::setprecision(3) << "\tFriction coefficient: " << tiresFrictionCoefficient << std::endl;
     143            0 :     out << std::setprecision(10) << "\tcr1: " << cr1 << std::endl;
     144            0 :     out << std::setprecision(10) << "\tcr2: " << cr2 << std::endl;
     145              : 
     146            0 :     out << "Mass:\n";
     147            0 :     out << std::setprecision(2) << "\tMass: " << mass_kg << " kg\n";
     148            0 :     out << std::setprecision(4) << "\tMass factor: " << massFactor << std::endl;
     149              : 
     150            0 :     out << "Air drag:\n";
     151            0 :     out << std::setprecision(4) << "\tDrag coefficient: " << cAir << std::endl;
     152            0 :     out << std::setprecision(3) << "\tMax section: " << a_m2 << " m^2\n";
     153              : 
     154            0 :     out << "Engine:\n";
     155            0 :     out << "\tEfficiency: " << engineEfficiency << std::endl;
     156            0 :     out << "\tCylinders: " << cylinders << std::endl;
     157            0 :     out << "\tMinimum rpm: " << minRpm << std::endl;
     158            0 :     out << "\tMaximum rpm: " << maxRpm << std::endl;
     159            0 :     out << "\tMapping (rpm to hp) degree: " << engineMapping.degree << std::endl;
     160            0 :     for (int i = 0; i < engineMapping.degree; i++) {
     161            0 :         out << "\t\tMapping coefficient x" << i << ": " << engineMapping.x[i] << std::endl;
     162              :     }
     163            0 :     out << "\tShifting rpm: " << shiftingRule.rpm << std::endl;
     164            0 :     out << "\tShifting delta: " << shiftingRule.deltaRpm << std::endl;
     165              : 
     166            0 :     out << "Brakes:\n";
     167            0 :     out << "\tTime constant (s): " << brakesTau_s << std::endl;
     168              : 
     169            0 :     out << "Vehicle unrelated parameters:\n";
     170            0 :     out << std::setprecision(4) << "\tAir density: " << rho_kgpm3 << " kg/m^3\n";
     171            0 :     out << "\tRoad slope: " << slope << " degrees\n";
     172            0 :     out << std::setprecision(3) << "\tSimulation sampling time: " << dt << " s\n";
     173            0 : }
        

Generated by: LCOV version 2.0-1