only:variable shadowing should be avoided #5676

This commit is contained in:
rusefillc 2023-11-01 13:02:20 -04:00
parent 629ed53f6f
commit e384914c95
10 changed files with 131 additions and 131 deletions

View File

@ -487,9 +487,9 @@ static void updateRawSensors() {
engine->outputChannels.luaGauges[1] = Sensor::getOrZero(SensorType::LuaGauge2);
for (int i = 0; i < LUA_ANALOG_INPUT_COUNT; i++) {
adc_channel_e ch = engineConfiguration->auxAnalogInputs[i];
if (isAdcChannelValid(ch)) {
engine->outputChannels.rawAnalogInput[i] = getVoltageDivided("raw aux", ch);
adc_channel_e channel = engineConfiguration->auxAnalogInputs[i];
if (isAdcChannelValid(channel)) {
engine->outputChannels.rawAnalogInput[i] = getVoltageDivided("raw aux", channel);
}
}

View File

@ -109,12 +109,12 @@ float GppwmChannel::setOutput(float result) {
}
}
void GppwmChannel::init(bool usePwm, IPwm* pwm, OutputPin* outputPin, const ValueProvider3D* table, const gppwm_channel* config) {
void GppwmChannel::init(bool usePwm, IPwm* pwm, OutputPin* outputPin, const ValueProvider3D* table, const gppwm_channel* p_config) {
m_usePwm = usePwm;
m_pwm = pwm;
m_output = outputPin;
m_table = table;
m_config = config;
m_config = p_config;
}
GppwmResult GppwmChannel::getOutput() const {

View File

@ -18,10 +18,10 @@ using vvt_map_t = Map3D<SCRIPT_TABLE_8, SCRIPT_TABLE_8, int8_t, uint16_t, uint16
static vvt_map_t vvtTable1;
static vvt_map_t vvtTable2;
VvtController::VvtController(int index)
: index(index)
, m_bank(BANK_BY_INDEX(index))
, m_cam(CAM_BY_INDEX(index))
VvtController::VvtController(int p_index)
: index(p_index)
, m_bank(BANK_BY_INDEX(p_index))
, m_cam(CAM_BY_INDEX(p_index))
{
}

View File

@ -137,23 +137,23 @@ static void runBench(OutputPin *output, float onTimeMs, float offTimeMs, int cou
// todo: migrate to smarter getOutputOnTheBenchTest() approach?
static volatile bool isBenchTestPending = false;
static bool widebandUpdatePending = false;
static float onTimeMs;
static float offTimeMs;
static int count;
static float globalOnTimeMs;
static float globalOffTimeMs;
static int globalCount;
static OutputPin* pinX;
static bool swapOnOff = false;
static chibios_rt::CounterSemaphore benchSemaphore(0);
static void pinbench(float p_ontimeMs, float p_offtimeMs, int iterations,
static void pinbench(float ontimeMs, float offtimeMs, int iterations,
OutputPin* pinParam, bool p_swapOnOff = false)
{
onTimeMs = p_ontimeMs;
offTimeMs = p_offtimeMs;
globalOnTimeMs = ontimeMs;
globalOffTimeMs = offtimeMs;
#if EFI_SIMULATOR
count = maxI(2, iterations);
globalCount = maxI(2, iterations);
#else
count = iterations;
globalCount = iterations;
#endif // EFI_SIMULATOR
pinX = pinParam;
swapOnOff = p_swapOnOff;
@ -313,7 +313,7 @@ private:
if (isBenchTestPending) {
isBenchTestPending = false;
runBench(pinX, onTimeMs, offTimeMs, count, swapOnOff);
runBench(pinX, globalOnTimeMs, globalOffTimeMs, globalCount, swapOnOff);
}
if (widebandUpdatePending) {

View File

@ -630,14 +630,14 @@ int lua_canRxAddMask(lua_State* l) {
}
#endif // EFI_CAN_SUPPORT
void configureRusefiLuaHooks(lua_State* l) {
LuaClass<Timer> luaTimer(l, "Timer");
void configureRusefiLuaHooks(lua_State* lState) {
LuaClass<Timer> luaTimer(lState, "Timer");
luaTimer
.ctor()
.fun("reset", static_cast<void (Timer::*)() >(&Timer::reset ))
.fun("getElapsedSeconds", static_cast<float(Timer::*)()const>(&Timer::getElapsedSeconds));
LuaClass<LuaSensor> luaSensor(l, "Sensor");
LuaClass<LuaSensor> luaSensor(lState, "Sensor");
luaSensor
.ctor<lua_State*, const char*>()
.fun("set", &LuaSensor::set)
@ -645,23 +645,23 @@ void configureRusefiLuaHooks(lua_State* l) {
.fun("setTimeout", &LuaSensor::setTimeout)
.fun("invalidate", &LuaSensor::invalidate);
LuaClass<LuaPid> luaPid(l, "Pid");
LuaClass<LuaPid> luaPid(lState, "Pid");
luaPid
.ctor<float, float, float, float, float>()
.fun("get", &LuaPid::get)
.fun("setOffset", &LuaPid::setOffset)
.fun("reset", &LuaPid::reset);
configureRusefiLuaUtilHooks(l);
configureRusefiLuaUtilHooks(lState);
lua_register(l, "readPin", lua_readpin);
lua_register(l, "vin", lua_vin);
lua_register(l, "getAuxAnalog", lua_getAuxAnalog);
lua_register(l, "getSensorByIndex", lua_getSensorByIndex);
lua_register(l, "getSensor", lua_getSensorByName);
lua_register(l, "getSensorRaw", lua_getSensorRaw);
lua_register(l, "hasSensor", lua_hasSensor);
lua_register(l, "table3d", [](lua_State* l) {
lua_register(lState, "readPin", lua_readpin);
lua_register(lState, "vin", lua_vin);
lua_register(lState, "getAuxAnalog", lua_getAuxAnalog);
lua_register(lState, "getSensorByIndex", lua_getSensorByIndex);
lua_register(lState, "getSensor", lua_getSensorByName);
lua_register(lState, "getSensorRaw", lua_getSensorRaw);
lua_register(lState, "hasSensor", lua_hasSensor);
lua_register(lState, "table3d", [](lua_State* l) {
auto humanTableIdx = luaL_checkinteger(l, 1);
auto x = luaL_checknumber(l, 2);
auto y = luaL_checknumber(l, 3);
@ -673,12 +673,12 @@ void configureRusefiLuaHooks(lua_State* l) {
return 1;
});
lua_register(l, "secondsSinceTsActivity", [](lua_State* l) {
lua_register(lState, "secondsSinceTsActivity", [](lua_State* l) {
lua_pushnumber(l, getSecondsSinceChannelsRequest());
return 1;
});
lua_register(l, "curve", [](lua_State* l) {
lua_register(lState, "curve", [](lua_State* l) {
// index starting from 1
auto humanCurveIdx = luaL_checkinteger(l, 1);
auto x = luaL_checknumber(l, 2);
@ -690,7 +690,7 @@ void configureRusefiLuaHooks(lua_State* l) {
});
#if EFI_SENT_SUPPORT
lua_register(l, "getSentValue",
lua_register(lState, "getSentValue",
[](lua_State* l) {
auto humanIndex = luaL_checkinteger(l, 1);
auto value = getSentValue(humanIndex - 1);
@ -698,7 +698,7 @@ void configureRusefiLuaHooks(lua_State* l) {
return 1;
});
lua_register(l, "getSentValues",
lua_register(lState, "getSentValues",
[](lua_State* l) {
uint16_t sig0;
uint16_t sig1;
@ -711,12 +711,12 @@ void configureRusefiLuaHooks(lua_State* l) {
#endif // EFI_SENT_SUPPORT
#if EFI_LAUNCH_CONTROL
lua_register(l, "setSparkSkipRatio", [](lua_State* l) {
lua_register(lState, "setSparkSkipRatio", [](lua_State* l) {
auto targetSkipRatio = luaL_checknumber(l, 1);
engine->softSparkLimiter.setTargetSkipRatio(targetSkipRatio);
return 1;
});
lua_register(l, "setSparkHardSkipRatio", [](lua_State* l) {
lua_register(lState, "setSparkHardSkipRatio", [](lua_State* l) {
auto targetSkipRatio = luaL_checknumber(l, 1);
engine->hardSparkLimiter.setTargetSkipRatio(targetSkipRatio);
return 1;
@ -724,7 +724,7 @@ void configureRusefiLuaHooks(lua_State* l) {
#endif // EFI_LAUNCH_CONTROL
#if EFI_EMULATE_POSITION_SENSORS && !EFI_UNIT_TEST
lua_register(l, "selfStimulateRPM", [](lua_State* l) {
lua_register(lState, "selfStimulateRPM", [](lua_State* l) {
auto rpm = luaL_checkinteger(l, 1);
if (rpm < 1) {
disableTriggerStimulator();
@ -741,7 +741,7 @@ void configureRusefiLuaHooks(lua_State* l) {
/**
* same exact could be accomplished via LuaSensor just with more API
*/
lua_register(l, "setLuaGauge", [](lua_State* l) {
lua_register(lState, "setLuaGauge", [](lua_State* l) {
auto index = luaL_checkinteger(l, 1) - 1;
auto value = luaL_checknumber(l, 2);
if (index < 0 || index >= LUA_GAUGE_COUNT)
@ -751,13 +751,13 @@ void configureRusefiLuaHooks(lua_State* l) {
return 0;
});
lua_register(l, "enableCanTx", [](lua_State* l) {
lua_register(lState, "enableCanTx", [](lua_State* l) {
engine->allowCanTx = lua_toboolean(l, 1);
return 0;
});
#if EFI_PROD_CODE
lua_register(l, "restartEtb", [](lua_State* l) {
lua_register(lState, "restartEtb", [](lua_State* l) {
// this is about Lua sensor acting in place of real analog PPS sensor
// todo: smarter implementation
doInitElectronicThrottle();
@ -766,7 +766,7 @@ void configureRusefiLuaHooks(lua_State* l) {
#endif // EFI_PROD_CODE
// checksum stuff
lua_register(l, "crc8_j1850", [](lua_State* l) {
lua_register(lState, "crc8_j1850", [](lua_State* l) {
uint8_t data[8];
uint32_t length = getArray(l, 1, data, sizeof(data));
auto trimLength = luaL_checkinteger(l, 2);
@ -777,75 +777,75 @@ void configureRusefiLuaHooks(lua_State* l) {
});
#if EFI_BOOST_CONTROL
lua_register(l, "setBoostTargetAdd", [](lua_State* l) {
lua_register(lState, "setBoostTargetAdd", [](lua_State* l) {
engine->module<BoostController>().unmock().luaTargetAdd = luaL_checknumber(l, 1);
return 0;
});
lua_register(l, "setBoostTargetMult", [](lua_State* l) {
lua_register(lState, "setBoostTargetMult", [](lua_State* l) {
engine->module<BoostController>().unmock().luaTargetMult = luaL_checknumber(l, 1);
return 0;
});
lua_register(l, "setBoostDutyAdd", [](lua_State* l) {
lua_register(lState, "setBoostDutyAdd", [](lua_State* l) {
engine->module<BoostController>().unmock().luaOpenLoopAdd = luaL_checknumber(l, 1);
return 0;
});
#endif // EFI_BOOST_CONTROL
#if EFI_IDLE_CONTROL
lua_register(l, "setIdleAdd", [](lua_State* l) {
lua_register(lState, "setIdleAdd", [](lua_State* l) {
engine->module<IdleController>().unmock().luaAdd = luaL_checknumber(l, 1);
return 0;
});
#endif
lua_register(l, "setTimingAdd", [](lua_State* l) {
lua_register(lState, "setTimingAdd", [](lua_State* l) {
engine->ignitionState.luaTimingAdd = luaL_checknumber(l, 1);
return 0;
});
lua_register(l, "setTimingMult", [](lua_State* l) {
lua_register(lState, "setTimingMult", [](lua_State* l) {
engine->ignitionState.luaTimingMult = luaL_checknumber(l, 1);
return 0;
});
lua_register(l, "setFuelAdd", [](lua_State* l) {
lua_register(lState, "setFuelAdd", [](lua_State* l) {
engine->engineState.lua.fuelAdd = luaL_checknumber(l, 1);
return 0;
});
lua_register(l, "setFuelMult", [](lua_State* l) {
lua_register(lState, "setFuelMult", [](lua_State* l) {
engine->engineState.lua.fuelMult = luaL_checknumber(l, 1);
return 0;
});
#if EFI_PROD_CODE
lua_register(l, "setEtbAdd", [](lua_State* l) {
lua_register(lState, "setEtbAdd", [](lua_State* l) {
auto luaAdjustment = luaL_checknumber(l, 1);
setEtbLuaAdjustment(luaAdjustment);
return 0;
});
lua_register(l, "setEtbDisabled", [](lua_State* l) {
lua_register(lState, "setEtbDisabled", [](lua_State* l) {
engine->engineState.lua.luaDisableEtb = lua_toboolean(l, 1);
return 0;
});
lua_register(l, "setIgnDisabled", [](lua_State* l) {
lua_register(lState, "setIgnDisabled", [](lua_State* l) {
engine->engineState.lua.luaIgnCut = lua_toboolean(l, 1);
return 0;
});
#endif // EFI_PROD_CODE
lua_register(l, "setClutchUpState", [](lua_State* l) {
lua_register(lState, "setClutchUpState", [](lua_State* l) {
engine->engineState.lua.clutchUpState = lua_toboolean(l, 1);
return 0;
});
lua_register(l, "setBrakePedalState", [](lua_State* l) {
lua_register(lState, "setBrakePedalState", [](lua_State* l) {
engine->engineState.lua.brakePedalState = lua_toboolean(l, 1);
return 0;
});
lua_register(l, "setAcRequestState", [](lua_State* l) {
lua_register(lState, "setAcRequestState", [](lua_State* l) {
engine->engineState.lua.acRequestState = lua_toboolean(l, 1);
return 0;
});
lua_register(l, "getCalibration", [](lua_State* l) {
lua_register(lState, "getCalibration", [](lua_State* l) {
auto propertyName = luaL_checklstring(l, 1, nullptr);
auto result = getConfigValueByName(propertyName);
lua_pushnumber(l, result);
@ -853,7 +853,7 @@ void configureRusefiLuaHooks(lua_State* l) {
});
#if EFI_TUNER_STUDIO && (EFI_PROD_CODE || EFI_SIMULATOR)
lua_register(l, "getOutput", [](lua_State* l) {
lua_register(lState, "getOutput", [](lua_State* l) {
auto propertyName = luaL_checklstring(l, 1, nullptr);
// fresh values need to be requested explicitly, there is no periodic invocation of that method
updateTunerStudioState();
@ -864,7 +864,7 @@ void configureRusefiLuaHooks(lua_State* l) {
#endif // EFI_PROD_CODE || EFI_SIMULATOR
#if EFI_SHAFT_POSITION_INPUT
lua_register(l, "getEngineState", [](lua_State* l) {
lua_register(lState, "getEngineState", [](lua_State* l) {
spinning_state_e state = engine->rpmCalculator.getState();
int luaStateCode;
if (state == STOPPED) {
@ -880,7 +880,7 @@ void configureRusefiLuaHooks(lua_State* l) {
});
#endif //EFI_SHAFT_POSITION_INPUT
lua_register(l, "setCalibration", [](lua_State* l) {
lua_register(lState, "setCalibration", [](lua_State* l) {
auto propertyName = luaL_checklstring(l, 1, nullptr);
auto value = luaL_checknumber(l, 2);
auto incrementVersion = lua_toboolean(l, 3);
@ -896,29 +896,29 @@ void configureRusefiLuaHooks(lua_State* l) {
return 0;
});
lua_register(l, "getGlobalConfigurationVersion", [](lua_State* l) {
lua_register(lState, "getGlobalConfigurationVersion", [](lua_State* l) {
lua_pushnumber(l, engine->getGlobalConfigurationVersion());
return 1;
});
lua_register(l, "setAcDisabled", [](lua_State* l) {
lua_register(lState, "setAcDisabled", [](lua_State* l) {
auto value = lua_toboolean(l, 1);
engine->module<AcController>().unmock().isDisabledByLua = value;
return 0;
});
lua_register(l, "getTimeSinceAcToggleMs", [](lua_State* l) {
lua_register(lState, "getTimeSinceAcToggleMs", [](lua_State* l) {
int result = US2MS(getTimeNowUs()) - engine->module<AcController>().unmock().acSwitchLastChangeTimeMs;
lua_pushnumber(l, result);
return 1;
});
#if EFI_VEHICLE_SPEED
lua_register(l, "getCurrentGear", [](lua_State* l) {
lua_register(lState, "getCurrentGear", [](lua_State* l) {
lua_pushinteger(l, Sensor::getOrZero(SensorType::DetectedGear));
return 1;
});
lua_register(l, "getRpmInGear", [](lua_State* l) {
lua_register(lState, "getRpmInGear", [](lua_State* l) {
auto idx = luaL_checkinteger(l, 1);
lua_pushinteger(l, engine->module<GearDetector>()->getRpmInGear(idx));
return 1;
@ -926,23 +926,23 @@ void configureRusefiLuaHooks(lua_State* l) {
#endif // EFI_VEHICLE_SPEED
#if !EFI_UNIT_TEST
lua_register(l, "startPwm", lua_startPwm);
lua_register(l, "setPwmDuty", lua_setPwmDuty);
lua_register(l, "setPwmFreq", lua_setPwmFreq);
lua_register(lState, "startPwm", lua_startPwm);
lua_register(lState, "setPwmDuty", lua_setPwmDuty);
lua_register(lState, "setPwmFreq", lua_setPwmFreq);
lua_register(l, "getFan", lua_fan);
lua_register(l, "getDigital", lua_getDigital);
lua_register(l, "getAuxDigital", lua_getAuxDigital);
lua_register(l, "setDebug", lua_setDebug);
lua_register(l, "getAirmass", lua_getAirmass);
lua_register(l, "setAirmass", lua_setAirmass);
lua_register(lState, "getFan", lua_fan);
lua_register(lState, "getDigital", lua_getDigital);
lua_register(lState, "getAuxDigital", lua_getAuxDigital);
lua_register(lState, "setDebug", lua_setDebug);
lua_register(lState, "getAirmass", lua_getAirmass);
lua_register(lState, "setAirmass", lua_setAirmass);
lua_register(l, "stopEngine", [](lua_State*) {
lua_register(lState, "stopEngine", [](lua_State*) {
doScheduleStopEngine();
return 0;
});
#if EFI_SHAFT_POSITION_INPUT
lua_register(l, "getTimeSinceTriggerEventMs", [](lua_State* l) {
lua_register(lState, "getTimeSinceTriggerEventMs", [](lua_State* l) {
int result = engine->triggerCentral.m_lastEventTimer.getElapsedUs() / 1000;
lua_pushnumber(l, result);
return 1;
@ -950,24 +950,24 @@ void configureRusefiLuaHooks(lua_State* l) {
#endif // EFI_SHAFT_POSITION_INPUT
#if EFI_CAN_SUPPORT
lua_register(l, "canRxAdd", lua_canRxAdd);
lua_register(l, "canRxAddMask", lua_canRxAddMask);
lua_register(lState, "canRxAdd", lua_canRxAdd);
lua_register(lState, "canRxAddMask", lua_canRxAddMask);
#endif // EFI_CAN_SUPPORT
#endif // not EFI_UNIT_TEST
#if EFI_CAN_SUPPORT || EFI_UNIT_TEST
lua_register(l, "txCan", lua_txCan);
lua_register(lState, "txCan", lua_txCan);
#endif
#if EFI_VEHICLE_SPEED
lua_register(l, "resetOdometer", [](lua_State*) {
lua_register(lState, "resetOdometer", [](lua_State*) {
engine->module<TripOdometer>()->reset();
return 0;
});
#endif // EFI_VEHICLE_SPEED
#if EFI_DAC
lua_register(l, "setDacVoltage", [](lua_State* l) {
lua_register(lState, "setDacVoltage", [](lua_State* l) {
auto channel = luaL_checkinteger(l, 1);
auto voltage = luaL_checknumber(l, 2);
setDacVoltage(channel, voltage);

View File

@ -36,11 +36,11 @@ static int lua_interpolate(lua_State* l) {
}
void configureRusefiLuaUtilHooks(lua_State* l) {
lua_register(l, "print", lua_efi_print);
lua_register(l, "interpolate", lua_interpolate);
void configureRusefiLuaUtilHooks(lua_State* lState) {
lua_register(lState, "print", lua_efi_print);
lua_register(lState, "interpolate", lua_interpolate);
lua_register(l, "findCurveIndex", [](lua_State* l) {
lua_register(lState, "findCurveIndex", [](lua_State* l) {
auto name = luaL_checklstring(l, 1, nullptr);
auto result = getCurveIndexByName(name);
if (!result) {
@ -52,7 +52,7 @@ void configureRusefiLuaUtilHooks(lua_State* l) {
return 1;
});
lua_register(l, "findTableIndex",
lua_register(lState, "findTableIndex",
[](lua_State* l) {
auto name = luaL_checklstring(l, 1, nullptr);
auto index = getTableIndexByName(name);
@ -65,7 +65,7 @@ void configureRusefiLuaUtilHooks(lua_State* l) {
return 1;
});
lua_register(l, "findSetting",
lua_register(lState, "findSetting",
[](lua_State* l) {
auto name = luaL_checklstring(l, 1, nullptr);
auto defaultValue = luaL_checknumber(l, 2);
@ -81,7 +81,7 @@ void configureRusefiLuaUtilHooks(lua_State* l) {
});
#if defined(STM32F4) || defined(STM32F7)
lua_register(l, "mcu_standby", [](lua_State*) {
lua_register(lState, "mcu_standby", [](lua_State*) {
onBoardStandBy();
stm32_standby();
return 0;

View File

@ -41,7 +41,7 @@ extern int waveChartUsedSize;
extern WaveChart waveChart;
#endif // EFI_ENGINE_SNIFFER
void printSpiState(const engine_configuration_s *engineConfiguration) {
void printSpiState() {
efiPrintf("spi 1=%s/2=%s/3=%s/4=%s",
boolToString(engineConfiguration->is_enabled_spi_1),
boolToString(engineConfiguration->is_enabled_spi_2),
@ -49,7 +49,7 @@ void printSpiState(const engine_configuration_s *engineConfiguration) {
boolToString(engineConfiguration->is_enabled_spi_4));
}
static void printOutputs(const engine_configuration_s *engineConfiguration) {
static void printOutputs() {
efiPrintf("injectionPins: mode %s", getPin_output_mode_e(engineConfiguration->injectionPinMode));
for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
brain_pin_e brainPin = engineConfiguration->injectionPins[i];
@ -87,7 +87,7 @@ static void printOutputs(const engine_configuration_s *engineConfiguration) {
/**
* @brief Prints current engine configuration to human-readable console.
*/
void printConfiguration(const engine_configuration_s *engineConfiguration) {
void printConfiguration() {
efiPrintf("Template %s/%d trigger %s/%s/%d", getEngine_type_e(engineConfiguration->engineType),
engineConfiguration->engineType, getTrigger_type_e(engineConfiguration->trigger.type),
@ -120,7 +120,7 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) {
efiPrintf("injection %s enabled=%s", getInjection_mode_e(engineConfiguration->injectionMode),
boolToString(engineConfiguration->isInjectionEnabled));
printOutputs(engineConfiguration);
printOutputs();
efiPrintf("map_avg=%s/wa=%s",
boolToString(engineConfiguration->isMapAveragingEnabled),
@ -143,12 +143,12 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) {
}
#if EFI_PROD_CODE
printSpiState(engineConfiguration);
printSpiState();
#endif // EFI_PROD_CODE
}
static void doPrintConfiguration() {
printConfiguration(engineConfiguration);
printConfiguration();
}
static void setFixedModeTiming(int value) {
@ -566,7 +566,7 @@ static void setSpiMode(int index, bool mode) {
efiPrintf("invalid spi index %d", index);
return;
}
printSpiState(engineConfiguration);
printSpiState();
}
bool verboseRxCan = false;

View File

@ -11,8 +11,8 @@
#include "engine_configuration_generated_structures.h"
void initSettings();
void printSpiState(const engine_configuration_s *engineConfiguration);
void printConfiguration(const engine_configuration_s *engineConfiguration);
void printSpiState();
void printConfiguration();
void scheduleStopEngine();
void printTPSInfo(void);

View File

@ -31,7 +31,7 @@ static SPIConfig spiConfig[EGT_CHANNEL_COUNT];
static void showEgtInfo() {
#if EFI_PROD_CODE
printSpiState(engineConfiguration);
printSpiState();
efiPrintf("EGT spi: %d", engineConfiguration->max31855spiDevice);

View File

@ -17,43 +17,43 @@ Pid::Pid() {
initPidClass(nullptr);
}
Pid::Pid(pid_s *parameters) {
initPidClass(parameters);
Pid::Pid(pid_s *p_parameters) {
initPidClass(p_parameters);
}
void Pid::initPidClass(pid_s *parameters) {
this->parameters = parameters;
void Pid::initPidClass(pid_s *p_parameters) {
parameters = p_parameters;
resetCounter = 0;
Pid::reset();
}
bool Pid::isSame(const pid_s *parameters) const {
if (!this->parameters) {
bool Pid::isSame(const pid_s *p_parameters) const {
if (!parameters) {
// this 'null' could happen on first execution during initialization
return false;
}
efiAssert(ObdCode::OBD_PCM_Processor_Fault, parameters != NULL, "PID::isSame NULL", false);
return this->parameters->pFactor == parameters->pFactor
&& this->parameters->iFactor == parameters->iFactor
&& this->parameters->dFactor == parameters->dFactor
&& this->parameters->offset == parameters->offset
&& this->parameters->periodMs == parameters->periodMs;
efiAssert(ObdCode::OBD_PCM_Processor_Fault, p_parameters != NULL, "PID::isSame NULL", false);
return parameters->pFactor == p_parameters->pFactor
&& parameters->iFactor == p_parameters->iFactor
&& parameters->dFactor == p_parameters->dFactor
&& parameters->offset == p_parameters->offset
&& parameters->periodMs == p_parameters->periodMs;
}
/**
* @param Controller input / process output
* @returns Output from the PID controller / the input to the process
*/
float Pid::getOutput(float target, float input) {
float Pid::getOutput(float p_target, float p_input) {
float dTime = MS2SEC(GET_PERIOD_LIMITED(parameters));
return getOutput(target, input, dTime);
return getOutput(p_target, p_input, dTime);
}
float Pid::getUnclampedOutput(float target, float input, float dTime) {
float Pid::getUnclampedOutput(float p_target, float p_input, float dTime) {
target = p_target;
input = p_input;
float error = (target - input) * errorAmplificationCoef;
this->target = target;
this->input = input;
float pTerm = parameters->pFactor * error;
updateITerm(parameters->iFactor * dTime * error);
@ -72,15 +72,15 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) {
/**
* @param dTime seconds probably? :)
*/
float Pid::getOutput(float target, float input, float dTime) {
float output = getUnclampedOutput(target, input, dTime);
float Pid::getOutput(float p_target, float p_input, float dTime) {
float l_output = getUnclampedOutput(p_target, p_input, dTime);
if (output > parameters->maxValue) {
output = parameters->maxValue;
} else if (output < getMinValue()) {
output = getMinValue();
if (l_output > parameters->maxValue) {
l_output = parameters->maxValue;
} else if (l_output < getMinValue()) {
l_output = getMinValue();
}
this->output = output;
output = l_output;
return output;
}
@ -193,7 +193,7 @@ PidCic::PidCic() {
PidCic::reset();
}
PidCic::PidCic(pid_s *parameters) : Pid(parameters) {
PidCic::PidCic(pid_s *p_parameters) : Pid(p_parameters) {
// call our derived reset()
PidCic::reset();
}
@ -207,8 +207,8 @@ void PidCic::reset(void) {
iTermInvNum = 1.0f / (float)PID_AVG_BUF_SIZE;
}
float PidCic::getOutput(float target, float input, float dTime) {
return getUnclampedOutput(target, input, dTime);
float PidCic::getOutput(float p_target, float p_input, float dTime) {
return getUnclampedOutput(p_target, p_input, dTime);
}
void PidCic::updateITerm(float value) {
@ -234,12 +234,12 @@ void PidCic::updateITerm(float value) {
PidIndustrial::PidIndustrial() : Pid() {
}
PidIndustrial::PidIndustrial(pid_s *parameters) : Pid(parameters) {
PidIndustrial::PidIndustrial(pid_s *p_parameters) : Pid(p_parameters) {
}
float PidIndustrial::getOutput(float target, float input, float dTime) {
float PidIndustrial::getOutput(float p_target, float p_input, float dTime) {
float ad, bd;
float error = (target - input) * errorAmplificationCoef;
float error = (p_target - p_input) * errorAmplificationCoef;
float pTerm = parameters->pFactor * error;
// calculate dTerm coefficients
@ -263,12 +263,12 @@ float PidIndustrial::getOutput(float target, float input, float dTime) {
updateITerm(parameters->iFactor * dTime * error);
// calculate output and apply the limits
float output = pTerm + iTerm + dTerm + getOffset();
float limitedOutput = limitOutput(output);
float l_output = pTerm + iTerm + dTerm + getOffset();
float limitedOutput = limitOutput(l_output);
// apply the integrator anti-windup on top of the "normal" iTerm change above
// If p.antiwindupFreq = 0, then iTerm is equal to PidParallelController's
iTerm += dTime * antiwindupFreq * (limitedOutput - output);
iTerm += dTime * antiwindupFreq * (limitedOutput - l_output);
// update the state
previousError = error;