mirror of https://github.com/rusefi/rusefi-1.git
This commit is contained in:
parent
bec88bf8c8
commit
eb305f0265
|
@ -58,12 +58,8 @@ public:
|
||||||
LocalVersionHolder auxParametersVersion;
|
LocalVersionHolder auxParametersVersion;
|
||||||
operation_mode_e getOperationMode(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
operation_mode_e getOperationMode(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
|
AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2];
|
||||||
|
|
||||||
scheduling_s auxTurnOnEvent[AUX_DIGITAL_VALVE_COUNT][/* we have two 180 cycles within engine 360 revolution */ 2][CYCLE_ALTERNATION];
|
|
||||||
scheduling_s auxTurnOffEvent[AUX_DIGITAL_VALVE_COUNT][2][CYCLE_ALTERNATION];
|
|
||||||
|
|
||||||
|
|
||||||
int auxSchedulingIndex = 2;
|
|
||||||
bool needTdcCallback = true;
|
bool needTdcCallback = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -120,3 +120,14 @@ public:
|
||||||
IgnitionEvent elements[MAX_IGNITION_EVENT_COUNT];
|
IgnitionEvent elements[MAX_IGNITION_EVENT_COUNT];
|
||||||
bool isReady = false;
|
bool isReady = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AuxActor {
|
||||||
|
public:
|
||||||
|
int phaseIndex;
|
||||||
|
int valveIndex;
|
||||||
|
angle_t extra;
|
||||||
|
|
||||||
|
AngleBasedEvent open;
|
||||||
|
AngleBasedEvent close;
|
||||||
|
DECLARE_ENGINE_PTR;
|
||||||
|
};
|
||||||
|
|
|
@ -10,54 +10,53 @@
|
||||||
* https://github.com/rusefi/rusefi/issues/490
|
* https://github.com/rusefi/rusefi/issues/490
|
||||||
*
|
*
|
||||||
* @date Nov 25, 2017
|
* @date Nov 25, 2017
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "engine_math.h"
|
#include "engine_math.h"
|
||||||
#include "aux_valves.h"
|
#include "aux_valves.h"
|
||||||
#include "allsensors.h"
|
#include "allsensors.h"
|
||||||
#include "trigger_central.h"
|
#include "trigger_central.h"
|
||||||
|
#include "spark_logic.h"
|
||||||
|
|
||||||
EXTERN_ENGINE
|
EXTERN_ENGINE
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
void plainPinTurnOn(AuxActor *current) {
|
||||||
//void plainPinTurnOn(AuxActor *current) {
|
NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
|
||||||
// NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
|
output->setHigh();
|
||||||
if (!engine->auxStarted) {
|
|
||||||
|
|
||||||
for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) {
|
|
||||||
for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
|
|
||||||
AuxActor *current = &actors[phaseIndex][valveIndex];
|
|
||||||
|
|
||||||
// if ()
|
|
||||||
|
|
||||||
|
#if EFI_UNIT_TEST
|
||||||
|
Engine *engine = current->engine;
|
||||||
|
EXPAND_Engine;
|
||||||
|
#endif /* EFI_UNIT_TEST */
|
||||||
|
|
||||||
scheduleOrQueue(¤t->open,
|
scheduleOrQueue(¤t->open,
|
||||||
trgEventIndex,
|
TRIGGER_EVENT_UNDEFINED,
|
||||||
current->extra + engine->engineState.auxValveStart,
|
current->extra + engine->engineState.auxValveStart,
|
||||||
(schfunc_t)plainPinTurnOn,
|
(schfunc_t)plainPinTurnOn,
|
||||||
current
|
current
|
||||||
PASS_ENGINE_PARAMETER_SUFFIX);
|
PASS_ENGINE_PARAMETER_SUFFIX
|
||||||
|
);
|
||||||
|
|
||||||
|
angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart;
|
||||||
|
|
||||||
}
|
fixAngle(duration, "duration", CUSTOM_ERR_6557);
|
||||||
}
|
|
||||||
|
|
||||||
|
scheduleOrQueue(¤t->close,
|
||||||
engine->auxStarted = true;
|
TRIGGER_EVENT_UNDEFINED,
|
||||||
}
|
current->extra + engine->engineState.auxValveEnd,
|
||||||
|
(schfunc_t)plainPinTurnOff,
|
||||||
*/
|
output
|
||||||
|
PASS_ENGINE_PARAMETER_SUFFIX
|
||||||
void plainPinTurnOn(NamedOutputPin *output) {
|
);
|
||||||
output->setHigh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void plainPinTurnOff(NamedOutputPin *output) {
|
void plainPinTurnOff(NamedOutputPin *output) {
|
||||||
output->setLow();
|
output->setLow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
|
static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
|
||||||
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
UNUSED(ckpSignalType);
|
UNUSED(ckpSignalType);
|
||||||
|
@ -69,12 +68,13 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
|
||||||
if (!isValidRpm(rpm)) {
|
if (!isValidRpm(rpm)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Sometimes previous event has not yet been executed by the time we are scheduling new events.
|
* Sometimes previous event has not yet been executed by the time we are scheduling new events.
|
||||||
* We use this array alternation in order to bring events that are scheled and waiting to be executed from
|
* We use this array alternation in order to bring events that are scheled and waiting to be executed from
|
||||||
* events which are already being scheduled
|
* events which are already being scheduled
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
int engineCycleAlternation = engine->triggerCentral.triggerState.getTotalRevolutionCounter() % CYCLE_ALTERNATION;
|
int engineCycleAlternation = engine->triggerCentral.triggerState.getTotalRevolutionCounter() % CYCLE_ALTERNATION;
|
||||||
|
|
||||||
for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) {
|
for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) {
|
||||||
|
@ -82,6 +82,7 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
|
||||||
NamedOutputPin *output = &enginePins.auxValve[valveIndex];
|
NamedOutputPin *output = &enginePins.auxValve[valveIndex];
|
||||||
|
|
||||||
for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
|
for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
|
||||||
|
*/
|
||||||
/* I believe a more correct implementation is the following:
|
/* I believe a more correct implementation is the following:
|
||||||
* here we properly account for trigger angle position in engine cycle coordinates
|
* here we properly account for trigger angle position in engine cycle coordinates
|
||||||
// todo: at the moment this logic is assuming four-stroke 720-degree engine cycle
|
// todo: at the moment this logic is assuming four-stroke 720-degree engine cycle
|
||||||
|
@ -91,6 +92,7 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
|
||||||
- ENGINE(triggerCentral.triggerShape.eventAngles[SCHEDULING_TRIGGER_INDEX])
|
- ENGINE(triggerCentral.triggerShape.eventAngles[SCHEDULING_TRIGGER_INDEX])
|
||||||
;
|
;
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
angle_t extra = phaseIndex * 360 + valveIndex * 180;
|
angle_t extra = phaseIndex * 360 + valveIndex * 180;
|
||||||
angle_t onTime = extra + engine->engineState.auxValveStart;
|
angle_t onTime = extra + engine->engineState.auxValveStart;
|
||||||
scheduling_s *onEvent = &engine->auxTurnOnEvent[valveIndex][phaseIndex][engineCycleAlternation];
|
scheduling_s *onEvent = &engine->auxTurnOnEvent[valveIndex][phaseIndex][engineCycleAlternation];
|
||||||
|
@ -115,13 +117,49 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
UNUSED(sharedLogger);
|
UNUSED(sharedLogger);
|
||||||
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
|
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addTriggerEventListener(auxValveTriggerCallback, "tach", engine);
|
|
||||||
|
#if !EFI_UNIT_TEST
|
||||||
|
// let's give it time to grab TPS value
|
||||||
|
chThdSleepMilliseconds(50);
|
||||||
|
#endif /* EFI_UNIT_TESTS */
|
||||||
|
|
||||||
|
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
if (cisnan(tps)) {
|
||||||
|
firmwareError(CUSTOM_OBD_91, "No TPS for Aux Valves");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateAuxValves(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
|
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,
|
||||||
|
actor->extra + engine->engineState.auxValveStart,
|
||||||
|
(schfunc_t)plainPinTurnOn,
|
||||||
|
actor
|
||||||
|
PASS_ENGINE_PARAMETER_SUFFIX
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// addTriggerEventListener(auxValveTriggerCallback, "AuxV", engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
@ -129,24 +167,23 @@ void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float x = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
if (cisnan(x)) {
|
if (cisnan(tps)) {
|
||||||
// error should be already reported by now
|
// error should be already reported by now
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
engine->engineState.auxValveStart = interpolate2d("aux", x,
|
engine->engineState.auxValveStart = interpolate2d("aux", tps,
|
||||||
engineConfiguration->fsioCurve1Bins,
|
engineConfiguration->fsioCurve1Bins,
|
||||||
engineConfiguration->fsioCurve1);
|
engineConfiguration->fsioCurve1);
|
||||||
|
|
||||||
engine->engineState.auxValveEnd = interpolate2d("aux", x,
|
engine->engineState.auxValveEnd = interpolate2d("aux", tps,
|
||||||
engineConfiguration->fsioCurve2Bins,
|
engineConfiguration->fsioCurve2Bins,
|
||||||
engineConfiguration->fsioCurve2);
|
engineConfiguration->fsioCurve2);
|
||||||
|
|
||||||
if (engine->engineState.auxValveStart >= engine->engineState.auxValveEnd) {
|
if (engine->engineState.auxValveStart >= engine->engineState.auxValveEnd) {
|
||||||
// this is a fatal error to make this really visible
|
// this is a fatal error to make this really visible
|
||||||
firmwareError(CUSTOM_AUX_OUT_OF_ORDER, "out of order at %.2f %.2f %.2f", x,
|
firmwareError(CUSTOM_AUX_OUT_OF_ORDER, "out of order at %.2f %.2f %.2f", tps,
|
||||||
engine->engineState.auxValveStart,
|
engine->engineState.auxValveStart,
|
||||||
engine->engineState.auxValveEnd);
|
engine->engineState.auxValveEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,28 +2,14 @@
|
||||||
* @file aux_valves.h
|
* @file aux_valves.h
|
||||||
*
|
*
|
||||||
* @date Nov 25, 2017
|
* @date Nov 25, 2017
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2017
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
/*
|
|
||||||
class AuxActor {
|
|
||||||
public:
|
|
||||||
int phaseIndex;
|
|
||||||
int valveIndex;
|
|
||||||
angle_t extra;
|
|
||||||
|
|
||||||
AngleBasedEvent open;
|
|
||||||
AngleBasedEvent close;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
//void plainPinTurnOn(AuxActor *current);
|
void plainPinTurnOn(AuxActor *current);
|
||||||
void plainPinTurnOn(NamedOutputPin *output);
|
|
||||||
void plainPinTurnOff(NamedOutputPin *output);
|
void plainPinTurnOff(NamedOutputPin *output);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
TEST(misc, testAuxValves) {
|
TEST(misc, testAuxValves) {
|
||||||
WITH_ENGINE_TEST_HELPER(NISSAN_PRIMERA);
|
WITH_ENGINE_TEST_HELPER(NISSAN_PRIMERA);
|
||||||
|
|
||||||
engine->auxSchedulingIndex = 0;
|
|
||||||
engine->needTdcCallback = false;
|
engine->needTdcCallback = false;
|
||||||
|
|
||||||
setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL);
|
setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL);
|
||||||
|
@ -20,8 +19,8 @@ TEST(misc, testAuxValves) {
|
||||||
eth.fireTriggerEvents2(2 /* count */ , 600 /* ms */);
|
eth.fireTriggerEvents2(2 /* count */ , 600 /* ms */);
|
||||||
ASSERT_EQ( 100, GET_RPM()) << "spinning-RPM#1";
|
ASSERT_EQ( 100, GET_RPM()) << "spinning-RPM#1";
|
||||||
|
|
||||||
eth.assertScheduling("a0", 0, &engine->auxTurnOnEvent[0][0][0], (void*)&plainPinTurnOn, -600000);
|
eth.assertTriggerEvent("a0", 0, &engine->auxValves[0][0].open, (void*)&plainPinTurnOn, 7, 86);
|
||||||
eth.assertScheduling("a1", 1, &engine->auxTurnOffEvent[0][0][0], (void*)&plainPinTurnOff, -550000);
|
eth.assertTriggerEvent("a1", 1, &engine->auxValves[0][1].open, (void*)&plainPinTurnOn, 3, 86);
|
||||||
eth.assertScheduling("a2", 2, &engine->auxTurnOnEvent[1][0][0], (void*)&plainPinTurnOn, -300000);
|
eth.assertTriggerEvent("a2", 2, &engine->auxValves[1][0].open, (void*)&plainPinTurnOn, 1, 86);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue