auto-sync

This commit is contained in:
rusEfi 2014-09-09 19:04:10 -05:00
parent 09f09380a3
commit 6377c10a1c
7 changed files with 113 additions and 16 deletions

View File

@ -73,6 +73,8 @@ public class EngineState {
// SensorStats.start(Sensor.IAT, Sensor.INTAKE_AIR_WIDTH);
SensorStats.start(Sensor.VREF, Sensor.VREF_WIDTH);
SensorStats.startStandardDeviation(Sensor.DWELL0, Sensor.DWELL0_SD);
registerStringValueAction("adcfast_co", NOTHING);
registerStringValueAction("adcfast_max", NOTHING);
registerStringValueAction("adcfast_min", NOTHING);

View File

@ -36,6 +36,9 @@ public enum Sensor {
DWELL1("Input dwl #2", "ms", 0, 30, BackgroundColor.BEIGE),
DWELL2("Input dwl #3", "ms", 0, 30, BackgroundColor.BEIGE),
DWELL3("Input dwl #4", "ms", 0, 30, BackgroundColor.BEIGE),
DWELL0_SD("Input d #1", "std dev", 100),
TOTAL_DWELL0("Input tdwl #1", "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL1("Input tdwl #2", "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL2("Input tdwl #3", "ms", 0, 30, BackgroundColor.BEIGE),
@ -62,13 +65,9 @@ public enum Sensor {
CHART_STATUS("CHART_STATUS"),
ADC_STATUS("ADC_STATUS"),
INJECTOR_0_STATUS("INJECTOR_0_STATUS"),
INJECTOR_1_STATUS("INJECTOR_1_STATUS"),
INJECTOR_2_STATUS("INJECTOR_2_STATUS"),
INJECTOR_3_STATUS("INJECTOR_3_STATUS"),
ADC_FAST("ADC_FAST", "b", 4000),
ADC_FAST_AVG("ADC_FAST_AVG", "b", 4000);
ADC_FAST_AVG("ADC_FAST_AVG", "b", 4000),
;
private final String name;
private final String units;

View File

@ -72,11 +72,6 @@ public class SensorCentral {
}
public void initialize(EngineState es) {
addDoubleSensor("injector0", Sensor.INJECTOR_0_STATUS, true, es);
addDoubleSensor("injector1", Sensor.INJECTOR_1_STATUS, true, es);
addDoubleSensor("injector2", Sensor.INJECTOR_2_STATUS, true, es);
addDoubleSensor("injector3", Sensor.INJECTOR_3_STATUS, true, es);
addDoubleSensor(RPM_KEY, Sensor.RPM, es);
addDoubleSensor("mat", Sensor.IAT, es);
addDoubleSensor("map", Sensor.MAP, es);
@ -114,7 +109,7 @@ public class SensorCentral {
addDoubleSensor("period1", Sensor.PERIOD0, es);
addDoubleSensor("duty0", Sensor.DUTY0, es);
addDoubleSensor("duty1", Sensor.DUTY1, es);
addDoubleSensor("timing", Sensor.TIMING, es);
addDoubleSensor(Sensor.TIMING, es);
addDoubleSensor(Sensor.TRG_0_DUTY, es);
addDoubleSensor(Sensor.TRG_1_DUTY, es);

View File

@ -1,5 +1,7 @@
package com.irnems.core;
import com.rusefi.CyclicBuffer;
/**
* 7/26/13
* (c) Andrey Belomutskiy
@ -35,4 +37,24 @@ public class SensorStats {
}
/**
* http://en.wikipedia.org/wiki/Standard_deviation
*/
public static void startStandardDeviation(Sensor source, final Sensor destination) {
final CyclicBuffer sb = new CyclicBuffer(30);
SensorCentral.getInstance().addListener(source, new SensorCentral.SensorListener() {
@Override
public void onSensorUpdate(double value) {
sb.add(value);
if (sb.getSize() == sb.getMaxSize()) {
double stdDev = sb.getStandardDeviation();
SensorCentral.getInstance().setValue(stdDev, destination);
}
}
}
);
}
}

View File

@ -0,0 +1,55 @@
package com.rusefi;
public class CyclicBuffer {
private final double values[];
private int size = 0;
private int pointer = 0;
public CyclicBuffer(int maxSize) {
values = new double[maxSize];
}
public double getStandardDeviation() {
double accumulator = 0;
double avg = average();
for (int i = 0; i < getSize(); i++) {
double v = get(i) - avg;
accumulator += v * v;
}
return Math.sqrt(accumulator);
}
public void add(double value) {
if (size < values.length)
size++;
values[pointer] = value;
pointer++;
if (pointer == values.length)
pointer = 0;
}
public double average() {
return sum() / size;
}
public double sum() {
double result = 0;
for (int i = 0; i < size; i++)
result += values[i];
return result;
}
public int getSize() {
return size;
}
public int getMaxSize() {
return values.length;
}
public double get(int i) {
return values[i];
}
}

View File

@ -0,0 +1,24 @@
package com.rusefi.test;
import com.rusefi.CyclicBuffer;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class CyclicBufferTest {
@Test
public void test() {
CyclicBuffer cb = new CyclicBuffer(3);
cb.add(1);
cb.add(3);
assertEquals(2.0, cb.average());
cb.add(111);
cb.add(211);
assertEquals(108.33333333333333, cb.average());
assertEquals(147.1144679039647, cb.getStandardDeviation());
}
}

View File

@ -103,10 +103,10 @@ public class RpmPanel {
controls.add(new AdcDebugControl().getControl(), "grow, wrap");
controls.add(new InjectorControl(0, Sensor.INJECTOR_0_STATUS).getControl(), "grow, wrap");
controls.add(new InjectorControl(1, Sensor.INJECTOR_1_STATUS).getControl(), "grow, wrap");
controls.add(new InjectorControl(2, Sensor.INJECTOR_2_STATUS).getControl(), "grow, wrap");
controls.add(new InjectorControl(3, Sensor.INJECTOR_3_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(0, Sensor.INJECTOR_0_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(1, Sensor.INJECTOR_1_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(2, Sensor.INJECTOR_2_STATUS).getControl(), "grow, wrap");
// controls.add(new InjectorControl(3, Sensor.INJECTOR_3_STATUS).getControl(), "grow, wrap");
controls.add(new LogModeWidget().getPanel(), "grow, wrap");