auto-sync

This commit is contained in:
rusEfi 2014-09-03 09:02:57 -05:00
parent 07bf8d077b
commit 760ac7850f
4 changed files with 97 additions and 50 deletions

View File

@ -34,10 +34,16 @@ public enum Sensor {
VREF_WIDTH("VRef w", "", 1),
DWELL0("Dwell0", "ms", 0, 30, BackgroundColor.BEIGE),
DWELL1("Dwell1", "ms", 0, 30, BackgroundColor.BEIGE),
DWELL2("Dwell2", "ms", 0, 30, BackgroundColor.BEIGE),
DWELL3("Dwell3", "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL0("total Dwell0", "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL1("total Dwell1", "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL2("total Dwell2", "ms", 0, 30, BackgroundColor.BEIGE),
TOTAL_DWELL3("total Dwell3", "ms", 0, 30, BackgroundColor.BEIGE),
ADVANCE0("Advance0", "dg", -40, 40, BackgroundColor.BROWN),
ADVANCE1("Advance1", "dg", -40, 40, BackgroundColor.BROWN),
ADVANCE2("Advance2", "dg", -40, 40, BackgroundColor.BROWN),
ADVANCE3("Advance3", "dg", -40, 40, BackgroundColor.BROWN),
PERIOD0("Period", "dg", 0, 400),
DUTY0("Duty0", "%", 0, 100, BackgroundColor.RED),
DUTY1("Duty1", "%", 0, 100, BackgroundColor.RED),

View File

@ -84,10 +84,20 @@ public class SensorCentral {
addDoubleSensor("baro", Sensor.BARO, es);
addDoubleSensor("clt", Sensor.CLT, es);
addDoubleSensor("tp", Sensor.TPS, es);
addDoubleSensor(Sensor.DWELL0, es);
addDoubleSensor(Sensor.DWELL1, es);
addDoubleSensor(Sensor.DWELL2, es);
addDoubleSensor(Sensor.DWELL3, es);
addDoubleSensor(Sensor.TOTAL_DWELL0, es);
addDoubleSensor(Sensor.TOTAL_DWELL1, es);
addDoubleSensor(Sensor.TOTAL_DWELL2, es);
addDoubleSensor(Sensor.TOTAL_DWELL3, es);
addDoubleSensor(Sensor.ADVANCE0, es);
addDoubleSensor(Sensor.ADVANCE1, es);
addDoubleSensor(Sensor.ADVANCE2, es);
addDoubleSensor(Sensor.ADVANCE3, es);
addDoubleSensor("tch", Sensor.T_CHARGE, es);
addDoubleSensor(Sensor.AFR, es);
addDoubleSensor("d_fuel", Sensor.DEFAULT_FUEL, es);
@ -97,8 +107,6 @@ public class SensorCentral {
addDoubleSensor(Sensor.FUEL_CLT, es);
addDoubleSensor(Sensor.FUEL_IAT, es);
addDoubleSensor(Sensor.TABLE_SPARK, es);
addDoubleSensor(Sensor.ADVANCE0, es);
addDoubleSensor(Sensor.ADVANCE1, es);
addDoubleSensor(Sensor.VREF, es);
addDoubleSensor(Sensor.VBATT, es);
addDoubleSensor(Sensor.MAF, es);

View File

@ -46,6 +46,7 @@ public class EcuStimulator {
private static final int RPM_MAX = 6000;
private static final int RPM_INCREMENT = 250;
private static final Sensor DWELL_SENSOR = Sensor.DWELL0;
public static final Sensor ADVANCE_SENSOR = Sensor.ADVANCE0;
private static final String CSV_FILE_NAME = "table" + RPM_INCREMENT + "_" + EL_INCREMENT + ".csv";
@ -71,7 +72,7 @@ public class EcuStimulator {
JPanel panel = ChartHelper.create3DControl(data, model, TITLE);
content.add(statusLabel, BorderLayout.NORTH);
content.add(panel, BorderLayout.CENTER);
content.add(inputs.getContent(), BorderLayout.WEST);
content.add(inputs.getContent(), BorderLayout.SOUTH);
}
public static EcuStimulator getInstance() {
@ -98,12 +99,12 @@ public class EcuStimulator {
ResultListener listener = new ResultListener() {
@Override
public void onResult(int rpm, double maf, float advance, double dwell) {
data.addPoint(new Point3D(rpm, maf, (float) dwell));
public void onResult(int rpm, double engineLoad, float advance, double dwell) {
data.addPoint(new Point3D(rpm, engineLoad, (float) advance));
model.plot().execute();
String msg = putValue("rpm", rpm) +
putValue("engine_load", maf) +
putValue("engine_load", engineLoad) +
putValue("advance", advance) +
putValue("dwell", dwell);
MessagesCentral.getInstance().postMessage(EcuStimulator.class, msg);
@ -131,50 +132,53 @@ public class EcuStimulator {
}
private void buildTable(ResultListener listener, Sensor dwellSensor) {
for (int rpm = RPM_MIN; rpm <= RPM_MAX; rpm += RPM_INCREMENT)
runSimulation(rpm, listener, dwellSensor);
for (int rpm = inputs.getRpmFrom(); rpm <= inputs.getRpmTo(); rpm += RPM_INCREMENT) {
for (double engineLoad = inputs.getEngineLoadMin(); engineLoad <= inputs.getEngineLoadMax(); engineLoad += EL_INCREMENT) {
for (int clt = inputs.getCltFrom(); clt <= inputs.getCltTo(); clt += 100) {
testPoint(rpm, engineLoad, clt, listener, dwellSensor);
}
}
}
}
private void runSimulation(int rpm, ResultListener resultListener, final Sensor dwellSensor) {
for (double engineLoad = inputs.getEngineLoadMin(); engineLoad <= inputs.getEngineLoadMax(); engineLoad += EL_INCREMENT) {
//setPotVoltage(maf, Sensor.MAF);
setPotVoltage(engineLoad, null);
setRpm(rpm);
/**
* Let's give the firmware some time to react
*/
sleepRuntime(SLEEP_TIME);
private void testPoint(int rpm, double engineLoad, int clt, ResultListener resultListener, Sensor dwellSensor) {
//setPotVoltage(maf, Sensor.MAF);
setPotVoltage(engineLoad, null);
setRpm(rpm);
/**
* Let's give the firmware some time to react
*/
sleepRuntime(SLEEP_TIME);
statusLabel.setText("RPM " + rpm + ", el " + engineLoad);
statusLabel.setText("RPM " + rpm + ", el " + engineLoad + ", CLT " + clt);
/**
* We are making a number of measurements and then we take the middle one
*/
MultipleMeasurements r = waitForMultipleResults(dwellSensor);
List<Double> dwells = r.getDwells();
List<Double> advances = r.getAdvances();
/**
* We are making a number of measurements and then we take the middle one
*/
MultipleMeasurements r = waitForMultipleResults(dwellSensor, ADVANCE_SENSOR);
List<Double> dwells = r.getDwells();
List<Double> advances = r.getAdvances();
// sorting measurements, taking middle value
Collections.sort(dwells);
Collections.sort(advances);
// sorting measurements, taking middle value
Collections.sort(dwells);
Collections.sort(advances);
double dwellDiff = Math.abs(dwells.get(0) - dwells.get(MEASURES - 1));
if (dwellDiff > 1)
System.out.println("dwells " + dwells);
double dwellDiff = Math.abs(dwells.get(0) - dwells.get(MEASURES - 1));
if (dwellDiff > 1)
System.out.println("dwells " + dwells);
double dwell = dwells.get(MEASURES / 2);
double advance = advances.get(MEASURES / 2);
double dwell = dwells.get(MEASURES / 2);
double advance = advances.get(MEASURES / 2);
if (dwell > 40)
throw new IllegalStateException("Unexpected value, how comes? " + dwell);
// if (dwell > 40)
// throw new IllegalStateException("Unexpected value, how comes? " + dwell);
log("Stimulator result: " + rpm + "@" + engineLoad + ": " + dwell);
log("Stimulator result: " + rpm + "@" + engineLoad + ": " + dwell);
// double dwell = Launcher.getAdcModel().getValue(Sensor.DWELL0);
// double advance = Launcher.getAdcModel().getValue(Sensor.ADVANCE);
resultListener.onResult(rpm, engineLoad, (float) advance, dwell);
}
resultListener.onResult(rpm, engineLoad, (float) advance, dwell);
}
private static void sleepRuntime(long sleepTime) {
@ -282,7 +286,7 @@ public class EcuStimulator {
void onResult(int rpm, double engineLoad, float advance, double dwell);
}
public MultipleMeasurements waitForMultipleResults(final Sensor dwellSensor) {
public MultipleMeasurements waitForMultipleResults(final Sensor dwellSensor, final Sensor advanceSensor) {
final MultipleMeasurements result = new MultipleMeasurements();
final CountDownLatch latch = new CountDownLatch(MEASURES);
@ -293,7 +297,8 @@ public class EcuStimulator {
if (latch.getCount() == 0)
return;
double dwell = getValue(dwellSensor);
double advance = 0;//getValue(Sensor.ADVANCE0);
double advance = getValue(advanceSensor);
advance = processAdvance(advance);
result.dwells.add(dwell);
result.advances.add(advance);
latch.countDown();
@ -309,6 +314,10 @@ public class EcuStimulator {
return result;
}
private double processAdvance(double advance) {
return advance > 360 ? advance - 720 : advance;
}
private class MultipleMeasurements {
private List<Double> dwells = new ArrayList<>(MEASURES);
private List<Double> advances = new ArrayList<>(MEASURES);

View File

@ -10,20 +10,28 @@ import java.awt.*;
* (c) Andrey Belomutskiy
*/
public class StimulationInputs {
private final JPanel content = new JPanel(new GridLayout(12, 1));
private final JSpinner loadEngineMin = new JSpinner(new SpinnerNumberModel(1.0, 0.0, 5.0, 0.1));
private final JSpinner loadEngineMax = new JSpinner(new SpinnerNumberModel(4.0, 0.0, 5.0, 0.1));
private final JPanel content = new JPanel(new GridLayout(7, 1));
private final JSpinner elResistance2 = new JSpinner(new SpinnerNumberModel(10000, 0, 100000, 1));
private final ValueRangeControl elRange = new ValueRangeControl("engine load", 1, 0.1, 4.6);
private final ValueRangeControl rpmRange = new ValueRangeControl("RPM", 400, 100, 6000);
private final ValueRangeControl cltRange = new ValueRangeControl("CLR r", 100, 100, 100);
private final ValueRangeControl iatRange = new ValueRangeControl("IAT r", 100, 100, 9900);
private final ValueRangeControl tpsRange = new ValueRangeControl("TPS", 1, 0.1, 4.5);
public StimulationInputs(EcuStimulator ecuStimulator) {
content.add(new JLabel("Engine load from"));
content.add(wrap(loadEngineMin));
content.add(new JLabel("Engine load to"));
content.add(wrap(loadEngineMax));
JPanel channelPanel = new JPanel(new FlowLayout());
channelPanel.add(new JLabel("Input channel"));
content.add(channelPanel);
content.add(rpmRange.getContent());
content.add(elRange.getContent());
content.add(cltRange.getContent());
content.add(iatRange.getContent());
content.add(tpsRange.getContent());
content.add(new JLabel("EL resistance"));
content.add(wrap(elResistance2));
@ -34,11 +42,27 @@ public class StimulationInputs {
}
public double getEngineLoadMin() {
return (Double) loadEngineMin.getValue();
return elRange.getFrom();
}
public double getEngineLoadMax() {
return (Double) loadEngineMax.getValue();
return elRange.getTo();
}
public int getRpmFrom() {
return (int) rpmRange.getFrom();
}
public int getRpmTo() {
return (int) rpmRange.getTo();
}
public int getCltFrom() {
return (int) cltRange.getFrom();
}
public int getCltTo() {
return (int) cltRange.getTo();
}
public static JComponent wrap(JComponent component) {