rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
shift_torque_reduction_controller.cpp
Go to the documentation of this file.
1//
2// Created by kifir on 9/27/24.
3//
4
5#include "pch.h"
6
7#if EFI_LAUNCH_CONTROL
9#include "boost_control.h"
10#include "launch_control.h"
11#include "advance_map.h"
12#include "engine_state.h"
13#include "advance_map.h"
14#include "tinymt32.h"
16
28
30 float result = 0.0f;
31 auto torqueReductionXAxis = readGppwmChannel(config->torqueReductionCutXaxis);
32 int8_t currentGear = Sensor::getOrZero(SensorType::DetectedGear);
33
35 result = interpolate3d(
38 config->torqueReductionCutXBins, torqueReductionXAxis.Value
39 ) / 100.0f;
40 }
41 return result;
42}
43
46 case TORQUE_REDUCTION_BUTTON: {
51 );
52 break;
53 }
54 case LAUNCH_BUTTON: {
58 false
59 );
60 break;
61 }
62 case TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH: {
67 );
68 break;
69 }
70 case TORQUE_REDUCTION_CLUTCH_UP_SWITCH: {
75 );
76 break;
77 }
78 default: {
79 break; // we shouldn't be here!
80 }
81 }
82}
83
90
91// todo: rename method since we now check temperature not just pin state
94 const pin_input_mode_e mode,
95 const bool invalidPinState
96) {
100 // disable by not even reading control pin below threshold temperature, unless already active
101 return;
102 }
103 }
104
105#if !EFI_SIMULATOR
107 const bool previousTorqueReductionTriggerPinState = torqueReductionTriggerPinState;
110 } else {
111 torqueReductionTriggerPinState = invalidPinState;
112 }
113 if (!previousTorqueReductionTriggerPinState && torqueReductionTriggerPinState) {
114 m_pinTriggeredTimer.reset();
115 }
116#endif // !EFI_SIMULATOR
117}
118
120 auto torqueReductionTimeXaxis = readGppwmChannel(config->torqueReductionTimeXaxis);
121 int8_t currentGear = Sensor::getOrZero(SensorType::DetectedGear);
122
123 auto torqueReductionTime = interpolate3d(
126 config->torqueReductionTimeXBins, torqueReductionTimeXaxis.Value
127 );
128
131 ((0.0f < torqueReductionTime)
132 && !m_pinTriggeredTimer.hasElapsedMs(torqueReductionTime)
133 )
134 : false;
135}
136
141
144
145 if (currentApp.Valid) {
147 } else {
149 }
150}
151
162
163#endif // EFI_LAUNCH_CONTROL
EngineState engineState
Definition engine.h:344
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
static EngineAccessor engine
Definition engine.h:413
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
One header which acts as gateway to current engine state.
expected< float > readGppwmChannel(gppwm_channel_e channel)
bool efiReadPin(brain_pin_e pin)
Definition io_pins.cpp:89
bool isBrainPinValid(brain_pin_e brainPin)
pin_input_mode_e
expected< float > SensorResult
Definition sensor.h:46
@ DriverThrottleIntent
static bool isShiftTorqueBelowTemperatureThreshold()
brain_pin_e pin
Definition stm32_adc.cpp:15
float torqueReductionTimeTable[TORQUE_TABLE_Y_SIZE][TORQUE_TABLE_X_SIZE]
float torqueReductionIgnitionRetardTable[TORQUE_TABLE_Y_SIZE][TORQUE_TABLE_X_SIZE]
int8_t torqueReductionIgnitionCutTable[TORQUE_TABLE_Y_SIZE][TORQUE_TABLE_X_SIZE]
Tiny Mersenne Twister only 127 bit internal state.