rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
EtbController Class Reference

#include <electronic_throttle_impl.h>

Inheritance diagram for EtbController:
Inheritance graph
[legend]
Collaboration diagram for EtbController:
Collaboration graph
[legend]

Public Member Functions

bool init (dc_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D *pedalMap) override
 
void setIdlePosition (percent_t pos) override
 
void setWastegatePosition (percent_t pos) override
 
void reset (const char *reason) override
 
void update () override
 
void onConfigurationChange (pid_s *previousConfiguration)
 
void showStatus ()
 
expected< percent_tobservePlant () override
 
expected< percent_tgetSetpoint () override
 
expected< percent_tgetSetpointEtb ()
 
expected< percent_tgetSetpointWastegate () const
 
expected< percent_tgetSetpointIdleValve () const
 
expected< percent_tgetOpenLoop (percent_t target) override
 
expected< percent_tgetClosedLoop (percent_t setpoint, percent_t observation) override
 
expected< percent_tgetClosedLoopAutotune (percent_t setpoint, percent_t actualThrottlePosition)
 
dc_function_e getFunction () const
 
void checkJam (percent_t setpoint, percent_t observation)
 
void setOutput (expected< percent_t > outputValue) override
 
const pid_state_sgetPidState () const override
 
virtual percent_t getThrottleTrim (float, percent_t) const
 
float getCurrentTarget () const override
 
bool isEtbMode () const override
 
void setLuaAdjustment (percent_t adjustment) override
 
float getLuaAdjustment () const
 
- Public Member Functions inherited from IEtbController
virtual void autoCalibrateTps (bool reportToTs=true)
 
- Public Member Functions inherited from ClosedLoopController< percent_t, percent_t >
void update ()
 

Data Fields

float prevOutput = 0
 
- Data Fields inherited from electronic_throttle_s
float targetWithIdlePosition = (float)0
 
float trim = (float)0
 
float boardEtbAdjustment = (float)0
 
float luaAdjustment = (float)0
 
float m_wastegatePosition = (float)0
 
float m_lastPidDtMs = (float)0
 
percent_t etbFeedForward = (percent_t)0
 
float integralError = (float)0
 
float etbCurrentTarget = (float)0
 
scaled_channel< int16_t, 100, 1 > m_adjustedTarget = (int16_t)0
 
uint8_t alignmentFill_at_38 [2] = {}
 
bool etbRevLimitActive: 1 {}
 
bool jamDetected: 1 {}
 
bool validPlantPosition: 1 {}
 
bool unusedBit_14_3: 1 {}
 
bool unusedBit_14_4: 1 {}
 
bool unusedBit_14_5: 1 {}
 
bool unusedBit_14_6: 1 {}
 
bool unusedBit_14_7: 1 {}
 
bool unusedBit_14_8: 1 {}
 
bool unusedBit_14_9: 1 {}
 
bool unusedBit_14_10: 1 {}
 
bool unusedBit_14_11: 1 {}
 
bool unusedBit_14_12: 1 {}
 
bool unusedBit_14_13: 1 {}
 
bool unusedBit_14_14: 1 {}
 
bool unusedBit_14_15: 1 {}
 
bool unusedBit_14_16: 1 {}
 
bool unusedBit_14_17: 1 {}
 
bool unusedBit_14_18: 1 {}
 
bool unusedBit_14_19: 1 {}
 
bool unusedBit_14_20: 1 {}
 
bool unusedBit_14_21: 1 {}
 
bool unusedBit_14_22: 1 {}
 
bool unusedBit_14_23: 1 {}
 
bool unusedBit_14_24: 1 {}
 
bool unusedBit_14_25: 1 {}
 
bool unusedBit_14_26: 1 {}
 
bool unusedBit_14_27: 1 {}
 
bool unusedBit_14_28: 1 {}
 
bool unusedBit_14_29: 1 {}
 
bool unusedBit_14_30: 1 {}
 
bool unusedBit_14_31: 1 {}
 
uint16_t etbTpsErrorCounter = (uint16_t)0
 
uint16_t etbPpsErrorCounter = (uint16_t)0
 
int8_t etbErrorCode = (int8_t)0
 
int8_t etbErrorCodeBlinker = (int8_t)0
 
int8_t tcEtbDrop = (int8_t)0
 
uint8_t alignmentFill_at_51 [1] = {}
 
scaled_channel< uint16_t, 100, 1 > jamTimer = (uint16_t)0
 
int8_t adjustedEtbTarget = (int8_t)0
 
uint8_t state = (uint8_t)0
 

Protected Member Functions

DcMotorgetMotor ()
 

Protected Attributes

bool hadTpsError = false
 
bool hadPpsError = false
 

Private Member Functions

bool checkStatus ()
 

Private Attributes

dc_function_e m_function = DC_None
 
SensorType m_positionSensor = SensorType::Invalid
 
DcMotorm_motor = nullptr
 
Pid m_pid
 
bool m_shouldResetPid = false
 
ErrorAccumulator m_targetErrorAccumulator
 
Timer m_jamDetectTimer
 
const ValueProvider3Dm_pedalProvider = nullptr
 
float m_idlePosition = 0
 
bool m_isAutotune = false
 
bool m_lastIsPositive = false
 
Timer m_cycleTimer
 
float m_minCycleTps = 0
 
float m_maxCycleTps = 0
 
float m_a = 8
 
float m_tu = 0.1f
 
uint8_t m_autotuneCounter = 0
 
uint8_t m_autotuneCurrentParam = 0
 
Timer m_luaAdjustmentTimer
 
efitimeus_t lastTickUs
 

Detailed Description

Definition at line 28 of file electronic_throttle_impl.h.

Member Function Documentation

◆ checkJam()

void EtbController::checkJam ( percent_t  setpoint,
percent_t  observation 
)

Definition at line 690 of file electronic_throttle.cpp.

690 {
691 float absError = std::abs(setpoint - observation);
692
693 auto jamDetectThreshold = engineConfiguration->etbJamDetectThreshold;
694 auto jamTimeout = engineConfiguration->etbJamTimeout;
695
696 if (jamDetectThreshold != 0 && jamTimeout != 0) {
697 auto nowNt = getTimeNowNt();
698
699 if (absError > jamDetectThreshold && engine->module<IgnitionController>()->getIgnState()) {
700 if (m_jamDetectTimer.hasElapsedSec(jamTimeout)) {
701 efiPrintf(" ************* ETB is jammed! ***************");
702 jamDetected = true;
703
705 }
706 } else {
707 m_jamDetectTimer.reset(nowNt);
708 jamDetected = false;
709 }
710
711 jamTimer = m_jamDetectTimer.getElapsedSeconds(nowNt);
712 }
713}
constexpr auto & module()
Definition engine.h:200
virtual bool getIgnState() const
void reportEtbProblem()
efitick_t getTimeNowNt()
Definition efitime.cpp:19
LimpManager * getLimpManager()
Definition engine.cpp:596
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
scaled_channel< uint16_t, 100, 1 > jamTimer

Referenced by getClosedLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkStatus()

bool EtbController::checkStatus ( )
private
Returns
true if OK, false if should be disabled

Definition at line 593 of file electronic_throttle.cpp.

