ETB autotune in its own function (#1350)

* pull out autotune

* oops
This commit is contained in:
Matthew Kennedy 2020-04-22 19:22:28 -07:00 committed by GitHub
parent 4947252830
commit df2db7036d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 69 deletions

View File

@ -199,23 +199,9 @@ expected<percent_t> EtbController::getOpenLoop(percent_t target) const {
return ff;
}
expected<percent_t> EtbController::getClosedLoop(percent_t target, percent_t actualThrottlePosition) {
if (m_shouldResetPid) {
m_pid.reset();
m_shouldResetPid = false;
}
// Only report the 0th throttle
if (m_myIndex == 0) {
#if EFI_TUNER_STUDIO
// Error is positive if the throttle needs to open further
tsOutputChannels.etb1Error = target - actualThrottlePosition;
#endif /* EFI_TUNER_STUDIO */
}
// Only allow autotune with stopped engine
if (GET_RPM() == 0 && engine->etbAutoTune) {
bool isPositive = actualThrottlePosition > target;
expected<percent_t> EtbController::getClosedLoopAutotune(percent_t actualThrottlePosition) {
// Estimate gain at 60% position - this should be well away from the spring and in the linear region
bool isPositive = actualThrottlePosition > 60.0f;
float autotuneAmplitude = 20;
@ -284,6 +270,25 @@ expected<percent_t> EtbController::getClosedLoop(percent_t target, percent_t act
// Bang-bang control the output to induce oscillation
return autotuneAmplitude * (isPositive ? -1 : 1);
}
expected<percent_t> EtbController::getClosedLoop(percent_t target, percent_t actualThrottlePosition) {
if (m_shouldResetPid) {
m_pid.reset();
m_shouldResetPid = false;
}
// Only report the 0th throttle
if (m_myIndex == 0) {
#if EFI_TUNER_STUDIO
// Error is positive if the throttle needs to open further
tsOutputChannels.etb1Error = target - actualThrottlePosition;
#endif /* EFI_TUNER_STUDIO */
}
// Only allow autotune with stopped engine
if (GET_RPM() == 0 && engine->etbAutoTune) {
return getClosedLoopAutotune(actualThrottlePosition);
} else {
// Normal case - use PID to compute closed loop part
return m_pid.getOutput(target, actualThrottlePosition);

View File

@ -50,6 +50,7 @@ public:
expected<percent_t> getOpenLoop(percent_t target) const override;
expected<percent_t> getClosedLoop(percent_t setpoint, percent_t target) override;
expected<percent_t> getClosedLoopAutotune(percent_t actualThrottlePosition);
void setOutput(expected<percent_t> outputValue) override;