minor ETB progress

This commit is contained in:
rusEfi 2018-10-21 17:45:14 -04:00
parent 935dd73c47
commit 117be1f09d
9 changed files with 876 additions and 771 deletions

@ -1 +1 @@
Subproject commit fe95e90b80a28dd2f40bfee1ad90822b99519c6a
Subproject commit b5321c7e0ef470ed2dbb50dc1322c1252dea2d50

View File

@ -75,6 +75,7 @@ static THD_WORKING_AREA(etbTreadStack, UTILITY_THREAD_STACK_SIZE);
* @brief Pulse-Width Modulation state
*/
static SimplePwm etbPwmUp CCM_OPTIONAL;
static float valueOverride = NAN;
/*
static SimplePwm etbPwmDown CCM_OPTIONAL;
static OutputPin outputDirectionOpen CCM_OPTIONAL;
@ -85,8 +86,6 @@ EXTERN_ENGINE;
static Pid pid(&engineConfiguration->etb);
//static float prevTps;
static percent_t currentEtbDuty;
static bool wasEtbBraking = false;
@ -94,12 +93,23 @@ static bool wasEtbBraking = false;
static msg_t etbThread(void *arg) {
UNUSED(arg);
while (true) {
if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) {
pid.postState(&tsOutputChannels);
} else if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_EXTRA) {
tsOutputChannels.debugFloatField1 = valueOverride;
}
if (shouldResetPid) {
pid.reset();
// alternatorPidResetCounter++;
shouldResetPid = false;
}
if (!cisnan(valueOverride)) {
etbPwmUp.setSimplePwmDutyCycle(valueOverride);
pid.sleep();
continue;
}
if (engine->etbAutoTune) {
autoTune.Runtime(&logger);
@ -127,19 +137,11 @@ static msg_t etbThread(void *arg) {
outputDirectionClose.setValue(needEtbBraking);
}
if (engineConfiguration->debugMode == DBG_ELECTRONIC_THROTTLE_PID) {
pid.postState(&tsOutputChannels);
}
if (engineConfiguration->isVerboseETB) {
pid.showPidStatus(&logger, "ETB");
}
// if (tps != prevTps) {
// prevTps = tps;
// scheduleMsg(&logger, "tps=%d", (int) tps);
// }
// this thread is activated 10 times per second
pid.sleep();
}
@ -149,12 +151,14 @@ static msg_t etbThread(void *arg) {
}
/**
* manual duty cycle control without PID
* manual duty cycle control without PID. Percent value from 0 to 100
*/
static void setThrottleDutyCycle(int level) {
scheduleMsg(&logger, "setting throttle=%d", level);
static void setThrottleDutyCycle(float level) {
scheduleMsg(&logger, "setting ETB duty=%f", level);
float dc = 0.01 + (minI(level, 98)) / 100.0;
float dc = (minI(level, 98)) / 100.0;
dc = maxF(dc, 0.00001); // todo: need to fix PWM so that it supports zero duty cycle
valueOverride = dc;
etbPwmUp.setSimplePwmDutyCycle(dc);
print("etb duty = %.2f\r\n", dc);
}
@ -276,7 +280,7 @@ void initElectronicThrottle(void) {
startETBPins();
//
addConsoleActionI("set_etb", setThrottleDutyCycle);
addConsoleActionF("set_etb", setThrottleDutyCycle);
addConsoleActionF("set_etb_output", setTempOutput);
addConsoleActionF("set_etb_step", setTempStep);

View File

@ -53,8 +53,10 @@ void PwmConfig::init(float *st, single_wave_s *waves) {
*/
void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) {
if (dutyCycle < 0 || dutyCycle > 1) {
firmwareError(CUSTOM_ERR_6579, "spwd:dutyCycle %.2f", dutyCycle);
warning(CUSTOM_ERR_6579, "spwd:dutyCycle %.2f", dutyCycle);
return;
}
// todo: need to fix PWM so that it supports zero duty cycle
multiWave.setSwitchTime(0, dutyCycle);
}

View File

@ -6,7 +6,7 @@
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />

View File

@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Launcher COM112" type="Application" factoryName="Application" folderName="10x">
<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="COM112" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="ui" />
<envs />
<method />
</configuration>
</component>

File diff suppressed because it is too large Load Diff

View File

@ -150,6 +150,10 @@ public class CommandQueue {
write(command, timeout, InvocationConfirmationListener.VOID);
}
public void write(String command, InvocationConfirmationListener listener) {
write(command, DEFAULT_TIMEOUT, listener, true);
}
public void write(String command, int timeoutMs, InvocationConfirmationListener listener) {
write(command, timeoutMs, listener, true);
}

View File

@ -3,6 +3,7 @@ package com.rusefi;
import com.rusefi.io.CommandQueue;
import com.rusefi.ui.MessagesView;
import com.rusefi.ui.util.UiUtils;
import com.rusefi.ui.widgets.EtbResearch;
import com.rusefi.ui.widgets.EtbTestSequence;
import org.jetbrains.annotations.NotNull;
import org.putgemin.VerticalFlowLayout;
@ -26,6 +27,7 @@ public class BenchTestPane {
content.add(createIdleTest());
content.add(createDizzyTest());
content.add(UiUtils.wrap(new EtbTestSequence().getButton()));
content.add(UiUtils.wrap(new EtbResearch().getButton()));
content.add(new MessagesView().messagesScroll);
}

View File

@ -0,0 +1,105 @@
package com.rusefi.ui.widgets;
import com.opensr5.Logger;
import com.rusefi.FileLog;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.CommandQueue;
import com.rusefi.io.InvocationConfirmationListener;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
/**
* (c) Andrey Belomutskiy
* 10/21/2018
*/
public class EtbResearch {
private static final long SLEEP = 1000;
private final JButton button = new JButton("ETB R");
private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
// close to zero but not really zero so that we can validate this value
private final static double LOW_VALUE = 0.5;
// private boolean isStarted;
State state;
private double currentValue;
InvocationConfirmationListener goingUp = new InvocationConfirmationListener() {
@Override
public void onCommandConfirmation() {
state = State.GOING_UP;
executor.execute(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(SLEEP);
} catch (InterruptedException unexpected) {
unexpected.printStackTrace();
return;
}
double tpsPosition = SensorCentral.getInstance().getValue(Sensor.TPS);
FileLog.MAIN.logLine("ETB duty " + currentValue + ": tps=" + tpsPosition);
if (tpsPosition == 0) {
currentValue += 1.0;
CommandQueue.getInstance().write("set_etb " + currentValue, goingUp);
}
}
});
}
};
InvocationConfirmationListener setDebugModeConfiguration = new InvocationConfirmationListener() {
@Override
public void onCommandConfirmation() {
executor.execute(new Runnable() {
@Override
public void run() {
state = State.START;
currentValue = LOW_VALUE;
CommandQueue.getInstance().write("set_etb " + currentValue, goingUp);
}
});
}
};
public EtbResearch() {
button.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// if (!isStarted) {
//// metric.start();
// isStarted = true;
// }
executor.execute(new Runnable() {
@Override
public void run() {
// magic constant for DBG_ELECTRONIC_THROTTLE_EXTRA
state = State.DEBUG_MODE;
CommandQueue.getInstance().write("set debug_mode " + 29, setDebugModeConfiguration);
}
});
}
});
}
public JComponent getButton() {
return button;
}
enum State {
DEBUG_MODE,
START,
GOING_UP,
}
}