593 {
594#if EFI_TUNER_STUDIO
595 // Only debug throttle #1
596 if (m_function == DC_Throttle1) {
598 } else if (m_function == DC_Wastegate) {
600 }
601#endif /* EFI_TUNER_STUDIO */
602
603 if (!isEtbMode()) {
604 // no validation for h-bridge or idle mode
605 return true;
606 }
607 // ETB-specific code belo. The whole mix-up between DC and ETB is shameful :(
608
609 // Only allow autotune with stopped engine, and on the first throttle
610 // Update local state about autotune
613 && m_function == DC_Throttle1;
614
615 bool shouldCheckSensorFunction = engine->module<SensorChecker>()->analogSensorsShouldWork();
616
617 if (!m_isAutotune && shouldCheckSensorFunction) {
618 bool isTpsError = !Sensor::get(m_positionSensor).Valid;
619
620 // If we have an error that's new, increment the counter
621 if (isTpsError && !hadTpsError) {
623 }
624
625 hadTpsError = isTpsError;
626
627 bool isPpsError = !Sensor::get(SensorType::AcceleratorPedal).Valid;
628
629 // If we have an error that's new, increment the counter
630 if (isPpsError && !hadPpsError) {
632 }
633
634 hadPpsError = isPpsError;
635 } else {
636 // Either sensors are expected to not work, or autotune is running, so reset the error counter
639 }
640
641 EtbStatus localReason = EtbStatus::None;
642 if (etbTpsErrorCounter > ETB_INTERMITTENT_LIMIT) {
643 localReason = EtbStatus::IntermittentTps;
644#if EFI_SHAFT_POSITION_INPUT
647 && !engine->etbAutoTune) {
648 localReason = EtbStatus::EngineStopped;
649#endif // EFI_SHAFT_POSITION_INPUT
650 } else if (etbPpsErrorCounter > ETB_INTERMITTENT_LIMIT) {
651 localReason = EtbStatus::IntermittentPps;
652 } else if (engine->engineState.lua.luaDisableEtb) {
653 localReason = EtbStatus::Lua;
654 } else if (!getLimpManager()->allowElectronicThrottle()) {
655 localReason = EtbStatus::JamDetected;
657 localReason = EtbStatus::Redundancy;
658 }
659
660 etbErrorCode = (int8_t)localReason;
661
662 return localReason == EtbStatus::None;
663}
TriggerCentral triggerCentral
Definition engine.h:318
bool etbAutoTune
Definition engine.h:296
EngineState engineState
Definition engine.h:344
TunerStudioOutputChannels outputChannels
Definition engine.h:109
bool isEtbMode() const override
void postState(pid_status_s &pidStatus) const
Definition efi_pid.cpp:144
virtual SensorResult get() const =0
virtual bool isRedundant() const
Definition sensor.h:155
static float getOrZero(SensorType type)
Definition sensor.h:83
bool engineMovedRecently(efitick_t nowNt) const
PUBLIC_API_WEAK bool isBoardAllowingLackOfPps()
EtbStatus

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getClosedLoop()

expected< percent_t > EtbController::getClosedLoop ( percent_t  setpoint,
percent_t  observation 
)
overridevirtual

Implements ClosedLoopController< percent_t, percent_t >.

Definition at line 525 of file electronic_throttle.cpp.

525 {
526 if (m_shouldResetPid) {
527 m_pid.reset();
529 m_shouldResetPid = false;
530 }
531
532 if (m_isAutotune) {
533 state = (uint8_t)EtbState::Autotune;
534
536
537 return getClosedLoopAutotune(target, observation);
538 } else {
539 checkJam(target, observation);
540
541 integralError = m_targetErrorAccumulator.accumulate(target - observation);
542
543 float dt = m_cycleTimer.getElapsedSecondsAndReset(getTimeNowNt());
544 m_lastPidDtMs = dt * 1000.0;
545
546 // Normal case - use PID to compute closed loop part
547 return m_pid.getOutput(target, observation, dt);
548 }
549}
float accumulate(float error)
void checkJam(percent_t setpoint, percent_t observation)
ErrorAccumulator m_targetErrorAccumulator
expected< percent_t > getClosedLoopAutotune(percent_t setpoint, percent_t actualThrottlePosition)
virtual void reset()
Definition efi_pid.cpp:103
float getOutput(float target, float input)
Definition efi_pid.cpp:56
void onTransitionEvent(TransitionEvent event)
Here is the call graph for this function:

◆ getClosedLoopAutotune()

expected< percent_t > EtbController::getClosedLoopAutotune ( percent_t  setpoint,
percent_t  actualThrottlePosition 
)

Definition at line 430 of file electronic_throttle.cpp.

