ETB quality instrumentation #494
This commit is contained in:
parent
921e493524
commit
e160077778
|
@ -15,6 +15,7 @@ import java.awt.*;
|
||||||
* (c) Andrey Belomutskiy 2013-2019
|
* (c) Andrey Belomutskiy 2013-2019
|
||||||
*/
|
*/
|
||||||
public class ETBPane {
|
public class ETBPane {
|
||||||
|
public static final String SET_ETB = "set_etb ";
|
||||||
private final JPanel content = new JPanel(new BorderLayout());
|
private final JPanel content = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
public ETBPane() {
|
public ETBPane() {
|
||||||
|
|
|
@ -1,15 +1,33 @@
|
||||||
package com.rusefi.ui.etb;
|
package com.rusefi.ui.etb;
|
||||||
|
|
||||||
|
import com.rusefi.ETBPane;
|
||||||
|
import com.rusefi.io.CommandQueue;
|
||||||
|
import com.rusefi.ui.storage.Node;
|
||||||
import com.rusefi.ui.util.UiUtils;
|
import com.rusefi.ui.util.UiUtils;
|
||||||
|
import com.rusefi.ui.widgets.AnyCommand;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class CommandsPanel {
|
public class CommandsPanel {
|
||||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||||
|
private final JLabel currentOverride = new JLabel();
|
||||||
|
|
||||||
public CommandsPanel() {
|
public CommandsPanel() {
|
||||||
|
content.add(currentOverride);
|
||||||
|
CommandQueue.getInstance().addListener(command -> {
|
||||||
|
if (command.startsWith(ETBPane.SET_ETB)) {
|
||||||
|
command = command.substring(ETBPane.SET_ETB.length());
|
||||||
|
String finalCommand = command;
|
||||||
|
SwingUtilities.invokeLater(() -> currentOverride.setText("PWM override " + finalCommand));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JPanel spotsPane = new JPanel(new VerticalFlowLayout());
|
||||||
|
spotsPane.setBorder(BorderFactory.createTitledBorder("Magic Spots"));
|
||||||
|
MagicSpotsFinder magicSpotsFinder = new MagicSpotsFinder();
|
||||||
|
spotsPane.add(UiUtils.wrap(magicSpotsFinder.getButton()));
|
||||||
|
spotsPane.add(magicSpotsFinder.getPoints());
|
||||||
|
|
||||||
JPanel testParameters = new JPanel(new VerticalFlowLayout());
|
JPanel testParameters = new JPanel(new VerticalFlowLayout());
|
||||||
testParameters.setBorder(BorderFactory.createTitledBorder("Try PID settings"));
|
testParameters.setBorder(BorderFactory.createTitledBorder("Try PID settings"));
|
||||||
|
@ -24,13 +42,13 @@ public class CommandsPanel {
|
||||||
testParameters.add(new JLabel("For example:"));
|
testParameters.add(new JLabel("For example:"));
|
||||||
testParameters.add(new JLabel("set etb_p 1.1"));
|
testParameters.add(new JLabel("set etb_p 1.1"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
content.setBorder(BorderFactory.createTitledBorder("Commands"));
|
content.setBorder(BorderFactory.createTitledBorder("Commands"));
|
||||||
|
|
||||||
content.add(testParameters);
|
content.add(testParameters);
|
||||||
|
content.add(spotsPane);
|
||||||
// content.add(UiUtils.wrap(new EtbMonteCarloSequence().getButton()));
|
// content.add(UiUtils.wrap(new EtbMonteCarloSequence().getButton()));
|
||||||
// content.add(UiUtils.wrap(new MagicSpotsFinder().getButton()));
|
|
||||||
|
content.add(AnyCommand.createArea(new Node(), ETBPane.SET_ETB + "10", false, false).getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getContent() {
|
public JPanel getContent() {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.rusefi.ui.etb;
|
package com.rusefi.ui.etb;
|
||||||
|
|
||||||
|
import com.rusefi.ETBPane;
|
||||||
import com.rusefi.core.MessagesCentral;
|
import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.core.SensorCentral;
|
import com.rusefi.core.SensorCentral;
|
||||||
import com.rusefi.io.CommandQueue;
|
import com.rusefi.io.CommandQueue;
|
||||||
import com.rusefi.io.InvocationConfirmationListener;
|
import com.rusefi.io.InvocationConfirmationListener;
|
||||||
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
@ -24,7 +26,9 @@ public class MagicSpotsFinder {
|
||||||
private static final long SLEEP = SECOND;
|
private static final long SLEEP = SECOND;
|
||||||
// how much do we want to change duty cycle on each iteration?
|
// how much do we want to change duty cycle on each iteration?
|
||||||
private static final double DUTY_CYCLE_STEP = 0.5;
|
private static final double DUTY_CYCLE_STEP = 0.5;
|
||||||
private final JButton button = new JButton("ETB Research");
|
private static final String MAGIC_SPOTS_FINDER = "Magic Spots Finder";
|
||||||
|
private static final int INITIAL_SLEEP = 10 * SECOND;
|
||||||
|
private final JButton button = new JButton(MAGIC_SPOTS_FINDER);
|
||||||
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||||
// close to zero but not really zero so that we can validate this value
|
// close to zero but not really zero so that we can validate this value
|
||||||
private final static double LOW_VALUE = 0.5;
|
private final static double LOW_VALUE = 0.5;
|
||||||
|
@ -41,7 +45,13 @@ public class MagicSpotsFinder {
|
||||||
private double startedToCloseValue;
|
private double startedToCloseValue;
|
||||||
private double backToZeroValue;
|
private double backToZeroValue;
|
||||||
|
|
||||||
private InvocationConfirmationListener goingDown = new InvocationConfirmationListener() {
|
private final JPanel points = new JPanel(new VerticalFlowLayout());
|
||||||
|
private final JLabel startedToOpenValueLabel = new JLabel("n/a");
|
||||||
|
private final JLabel reached100ValueLabel = new JLabel("n/a");
|
||||||
|
private final JLabel startedToCloseValueLabel = new JLabel("n/a");
|
||||||
|
private final JLabel backToZeroValueLabel = new JLabel("n/a");
|
||||||
|
|
||||||
|
private final InvocationConfirmationListener goingDown = new InvocationConfirmationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCommandConfirmation() {
|
public void onCommandConfirmation() {
|
||||||
state = State.GOING_DOWN;
|
state = State.GOING_DOWN;
|
||||||
|
@ -49,40 +59,41 @@ public class MagicSpotsFinder {
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sleep();
|
sleep(SLEEP);
|
||||||
|
|
||||||
double tpsPosition = SensorCentral.getInstance().getValue(Sensor.TPS);
|
double tpsPosition = SensorCentral.getInstance().getValue(Sensor.TPS);
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "ETB duty " + currentValue + ": tps=" + tpsPosition);
|
MessagesCentral.getInstance().postMessage(getClass(), "ETB duty " + currentValue + ": tps=" + tpsPosition);
|
||||||
|
|
||||||
if (tpsPosition >= 100) {
|
if (tpsPosition >= 100) {
|
||||||
currentValue -= DUTY_CYCLE_STEP;
|
currentValue -= DUTY_CYCLE_STEP;
|
||||||
CommandQueue.getInstance().write("set_etb " + currentValue, goingDown);
|
CommandQueue.getInstance().write(ETBPane.SET_ETB + currentValue, goingDown);
|
||||||
} else if (tpsPosition > 0) {
|
} else if (tpsPosition > 0) {
|
||||||
|
|
||||||
if (startedToCloseValue == 0) {
|
if (startedToCloseValue == 0) {
|
||||||
// if that's the first we've moved let's remember duty cycle value
|
// if that's the first we've moved let's remember duty cycle value
|
||||||
startedToCloseValue = currentValue;
|
startedToCloseValue = currentValue;
|
||||||
|
startedToCloseValueLabel.setText(String.format("Started Close %.1f", startedToCloseValue));
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "Started to close at " + startedToCloseValue);
|
MessagesCentral.getInstance().postMessage(getClass(), "Started to close at " + startedToCloseValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentValue -= DUTY_CYCLE_STEP;
|
currentValue -= DUTY_CYCLE_STEP;
|
||||||
CommandQueue.getInstance().write("set_etb " + currentValue, goingDown);
|
CommandQueue.getInstance().write(ETBPane.SET_ETB + currentValue, goingDown);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
backToZeroValue = currentValue;
|
backToZeroValue = currentValue;
|
||||||
|
backToZeroValueLabel.setText(String.format("Back Zero %.1f", backToZeroValue));
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "Back closed to close at " + backToZeroValue);
|
MessagesCentral.getInstance().postMessage(getClass(), "Back closed to close at " + backToZeroValue);
|
||||||
|
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "startedToOpenValue = " + startedToOpenValue + ", reached100Value = " + reached100Value);
|
MessagesCentral.getInstance().postMessage(getClass(), "startedToOpenValue = " + startedToOpenValue + ", reached100Value = " + reached100Value);
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "startedToCloseValue = " + startedToCloseValue + ", backToZeroValue = " + backToZeroValue);
|
MessagesCentral.getInstance().postMessage(getClass(), "startedToCloseValue = " + startedToCloseValue + ", backToZeroValue = " + backToZeroValue);
|
||||||
|
button.setEnabled(true);
|
||||||
|
button.setText(MAGIC_SPOTS_FINDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private InvocationConfirmationListener goingUp = new InvocationConfirmationListener() {
|
private final InvocationConfirmationListener goingUp = new InvocationConfirmationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCommandConfirmation() {
|
public void onCommandConfirmation() {
|
||||||
state = State.GOING_UP;
|
state = State.GOING_UP;
|
||||||
|
@ -90,7 +101,7 @@ public class MagicSpotsFinder {
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sleep();
|
sleep(SLEEP);
|
||||||
|
|
||||||
double tpsPosition = SensorCentral.getInstance().getValue(Sensor.TPS);
|
double tpsPosition = SensorCentral.getInstance().getValue(Sensor.TPS);
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "ETB duty " + currentValue + ": tps=" + tpsPosition);
|
MessagesCentral.getInstance().postMessage(getClass(), "ETB duty " + currentValue + ": tps=" + tpsPosition);
|
||||||
|
@ -98,27 +109,29 @@ public class MagicSpotsFinder {
|
||||||
if (tpsPosition == 0) {
|
if (tpsPosition == 0) {
|
||||||
// ETB has not moved yet, keep going up
|
// ETB has not moved yet, keep going up
|
||||||
currentValue += DUTY_CYCLE_STEP;
|
currentValue += DUTY_CYCLE_STEP;
|
||||||
CommandQueue.getInstance().write("set_etb " + currentValue, goingUp);
|
CommandQueue.getInstance().write(ETBPane.SET_ETB + currentValue, goingUp);
|
||||||
} else if (tpsPosition < 100) {
|
} else if (tpsPosition < 100) {
|
||||||
|
|
||||||
if (startedToOpenValue == 0) {
|
if (startedToOpenValue == 0) {
|
||||||
// if that's the first we've moved let's remember duty cycle value
|
// if that's the first we've moved let's remember duty cycle value
|
||||||
startedToOpenValue = currentValue;
|
startedToOpenValue = currentValue;
|
||||||
|
startedToOpenValueLabel.setText(String.format("Start to open: %.1f", startedToOpenValue));
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "Started to open at " + startedToOpenValue);
|
MessagesCentral.getInstance().postMessage(getClass(), "Started to open at " + startedToOpenValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ETB has not reached 100%, keep going up
|
// ETB has not reached 100%, keep going up
|
||||||
currentValue += DUTY_CYCLE_STEP;
|
currentValue += DUTY_CYCLE_STEP;
|
||||||
CommandQueue.getInstance().write("set_etb " + currentValue, goingUp);
|
CommandQueue.getInstance().write(ETBPane.SET_ETB + currentValue, goingUp);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// looks like we have reached 100%, cool!
|
// looks like we have reached 100%, cool!
|
||||||
reached100Value = currentValue;
|
reached100Value = currentValue;
|
||||||
|
reached100ValueLabel.setText(String.format("Reached 100: %.1f", reached100Value));
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "startedToOpenValue = " + startedToOpenValue + ", reached100Value = " + reached100Value);
|
MessagesCentral.getInstance().postMessage(getClass(), "startedToOpenValue = " + startedToOpenValue + ", reached100Value = " + reached100Value);
|
||||||
|
|
||||||
currentValue -= DUTY_CYCLE_STEP;
|
currentValue -= DUTY_CYCLE_STEP;
|
||||||
CommandQueue.getInstance().write("set_etb " + currentValue, goingDown);
|
CommandQueue.getInstance().write(ETBPane.SET_ETB + currentValue, goingDown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +140,10 @@ public class MagicSpotsFinder {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public JPanel getPoints() {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
// settings are confirmed, let's start going up from zero
|
// settings are confirmed, let's start going up from zero
|
||||||
private InvocationConfirmationListener setDebugModeConfiguration = new InvocationConfirmationListener() {
|
private InvocationConfirmationListener setDebugModeConfiguration = new InvocationConfirmationListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,7 +156,8 @@ public class MagicSpotsFinder {
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "Start!");
|
MessagesCentral.getInstance().postMessage(getClass(), "Start!");
|
||||||
resetValues();
|
resetValues();
|
||||||
|
|
||||||
CommandQueue.getInstance().write("set_etb " + currentValue, goingUp);
|
CommandQueue.getInstance().write(ETBPane.SET_ETB + currentValue, goingUp);
|
||||||
|
sleep(INITIAL_SLEEP);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -154,9 +172,16 @@ public class MagicSpotsFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MagicSpotsFinder() {
|
public MagicSpotsFinder() {
|
||||||
|
points.add(startedToOpenValueLabel);
|
||||||
|
points.add(reached100ValueLabel);
|
||||||
|
points.add(startedToCloseValueLabel);
|
||||||
|
points.add(backToZeroValueLabel);
|
||||||
|
|
||||||
button.addActionListener(new AbstractAction() {
|
button.addActionListener(new AbstractAction() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
button.setEnabled(false);
|
||||||
|
button.setText("Running...");
|
||||||
// if (!isStarted) {
|
// if (!isStarted) {
|
||||||
//// metric.start();
|
//// metric.start();
|
||||||
// isStarted = true;
|
// isStarted = true;
|
||||||
|
@ -169,7 +194,6 @@ public class MagicSpotsFinder {
|
||||||
CommandQueue.getInstance().write("set debug_mode " + 29, setDebugModeConfiguration);
|
CommandQueue.getInstance().write("set debug_mode " + 29, setDebugModeConfiguration);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -178,10 +202,10 @@ public class MagicSpotsFinder {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sleep() {
|
private void sleep(long millis) {
|
||||||
try {
|
try {
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "Sleeping " + SLEEP + "ms");
|
MessagesCentral.getInstance().postMessage(getClass(), "Sleeping " + millis + "ms");
|
||||||
Thread.sleep(SLEEP);
|
Thread.sleep(millis);
|
||||||
} catch (InterruptedException unexpected) {
|
} catch (InterruptedException unexpected) {
|
||||||
unexpected.printStackTrace();
|
unexpected.printStackTrace();
|
||||||
throw new IllegalStateException(unexpected);
|
throw new IllegalStateException(unexpected);
|
||||||
|
|
Loading…
Reference in New Issue