More than one aux pid #866

progress!
This commit is contained in:
rusefi 2019-07-12 08:00:07 -04:00
parent 974f80988f
commit 8dcb49bdf9
4 changed files with 20 additions and 15 deletions

View File

@ -103,7 +103,7 @@ class AlternatorController : public PeriodicTimerController {
} }
alternatorControl.setSimplePwmDutyCycle(currentAltDuty / 100); alternatorControl.setSimplePwmDutyCycle(PERCENT_TO_DUTY(currentAltDuty));
} }
}; };

View File

@ -37,8 +37,6 @@ extern fsio8_Map3D_f32t fsioTable1;
extern TunerStudioOutputChannels tsOutputChannels; extern TunerStudioOutputChannels tsOutputChannels;
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
static pid_s *auxPidS = &persistentState.persistentConfiguration.engineConfiguration.auxPid[0];
static Pid auxPid(auxPidS);
static Logging *logger; static Logging *logger;
static bool isEnabled(int index) { static bool isEnabled(int index) {
@ -55,17 +53,17 @@ static bool isEnabled(int index) {
} }
} }
static void pidReset(void) {
auxPid.reset();
}
class AuxPidController : public PeriodicTimerController { class AuxPidController : public PeriodicTimerController {
public: public:
int index = 0;
SimplePwm auxPidPwm; SimplePwm auxPidPwm;
OutputPin auxOutputPin; OutputPin auxOutputPin;
void init(int index) {
this->index = index;
pid_s *auxPidS = &persistentState.persistentConfiguration.engineConfiguration.auxPid[index];
auxPid.initPidClass(auxPidS);
}
int getPeriodMs() override { int getPeriodMs() override {
return engineConfiguration->auxPidPins[index] == GPIO_UNASSIGNED ? NO_PIN_PERIOD : GET_PERIOD_LIMITED(&engineConfiguration->auxPid[index]); return engineConfiguration->auxPidPins[index] == GPIO_UNASSIGNED ? NO_PIN_PERIOD : GET_PERIOD_LIMITED(&engineConfiguration->auxPid[index]);
@ -73,7 +71,8 @@ public:
void PeriodicTask() override { void PeriodicTask() override {
if (engine->auxParametersVersion.isOld(engine->getGlobalConfigurationVersion())) { if (engine->auxParametersVersion.isOld(engine->getGlobalConfigurationVersion())) {
pidReset(); auxPid.reset();
} }
float rpm = GET_RPM_VALUE; float rpm = GET_RPM_VALUE;
@ -83,7 +82,7 @@ public:
if (!enabledAtCurrentRpm) { if (!enabledAtCurrentRpm) {
// we need to avoid accumulating iTerm while engine is not running // we need to avoid accumulating iTerm while engine is not running
pidReset(); auxPid.reset();
return; return;
} }
@ -105,10 +104,11 @@ public:
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
} }
auxPidPwm.setSimplePwmDutyCycle(pwm / 100); auxPidPwm.setSimplePwmDutyCycle(PERCENT_TO_DUTY(pwm));
} }
private:
Pid auxPid;
int index = 0;
}; };
static AuxPidController instances[AUX_PID_COUNT]; static AuxPidController instances[AUX_PID_COUNT];
@ -144,9 +144,12 @@ void stopAuxPins(void) {
void initAuxPid(Logging *sharedLogger) { void initAuxPid(Logging *sharedLogger) {
logger = sharedLogger; logger = sharedLogger;
for (int i = 0;i < AUX_PID_COUNT;i++) {
instances[i].init(i);
}
startAuxPins(); startAuxPins();
for (int i = 0;i < AUX_PID_COUNT;i++) { for (int i = 0;i < AUX_PID_COUNT;i++) {
instances[i].index = i;
instances[i].Start(); instances[i].Start();
} }
} }

View File

@ -122,7 +122,7 @@ static void applyIACposition(percent_t position) {
* currently idle level is an percent value (0-100 range), and PWM takes a float in the 0..1 range * currently idle level is an percent value (0-100 range), and PWM takes a float in the 0..1 range
* todo: unify? * todo: unify?
*/ */
idleSolenoid.setSimplePwmDutyCycle(position / 100.0); idleSolenoid.setSimplePwmDutyCycle(PERCENT_TO_DUTY(position));
} }
} }

View File

@ -13,6 +13,8 @@
#include "scheduler.h" #include "scheduler.h"
#include "efi_gpio.h" #include "efi_gpio.h"
#define PERCENT_TO_DUTY(x) (x) * 0.01
#define NAN_FREQUENCY_SLEEP_PERIOD_MS 100 #define NAN_FREQUENCY_SLEEP_PERIOD_MS 100
// 99% duty cycle // 99% duty cycle