430 {
431 // Estimate gain at current position - this should be well away from the spring and in the linear region
432 // GetSetpoint sets this to 50%
433 bool isPositive = actualThrottlePosition > target;
434
435 float autotuneAmplitude = 20;
436
437 // End of cycle - record & reset
438 if (!isPositive && m_lastIsPositive) {
439 // Determine period
440 float tu = m_cycleTimer.getElapsedSecondsAndReset(getTimeNowNt());
441
442 // Determine amplitude
443 float a = m_maxCycleTps - m_minCycleTps;
444
445 // Filter - it's pretty noisy since the ultimate period is not very many loop periods
446 constexpr float alpha = 0.05;
447 m_a = alpha * a + (1 - alpha) * m_a;
448 m_tu = alpha * tu + (1 - alpha) * m_tu;
449
450 // Reset bounds
451 m_minCycleTps = 100;
452 m_maxCycleTps = 0;
453
454 // Math is for Åström–Hägglund (relay) auto tuning
455 // https://warwick.ac.uk/fac/cross_fac/iatl/reinvention/archive/volume5issue2/hornsey
456
457 // Amplitude of input (duty cycle %)
458 float b = 2 * autotuneAmplitude;
459
460 // Ultimate gain per A-H relay tuning rule
461 float ku = 4 * b / (CONST_PI * m_a);
462
463 // The multipliers below are somewhere near the "no overshoot"
464 // and "some overshoot" flavors of the Ziegler-Nichols method
465 // Kp
466 float kp = 0.35f * ku;
467 float ki = 0.25f * ku / m_tu;
468 float kd = 0.08f * ku * m_tu;
469
470 // Publish to TS state
471#if EFI_TUNER_STUDIO
472 // Every 5 cycles (of the throttle), cycle to the next value
473 if (m_autotuneCounter >= 5) {
475 m_autotuneCurrentParam = (m_autotuneCurrentParam + 1) % 3; // three ETB calibs: P-I-D
476 }
477
479
480 switch (m_autotuneCurrentParam) {
481 case 0:
483 break;
484 case 1:
486 break;
487 case 2:
489 break;
490 }
491
492 // Also output to debug channels if configured
493 if (engineConfiguration->debugMode == DBG_ETB_AUTOTUNE) {
494 // a - amplitude of output (TPS %)
496 // b - amplitude of input (Duty cycle %)
498 // Tu - oscillation period (seconds)
500
505 }
506#endif
507 // TODO: directly update PID settings in engineConfiguration
508 }
509
510 m_lastIsPositive = isPositive;
511
512 // Find the min/max of each cycle
513 if (actualThrottlePosition < m_minCycleTps) {
514 m_minCycleTps = actualThrottlePosition;
515 }
516
517 if (actualThrottlePosition > m_maxCycleTps) {
518 m_maxCycleTps = actualThrottlePosition;
519 }
520
521 // Bang-bang control the output to induce oscillation
522 return autotuneAmplitude * (isPositive ? -1 : 1);
523}
void tsCalibrationSetData(TsCalMode mode, float value, float value2, float timeoutMs)

Referenced by getClosedLoop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCurrentTarget()

float EtbController::getCurrentTarget ( ) const
inlineoverridevirtual

Implements IEtbController.

Definition at line 72 of file electronic_throttle_impl.h.

◆ getFunction()

dc_function_e EtbController::getFunction ( ) const
inline

Definition at line 57 of file electronic_throttle_impl.h.

57{ return m_function; }

◆ getLuaAdjustment()

float EtbController::getLuaAdjustment ( ) const

positive adjustment opens TPS, negative closes TPS

Definition at line 392 of file electronic_throttle.cpp.

392 {
393 // If the lua position hasn't been set in 0.2 second, don't adjust!
394 // This avoids a stuck throttle due to hung/rogue/etc Lua script
395 if (m_luaAdjustmentTimer.getElapsedSeconds() > 0.2f) {
396 return 0;
397 } else {
398 return luaAdjustment;
399 }
400}

Referenced by getSetpointEtb(), and getSetpointWastegate().

Here is the caller graph for this function:

◆ getMotor()

DcMotor * EtbController::getMotor ( )
inlineprotected

Definition at line 90 of file electronic_throttle_impl.h.

90{ return m_motor; }

◆ getOpenLoop()

expected< percent_t > EtbController::getOpenLoop ( percent_t  target)
overridevirtual

Implements ClosedLoopController< percent_t, percent_t >.

Definition at line 406 of file electronic_throttle.cpp.

406 {
407 // Don't apply open loop for idle valve, only real ETB or wastegate
408 switch(m_function){
409 case DC_Throttle1:
410 case DC_Throttle2: {
411 etbFeedForward = interpolate2d(target, config->etbBiasBins, config->etbBiasValues);
412 break;
413 }
414 case DC_Wastegate: {
416 break;
417 }
418 case DC_IdleValve: {
419 etbFeedForward = 0;
420 break;
421 }
422 default: { // or DC_None
423 etbFeedForward = 0;
424 }
425 }
426
427 return etbFeedForward;
428}
static constexpr persistent_config_s * config
scaled_channel< int16_t, 100, 1 > dcWastegateBiasValues[ETB_BIAS_CURVE_LENGTH]

◆ getPidState()

