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 trqRedCutXaxisValue = torqueReductionXAxis.Value;
33 int8_t currentGear = Sensor::getOrZero(SensorType::DetectedGear);
34
36 result = interpolate3d(
39 config->torqueReductionCutXBins, torqueReductionXAxis.Value
40 ) / 100.0f;
41 }
42 return result;
43}
44
47 case TORQUE_REDUCTION_BUTTON: {
51 /*invertPhysicalPin*/false,
53 );
54 break;
55 }
56 case LAUNCH_BUTTON: {
60 /*invertPhysicalPin*/false,
61 false
62 );
63 break;
64 }
65 case TORQUE_REDUCTION_CLUTCH_DOWN_SWITCH: {
69 /*invertPhysicalPin*/false,
71 );
72 break;
73 }
74 case TORQUE_REDUCTION_CLUTCH_UP_SWITCH: {
78 /*invertPhysicalPin*/true,
80 );
81 break;
82 }
83 default: {
84 break; // we shouldn't be here!
85 }
86 }
87}
88
95
96// todo: rename method since we now check temperature not just pin state
99 const pin_input_mode_e mode,
100 const bool invertPhysicalPin,
101 const bool invalidPinState
102) {
106 // disable by not even reading control pin below threshold temperature, unless already active
107 return;
108 }
109 }
110
111#if !EFI_SIMULATOR
113 const bool previousTorqueReductionTriggerPinState = torqueReductionTriggerPinState;
115 torqueReductionTriggerPinState = efiReadPin(pin, mode) ^ invertPhysicalPin;
116 } else {
117 torqueReductionTriggerPinState = invalidPinState;
118 }
119 if (!previousTorqueReductionTriggerPinState && torqueReductionTriggerPinState) {
120 m_pinTriggeredTimer.reset();
121 }
122#endif // !EFI_SIMULATOR
123}
124
126 auto torqueReductionTimeXaxis = readGppwmChannel(config->torqueReductionTimeXaxis);
127 trqRedTimeXaxisValue = torqueReductionTimeXaxis.Value;
128 int8_t currentGear = Sensor::getOrZero(SensorType::DetectedGear);
129
130 auto torqueReductionTime = interpolate3d(
133 config->torqueReductionTimeXBins, torqueReductionTimeXaxis.Value
134 );
135
138 ((0.0f < torqueReductionTime)
139 && !m_pinTriggeredTimer.hasElapsedMs(torqueReductionTime)
140 )
141 : false;
142}
143
148
151
152 if (currentApp.Valid) {
154 } else {
156 }
157}
158
160 auto torqueReductionXAxis = readGppwmChannel(config->torqueReductionIgnitionRetardXaxis);
161 trqRedIgnRetXaxisValue = torqueReductionXAxis.Value;
162 int8_t currentGear = Sensor::getOrZero(SensorType::DetectedGear);
163
164 return interpolate3d(
167 config->torqueReductionIgnitionRetardXBins, torqueReductionXAxis.Value
168 );
169}
170
171#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.