rusEFI
The most advanced open source ECU
init_map.cpp
Go to the documentation of this file.
1 #include "pch.h"
2 
3 #include "adc_subscription.h"
4 #include "linear_func.h"
5 #include "fallback_sensor.h"
6 #include "functional_sensor.h"
7 #include "map_averaging.h"
8 
11 
12 // This converter is shared between both fast and slow: the only difference is
13 // how the *voltage* is determined, not how its converted to a pressure.
19 
20 // lowest reasonable idle is maybe 600 rpm
21 // one sample per cycle (1 cylinder, or "sample one cyl" mode) gives a period of 100ms
22 // add some margin -> 200ms timeout for fast MAP sampling
25 
26 MapAverager& getMapAvg(size_t idx) {
27  return idx == 0 ? fastMapSensor : fastMapSensor2;
28 }
29 
30 // Combine MAP sensors: prefer fast sensor, but use slow if fast is unavailable.
33 
34 // helper struct for the local getMapCfg function
35 struct MapCfg {
36  float v1;
37  float map1;
38  float v2;
39  float map2;
40 };
41 
42 static MapCfg getMapCfg(air_pressure_sensor_type_e sensorType) {
43  switch (sensorType) {
44  case MT_DENSO183:
45  return {0, -6.64, 5, 182.78};
46  case MT_MPX4100:
47  return {0.306, 20, 4.897, 105};
48  case MT_MPX4250:
49  case MT_MPX4250A:
50  return {0.204, 20, 4.896, 250};
51  case MT_HONDA3BAR:
52  return {0.5, 91.422, 3.0, 0};
53  case MT_DODGE_NEON_2003:
54  return {0.4, 15.34, 4.5, 100};
55  case MT_SUBY_DENSO:
56  return {0, 0, 5, 200};
57  case MT_GM_3_BAR:
58  return {0.631, 40, 4.914, 304};
59  case MT_GM_2_BAR:
60  return {0, 8.8, 5, 208};
61  case MT_GM_1_BAR:
62  return {0, 10, 5, 105};
63  case MT_TOYOTA_89420_02010:
64  return {3.7 - 2, 33.32, 3.7, 100};
65  case MT_MAZDA_1_BAR:
66  return {0, 2.5, 5, 117};
67  case MT_BOSCH_2_5:
68  // kpa=54.11764705882353v−1.6470588235294201
69  return {0.4 , 20 , 4.65, 250};
70  case MT_MPXH6400:
71  return {0.2, 20, 4.8, 400};
72  case MT_MPXH6300:
73  return {1.0, 60, 4.5, 270};
74  default:
75  firmwareError(ObdCode::CUSTOM_ERR_MAP_TYPE, "Unknown MAP type: decoder %d", sensorType);
76  // falls through to custom
77  return {};
78  case MT_CUSTOM: {
79  auto& mapConfig = engineConfiguration->map.sensor;
80  return {
82  mapConfig.lowValue,
84  mapConfig.highValue
85  };
86  }}
87 }
88 
90  auto cfg = getMapCfg(sensorType);
91 
92  converter.configure(
93  cfg.v1,
94  cfg.map1,
95  cfg.v2,
96  cfg.map2,
99  );
100 }
101 
102 void initMap() {
103  // Set up the conversion function
105 
112 
113  auto mapChannel = engineConfiguration->map.sensor.hwChannel;
114  if (isAdcChannelValid(mapChannel)) {
121 
122  // Configure slow MAP as a normal analog sensor
124  }
125 
128 
129  auto baroChannel = engineConfiguration->baroSensor.hwChannel;
130  if (isAdcChannelValid(baroChannel)) {
132 
135 
137  }
138 }
139 
140 void deinitMap() {
145 }
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition: adc_inputs.h:20
static void UnsubscribeSensor(FunctionalSensor &sensor)
static AdcSubscriptionEntry * SubscribeSensor(FunctionalSensor &sensor, adc_channel_e channel, float lowpassCutoffHZ, float voltsPerAdcVolt=0.0f)
Class for sensors that convert from some raw floating point value (ex: voltage, frequency,...
void setFunction(SensorConverter &func)
void setFunction(SensorConverter &func)
Definition: map_averaging.h:45
bool Register()
Definition: sensor.cpp:131
void firmwareError(ObdCode code, const char *fmt,...)
converter
static FunctionalSensor throttleInletPress(SensorType::ThrottleInletPressure, MS2NT(50))
static FallbackSensor mapCombiner(SensorType::Map, SensorType::MapFast, SensorType::MapSlow)
static FunctionalSensor slowMapSensor2(SensorType::MapSlow2, MS2NT(50))
static FunctionalSensor baroSensor(SensorType::BarometricPressure, MS2NT(50))
MapAverager & getMapAvg(size_t idx)
Definition: init_map.cpp:26
static MapCfg getMapCfg(air_pressure_sensor_type_e sensorType)
Definition: init_map.cpp:42
void initMap()
Definition: init_map.cpp:102
static FallbackSensor mapCombiner2(SensorType::Map2, SensorType::MapFast2, SensorType::MapSlow2)
static LinearFunc mapConverter
Definition: init_map.cpp:14
static FunctionalSensor slowMapSensor(SensorType::MapSlow, MS2NT(50))
static LinearFunc baroConverter
Definition: init_map.cpp:9
void configureMapFunction(LinearFunc &converter, air_pressure_sensor_type_e sensorType)
Definition: init_map.cpp:89
MapAverager fastMapSensor(SensorType::MapFast, MS2NT(200))
MapAverager fastMapSensor2(SensorType::MapFast2, MS2NT(200))
static FunctionalSensor compressorDischargePress(SensorType::CompressorDischargePressure, MS2NT(50))
void deinitMap()
Definition: init_map.cpp:140
@ CUSTOM_ERR_MAP_TYPE
engine_configuration_s * engineConfiguration
air_pressure_sensor_type_e
Definition: rusefi_enums.h:483
@ ThrottleInletPressure
@ CompressorDischargePressure
@ BarometricPressure