rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Attributes
EtbImpl< TBase > Class Template Referencefinal

#include <electronic_throttle_impl.h>

Inheritance diagram for EtbImpl< TBase >:
Inheritance graph
[legend]
Collaboration diagram for EtbImpl< TBase >:
Collaboration graph
[legend]

Public Member Functions

template<typename... TArgs>
 EtbImpl (TArgs &&... args)
 
void update () override
 
void startBenchTest () override
 
void autoCalibrateTps (bool reportToTs) override
 
ACPhase doAutocal (ACPhase phase)
 

Private Types

enum class  ACPhase {
  Stopped , Start , Open , Close ,
  TransmitPrimaryMax , TransmitPrimaryMin , TransmitSecondaryMax , TransmitSecondaryMin
}
 

Private Attributes

ACPhase m_autocalPhase = ACPhase::Stopped
 
Timer m_autocalTimer
 
bool m_isAutocalTs
 
bool m_benchTestActive = false
 
Timer m_benchTestTimer
 
float m_primaryMax
 
float m_secondaryMax
 
float m_primaryMin
 
float m_secondaryMin
 

Detailed Description

template<typename TBase>
class EtbImpl< TBase >

Definition at line 155 of file electronic_throttle_impl.h.

Member Enumeration Documentation

◆ ACPhase

template<typename TBase >
enum class EtbImpl::ACPhase
strongprivate
Enumerator
Stopped 
Start 
Open 
Close 
TransmitPrimaryMax 
TransmitPrimaryMin 
TransmitSecondaryMax 
TransmitSecondaryMin 

Definition at line 157 of file electronic_throttle_impl.h.

157 {
158 Stopped,
159
160 Start,
161
162 // Drive the motor open
163 Open,
164
165 // Drive the motor closed
166 Close,
167
168 // Write learned values to TS
173 };

Constructor & Destructor Documentation

◆ EtbImpl()

template<typename TBase >
template<typename... TArgs>
EtbImpl< TBase >::EtbImpl ( TArgs &&...  args)
inline

Definition at line 177 of file electronic_throttle_impl.h.

177: TBase(std::forward<TArgs>(args)...) { }

Member Function Documentation

◆ autoCalibrateTps()

template<typename TBase >
void EtbImpl< TBase >::autoCalibrateTps ( bool  reportToTs)
inlineoverride

Definition at line 223 of file electronic_throttle_impl.h.

223 {
224 // Only auto calibrate throttles
225 if (TBase::getFunction() == DC_Throttle1 || TBase::getFunction() == DC_Throttle2 || TBase::getFunction() == DC_Wastegate) {
226 m_isAutocalTs = reportToTs;
228 }
229 }

◆ doAutocal()

template<typename TBase >
ACPhase EtbImpl< TBase >::doAutocal ( ACPhase  phase)
inline

Definition at line 231 of file electronic_throttle_impl.h.

231 {
232 // Don't allow if engine is running!
234 efiPrintf(" ****************** ERROR: Not while RPM ********************");
235 return ACPhase::Stopped;
236 }
237
238 auto motor = TBase::getMotor();
239 if (!motor) {
240 efiPrintf(" ****************** ERROR: No DC motor ********************");
241 return ACPhase::Stopped;
242 }
243
244 TBase::etbErrorCode = (uint8_t)EtbStatus::AutoCalibrate;
245
246 auto myFunction = TBase::getFunction();
247
248 switch (phase) {
249 case ACPhase::Start:
250 // Open the throttle
251 motor->set(0.5f);
252 motor->enable();
253 return ACPhase::Open;
254 case ACPhase::Open:
255 if (m_autocalTimer.hasElapsedMs(1000)) {
256 // Capture open position
259
260 // Next: close the throttle
261 motor->set(-0.5f);
262 return ACPhase::Close;
263 }
264 break;
265 case ACPhase::Close:
266 if (m_autocalTimer.hasElapsedMs(1000)) {
267 // Capture closed position
270
271 // Disable the motor, we're done
272 motor->disable("autotune");
273
274 // Check that the calibrate actually moved the throttle
275 if (std::abs(m_primaryMax - m_primaryMin) < 0.5f) {
276 firmwareError(ObdCode::OBD_TPS_Configuration, "Auto calibrate failed, check your wiring!\r\nClosed voltage: %.1fv Open voltage: %.1fv", m_primaryMin, m_primaryMax);
277 return ACPhase::Stopped;
278 }
279
280 if (!m_isAutocalTs) {
281 // configuration on ECU side is in ADC, TS sees Volts, see "tps_limit_t"
282 if (myFunction == DC_Throttle1) {
287 } else if (myFunction == DC_Throttle2) {
292 } else if (myFunction == DC_Wastegate) {
295 } else {
296 /* TODO */
297 }
298 return ACPhase::Stopped;
299 }
300
301 // Next: start transmitting results
304 }
305 break;
307 if (tsCalibrationIsIdle()) {
310 }
311 break;
313 if (tsCalibrationIsIdle()) {
315 // No secondary sensor?
317 return ACPhase::Stopped;
319 }
320 break;
322 if (tsCalibrationIsIdle()) {
325 }
326 break;
328 if (tsCalibrationIsIdle()) {
329 // Done!
330 return ACPhase::Stopped;
331 }
332 break;
333 case ACPhase::Stopped: break;
334 }
335
336 // by default, stay in the same phase
337 return phase;
338 }
virtual float getRaw() const
Definition sensor.h:152
static float getOrZero(SensorType type)
Definition sensor.h:87
static TsCalMode functionToCalModePriMin(dc_function_e func)
static TsCalMode functionToCalModeSecMin(dc_function_e func)
static SensorType functionToTpsSensorPrimary(dc_function_e func)
static TsCalMode functionToCalModePriMax(dc_function_e func)
static SensorType functionToTpsSensorSecondary(dc_function_e func)
static TsCalMode functionToCalModeSecMax(dc_function_e func)
static constexpr engine_configuration_s * engineConfiguration
void firmwareError(ObdCode code, const char *fmt,...)
@ OBD_TPS_Configuration
constexpr int convertVoltageTo10bitADC(float voltage)
Definition tps.h:21
void tsCalibrationSetData(TsCalMode mode, float value, float value2, float timeoutMs)