const pid_state_s & EtbController::getPidState ( ) const
inlineoverridevirtual

Implements IEtbController.

Definition at line 64 of file electronic_throttle_impl.h.

64{ return m_pid; };

◆ getSetpoint()

expected< percent_t > EtbController::getSetpoint ( )
overridevirtual

Implements ClosedLoopController< percent_t, percent_t >.

Definition at line 262 of file electronic_throttle.cpp.

262 {
263 switch (m_function) {
264 case DC_Throttle1:
265 case DC_Throttle2:
266 return getSetpointEtb();
267 case DC_IdleValve:
268 return getSetpointIdleValve();
269 case DC_Wastegate:
270 return getSetpointWastegate();
271 default:
272 return unexpected;
273 }
274}
expected< percent_t > getSetpointIdleValve() const
expected< percent_t > getSetpointEtb()
expected< percent_t > getSetpointWastegate() const
Here is the call graph for this function:

◆ getSetpointEtb()

expected< percent_t > EtbController::getSetpointEtb ( )

Definition at line 303 of file electronic_throttle.cpp.

303 {
304 // Autotune runs with 50% target position
305 if (m_isAutotune) {
306 return 50.0f;
307 }
308
309// // A few extra preconditions if throttle control is invalid
310// if (startupPositionError) {
311// return unexpected;
312// }
313
314 // If the pedal map hasn't been set, we can't provide a setpoint.
315 if (!m_pedalProvider) {
316 state = (uint8_t)EtbState::NoPedal;
317 return unexpected;
318 }
319
320 float sanitizedPedal = getSanitizedPedal();
321
323 percent_t preBoard = m_pedalProvider->getValue(rpm, sanitizedPedal);
326
327 percent_t etbIdlePosition = clampPercentValue(m_idlePosition);
328 percent_t etbIdleAddition = PERCENT_DIV * engineConfiguration->etbIdleThrottleRange * etbIdlePosition;
329
330 // Interpolate so that the idle adder just "compresses" the throttle's range upward.
331 // [0, 100] -> [idle, 100]
332 // 0% target from table -> idle position as target
333 // 100% target from table -> 100% target position
334 targetWithIdlePosition = interpolateClamped(0, etbIdleAddition, 100, 100, etbCurrentTarget);
335
337 // just an additional logging data point
338 adjustedEtbTarget = targetPosition;
339
340#if EFI_ANTILAG_SYSTEM
342 targetPosition += engineConfiguration->ALSEtbAdd;
343 }
344#endif /* EFI_ANTILAG_SYSTEM */
345
346 float vehicleSpeed = Sensor::getOrZero(SensorType::VehicleSpeed);
348 tcEtbDrop = tcEtbDropTable.getValue(wheelSlip, vehicleSpeed);
349
350 // Apply any adjustment that this throttle alone needs
351 // Clamped to +-10 to prevent anything too wild
352 trim = clampF(-10, getThrottleTrim(rpm, targetPosition), 10);
353 targetPosition += trim + tcEtbDrop;
354
355 // Clamp before rev limiter to avoid ineffective rev limit due to crazy out of range position target
356 targetPosition = clampPercentValue(targetPosition);
357
358 // Lastly, apply ETB rev limiter
359 auto etbRpmLimit = engineConfiguration->etbRevLimitStart;
360 if (etbRpmLimit != 0) {
361 auto fullyLimitedRpm = etbRpmLimit + engineConfiguration->etbRevLimitRange;
362
363 float targetPositionBefore = targetPosition;
364 // Linearly taper throttle to closed from the limit across the range
365 targetPosition = interpolateClamped(etbRpmLimit, targetPosition, fullyLimitedRpm, 0, rpm);
366
367 // rev limit active if the position was changed by rev limiter
368 etbRevLimitActive = std::abs(targetPosition - targetPositionBefore) > 0.1f;
369 }
370
371 float minPosition = engineConfiguration->etbMinimumPosition;
372
373 // Keep the throttle just barely off the lower stop, and less than the user-configured maximum
374 float maxPosition = engineConfiguration->etbMaximumPosition;
375 // Don't allow max position over 100
376 maxPosition = std::min(maxPosition, 100.0f);
377
378 targetPosition = clampF(minPosition, targetPosition, maxPosition);
379 m_adjustedTarget = targetPosition;
380
381 return targetPosition;
382}
AntilagSystemBase antilagController
Definition engine.h:228
float getLuaAdjustment() const
virtual percent_t getThrottleTrim(float, percent_t) const
const ValueProvider3D * m_pedalProvider
virtual float getValue(float xColumn, float yRow) const =0
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
static Map3D< TRACTION_CONTROL_ETB_DROP_SLIP_SIZE, TRACTION_CONTROL_ETB_DROP_SPEED_SIZE, int8_t, uint16_t, uint8_t > tcEtbDropTable
PUBLIC_API_WEAK float boardAdjustEtbTarget(float currentEtbTarget)
float getSanitizedPedal()
float percent_t
scaled_channel< int16_t, 100, 1 > m_adjustedTarget

Referenced by getSetpoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSetpointIdleValve()

expected< percent_t > EtbController::getSetpointIdleValve ( ) const

Definition at line 276 of file electronic_throttle.cpp.

276 {
277 // VW ETB idle mode uses an ETB only for idle (a mini-ETB sets the lower stop, and a normal cable
278 // can pull the throttle up off the stop.), so we directly control the throttle with the idle position.
279#if EFI_TUNER_STUDIO && (EFI_PROD_CODE || EFI_SIMULATOR)
280 // todo: where do we want to log this? engine->outputChannels.etbTarget = m_idlePosition;
281#endif // EFI_TUNER_STUDIO
282 return clampPercentValue(m_idlePosition);
283}

Referenced by getSetpoint().

Here is the caller graph for this function:

◆ getSetpointWastegate()

expected< percent_t > EtbController::getSetpointWastegate ( ) const

Definition at line 285 of file electronic_throttle.cpp.

285 {
287
288 return clampPercentValue(targetPosition);
289}

Referenced by getSetpoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getThrottleTrim()

virtual percent_t EtbController::getThrottleTrim ( float  ,
percent_t   
) const
inlinevirtual

Reimplemented in EtbController2.

Definition at line 67 of file electronic_throttle_impl.h.

67 {
68 return 0;
69 }

Referenced by getSetpointEtb().

Here is the caller graph for this function:

◆ init()

bool EtbController::init ( dc_function_e  function,
DcMotor motor,
pid_s pidParameters,
const ValueProvider3D pedalMap 
)
overridevirtual

Implements IEtbController.

Definition at line 170 of file electronic_throttle.cpp.

170 {
171 state = (uint8_t)EtbState::InInit;
172 if (function == DC_None) {
173 // if not configured, don't init.
174 state = (uint8_t)EtbState::NotEbt;
176 return false;
177 }
178
179 m_function = function;
181
182 // If we are a throttle, require redundant TPS sensor
183 if (isEtbMode()) {
184 // If no sensor is configured for this throttle, skip initialization.
185 if (!Sensor::hasSensor(functionToTpsSensor(function))) {
187 return false;
188 }
189
192 return false;
193 }
194 }
195
196 m_motor = motor;
197 m_pedalProvider = pedalProvider;
198
199 m_pid.initPidClass(pidParameters);
200
201#if !EFI_UNIT_TEST
202 if (isEtbMode()) {
205 } else {
206 // Some defaults from setDefaultEtbParameters(), find better values for EWG and Idle or add config options
207 m_pid.iTermMin = -30;
208 m_pid.iTermMax = 30;
209 }
210#endif
211
212 // Ignore 3% position error before complaining
214
216 return true;
217}
void init(float ignoreError, float dt)
float iTermMax
Definition efi_pid.h:69
float iTermMin
Definition efi_pid.h:68
void initPidClass(pid_s *parameters)
Definition efi_pid.cpp:24
virtual bool hasSensor() const
Definition sensor.h:141
constexpr float etbPeriodSeconds
static SensorType functionToPositionSensor(dc_function_e func)
static SensorType functionToTpsSensor(dc_function_e func)
@ SuccessfulInit
Here is the call graph for this function:

◆ isEtbMode()

bool EtbController::isEtbMode ( ) const
inlineoverridevirtual

Implements IEtbController.

Definition at line 76 of file electronic_throttle_impl.h.

76 {
77 return m_function == DC_Throttle1 || m_function == DC_Throttle2;
78 }

Referenced by checkStatus(), init(), setOutput(), and update().

Here is the caller graph for this function:

◆ observePlant()

