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: {
50 /*invertPhysicalPin*/false,
52 );
53 break;
54 }
55 case LAUNCH_BUTTON: {
59 /*invertPhysicalPin*/false,
60 false
61 );
62 break;
63 }
64 case TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH: {
68 /*invertPhysicalPin*/false,
70 );
71 break;
72 }
73 case TORQUE_REDUCTION_CLUTCH_UP_SWITCH: {
77 /*invertPhysicalPin*/true,
79 );
80 break;
81 }
82 default: {
83 break; // we shouldn't be here!
84 }
85 }
86}
87
94
95// todo: rename method since we now check temperature not just pin state
98 const pin_input_mode_e mode,
99 const bool invertPhysicalPin,
100 const bool invalidPinState
101) {
105 // disable by not even reading control pin below threshold temperature, unless already active
106 return;
107 }
108 }
109
110#if !EFI_SIMULATOR
112 const bool previousTorqueReductionTriggerPinState = torqueReductionTriggerPinState;
114 torqueReductionTriggerPinState = efiReadPin(pin, mode) ^ invertPhysicalPin;
115 } else {
116 torqueReductionTriggerPinState = invalidPinState;
117 }
118 if (!previousTorqueReductionTriggerPinState && torqueReductionTriggerPinState) {
119 m_pinTriggeredTimer.reset();
120 }
121#endif // !EFI_SIMULATOR
122}
123
125 auto torqueReductionTimeXaxis = readGppwmChannel(config->torqueReductionTimeXaxis);
126 int8_t currentGear = Sensor::getOrZero(SensorType::DetectedGear);
127
128 auto torqueReductionTime = interpolate3d(
131 config->torqueReductionTimeXBins, torqueReductionTimeXaxis.Value
132 );
133
136 ((0.0f < torqueReductionTime)
137 && !m_pinTriggeredTimer.hasElapsedMs(torqueReductionTime)
138 )
139 : false;
140}
141
146
149
150 if (currentApp.Valid) {
152 } else {
154 }
155}
156
167
168#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.