LCOV - code coverage report
Current view: top level - firmware/controllers/algo/fuel - dfco.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 36 97.2 %
Date: 2024-04-25 02:23:43 Functions: 4 4 100.0 %

          Line data    Source code
       1             : 
       2             : #include "engine_configuration.h"
       3             : #include "sensor.h"
       4             : 
       5             : #include "dfco.h"
       6             : 
       7         226 : bool DfcoController::getState() const {
       8         226 :         if (!engineConfiguration->coastingFuelCutEnabled) {
       9         209 :                 return false;
      10             :         }
      11             : 
      12          17 :         const auto tps = Sensor::get(SensorType::DriverThrottleIntent);
      13          17 :         const auto clt = Sensor::get(SensorType::Clt);
      14          17 :         const auto map = Sensor::get(SensorType::Map);
      15             : 
      16             :         // If some sensor is broken, inhibit DFCO
      17          17 :         if (!tps || !clt || !map) {
      18           0 :                 return false;
      19             :         }
      20             : 
      21          17 :         float rpm = Sensor::getOrZero(SensorType::Rpm);
      22          17 :         float vss = Sensor::getOrZero(SensorType::VehicleSpeed);
      23             : 
      24          17 :         bool mapActivate = map.Value < engineConfiguration->coastingFuelCutMap;
      25          17 :         bool tpsActivate = tps.Value < engineConfiguration->coastingFuelCutTps;
      26          17 :         bool cltActivate = clt.Value > engineConfiguration->coastingFuelCutClt;
      27             :         // True if throttle, MAP, and CLT are all acceptable for DFCO to occur
      28          17 :         bool dfcoAllowed = mapActivate && tpsActivate && cltActivate;
      29             : 
      30          17 :         bool rpmActivate = (rpm > engineConfiguration->coastingFuelCutRpmHigh);
      31          17 :         bool rpmDeactivate = (rpm < engineConfiguration->coastingFuelCutRpmLow);
      32             : 
      33             :         // greater than or equal so that it works if both config params are set to 0
      34          17 :         bool vssActivate = (vss >= engineConfiguration->coastingFuelCutVssHigh);
      35          17 :         bool vssDeactivate = (vss < engineConfiguration->coastingFuelCutVssLow);
      36             : 
      37             :         // RPM is high enough, VSS high enough, and DFCO allowed
      38          17 :         if (dfcoAllowed && rpmActivate && vssActivate) {
      39           7 :                 return true;
      40             :         }
      41             : 
      42             :         // RPM too low, VSS too low, or DFCO not allowed
      43          10 :         if (!dfcoAllowed || rpmDeactivate || vssDeactivate) {
      44           6 :                 return false;
      45             :         }
      46             : 
      47             :         // No conditions hit, no change to state (provides hysteresis)
      48           4 :         return m_isDfco;
      49             : }
      50             : 
      51         226 : void DfcoController::update() {
      52             :         // Run state machine
      53         226 :         bool newState = getState();
      54             : 
      55             :         // If fuel is cut, reset the timer
      56         226 :         if (newState) {
      57           8 :                 m_timeSinceCut.reset();
      58             :         } else {
      59             :                 // If fuel is not cut, reset the not-cut timer
      60         218 :                 m_timeSinceNoCut.reset();
      61             :         }
      62             : 
      63         226 :         m_isDfco = newState;
      64         226 : }
      65             : 
      66         231 : bool DfcoController::cutFuel() const {
      67         231 :         float cutDelay = engineConfiguration->dfcoDelay;
      68             : 
      69             :         // 0 delay means cut immediately, aka timer has always expired
      70         231 :         bool hasBeenDelay = (cutDelay == 0) || m_timeSinceNoCut.hasElapsedSec(cutDelay);
      71             : 
      72         231 :         return m_isDfco && hasBeenDelay;
      73             : }
      74             : 
      75           1 : float DfcoController::getTimeSinceCut() const {
      76           1 :         return m_timeSinceCut.getElapsedSeconds();
      77             : }

Generated by: LCOV version 1.14