put vbatt in sensor model (#2261)

* vbatt in sensor model

* sensor name

* vbatt

* s

* oy vei

* a little bit of cleanup

* memory apparently

* cj125 test

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-02-03 05:55:40 -08:00 committed by GitHub
parent c9b0334eb5
commit 5ceeac93e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 8 deletions

View File

@ -268,7 +268,8 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
CONFIG(fuelLevelFullTankVoltage), 100,
fuelLevelVoltage);
}
sensors.vBatt = hasVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) ? getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) : 12;
sensors.vBatt = Sensor::get(SensorType::BatteryVoltage).value_or(12);
#if (BOARD_TLE8888_COUNT > 0)
// nasty value injection into C driver which would not be able to access Engine class

View File

@ -711,7 +711,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
* UNUSED_SIZE constants.
*/
#ifndef RAM_UNUSED_SIZE
#define RAM_UNUSED_SIZE 3200
#define RAM_UNUSED_SIZE 3150
#endif
#ifndef CCM_UNUSED_SIZE
#define CCM_UNUSED_SIZE 2800

View File

@ -41,6 +41,8 @@ static const char* s_sensorNames[] = {
"Idle Valve Position",
"Flex Fuel",
"Battery Voltage",
};
// This struct represents one sensor in the registry.

View File

@ -60,6 +60,8 @@ enum class SensorType : unsigned char {
FuelEthanolPercent,
BatteryVoltage,
// Leave me at the end!
PlaceholderLast
};

View File

@ -14,10 +14,6 @@
EXTERN_ENGINE;
bool hasVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return isAdcChannelValid(engineConfiguration->vbattAdcChannel);
}
float getVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#ifdef USE_ADC3_VBATT_HACK
extern adcsample_t vbattSampleProteus;

View File

@ -16,6 +16,5 @@
#include "engine_configuration.h"
float getVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool hasVBatt(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#endif /* __cplusplus */

View File

@ -19,6 +19,7 @@ void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// Internal init functions for individual systems
// Sensor init/config
void initVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void initMap(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void initTps(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void initOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);
@ -28,6 +29,7 @@ void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE);
// Sensor reconfiguration
void reconfigureVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void reconfigureTps(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void reconfigureThermistors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void reconfigureOilPressure(DECLARE_CONFIG_PARAMETER_SIGNATURE);

View File

@ -7,3 +7,4 @@ INIT_SRC_CPP = $(PROJECT_DIR)/init/sensor/init_sensors.cpp \
$(PROJECT_DIR)/init/sensor/init_lambda.cpp \
$(PROJECT_DIR)/init/sensor/init_map.cpp \
$(PROJECT_DIR)/init/sensor/init_flex.cpp \
$(PROJECT_DIR)/init/sensor/init_vbatt.cpp \

View File

@ -13,6 +13,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
initCanSensors();
#endif
initVbatt(PASS_CONFIG_PARAMETER_SIGNATURE);
initMap(PASS_ENGINE_PARAMETER_SIGNATURE);
initTps(PASS_CONFIG_PARAMETER_SIGNATURE);
initOilPressure(PASS_CONFIG_PARAMETER_SIGNATURE);
@ -25,6 +26,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
}
void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
reconfigureVbatt(PASS_CONFIG_PARAMETER_SIGNATURE);
reconfigureTps(PASS_CONFIG_PARAMETER_SIGNATURE);
reconfigureOilPressure(PASS_CONFIG_PARAMETER_SIGNATURE);
reconfigureThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);

View File

@ -0,0 +1,29 @@
#include "init.h"
#include "adc_inputs.h"
#include "adc_subscription.h"
#include "engine.h"
#include "functional_sensor.h"
#include "linear_func.h"
EXTERN_ENGINE;
static LinearFunc vbattFunc;
static FunctionalSensor vbattSensor(SensorType::BatteryVoltage, /* timeout = */ MS2NT(100));
void initVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
vbattFunc.configure(0, 0, 1, engineConfiguration->vbattDividerCoeff, 0, 50);
vbattSensor.setFunction(vbattFunc);
if (!isAdcChannelValid(engineConfiguration->vbattAdcChannel)) {
return;
}
// adcVoltsPerVolt is set to 1.0 because vbatt doesn't go thru the analog input divider
AdcSubscription::SubscribeSensor(vbattSensor, CONFIG(vbattAdcChannel), /* filter HZ = */ 20, /* adcVoltsPerVolt = */ 1.0f);
vbattSensor.Register();
}
void reconfigureVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
vbattFunc.configure(0, 0, 1, engineConfiguration->vbattDividerCoeff, 0, 50);
}

View File

@ -26,7 +26,6 @@ TEST(testCJ125, testInitialState) {
ASSERT_EQ(cj.heaterDuty, 0);
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
ASSERT_EQ(engine->sensors.vBatt, 0);
cj.StartHeaterControl((pwm_gen_callback*)&applyHeaterPinState PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_EQ(cj.heaterDuty, CJ125_HEATER_IDLE_RATE);