fome-fw/firmware/controllers/engine_cycle/aux_valves.cpp

119 lines
3.2 KiB
C++
Raw Normal View History

2017-11-25 22:17:37 -08:00
/*
2020-11-05 13:34:25 -08:00
* @file aux_valves.cpp
2017-11-25 22:17:37 -08:00
*
2017-11-27 18:49:58 -08:00
*
* Here we have two auxilary digital on/off outputs which would open once per each 360 degrees of engine crank revolution.
* The second valve is 180 degrees after the first one.
*
* Valve open and close angles are taken from fsioCurve1 and fsioCurve2 tables respectively, the position depend on TPS input.
*
* https://github.com/rusefi/rusefi/issues/490
*
2017-11-25 22:17:37 -08:00
* @date Nov 25, 2017
2020-01-07 21:02:40 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2017-11-25 22:17:37 -08:00
*/
2019-01-20 21:10:09 -08:00
#include "engine_math.h"
2017-11-25 22:17:37 -08:00
#include "aux_valves.h"
2017-11-26 19:30:37 -08:00
#include "allsensors.h"
#include "sensor.h"
2017-11-26 19:30:37 -08:00
#include "trigger_central.h"
2019-12-02 21:29:12 -08:00
#include "spark_logic.h"
2017-11-26 19:30:37 -08:00
EXTERN_ENGINE;
2017-11-26 19:30:37 -08:00
2019-12-02 21:29:12 -08:00
void plainPinTurnOn(AuxActor *current) {
NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
output->setHigh();
2019-11-24 09:45:38 -08:00
2019-12-02 21:29:12 -08:00
#if EFI_UNIT_TEST
Engine *engine = current->engine;
EXPAND_Engine;
#endif /* EFI_UNIT_TEST */
scheduleOrQueue(&current->open,
TRIGGER_EVENT_UNDEFINED,
getTimeNowNt(),
2019-12-02 21:29:12 -08:00
current->extra + engine->engineState.auxValveStart,
{ plainPinTurnOn, current }
2019-12-02 21:29:12 -08:00
PASS_ENGINE_PARAMETER_SUFFIX
);
angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart;
fixAngle(duration, "duration", CUSTOM_ERR_6557);
scheduleOrQueue(&current->close,
TRIGGER_EVENT_UNDEFINED,
getTimeNowNt(),
2019-12-02 21:29:12 -08:00
current->extra + engine->engineState.auxValveEnd,
{ plainPinTurnOff, output }
2019-12-02 21:29:12 -08:00
PASS_ENGINE_PARAMETER_SUFFIX
);
2019-11-24 09:45:38 -08:00
}
2019-11-23 19:55:21 -08:00
void plainPinTurnOff(NamedOutputPin *output) {
2017-11-27 18:49:58 -08:00
output->setLow();
2017-11-26 21:06:43 -08:00
}
2017-11-27 18:49:58 -08:00
2019-11-19 22:42:03 -08:00
void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
UNUSED(sharedLogger);
2017-11-26 19:30:37 -08:00
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
return;
}
2019-12-02 21:29:12 -08:00
if (!Sensor::hasSensor(SensorType::DriverThrottleIntent)) {
firmwareError(CUSTOM_OBD_91, "No TPS for Aux Valves");
2019-12-02 21:29:12 -08:00
return;
}
2020-10-17 15:45:08 -07:00
recalculateAuxValveTiming(PASS_ENGINE_PARAMETER_SIGNATURE);
2019-12-02 21:29:12 -08:00
for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) {
for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
AuxActor *actor = &engine->auxValves[valveIndex][phaseIndex];
actor->phaseIndex = phaseIndex;
actor->valveIndex = valveIndex;
actor->extra = phaseIndex * 360 + valveIndex * 180;
INJECT_ENGINE_REFERENCE(actor);
scheduleOrQueue(&actor->open,
TRIGGER_EVENT_UNDEFINED,
getTimeNowNt(),
2019-12-02 21:29:12 -08:00
actor->extra + engine->engineState.auxValveStart,
{ plainPinTurnOn, actor }
2019-12-02 21:29:12 -08:00
PASS_ENGINE_PARAMETER_SUFFIX
);
}
}
2017-11-26 19:30:37 -08:00
}
2020-10-17 15:45:08 -07:00
void recalculateAuxValveTiming(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
2017-11-26 19:30:37 -08:00
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
return;
}
auto [valid, tps] = Sensor::get(SensorType::DriverThrottleIntent);
if (!valid) {
2018-01-01 09:56:27 -08:00
// error should be already reported by now
return;
}
2019-12-02 21:29:12 -08:00
engine->engineState.auxValveStart = interpolate2d("aux", tps,
2017-11-27 18:49:58 -08:00
engineConfiguration->fsioCurve1Bins,
engineConfiguration->fsioCurve1);
2017-11-25 22:17:37 -08:00
2019-12-02 21:29:12 -08:00
engine->engineState.auxValveEnd = interpolate2d("aux", tps,
2017-11-27 18:49:58 -08:00
engineConfiguration->fsioCurve2Bins,
engineConfiguration->fsioCurve2);
2017-12-08 17:04:58 -08:00
if (engine->engineState.auxValveStart >= engine->engineState.auxValveEnd) {
// this is a fatal error to make this really visible
2019-12-02 21:29:12 -08:00
firmwareError(CUSTOM_AUX_OUT_OF_ORDER, "out of order at %.2f %.2f %.2f", tps,
2017-12-08 17:04:58 -08:00
engine->engineState.auxValveStart,
engine->engineState.auxValveEnd);
}
2017-11-25 22:17:37 -08:00
}