auto-sync

This commit is contained in:
rusEfi 2014-12-31 23:04:10 -06:00
parent 98582a4344
commit 00ae33a668
5 changed files with 24 additions and 11 deletions

View File

@ -38,7 +38,7 @@ void setIdleRpm(IdleValveState *idle, int targetRpm) {
/**
* @brief sets new idle valve duty cycle: checks the bounds and reports new value
*/
static int setNewValue(IdleValveState *idle, int currentRpm, int now, const char * msg, int newValue) {
static int setNewValue(IdleValveState *idle, int currentRpm, efitimems_t now, const char * msg, int newValue) {
newValue = maxI(newValue, MIN_IDLE);
newValue = minI(newValue, MAX_IDLE);
@ -62,9 +62,9 @@ static int changeValue(IdleValveState *idle, int currentRpm, int now, const char
}
/**
* now - current time in seconds
* now - current time in milliseconds
*/
int getIdle(IdleValveState *idle, int currentRpm, int now DECLARE_ENGINE_PARAMETER_S) {
int getIdle(IdleValveState *idle, int currentRpm, efitimems_t now DECLARE_ENGINE_PARAMETER_S) {
if (currentRpm == 0 || isCranking()) {
return setNewValue(idle, currentRpm, now, "cranking value: ", DEFAULT_IDLE_DUTY);
}

View File

@ -13,7 +13,7 @@
// 600‰ duty cycle by default
#define DEFAULT_IDLE_DUTY 600
#define IDLE_PERIOD 1
#define IDLE_PERIOD 1000
// Per mil (1/1000) values
#define MIN_IDLE 100
@ -28,11 +28,11 @@ public:
int targetRpmRangeLeft, targetRpmRangeRight;
int value;
int timeOfLastIdleChange;
efitimems_t timeOfLastIdleChange;
};
void idleInit(IdleValveState *idle DECLARE_ENGINE_PARAMETER_S);
int getIdle(IdleValveState *idle, int currentRpm, int time DECLARE_ENGINE_PARAMETER_S);
int getIdle(IdleValveState *idle, int currentRpm, efitimems_t now DECLARE_ENGINE_PARAMETER_S);
void setIdleRpm(IdleValveState *idle, int targetRpm);
void idleDebug(const char *msg, int value);

View File

@ -67,7 +67,7 @@ static void showIdleInfo(void) {
hwPortname(boardConfiguration->idleValvePin));
}
static void setIdleControlEnabled(int value, Engine *engine) {
static void setIdleControlEnabled(int value) {
engineConfiguration->idleMode = value ? IM_AUTO : IM_MANUAL;
showIdleInfo();
}
@ -102,9 +102,9 @@ static msg_t ivThread(int param) {
if (engineConfiguration->idleMode != IM_AUTO)
continue;
int nowSec = getTimeNowSeconds();
efitimems_t now = currentTimeMillis();
int newValue = getIdle(&idle, getRpm(), nowSec PASS_ENGINE_PARAMETER);
int newValue = getIdle(&idle, getRpm(), now PASS_ENGINE_PARAMETER);
if (currentIdleValve != newValue) {
currentIdleValve = newValue;
@ -152,7 +152,7 @@ void startIdleThread(Engine *engine) {
addConsoleAction("idleinfo", showIdleInfo);
addConsoleActionI("set_idle_rpm", setIdleRpmAction);
addConsoleActionI("set_idle_pwm", setIdleValvePwm);
addConsoleActionIP("set_idle_enabled", (VoidIntVoidPtr) setIdleControlEnabled, engine);
addConsoleActionI("set_idle_enabled", (VoidInt) setIdleControlEnabled);
}
#endif

View File

@ -41,3 +41,15 @@ float Pid::getValue(float target, float input, float dTime) {
return result;
}
void Pid::updateFactors(float pFactor, float iFactor, float dFactor) {
this->pFactor = pFactor;
this->iFactor = iFactor;
this->dFactor = dFactor;
reset();
}
void Pid::reset(void) {
integration = 0;
prevError = 0;
}

View File

@ -13,7 +13,8 @@ class Pid {
public:
Pid(float pFactor, float iFactor, float dFactor, float minResult, float maxResult);
float getValue(float target, float input, float dTime);
void updateFactors(float pFactor, float iFactor, float dFactor);
void reset(void);
private:
float pFactor;
float iFactor;