expected< percent_t > EtbController::observePlant ( )
overridevirtual

Implements ClosedLoopController< percent_t, percent_t >.

Definition at line 248 of file electronic_throttle.cpp.

248 {
249 expected<percent_t> plant = Sensor::get(m_positionSensor);
250 validPlantPosition = plant.Valid;
251 return plant;
252}
Here is the call graph for this function:

◆ onConfigurationChange()

void EtbController::onConfigurationChange ( pid_s previousConfiguration)

Definition at line 235 of file electronic_throttle.cpp.

235 {
236 if (m_motor && !m_pid.isSame(previousConfiguration)) {
237 efiPrintf(" ETB m_shouldResetPid");
238 m_shouldResetPid = true;
239 }
240
241 doInitElectronicThrottle(/*isStartupInit*/false);
242}
bool isSame(const pid_s *parameters) const
Definition efi_pid.cpp:39
void doInitElectronicThrottle(bool isStartupInit)

Referenced by onConfigurationChangeElectronicThrottleCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void EtbController::reset ( const char reason)
overridevirtual

Implements IEtbController.

Definition at line 223 of file electronic_throttle.cpp.

223 {
224 efiPrintf("ETB reset %s", reason);
225 m_shouldResetPid = true;
228#if EFI_UNIT_TEST
230#endif // EFI_UNIT_TEST
231
232}
int ebtResetCounter

◆ setIdlePosition()

void EtbController::setIdlePosition ( percent_t  pos)
overridevirtual

Implements IEtbController.

Definition at line 254 of file electronic_throttle.cpp.

254 {
255 m_idlePosition = pos;
256}

◆ setLuaAdjustment()

void EtbController::setLuaAdjustment ( percent_t  adjustment)
overridevirtual

Implements IEtbController.

Definition at line 384 of file electronic_throttle.cpp.

384 {
385 luaAdjustment = adjustment;
386 m_luaAdjustmentTimer.reset();
387}

◆ setOutput()

void EtbController::setOutput ( expected< percent_t outputValue)
overridevirtual

Implements ClosedLoopController< percent_t, percent_t >.

Definition at line 551 of file electronic_throttle.cpp.

551 {
552#if EFI_TUNER_STUDIO
553 // Only report first-throttle stats
554 if (m_function == DC_Throttle1) {
555 engine->outputChannels.etb1DutyCycle = outputValue.value_or(0);
556 }
557#endif
558
559 if (!m_motor) {
560 state = (uint8_t)EtbState::NoMotor;
561 return;
562 }
563
564 bool isEnabled;
565 if (!isEtbMode()) {
566 // technical debt: non-ETB usages of DC motor are still mixed into ETB controller?
567 state = (uint8_t)EtbState::NotEbt;
568 isEnabled = true;
569 } else if (!getLimpManager()->allowElectronicThrottle()) {
571 isEnabled = false;
573 state = (uint8_t)EtbState::Paused;
574 isEnabled = false;
575 } else if (!outputValue) {
576 state = (uint8_t)EtbState::NoOutput;
577 isEnabled = false;
578 } else {
579 state = (uint8_t)EtbState::Active;
580 isEnabled = true;
581 }
582
583 // If not ETB, or ETB is allowed, output is valid, and we aren't paused, output to motor.
584 if (isEnabled) {
585 m_motor->enable();
586 m_motor->set(ETB_PERCENT_TO_DUTY(outputValue.Value));
587 } else {
588 // Otherwise disable the motor.
589 m_motor->disable("no-ETB");
590 }
591}
virtual bool set(float duty)=0
Sets the motor duty cycle.
virtual void enable()=0
virtual void disable(const char *msg)=0
bool allowElectronicThrottle() const
@ LimpProhibited
scaled_channel< int16_t, 100, 1 > etb1DutyCycle
Here is the call graph for this function:

◆ setWastegatePosition()

void EtbController::setWastegatePosition ( percent_t  pos)
overridevirtual

Implements IEtbController.

Definition at line 258 of file electronic_throttle.cpp.

258 {
260}

◆ showStatus()

void EtbController::showStatus ( )

Definition at line 244 of file electronic_throttle.cpp.

244 {
245 m_pid.showPidStatus("ETB");
246}
void showPidStatus(const char *msg) const
Definition efi_pid.cpp:160
Here is the call graph for this function:

◆ update()

void EtbController::update ( )
overridevirtual

Implements IEtbController.

Definition at line 665 of file electronic_throttle.cpp.

665 {
666#if !EFI_UNIT_TEST
667 // If we didn't get initialized, fail fast
668 if (!m_motor) {
669 state = (uint8_t)EtbState::FailFast;
670 return;
671 }
672#endif // EFI_UNIT_TEST
673
674 bool isOk = checkStatus();
675
676 if (!isOk) {
677 // If engine is stopped and so configured, skip the ETB update entirely
678 // This is quieter and pulls less power than leaving it on all the time
679 m_motor->disable("etb status");
680 return;
681 }
682
684
685 if (isEtbMode() && !validPlantPosition) {
687 }
688}
Here is the call graph for this function:

Field Documentation

◆ hadPpsError

bool EtbController::hadPpsError = false
protected

Definition at line 88 of file electronic_throttle_impl.h.

Referenced by checkStatus().

◆ hadTpsError

bool EtbController::hadTpsError = false
protected

Definition at line 87 of file electronic_throttle_impl.h.

Referenced by checkStatus().

◆ lastTickUs

efitimeus_t EtbController::lastTickUs
private

Definition at line 134 of file electronic_throttle_impl.h.

◆ m_a

float EtbController::m_a = 8
private

Definition at line 124 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ m_autotuneCounter

uint8_t EtbController::m_autotuneCounter = 0
private

Definition at line 128 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ m_autotuneCurrentParam

uint8_t EtbController::m_autotuneCurrentParam = 0
private

Definition at line 129 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ m_cycleTimer

Timer EtbController::m_cycleTimer
private

Definition at line 118 of file electronic_throttle_impl.h.

Referenced by getClosedLoop(), and getClosedLoopAutotune().

◆ m_function

dc_function_e EtbController::m_function = DC_None
private

◆ m_idlePosition

float EtbController::m_idlePosition = 0
private

◆ m_isAutotune

bool EtbController::m_isAutotune = false
private

Definition at line 114 of file electronic_throttle_impl.h.

Referenced by checkStatus(), getClosedLoop(), and getSetpointEtb().

◆ m_jamDetectTimer

Timer EtbController::m_jamDetectTimer
private

Definition at line 106 of file electronic_throttle_impl.h.

Referenced by checkJam().

◆ m_lastIsPositive

bool EtbController::m_lastIsPositive = false
private

Definition at line 117 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ m_luaAdjustmentTimer

Timer EtbController::m_luaAdjustmentTimer
private

Definition at line 132 of file electronic_throttle_impl.h.

Referenced by getLuaAdjustment(), and setLuaAdjustment().

◆ m_maxCycleTps

float EtbController::m_maxCycleTps = 0
private

Definition at line 120 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ m_minCycleTps

float EtbController::m_minCycleTps = 0
private

Definition at line 119 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ m_motor

DcMotor* EtbController::m_motor = nullptr
private

Definition at line 95 of file electronic_throttle_impl.h.

Referenced by getMotor(), init(), onConfigurationChange(), setOutput(), and update().

◆ m_pedalProvider

const ValueProvider3D* EtbController::m_pedalProvider = nullptr
private

Definition at line 109 of file electronic_throttle_impl.h.

Referenced by getSetpointEtb(), and init().

◆ m_pid

Pid EtbController::m_pid
private

◆ m_positionSensor

SensorType EtbController::m_positionSensor = SensorType::Invalid
private

Definition at line 94 of file electronic_throttle_impl.h.

Referenced by checkStatus(), init(), and observePlant().

◆ m_shouldResetPid

bool EtbController::m_shouldResetPid = false
private

Definition at line 97 of file electronic_throttle_impl.h.

Referenced by getClosedLoop(), onConfigurationChange(), and reset().

◆ m_targetErrorAccumulator

ErrorAccumulator EtbController::m_targetErrorAccumulator
private

Definition at line 99 of file electronic_throttle_impl.h.

Referenced by getClosedLoop(), and init().

◆ m_tu

float EtbController::m_tu = 0.1f
private

Definition at line 125 of file electronic_throttle_impl.h.

Referenced by getClosedLoopAutotune().

◆ prevOutput

float EtbController::prevOutput = 0

Definition at line 84 of file electronic_throttle_impl.h.


The documentation for this class was generated from the following files: