This commit is contained in:
rusEfi 2017-12-13 21:59:11 -05:00
parent 419133b905
commit 5c0be05378
4 changed files with 71 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="com.rusefi.Launcher" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="COM17" />
<option name="PROGRAM_PARAMETERS" value="COM107" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />

View File

@ -30,7 +30,7 @@ public enum Sensor {
MAF("MAF", SensorCategory.SENSOR_INPUTS, "Volts", 4),
MAFR("MAFR", SensorCategory.SENSOR_INPUTS, "kg/hr", 4),
PPS("pedal", SensorCategory.SENSOR_INPUTS, "%", 100),
PPS("pedal", SensorCategory.SENSOR_INPUTS, "%", 100), // pedal position sensor
knockCount("Knock", SensorCategory.SENSOR_INPUTS, "count", 30),
KnockValue("Knock level", SensorCategory.SENSOR_INPUTS, "v", 6),
@ -62,6 +62,8 @@ public enum Sensor {
DWELL3("Input dwl #4", SensorCategory.SNIFFING, "ms", 0, 30, BackgroundColor.BEIGE),
DWELL0_SD("Input d #1", SensorCategory.SNIFFING, "std dev", 100),
ETB_CONTROL_QUALITY("ETB metric", SensorCategory.SNIFFING, "", 100),
TOTAL_DWELL0("Input tdwl #1", SensorCategory.SNIFFING, "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL1("Input tdwl #2", SensorCategory.SNIFFING, "ms", 0, 30, BackgroundColor.BEIGE),
@ -96,7 +98,7 @@ public enum Sensor {
FUEL_LAG("F Lag", SensorCategory.FUEL, "", 0, 30),
IAT(SensorCategory.SENSOR_INPUTS, FieldType.FLOAT, 8, BackgroundColor.WHITE, -40, 150, "C"),
TPS(SensorCategory.SENSOR_INPUTS, FieldType.FLOAT, 12, BackgroundColor.MUD, 0, 100, "%"),
TPS(SensorCategory.SENSOR_INPUTS, FieldType.FLOAT, 12, BackgroundColor.MUD, 0, 100, "%"), // throttle position sensor
CRANKING_BASE(SensorCategory.FUEL, FieldType.FLOAT, 44, BackgroundColor.MUD, 0, 30, "ms"),
FUEL_BASE(Fields.GAUGE_NAME_FUEL_BASE, SensorCategory.FUEL, FieldType.FLOAT, 48, BackgroundColor.MUD, 0, 30, "ms"),
T_CHARGE(SensorCategory.FUEL, FieldType.FLOAT, 52, BackgroundColor.MUD, 30, 140),

View File

@ -5,6 +5,11 @@ import com.rusefi.core.SensorCentral;
import com.rusefi.core.SensorStats;
import com.rusefi.core.ValueSource;
import java.util.LinkedList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* https://github.com/rusefi/rusefi/issues/494
* <p>
@ -14,15 +19,53 @@ import com.rusefi.core.ValueSource;
* @see SensorStats
*/
public class ClosedLoopControlQualityMetric {
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private final ValueSource target;
private final ValueSource result;
private final Sensor destination;
private int maxSize = 100;
/**
* Last maxSize number of error measurements
* GuardedBy(this)
*/
private LinkedList<Double> errors = new LinkedList<>();
/**
* @param target what value are we trying to achieve
* @param result what value do we actually have
*/
public ClosedLoopControlQualityMetric(ValueSource target, ValueSource result, Sensor destination) {
this.target = target;
this.result = result;
this.destination = destination;
}
// void start()
public void start() {
executor.scheduleAtFixedRate(() -> {
rememberCurrentError(target.getValue() - result.getValue());
SensorCentral.getInstance().setValue(getStandardDeviation(), destination);
}, 0, 100, TimeUnit.MILLISECONDS);
}
public synchronized void reset() {
errors.clear();
}
private synchronized double getStandardDeviation() {
float sum = 0;
for (Double error : errors) {
sum += error * error;
}
return Math.sqrt(sum / errors.size());
}
private synchronized void rememberCurrentError(double error) {
if (errors.size() == maxSize)
errors.removeFirst();
errors.add(error);
}
}

View File

@ -1,6 +1,9 @@
package com.rusefi.ui.widgets;
import com.rusefi.FileLog;
import com.rusefi.SensorSnifferCentral;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.CommandQueue;
import javax.swing.*;
@ -19,17 +22,34 @@ import java.util.concurrent.TimeUnit;
*/
public class EtbTestSequence {
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private boolean isStarted;
private ClosedLoopControlQualityMetric metric = new ClosedLoopControlQualityMetric(
SensorCentral.getInstance().getValueSource(Sensor.PPS),
SensorCentral.getInstance().getValueSource(Sensor.TPS),
Sensor.ETB_CONTROL_QUALITY
);
private final static long SECOND = 1000;
private final JButton button = new JButton("ETB Test");
private static EtbTarget FIRST_STEP = new EtbTarget(SECOND, 0)
private static EtbTarget FIRST_STEP = new EtbTarget(SECOND, 0);
static {
FIRST_STEP
.addNext(5 * SECOND, 30)
.addNext(10 * SECOND, 50);
}
public EtbTestSequence() {
button.addActionListener(e -> FIRST_STEP.execute(executor));
button.addActionListener(e -> {
if (!isStarted) {
metric.start();
isStarted = true;
}
FIRST_STEP.execute(executor);
});
}
public JButton getButton() {