rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
launch_control.cpp
Go to the documentation of this file.
1/*
2 * @file launch_control.cpp
3 *
4 * @date 10. sep. 2019
5 * Author: Ola Ruud
6 * Rework: Patryk Chmura
7 */
8
9#include "pch.h"
10
11#if EFI_LAUNCH_CONTROL
12#include "boost_control.h"
13#include "launch_control.h"
14#include "engine_state.h"
15#include "tinymt32.h" // TL,DR: basic implementation of 'random'
17
18/**
19 * We can have active condition from switch or from clutch.
20 * In case we are dependent on VSS we just return true.
21 */
26
28#if !EFI_SIMULATOR
31 }
32#endif // EFI_PROD_CODE
34 } else if (isClutchActivated) {
35 return getClutchDownState();
36 } else if (isBrakePedalActivated) {
37 return getBrakePedalState();
38 } else if (engineConfiguration->launchActivationMode == LUA_LAUNCH) {
39 return luaLaunchState;
40 } else {
41 // ALWAYS_ACTIVE_LAUNCH
42 return true;
43 }
44}
45
46/**
47 * Returns True when Vehicle speed ALLOWS launch control
48 */
51 return true; // allow launch, speed does not matter
52 }
53
55
57}
58
59/**
60 * Returns false if TPS is invalid or TPS > preset threshold
61 */
64
65 // Disallow launch without valid TPS
66 if (!tps.Valid) {
67 return false;
68 }
69
70 // todo: should this be 'launchTpsThreshold <= tps.Value' so that nicely calibrated TPS of zero does not prevent launch?
71 return engineConfiguration->launchTpsThreshold < tps.Value;
72}
73
75 if ((engineConfiguration->launchActivationMode == SWITCH_INPUT_LAUNCH)
79 ) {
80 // We need perform Shift Torque Reduction stuff (see
81 // https://github.com/rusefi/rusefi/issues/5608#issuecomment-2391500472 and
82 // https://github.com/rusefi/rusefi/issues/5608#issuecomment-2391772899 for details)
84 }
85
86 const int launchRpm = engineConfiguration->launchRpm;
87 const int preLaunchRpm = launchRpm - engineConfiguration->launchRpmWindow;
88 if (rpm < preLaunchRpm) {
90 } else if (launchRpm <= rpm) {
92 } else {
94 }
95}
96
98 const LaunchCondition currentRpmLaunchCondition = calculateRPMLaunchCondition(rpm);
100 rpmLaunchCondition = (currentRpmLaunchCondition == LaunchCondition::Launch);
101 rpmPreLaunchCondition = (currentRpmLaunchCondition == LaunchCondition::PreLaunch);
104
106 return currentRpmLaunchCondition;
107 } else {
109 }
110}
111
117
121
124 return;
125 }
126
127 const float rpm = Sensor::getOrZero(SensorType::Rpm);
128 const LaunchCondition launchCondition = calculateLaunchCondition(rpm);
129 isLaunchCondition = (launchCondition == LaunchCondition::Launch);
131
132 //and still recalculate in case user changed the values
134
136}
137
141
145
149
150float LaunchControlBase::calculateSparkSkipRatio(const float rpm) const {
151 float result = 0.0f;
153 if (isLaunchCondition) {
154 result = 1.0f;
155 } else if (isPreLaunchCondition) {
156 const int launchRpm = engineConfiguration->launchRpm;
157 const int sparkSkipStartRpm = launchRpm - engineConfiguration->launchRpmWindow;
158 if (sparkSkipStartRpm <= rpm) {
159 const float initialIgnitionCutRatio = engineConfiguration->initialIgnitionCutPercent / 100.0f;
160 const int sparkSkipEndRpm = launchRpm - engineConfiguration->launchCorrectionsEndRpm;
161 const float finalIgnitionCutRatio = engineConfiguration->finalIgnitionCutPercentBeforeLaunch / 100.0f;
162 result = interpolateClamped(sparkSkipStartRpm, initialIgnitionCutRatio, sparkSkipEndRpm, finalIgnitionCutRatio, rpm);
163 }
164 }
165 }
166 return result;
167}
168
169SoftSparkLimiter::SoftSparkLimiter(const bool p_allowHardCut)
170 : allowHardCut(p_allowHardCut) {
171#if EFI_UNIT_TEST
173#endif // EFI_UNIT_TEST
174}
175
177 const float luaSparkSkip,
178 const float tractionControlSparkSkip,
179 const float launchOrShiftTorqueReductionControllerSparkSkipRatio
180) {
181 targetSkipRatio = luaSparkSkip;
183 if (allowHardCut) {
185 }
186 } else if (!allowHardCut) {
188 }
189
190 if (allowHardCut) {
191 /*
192 * We are applying launch controller spark skip ratio only for hard skip limiter (see
193 * https://github.com/rusefi/rusefi/issues/6566#issuecomment-2153149902).
194 */
195 targetSkipRatio += launchOrShiftTorqueReductionControllerSparkSkipRatio;
196 }
197}
198
200
202 if (targetSkipRatio == 0 || (!allowHardCut && wasJustSkipped)) {
203 wasJustSkipped = false;
204 return false;
205 }
206
207 float random = tinymt32_generate_float(&tinymt);
208 wasJustSkipped = random < (allowHardCut ? 1 : 2) * targetSkipRatio;
209 return wasJustSkipped;
210}
211
213 tinymt32_init(&tinymt, 1345135);
214}
215
216#endif /* EFI_LAUNCH_CONTROL */
float calculateSparkSkipRatio(float rpm) const
LaunchCondition calculateLaunchCondition(float rpm)
bool isLaunchRpmRetardCondition() const
bool isLaunchFuelRpmRetardCondition() const
float getFuelCoefficient() const
bool isLaunchSparkRpmRetardCondition() const
LaunchCondition calculateRPMLaunchCondition(float rpm)
bool isInsideSpeedCondition() const
bool isInsideTpsCondition() const
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
const bool allowHardCut
void updateTargetSkipRatio(float luaSoftSparkSkip, float tractionControlSparkSkip, float launchOrShiftTorqueReductionControllerSparkSkipRatio=0.0f)
SoftSparkLimiter(bool p_allowHardCut)
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
bool getBrakePedalState()
Definition engine.cpp:243
bool getClutchDownState()
Definition engine.cpp:223
static constexpr engine_configuration_s * engineConfiguration
One header which acts as gateway to current engine state.
bool efiReadPin(brain_pin_e pin)
Definition io_pins.cpp:89
void initLaunchControl()
static tinymt32_t tinymt
void initLaunchControl()
LaunchCondition
bool isBrainPinValid(brain_pin_e brainPin)
@ DriverThrottleIntent
tractionControlSparkSkip("tractionControlSparkSkip", SensorCategory.SENSOR_INPUTS, FieldType.INT, 1396, 1.0, -1.0, -1.0, "")
void tinymt32_init(tinymt32_t *random, uint32_t seed)
Definition tinymt32.c:62
Tiny Mersenne Twister only 127 bit internal state.
static float tinymt32_generate_float(tinymt32_t *random)
Definition tinymt32.h:191