rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
alternator_controller.cpp
Go to the documentation of this file.
1/**
2 * @file alternator_controller.cpp
3 * @brief alternator controller - some newer vehicles control alternator with ECU
4 *
5 * @date Apr 6, 2014
6 * @author Dmitry Sidin
7 * @author Andrey Belomutskiy, (c) 2012-2020
8 */
9
10#include "pch.h"
11
12#if EFI_ALTERNATOR_CONTROL
14#include "efi_pid.h"
16#include "periodic_task.h"
17
18#if defined(HAS_OS_ACCESS)
19#error "Unexpected OS ACCESS HERE"
20#endif /* HAS_OS_ACCESS */
21
23
27
30 return;
31 }
32
33 // this block could be executed even in on/off alternator control mode
34 // but at least we would reflect latest state
35#if EFI_TUNER_STUDIO
37#endif /* EFI_TUNER_STUDIO */
38
39 update();
40}
41
43 const float rpm = Sensor::getOrZero(SensorType::Rpm);
44 bool alternatorShouldBeEnabledAtCurrentRpm = rpm > engineConfiguration->cranking.rpm;
45
46 if (!engineConfiguration->isAlternatorControlEnabled || !alternatorShouldBeEnabledAtCurrentRpm) {
47 return unexpected;
48 }
49
50 const float load = getEngineState()->fuelingLoad;
51 return interpolate3d(
55 );
56}
57
61
62expected<percent_t> AlternatorController::getOpenLoop(float /*target*/) {
63 // see "idle air Bump for AC" comment
65}
66
67expected<percent_t> AlternatorController::getClosedLoop(float setpoint, float observation) {
70 return alternatorPid.getOutput(setpoint, observation, FAST_CALLBACK_PERIOD_MS / 1000.0f);
71}
72
73void AlternatorController::setOutput(expected<percent_t> outputValue) {
74 if (outputValue) {
75 alternatorControl.setSimplePwmDutyCycle(PERCENT_TO_DUTY(outputValue.Value));
76 } else {
77 // Shut off output if not needed
80 }
81}
82
84 if(!alternatorPid.isSame(&previousConfiguration->alternatorControl)) {
86 }
87}
88
99
100#endif /* EFI_ALTERNATOR_CONTROL */
static SimplePwm alternatorControl("alt")
void initAlternatorCtrl()
alternator controller
expected< percent_t > getOpenLoop(float target) override
expected< float > getSetpoint() override
expected< float > observePlant() override
void onConfigurationChange(engine_configuration_s const *previousConfiguration) override
void setOutput(expected< percent_t > outputValue) override
expected< percent_t > getClosedLoop(float setpoint, float observation) override
SingleTimerExecutor scheduler
Definition engine.h:271
TunerStudioOutputChannels outputChannels
Definition engine.h:109
constexpr auto & module()
Definition engine.h:200
RegisteredOutputPin alternatorPin
Definition efi_gpio.h:114
float iTermMax
Definition efi_pid.h:69
float iTermMin
Definition efi_pid.h:68
bool isSame(const pid_s *parameters) const
Definition efi_pid.cpp:39
void postState(pid_status_s &pidStatus) const
Definition efi_pid.cpp:144
virtual void reset()
Definition efi_pid.cpp:103
void initPidClass(pid_s *parameters)
Definition efi_pid.cpp:24
float getOutput(float target, float input)
Definition efi_pid.cpp:56
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
void setSimplePwmDutyCycle(float dutyCycle) override
EnginePins enginePins
Definition efi_gpio.cpp:24
EngineState * getEngineState()
Definition engine.cpp:577
static EngineAccessor engine
Definition engine.h:413
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
bool isBrainPinValid(brain_pin_e brainPin)
void startSimplePwm(SimplePwm *state, const char *msg, Scheduler *executor, OutputPin *output, float frequency, float dutyCycle, pwm_gen_callback *callback)
uint16_t alternatorVoltageTargetLoadBins[ALTERNATOR_VOLTAGE_TARGET_SIZE]
scaled_channel< int16_t, 10, 1 > alternatorVoltageTargetTable[ALTERNATOR_VOLTAGE_TARGET_SIZE][ALTERNATOR_VOLTAGE_TARGET_SIZE]
uint16_t alternatorVoltageTargetRpmBins[ALTERNATOR_VOLTAGE_TARGET_SIZE]