Referenced by EtbImpl< TBase >::update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startBenchTest()

template<typename TBase >
void EtbImpl< TBase >::startBenchTest ( )
inlineoverride

Definition at line 206 of file electronic_throttle_impl.h.

206 {
207 auto motor = TBase::getMotor();
208 if (!motor) {
209 efiPrintf("ETB bench test: no motor configured");
210 return;
211 }
212 if (TBase::getFunction() != DC_Throttle1 && TBase::getFunction() != DC_Throttle2) {
213 efiPrintf("ETB bench test: not a throttle");
214 return;
215 }
216 motor->set(0.5f);
217 motor->enable();
218 m_benchTestTimer.reset();
219 m_benchTestActive = true;
220 efiPrintf("ETB bench test: opening for 300ms");
221 }

◆ update()

template<typename TBase >
void EtbImpl< TBase >::update ( )
inlineoverride

Definition at line 179 of file electronic_throttle_impl.h.

179 {
180#if EFI_TUNER_STUDIO
181 if (m_benchTestActive) {
182 if (m_benchTestTimer.hasElapsedMs(300)) {
183 auto motor = TBase::getMotor();
184 if (motor) {
185 motor->disable("bench test");
186 }
187 m_benchTestActive = false;
188 efiPrintf("ETB bench test done");
189 }
190 } else if (m_autocalPhase != ACPhase::Stopped) {
191 ACPhase nextPhase = doAutocal(m_autocalPhase);
192
193 // if we changed phase, reset the phase timer
194 if (m_autocalPhase != nextPhase) {
195 m_autocalTimer.reset();
196 m_autocalPhase = nextPhase;
197 }
198 } else
199#endif /* EFI_TUNER_STUDIO */
200
201 {
202 TBase::update();
203 }
204 }
ACPhase doAutocal(ACPhase phase)
Here is the call graph for this function:

Field Documentation

◆ m_autocalPhase

template<typename TBase >
ACPhase EtbImpl< TBase >::m_autocalPhase = ACPhase::Stopped
private

◆ m_autocalTimer

template<typename TBase >
Timer EtbImpl< TBase >::m_autocalTimer
private

◆ m_benchTestActive

template<typename TBase >
bool EtbImpl< TBase >::m_benchTestActive = false
private

◆ m_benchTestTimer

template<typename TBase >
Timer EtbImpl< TBase >::m_benchTestTimer
private

◆ m_isAutocalTs

template<typename TBase >
bool EtbImpl< TBase >::m_isAutocalTs
private

◆ m_primaryMax

template<typename TBase >
float EtbImpl< TBase >::m_primaryMax
private

Definition at line 349 of file electronic_throttle_impl.h.

Referenced by EtbImpl< TBase >::doAutocal().

◆ m_primaryMin

template<typename TBase >
float EtbImpl< TBase >::m_primaryMin
private

Definition at line 351 of file electronic_throttle_impl.h.

Referenced by EtbImpl< TBase >::doAutocal().

◆ m_secondaryMax

template<typename TBase >
float EtbImpl< TBase >::m_secondaryMax
private

Definition at line 350 of file electronic_throttle_impl.h.

Referenced by EtbImpl< TBase >::doAutocal().

◆ m_secondaryMin

template<typename TBase >
float EtbImpl< TBase >::m_secondaryMin
private

Definition at line 352 of file electronic_throttle_impl.h.

Referenced by EtbImpl< TBase >::doAutocal().


The documentation for this class was generated from the following file: