fome-fw/firmware/controllers/algo/aux_pid.cpp

64 lines
1.4 KiB
C++
Raw Normal View History

2016-06-26 10:02:23 -07:00
/*
* @file aux_pid.cpp
*
* @date Jun 26, 2016
* @author Andrey Belomutskiy, (c) 2012-2016
*/
#include "aux_pid.h"
2016-06-30 19:02:49 -07:00
#include "LocalVersionHolder.h"
2016-06-26 10:02:23 -07:00
2016-06-27 19:02:41 -07:00
#if EFI_AUX_PID || defined(__DOXYGEN__)
2016-06-30 19:02:49 -07:00
#include "pwm_generator.h"
2016-06-27 19:02:41 -07:00
EXTERN_ENGINE
;
// todo: this is to some extent a copy-paste of alternatorController. maybe same loop
// for all PIDs?
static THD_WORKING_AREA(auxPidThreadStack, UTILITY_THREAD_STACK_SIZE);
2016-06-30 19:02:49 -07:00
static LocalVersionHolder parametersVersion;
static SimplePwm auxPid1;
static OutputPin auxPid1Pin;
static pid_s *altPidS = &persistentState.persistentConfiguration.engineConfiguration.alternatorControl;
static Pid altPid(altPidS, 1, 90);
2016-06-27 19:02:41 -07:00
static msg_t auxPidThread(int param) {
UNUSED(param);
chRegSetThreadName("AuxPidController");
while (true) {
int dt = maxI(10, engineConfiguration->auxPid1DT);
chThdSleepMilliseconds(dt);
2016-06-30 19:02:49 -07:00
if (parametersVersion.isOld())
altPid.reset();
2016-06-27 19:02:41 -07:00
}
#if defined __GNUC__
return -1;
#endif
}
2016-06-26 10:02:23 -07:00
void initAuxPid(Logging *sharedLogger) {
2016-06-27 19:02:41 -07:00
chThdCreateStatic(auxPidThreadStack, sizeof(auxPidThreadStack), LOWPRIO,
(tfunc_t) auxPidThread, NULL);
2016-06-26 10:02:23 -07:00
2016-06-30 19:02:49 -07:00
if (engineConfiguration->activateAuxPid1) {
return;
}
if (boardConfiguration->fsioPins[0] == GPIO_UNASSIGNED) {
return;
}
startSimplePwmExt(&auxPid1, "Aux PID", boardConfiguration->fsioPins[0],
&auxPid1Pin,
boardConfiguration->fsioFrequency[0], 0.1, applyPinState);
2016-06-26 10:02:23 -07:00
}
2016-06-27 19:02:41 -07:00
#endif