2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file idle_thread.h
|
|
|
|
* @brief Idle Valve Control thread
|
|
|
|
*
|
|
|
|
* @date May 23, 2013
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2019-10-18 16:45:32 -07:00
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-17 09:13:19 -08:00
|
|
|
#include "engine_module.h"
|
2020-11-11 16:06:04 -08:00
|
|
|
#include "rusefi_types.h"
|
2019-09-19 19:56:54 -07:00
|
|
|
#include "periodic_task.h"
|
2021-01-07 05:06:36 -08:00
|
|
|
#include "pid.h"
|
2019-09-19 19:56:54 -07:00
|
|
|
|
2020-12-17 14:46:51 -08:00
|
|
|
struct IIdleController {
|
2020-12-26 05:32:01 -08:00
|
|
|
enum class Phase : uint8_t {
|
|
|
|
Cranking, // Below cranking threshold
|
|
|
|
Idling, // Below idle RPM, off throttle
|
|
|
|
Coasting, // Off throttle but above idle RPM
|
2021-10-06 09:05:20 -07:00
|
|
|
CrankToIdleTaper, // Taper between cranking and idling
|
2020-12-26 05:32:01 -08:00
|
|
|
Running, // On throttle
|
|
|
|
};
|
|
|
|
|
2021-07-06 05:47:06 -07:00
|
|
|
virtual Phase determinePhase(int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction) const = 0;
|
2020-12-17 14:46:51 -08:00
|
|
|
virtual int getTargetRpm(float clt) const = 0;
|
2020-12-26 16:34:42 -08:00
|
|
|
virtual float getCrankingOpenLoop(float clt) const = 0;
|
|
|
|
virtual float getRunningOpenLoop(float clt, SensorResult tps) const = 0;
|
2021-11-23 12:52:43 -08:00
|
|
|
virtual float getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) = 0;
|
2021-05-31 14:43:58 -07:00
|
|
|
virtual float getClosedLoop(Phase phase, float tps, int rpm, int target) = 0;
|
2021-07-06 05:47:06 -07:00
|
|
|
virtual float getCrankingTaperFraction() const = 0;
|
2020-12-17 14:46:51 -08:00
|
|
|
};
|
|
|
|
|
2021-11-17 09:13:19 -08:00
|
|
|
class IdleController : public IIdleController, public EngineModule {
|
2019-09-19 19:56:54 -07:00
|
|
|
public:
|
2021-11-17 09:13:19 -08:00
|
|
|
typedef IIdleController interface_t;
|
|
|
|
|
2021-01-07 05:06:36 -08:00
|
|
|
void init(pid_s* idlePidConfig);
|
|
|
|
|
2020-11-11 18:47:19 -08:00
|
|
|
float getIdlePosition();
|
2020-12-17 14:46:51 -08:00
|
|
|
|
|
|
|
// TARGET DETERMINATION
|
|
|
|
int getTargetRpm(float clt) const override;
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// PHASE DETERMINATION: what is the driver trying to do right now?
|
2021-07-06 05:47:06 -07:00
|
|
|
Phase determinePhase(int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction) const override;
|
|
|
|
float getCrankingTaperFraction() const override;
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
// OPEN LOOP CORRECTIONS
|
|
|
|
float getCrankingOpenLoop(float clt) const override;
|
|
|
|
float getRunningOpenLoop(float clt, SensorResult tps) const override;
|
2021-11-23 12:52:43 -08:00
|
|
|
float getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) override;
|
2021-01-07 05:06:36 -08:00
|
|
|
|
|
|
|
float getIdleTimingAdjustment(int rpm);
|
|
|
|
float getIdleTimingAdjustment(int rpm, int targetRpm, Phase phase);
|
|
|
|
|
2021-05-31 03:18:15 -07:00
|
|
|
// CLOSED LOOP CORRECTION
|
2021-05-31 14:43:58 -07:00
|
|
|
float getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm) override;
|
2021-05-31 03:18:15 -07:00
|
|
|
|
2021-11-17 09:13:19 -08:00
|
|
|
void onConfigurationChange(engine_configuration_s const * previousConfig) final;
|
|
|
|
void onSlowCallback() final;
|
|
|
|
|
2021-01-10 21:54:37 -08:00
|
|
|
// Allow querying state from outside
|
2021-10-06 09:05:20 -07:00
|
|
|
bool isIdlingOrTaper() {
|
2021-11-17 00:54:21 -08:00
|
|
|
return m_lastPhase == Phase::Idling || (engineConfiguration->useSeparateIdleTablesForCrankingTaper && m_lastPhase == Phase::CrankToIdleTaper);
|
2021-01-10 21:54:37 -08:00
|
|
|
}
|
|
|
|
|
2021-01-07 05:06:36 -08:00
|
|
|
private:
|
|
|
|
// These are stored by getIdlePosition() and used by getIdleTimingAdjustment()
|
|
|
|
Phase m_lastPhase = Phase::Cranking;
|
|
|
|
int m_lastTargetRpm = 0;
|
|
|
|
|
2021-06-12 11:21:11 -07:00
|
|
|
// This is stored by getClosedLoop and used in case we want to "do nothing"
|
|
|
|
float m_lastAutomaticPosition = 0;
|
|
|
|
|
2021-01-07 05:06:36 -08:00
|
|
|
Pid m_timingPid;
|
2019-09-19 19:56:54 -07:00
|
|
|
};
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-11-11 18:47:19 -08:00
|
|
|
percent_t getIdlePosition();
|
2020-07-26 09:03:36 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void applyIACposition(percent_t position);
|
2020-07-26 09:03:36 -07:00
|
|
|
void setManualIdleValvePosition(int positionPercent);
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void startIdleThread();
|
|
|
|
void setDefaultIdleParameters();
|
2016-12-26 18:04:16 -08:00
|
|
|
void startIdleBench(void);
|
2017-05-22 20:25:34 -07:00
|
|
|
void setIdleOffset(float value);
|
2017-01-06 13:03:41 -08:00
|
|
|
void setIdlePFactor(float value);
|
|
|
|
void setIdleIFactor(float value);
|
|
|
|
void setIdleDFactor(float value);
|
2021-11-16 01:15:29 -08:00
|
|
|
void setIdleMode(idle_mode_e value);
|
2017-01-06 14:01:28 -08:00
|
|
|
void setTargetIdleRpm(int value);
|
2021-11-16 01:15:29 -08:00
|
|
|
Pid * getIdlePid();
|
|
|
|
void startPedalPins();
|
|
|
|
void stopPedalPins();
|