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

105 lines
2.7 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.
*
2021-11-04 20:19:44 -07:00
* Valve open and close angles are taken from scriptCurve1 and scriptCurve2 tables respectively, the position depend on TPS input.
2017-11-27 18:49:58 -08:00
*
* 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
*/
#include "pch.h"
2017-11-25 22:17:37 -08:00
#include "aux_valves.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
2020-11-05 15:10:44 -08:00
static void plainPinTurnOff(NamedOutputPin *output) {
output->setLow();
}
2020-11-06 18:24:58 -08:00
static void scheduleOpen(AuxActor *current) {
engine->module<TriggerScheduler>()->scheduleOrQueue(&current->open,
2019-12-02 21:29:12 -08:00
TRIGGER_EVENT_UNDEFINED,
getTimeNowNt(),
2019-12-02 21:29:12 -08:00
current->extra + engine->engineState.auxValveStart,
2020-11-05 15:10:44 -08:00
{ auxPlainPinTurnOn, current }
2019-12-02 21:29:12 -08:00
);
2020-11-06 18:24:58 -08:00
}
void auxPlainPinTurnOn(AuxActor *current) {
NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
output->setHigh();
scheduleOpen(current);
2019-12-02 21:29:12 -08:00
angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart;
fixAngle(duration, "duration", CUSTOM_ERR_6557);
engine->module<TriggerScheduler>()->scheduleOrQueue(&current->close,
2019-12-02 21:29:12 -08:00
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
);
2019-11-24 09:45:38 -08:00
}
void initAuxValves() {
if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
2017-11-26 19:30:37 -08:00
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;
}
recalculateAuxValveTiming();
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;
2020-11-06 18:24:58 -08:00
scheduleOpen(actor);
2019-12-02 21:29:12 -08:00
}
}
2017-11-26 19:30:37 -08:00
}
void recalculateAuxValveTiming() {
if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
2017-11-26 19:30:37 -08:00
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;
}
engine->engineState.auxValveStart = interpolate2d(tps,
config->scriptCurve1Bins,
config->scriptCurve1);
2017-11-25 22:17:37 -08:00
engine->engineState.auxValveEnd = interpolate2d(tps,
config->scriptCurve2Bins,
config->scriptCurve2);
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
}