rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
idle_thread_io.cpp
Go to the documentation of this file.
1/*
2 * @file idle_thread_io.cpp
3 *
4 *
5 * enable verbose_idle
6 * disable verbose_idle
7 *
8 * This file is part of rusEfi - see http://rusefi.com
9 *
10 * rusEfi is free software; you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by the Free Software Foundation; either
12 * version 3 of the License, or (at your option) any later version.
13 *
14 * rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with this program.
19 * If not, see <http://www.gnu.org/licenses/>.
20 *
21 * @date Oct 17, 2021
22 * @author Andrey Belomutskiy, (c) 2012-2020
23 */
24
25#include "pch.h"
26
27#if ! EFI_UNIT_TEST
28#include "dc_motors.h"
29#include "idle_hardware.h"
30
31void setManualIdleValvePosition(int positionPercent) {
32 if (positionPercent < 1 || positionPercent > 99)
33 return;
34 efiPrintf("setting idle valve position %d", positionPercent);
35 // todo: this is not great that we have to write into configuration here
36 setTable(config->cltIdleCorrTable, positionPercent);
37}
38
39#endif /* EFI_UNIT_TEST */
40
41#if EFI_PROD_CODE
42static void startInputPinIfValid(const char *msg, brain_pin_e pin, pin_input_mode_e mode) {
43 efiSetPadMode(msg, pin, getInputMode(mode));
44}
45#endif // EFI_PROD_CODE
46
48#if EFI_IDLE_CONTROL
50#else
51 return 0;
52#endif
53}
54
71
80
81#if ! EFI_UNIT_TEST
82
83#if EFI_IDLE_CONTROL
87#endif // EFI_IDLE_CONTROL
88
89void setTargetIdleRpm(int value) {
90 setTargetRpmCurve(value);
91 efiPrintf("target idle RPM %d", value);
92}
93
94/**
95 * Idle test would activate the solenoid for three seconds
96 */
97void startIdleBench(void) {
98 engine->timeToStopIdleTest = getTimeNowUs() + MS2US(3000); // 3 seconds
99 efiPrintf("idle valve bench test");
100}
101
102#endif /* EFI_UNIT_TEST */
103
104#if EFI_IDLE_CONTROL
105
110
113
114 // Good starting point is 10 degrees per 100 rpm, aka 0.1 deg/rpm
118
119 // Allow +- 10 degrees adjustment
122
123 // Idle region is target + 300 RPM
125
128}
129
131 // Force the idle controller to use 0 offset, as this is handled by the open loop table instead.
133
134 IdleController *controller = &engine->module<IdleController>().unmock();
135
136 controller->init();
137
138#if ! EFI_UNIT_TEST
139 // todo: we still have to explicitly init all hardware on start in addition to handling configuration change via
140 // 'applyNewHardwareSettings' todo: maybe unify these two use-cases?
142#endif /* EFI_UNIT_TEST */
143
144 controller->idleState = INIT;
145 controller->baseIdlePosition = -100.0f;
146 controller->currentIdlePosition = -100.0f;
147
148#if ! EFI_UNIT_TEST
149 // split this whole file into manual controller and auto controller? move these commands into the file
150 // which would be dedicated to just auto-controller?
151
152 addConsoleAction("idlebench", startIdleBench);
154#endif /* EFI_UNIT_TEST */
155}
156
157#endif /* EFI_IDLE_CONTROL */
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
efitimeus_t timeToStopIdleTest
Definition engine.h:351
constexpr auto & module()
Definition engine.h:200
Pid * getIdlePid()
void updateFactors(float pFactor, float iFactor, float dFactor)
Definition efi_pid.cpp:96
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
efitimeus_t getTimeNowUs()
Definition efitime.cpp:26
static EngineAccessor engine
Definition engine.h:413
void setTargetRpmCurve(float rpm)
engine_configuration_s & activeConfiguration
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
Idle Air Control valve hardware.
void initIdleHardware()
void setTargetIdleRpm(int value)
void setDefaultIdleParameters()
static void applyPidSettings()
void setManualIdleValvePosition(int positionPercent)
void startIdleBench(void)
void stopSwitchPins()
percent_t getIdlePosition()
static void startInputPinIfValid(const char *msg, brain_pin_e pin, pin_input_mode_e mode)
void startIdleThread()
void startSwitchPins()
iomode_t getInputMode(pin_input_mode_e mode)
Definition io_pins.cpp:103
void brain_pin_markUnused(brain_pin_e brainPin)
pin_input_mode_e
float percent_t
brain_pin_e pin
Definition stm32_adc.cpp:15
percent_t currentIdlePosition
percent_t baseIdlePosition
idle_state_e idleState
float cltIdleCorrTable[CLT_IDLE_TABLE_RPM_SIZE][CLT_IDLE_TABLE_CLT_SIZE]
constexpr void setTable(TElement(&dest)[N][M], const VElement value)