fome-fw/firmware/controllers/actuators/idle_thread.h

105 lines
3.3 KiB
C
Raw Normal View History

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
#include "engine_module.h"
#include "rusefi_types.h"
2019-09-19 19:56:54 -07:00
#include "periodic_task.h"
#include "efi_pid.h"
#include "sensor.h"
#include "idle_state_generated.h"
2019-09-19 19:56:54 -07:00
2020-12-17 14:46:51 -08:00
struct IIdleController {
enum class Phase : uint8_t {
Cranking, // Below cranking threshold
Idling, // Below idle RPM, off throttle
Coasting, // Off throttle but above idle RPM
CrankToIdleTaper, // Taper between cranking and idling
Running, // On throttle
};
virtual Phase determinePhase(int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction) = 0;
virtual int getTargetRpm(float clt) = 0;
virtual float getCrankingOpenLoop(float clt) const = 0;
virtual float getRunningOpenLoop(float rpm, float clt, SensorResult tps) = 0;
virtual float getOpenLoop(Phase phase, float rpm, 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;
virtual float getCrankingTaperFraction(float clt) const = 0;
virtual bool isIdlingOrTaper() const = 0;
virtual float getIdleTimingAdjustment(int rpm) = 0;
2020-12-17 14:46:51 -08:00
};
class IdleController : public IIdleController, public EngineModule, public idle_state_s {
2019-09-19 19:56:54 -07:00
public:
2023-05-11 14:37:48 -07:00
// Mockable<> interface
using interface_t = IIdleController;
void init();
float getIdlePosition(float rpm);
2020-12-17 14:46:51 -08:00
// TARGET DETERMINATION
int getTargetRpm(float clt) override;
// PHASE DETERMINATION: what is the driver trying to do right now?
Phase determinePhase(int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction) override;
float getCrankingTaperFraction(float clt) const override;
// OPEN LOOP CORRECTIONS
percent_t getCrankingOpenLoop(float clt) const override;
percent_t getRunningOpenLoop(float rpm, float clt, SensorResult tps) override;
percent_t getOpenLoop(Phase phase, float rpm, float clt, SensorResult tps, float crankingTaperFraction) override;
float getIdleTimingAdjustment(int rpm) override;
float getIdleTimingAdjustment(int rpm, int targetRpm, Phase phase);
// CLOSED LOOP CORRECTION
2021-05-31 14:43:58 -07:00
float getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm) override;
void onConfigurationChange(engine_configuration_s const * previousConfig) final;
void onSlowCallback() final;
// Allow querying state from outside
bool isIdlingOrTaper() const override {
return m_lastPhase == Phase::Idling || (engineConfiguration->useSeparateIdleTablesForCrankingTaper && m_lastPhase == Phase::CrankToIdleTaper);
}
PidIndustrial industrialWithOverrideIdlePid;
Pid * getIdlePid() {
return &industrialWithOverrideIdlePid;
}
private:
// These are stored by getIdlePosition() and used by getIdleTimingAdjustment()
Phase m_lastPhase = Phase::Cranking;
int m_lastTargetRpm = 0;
efitimeus_t restoreAfterPidResetTimeUs = 0;
// This is stored by getClosedLoop and used in case we want to "do nothing"
float m_lastAutomaticPosition = 0;
Pid m_timingPid;
2019-09-19 19:56:54 -07:00
};
2015-07-10 06:01:56 -07:00
percent_t getIdlePosition();
void applyIACposition(percent_t position);
void setManualIdleValvePosition(int positionPercent);
void startIdleThread();
void setDefaultIdleParameters();
2016-12-26 18:04:16 -08:00
void startIdleBench(void);
void setIdleMode(idle_mode_e value);
2017-01-06 14:01:28 -08:00
void setTargetIdleRpm(int value);
void startPedalPins();
void stopPedalPins();