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

92 lines
2.7 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_ptr.h"
#include "rusefi_types.h"
2019-09-19 19:56:54 -07:00
#include "periodic_task.h"
#include "pid.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
Running, // On throttle
};
virtual Phase determinePhase(int rpm, int targetRpm, SensorResult tps) const = 0;
2020-12-17 14:46:51 -08:00
virtual int getTargetRpm(float clt) const = 0;
virtual float getCrankingOpenLoop(float clt) const = 0;
virtual float getRunningOpenLoop(float clt, SensorResult tps) const = 0;
virtual float getOpenLoop(Phase phase, float clt, SensorResult tps) const = 0;
2020-12-17 14:46:51 -08:00
};
class Logging;
2020-12-17 14:46:51 -08:00
class IdleController : public IIdleController {
2019-09-19 19:56:54 -07:00
public:
DECLARE_ENGINE_PTR;
2019-09-19 19:56:54 -07:00
void init(pid_s* idlePidConfig);
float getIdlePosition();
void update();
2020-12-17 14:46:51 -08:00
// TARGET DETERMINATION
int getTargetRpm(float clt) const override;
// PHASE DETERMINATION: what is the driver trying to do right now?
Phase determinePhase(int rpm, int targetRpm, SensorResult tps) const override;
// OPEN LOOP CORRECTIONS
float getCrankingOpenLoop(float clt) const override;
float getRunningOpenLoop(float clt, SensorResult tps) const override;
float getOpenLoop(Phase phase, float clt, SensorResult tps) const override;
float getIdleTimingAdjustment(int rpm);
float getIdleTimingAdjustment(int rpm, int targetRpm, Phase phase);
// Allow querying state from outside
bool isIdling() {
return m_lastPhase == Phase::Idling;
}
private:
// These are stored by getIdlePosition() and used by getIdleTimingAdjustment()
Phase m_lastPhase = Phase::Cranking;
int m_lastTargetRpm = 0;
Pid m_timingPid;
2019-09-19 19:56:54 -07:00
};
2015-07-10 06:01:56 -07:00
void updateIdleControl();
percent_t getIdlePosition();
float getIdleTimingAdjustment(int rpm);
bool isIdling();
void applyIACposition(percent_t position DECLARE_ENGINE_PARAMETER_SUFFIX);
void setManualIdleValvePosition(int positionPercent);
void startIdleThread(Logging* sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
2019-08-29 20:50:20 -07:00
void setDefaultIdleParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
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);
void setIdleMode(idle_mode_e value DECLARE_ENGINE_PARAMETER_SUFFIX);
2017-01-06 14:01:28 -08:00
void setTargetIdleRpm(int value);
2017-05-28 10:44:26 -07:00
void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration);
float getIdlePidOffset(DECLARE_ENGINE_PARAMETER_SIGNATURE);
Pid * getIdlePid(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getIdlePidMinValue(DECLARE_ENGINE_PARAMETER_SIGNATURE);