auto-sync
This commit is contained in:
parent
7792a0fbe2
commit
6ce6f6c667
|
@ -63,15 +63,29 @@ floatms_t WallFuel::getWallFuel(int injectorIndex) {
|
|||
return wallFuel[injectorIndex];
|
||||
}
|
||||
|
||||
float AccelEnrichmemnt::getMaxDelta() {
|
||||
if (cb.getCount() == 0)
|
||||
return 0; // no recent data
|
||||
return cb.maxValue(cb.getSize());
|
||||
float AccelEnrichmemnt::getMaxDelta(DECLARE_ENGINE_PARAMETER_F) {
|
||||
|
||||
int len = minI(cb.getSize(), cb.getCount());
|
||||
if (len < 2)
|
||||
return 0;
|
||||
float maxValue = cb.elements[0] - cb.elements[len - 1];
|
||||
int resultIndex = 0;
|
||||
|
||||
for (int i = 1; i<len;i++) {
|
||||
float v = cb.elements[i] - cb.elements[i - 1];
|
||||
if (v > maxValue) {
|
||||
maxValue = v;
|
||||
resultIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
FuelSchedule *fs = engine->engineConfiguration2->injectionEvents;
|
||||
return maxValue * fs->eventsCount;
|
||||
}
|
||||
|
||||
// todo: eliminate code duplication between these two methods! Some pointer magic would help.
|
||||
floatms_t AccelEnrichmemnt::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_F) {
|
||||
float d = getMaxDelta();
|
||||
float d = getMaxDelta(PASS_ENGINE_PARAMETER_F);
|
||||
if (d > engineConfiguration->tpsAccelEnrichmentThreshold) {
|
||||
return d * engineConfiguration->tpsAccelEnrichmentMultiplier;
|
||||
}
|
||||
|
@ -82,7 +96,7 @@ floatms_t AccelEnrichmemnt::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_F) {
|
|||
}
|
||||
|
||||
float AccelEnrichmemnt::getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_F) {
|
||||
float d = getMaxDelta();
|
||||
float d = getMaxDelta(PASS_ENGINE_PARAMETER_F);
|
||||
if (d > engineConfiguration->engineLoadAccelEnrichmentThreshold) {
|
||||
return d * engineConfiguration->engineLoadAccelEnrichmentMultiplier;
|
||||
}
|
||||
|
@ -102,16 +116,7 @@ void AccelEnrichmemnt::setLength(int length) {
|
|||
}
|
||||
|
||||
void AccelEnrichmemnt::onNewValue(float currentValue DECLARE_ENGINE_PARAMETER_S) {
|
||||
if (!cisnan(previousValue)) {
|
||||
/**
|
||||
* this could be negative, zero or positive
|
||||
*/
|
||||
float delta = currentValue - previousValue;
|
||||
FuelSchedule *fs = engine->engineConfiguration2->injectionEvents;
|
||||
cb.add(delta * fs->eventsCount);
|
||||
}
|
||||
|
||||
previousValue = currentValue;
|
||||
cb.add(currentValue);
|
||||
}
|
||||
|
||||
void AccelEnrichmemnt::onEngineCycleTps(DECLARE_ENGINE_PARAMETER_F) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
* @return Extra fuel squirt duration for TPS acceleration
|
||||
*/
|
||||
floatms_t getTpsEnrichment(DECLARE_ENGINE_PARAMETER_F);
|
||||
float getMaxDelta();
|
||||
float getMaxDelta(DECLARE_ENGINE_PARAMETER_F);
|
||||
|
||||
void onEngineCycle(DECLARE_ENGINE_PARAMETER_F);
|
||||
void onEngineCycleTps(DECLARE_ENGINE_PARAMETER_F);
|
||||
|
|
|
@ -44,10 +44,10 @@ class cyclic_buffer
|
|||
int getSize();
|
||||
int getCount();
|
||||
void clear();
|
||||
volatile T elements[CB_MAX_SIZE];
|
||||
|
||||
private:
|
||||
void baseC(int size);
|
||||
volatile T elements[CB_MAX_SIZE];
|
||||
volatile int currentIndex;
|
||||
/**
|
||||
* number of elements added into this buffer, would be eventually bigger then size
|
||||
|
@ -101,11 +101,12 @@ cyclic_buffer<T>::~cyclic_buffer() {
|
|||
|
||||
template<typename T>
|
||||
void cyclic_buffer<T>::add(T value) {
|
||||
elements[currentIndex] = value;
|
||||
|
||||
++currentIndex;
|
||||
if (currentIndex == size) {
|
||||
currentIndex = 0;
|
||||
}
|
||||
elements[currentIndex] = value;
|
||||
|
||||
++count;
|
||||
}
|
||||
|
@ -146,7 +147,7 @@ T cyclic_buffer<T>::maxValue(int length) {
|
|||
int ci = currentIndex; // local copy to increase thread-safety
|
||||
T result = -BUFFER_MAX_VALUE; // todo: better min value?
|
||||
for (int i = 0; i < length; ++i) {
|
||||
int index = ci - i;
|
||||
int index = ci - i - 1;
|
||||
while (index < 0) {
|
||||
index += size;
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ T cyclic_buffer<T>::minValue(int length) {
|
|||
int ci = currentIndex; // local copy to increase thread-safety
|
||||
T result = +BUFFER_MAX_VALUE; // todo: better max value?
|
||||
for (int i = 0; i < length; ++i) {
|
||||
int index = ci - i;
|
||||
int index = ci - i - 1;
|
||||
while (index < 0) {
|
||||
index += size;
|
||||
}
|
||||
|
@ -188,7 +189,7 @@ T cyclic_buffer<T>::sum(int length) {
|
|||
T result = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
int index = ci - i;
|
||||
int index = ci - i - 1;
|
||||
while (index < 0) {
|
||||
index += size;
|
||||
}
|
||||
|
|
|
@ -26,13 +26,15 @@ void testAccelEnrichment(void) {
|
|||
engine->tpsAccelEnrichment.setLength(4);
|
||||
|
||||
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER);
|
||||
assertEqualsM("maxDelta", 0, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_F));
|
||||
engine->tpsAccelEnrichment.onNewValue(10 PASS_ENGINE_PARAMETER);
|
||||
assertEqualsM("maxDelta", 40, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_F));
|
||||
engine->tpsAccelEnrichment.onNewValue(30 PASS_ENGINE_PARAMETER);
|
||||
assertEqualsM("maxDelta", 80, engine->tpsAccelEnrichment.getMaxDelta());
|
||||
assertEqualsM("maxDelta", 80, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_F));
|
||||
|
||||
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER);
|
||||
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER);
|
||||
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER);
|
||||
engine->tpsAccelEnrichment.onNewValue(0 PASS_ENGINE_PARAMETER);
|
||||
assertEqualsM("maxDelta", 0, engine->tpsAccelEnrichment.getMaxDelta());
|
||||
assertEqualsM("maxDelta", 0, engine->tpsAccelEnrichment.getMaxDelta(PASS_ENGINE_PARAMETER_F));
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ void testCyclicBuffer(void) {
|
|||
|
||||
assertEquals(4, sb.maxValue(3));
|
||||
assertEquals(4, sb.maxValue(113));
|
||||
assertEquals(2, sb.minValue(3));
|
||||
assertEqualsM("minValue(3)", 2, sb.minValue(3));
|
||||
assertEquals(1, sb.minValue(113));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue