2020-03-23 20:20:54 -07:00
|
|
|
/*
|
|
|
|
* @file launch_control.cpp
|
|
|
|
*
|
|
|
|
* @date 10. sep. 2019
|
|
|
|
* Author: Ola Ruud
|
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2020-03-23 20:20:54 -07:00
|
|
|
|
|
|
|
#if EFI_LAUNCH_CONTROL
|
|
|
|
#include "boost_control.h"
|
|
|
|
#include "launch_control.h"
|
|
|
|
#include "periodic_task.h"
|
|
|
|
#include "advance_map.h"
|
|
|
|
#include "engine_state.h"
|
|
|
|
#include "advance_map.h"
|
|
|
|
|
2020-11-19 18:14:38 -08:00
|
|
|
/**
|
|
|
|
* We can have active condition from switch or from clutch.
|
|
|
|
* In case we are dependent on VSS we just return true.
|
|
|
|
*/
|
2021-11-15 17:09:03 -08:00
|
|
|
bool LaunchControlBase::isInsideSwitchCondition() {
|
2020-11-19 18:14:38 -08:00
|
|
|
switch (CONFIG(launchActivationMode)) {
|
2020-03-23 20:20:54 -07:00
|
|
|
case SWITCH_INPUT_LAUNCH:
|
2021-01-08 17:01:26 -08:00
|
|
|
if (isBrainPinValid(CONFIG(launchActivatePin))) {
|
2020-11-19 18:14:38 -08:00
|
|
|
//todo: we should take into consideration if this sw is pulled high or low!
|
2021-11-15 17:09:03 -08:00
|
|
|
launchActivatePinState = efiReadPin(CONFIG(launchActivatePin));
|
2020-03-23 20:20:54 -07:00
|
|
|
}
|
2021-11-15 17:09:03 -08:00
|
|
|
return launchActivatePinState;
|
2020-03-23 20:20:54 -07:00
|
|
|
|
|
|
|
case CLUTCH_INPUT_LAUNCH:
|
2021-01-08 17:01:26 -08:00
|
|
|
if (isBrainPinValid(CONFIG(clutchDownPin))) {
|
2021-07-24 16:32:50 -07:00
|
|
|
return engine->clutchDownState;
|
2020-11-19 18:14:38 -08:00
|
|
|
} else {
|
|
|
|
return false;
|
2020-03-23 20:20:54 -07:00
|
|
|
}
|
2020-11-19 18:14:38 -08:00
|
|
|
|
2020-03-23 20:20:54 -07:00
|
|
|
default:
|
|
|
|
// ALWAYS_ACTIVE_LAUNCH
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:14:38 -08:00
|
|
|
/**
|
|
|
|
* Returns True in case Vehicle speed is less then trashold.
|
|
|
|
* This condiiion would only return true based on speed if DisablebySpeed is true
|
|
|
|
* The condition logic is written in that way, that if we do not use disable by speed
|
|
|
|
* then we have to return true, and trust that we would disable by other condition!
|
|
|
|
*/
|
2020-11-19 05:15:56 -08:00
|
|
|
bool LaunchControlBase::isInsideSpeedCondition() const {
|
2021-10-05 16:59:07 -07:00
|
|
|
int speed = Sensor::getOrZero(SensorType::VehicleSpeed);
|
2020-12-01 10:03:42 -08:00
|
|
|
|
2021-11-15 18:13:01 -08:00
|
|
|
return (CONFIG(launchSpeedThreshold) > speed) || (!(CONFIG(launchActivationMode) == ALWAYS_ACTIVE_LAUNCH));
|
2020-11-19 05:15:56 -08:00
|
|
|
}
|
|
|
|
|
2020-11-19 18:14:38 -08:00
|
|
|
/**
|
|
|
|
* Returns false if TPS is invalid or TPS > preset trashold
|
|
|
|
*/
|
2020-11-19 05:15:56 -08:00
|
|
|
bool LaunchControlBase::isInsideTpsCondition() const {
|
|
|
|
auto tps = Sensor::get(SensorType::DriverThrottleIntent);
|
|
|
|
|
|
|
|
// Disallow launch without valid TPS
|
|
|
|
if (!tps.Valid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CONFIG(launchTpsTreshold) < tps.Value;
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:14:38 -08:00
|
|
|
/**
|
|
|
|
* Condition is true as soon as we are above LaunchRpm
|
|
|
|
*/
|
|
|
|
bool LaunchControlBase::isInsideRPMCondition(int rpm) const {
|
|
|
|
int launchRpm = CONFIG(launchRpm);
|
|
|
|
return (launchRpm < rpm);
|
|
|
|
}
|
2020-11-19 05:15:56 -08:00
|
|
|
|
2021-11-15 17:09:03 -08:00
|
|
|
bool LaunchControlBase::isLaunchConditionMet(int rpm) {
|
2020-11-19 05:15:56 -08:00
|
|
|
|
2020-11-19 18:14:38 -08:00
|
|
|
bool activateSwitchCondition = isInsideSwitchCondition();
|
|
|
|
bool rpmCondition = isInsideRPMCondition(rpm);
|
2020-11-19 05:15:56 -08:00
|
|
|
bool speedCondition = isInsideSpeedCondition();
|
|
|
|
bool tpsCondition = isInsideTpsCondition();
|
2020-03-23 20:20:54 -07:00
|
|
|
|
|
|
|
#if EFI_TUNER_STUDIO
|
2020-11-19 05:15:56 -08:00
|
|
|
if (engineConfiguration->debugMode == DBG_LAUNCH) {
|
|
|
|
tsOutputChannels.debugIntField1 = rpmCondition;
|
|
|
|
tsOutputChannels.debugIntField2 = tpsCondition;
|
|
|
|
tsOutputChannels.debugIntField3 = speedCondition;
|
|
|
|
tsOutputChannels.debugIntField4 = activateSwitchCondition;
|
|
|
|
}
|
2020-03-23 20:20:54 -07:00
|
|
|
#endif /* EFI_TUNER_STUDIO */
|
2020-11-19 05:15:56 -08:00
|
|
|
|
|
|
|
return speedCondition && activateSwitchCondition && rpmCondition && tpsCondition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchControlBase::update() {
|
|
|
|
if (!CONFIG(launchControlEnabled)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpm = GET_RPM();
|
|
|
|
bool combinedConditions = isLaunchConditionMet(rpm);
|
2020-11-19 18:14:38 -08:00
|
|
|
|
|
|
|
//and still recalculat in case user changed the values
|
2020-12-01 10:03:42 -08:00
|
|
|
retardThresholdRpm = CONFIG(launchRpm) + (CONFIG(enableLaunchRetard) ?
|
|
|
|
CONFIG(launchAdvanceRpmRange) : 0) + CONFIG(hardCutRpmRange);
|
2020-11-19 05:15:56 -08:00
|
|
|
|
|
|
|
if (!combinedConditions) {
|
|
|
|
// conditions not met, reset timer
|
2020-11-30 16:35:06 -08:00
|
|
|
m_launchTimer.reset();
|
2021-11-15 17:09:03 -08:00
|
|
|
isLaunchCondition = false;
|
2020-11-19 05:15:56 -08:00
|
|
|
} else {
|
|
|
|
// If conditions are met...
|
2021-11-15 17:09:03 -08:00
|
|
|
isLaunchCondition = m_launchTimer.hasElapsedSec(CONFIG(launchActivateDelay));
|
2020-03-23 20:20:54 -07:00
|
|
|
}
|
|
|
|
|
2020-11-19 05:15:56 -08:00
|
|
|
#if EFI_TUNER_STUDIO
|
2020-11-19 18:14:38 -08:00
|
|
|
if (CONFIG(debugMode) == DBG_LAUNCH) {
|
2020-11-19 05:15:56 -08:00
|
|
|
tsOutputChannels.debugIntField5 = engine->clutchDownState;
|
2021-11-15 17:09:03 -08:00
|
|
|
tsOutputChannels.debugFloatField1 = launchActivatePinState;
|
|
|
|
tsOutputChannels.debugFloatField2 = isLaunchCondition;
|
2020-11-19 05:15:56 -08:00
|
|
|
tsOutputChannels.debugFloatField3 = combinedConditions;
|
|
|
|
}
|
|
|
|
#endif /* EFI_TUNER_STUDIO */
|
|
|
|
}
|
|
|
|
|
2021-11-15 16:48:55 -08:00
|
|
|
bool LaunchControlBase::isLaunchRpmRetardCondition() const {
|
2021-11-15 17:09:03 -08:00
|
|
|
return isLaunchCondition && (retardThresholdRpm < GET_RPM());
|
2021-11-15 16:48:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LaunchControlBase::isLaunchSparkRpmRetardCondition() const {
|
|
|
|
return isLaunchRpmRetardCondition() && engineConfiguration->launchSparkCutEnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LaunchControlBase::isLaunchFuelRpmRetardCondition() const {
|
|
|
|
return isLaunchRpmRetardCondition() && engineConfiguration->launchFuelCutEnable;
|
2020-03-23 20:20:54 -07:00
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initLaunchControl() {
|
|
|
|
engine->launchController.inject();
|
2020-03-23 20:20:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EFI_LAUNCH_CONTROL */
|