Speeduino
Loading...
Searching...
No Matches
crank_angle_calculator.h
Go to the documentation of this file.
1
14#pragma once
15#include "src/utils/nominmax.h"
16#include <tuple>
17#include "config_pages.h"
18#include "atomic.h"
19#include "decoder_state.h"
20
21namespace decoders {
22
23namespace shared {
24
25
36{
37 uint32_t _toothLastToothTime = 0;
38
39#if !defined(UNIT_TEST)
40protected:
41#endif
43 explicit last_tooth_rev_calculator_t(uint32_t toothLastToothTime);
44
45 int16_t calculate(uint32_t currMicros) const;
46};
47
51{
52 uint32_t _toothLastToothTime = 0;
54 uint16_t _toothAngle = 0;
56
57#if !defined(UNIT_TEST)
58protected:
59#endif
61 explicit tooth_interval_calculator_t(uint32_t toothLastToothTime, uint32_t toothLastMinusOneToothTime, uint16_t toothAngle, bool toothAngleCorrect);
62
63 int16_t calculate(uint32_t currMicros) const;
64};
65
70{
71 uint16_t _toothCurrentCount = 0;
72
73#if !defined(UNIT_TEST)
74protected:
75#endif
77 explicit lookup_initial_calculator_t(uint16_t toothCurrentCount);
78
84 int16_t calculate(const int16_t toothAngles[]) const;
85};
86
91{
92 uint16_t _toothCurrentCount = 0;
93 uint16_t _toothAngle = 0;
94
95#if !defined(UNIT_TEST)
96protected:
97#endif
99 explicit compute_initial_calculator_t(uint16_t toothCurrentCount, uint16_t toothAngle);
100
101 int16_t calculate(void) const;
102};
103
106{
107 bool _revZeroOrOne = false;
108
109#if !defined(UNIT_TEST)
110protected:
111#endif
113 explicit sequential_correction_calculator_t(bool revZeroOrOne);
114
115 int16_t calculate(const config4 &page4) const;
116};
117
119
127 {
128 int16_t calculateCrankAngle(int16_t initialCrankAngle, uint32_t currMicros, const config4 &page4) const;
129};
130
132{
134 explicit lookup_crank_angle_calculator_t(const std::tuple<uint32_t, bool, uint16_t> &data);
135
143 int16_t calculateCrankAngle(uint32_t currMicros, const int16_t toothAngles[], const config4 &page4) const;
144};
145
147{
149 explicit trigger_angle_crank_angle_calculator_t(const std::tuple<uint32_t, bool, uint16_t, uint16_t> &data);
150
157 int16_t calculateCrankAngle(uint32_t currMicros, const config4 &page4) const;
158};
159
161{
163 explicit lookup_crank_angle_calculator_tooth_interval_t(const std::tuple<uint32_t, uint32_t, bool, uint16_t, uint16_t, bool> &data);
164
172 int16_t calculateCrankAngle(uint32_t currMicros, const int16_t toothAngles[], const config4 &page4) const;
173};
174
176{
178 explicit compute_crank_angle_calculator_tooth_interval_t(const std::tuple<uint32_t, uint32_t, bool, uint16_t, uint16_t, bool> &data);
179
186 int16_t calculateCrankAngle(uint32_t currMicros, const config4 &page4) const;
187};
188
190
191static inline auto atomic_make_lookup_caa(const state_t &decoderState)
192{
193 return lookup_crank_angle_calculator_t(atomic_copy(decoderState.toothLastToothTime, decoderState.revolutionOne, decoderState.toothCurrentCount));
194}
195static inline auto atomic_make_lookup_caa_secondary(const state_t &decoderState)
196{
198}
199static inline auto atomic_make_angle_caa(const state_t &decoderState)
200{
202}
203
204static inline uint16_t clampCrankAngle(int16_t crankAngle)
205{
206 auto crankMax = std::max(CRANK_ANGLE_MAX_IGN, CRANK_ANGLE_MAX_INJ);
207 return nudge((int16_t)0, (int16_t)crankMax, (int16_t)crankAngle);
208}
209
210}
211}
static auto atomic_copy(Args &&... args)
Atomically copy the forwarding reference arguments into a std::tuple<>
Definition atomic.h:24
The tune page structs and related defines.
int16_t CRANK_ANGLE_MAX_IGN
The number of crank degrees that the system tracks ignition over.
Definition crankMaths.cpp:14
int16_t CRANK_ANGLE_MAX_INJ
The number of crank degrees that the system tracks fuel injection over.
Definition crankMaths.cpp:15
const config4 & page4
Definition engineProtection.cpp:172
static T nudge(T min, T max, T value)
Make **one* pass at correcting the value into the range [ min, max)
Definition maths.h:351
static auto atomic_make_lookup_caa(const state_t &decoderState)
Definition crank_angle_calculator.h:191
static uint16_t clampCrankAngle(int16_t crankAngle)
Definition crank_angle_calculator.h:204
static auto atomic_make_angle_caa(const state_t &decoderState)
Definition crank_angle_calculator.h:199
static auto atomic_make_lookup_caa_secondary(const state_t &decoderState)
Definition crank_angle_calculator.h:195
Definition basicDistributor.cpp:8
Workaround when min() & max() are defined as macros, which generates compile errors in most C++ stand...
const config4 uint16_t crankAngle
Definition scheduler_ignition_controller.cpp:724
Definition config_pages.h:357
int16_t calculateCrankAngle(uint32_t currMicros, const config4 &page4) const
Calculate the crank angle.
Definition crank_angle_calculator.cpp:160
A crank angle calculator that computes the initial crank angle from a tooth angle.
Definition crank_angle_calculator.h:91
int16_t calculate(void) const
Definition crank_angle_calculator.cpp:69
uint16_t _toothCurrentCount
1-based tooth number
Definition crank_angle_calculator.h:92
uint16_t _toothAngle
Tooth angle (1-359°)
Definition crank_angle_calculator.h:93
A crank angle calculator that computes a temporal adjustment based on when the tooth was last detecte...
Definition crank_angle_calculator.h:36
uint32_t _toothLastToothTime
Time in µS that the current tooth was last detected.
Definition crank_angle_calculator.h:37
int16_t calculate(uint32_t currMicros) const
Definition crank_angle_calculator.cpp:18
Definition crank_angle_calculator.h:132
int16_t calculateCrankAngle(uint32_t currMicros, const int16_t toothAngles[], const config4 &page4) const
Calculate the crank angle.
Definition crank_angle_calculator.cpp:114
int16_t calculateCrankAngle(uint32_t currMicros, const int16_t toothAngles[], const config4 &page4) const
Calculate the crank angle.
Definition crank_angle_calculator.cpp:144
A crank angle calculator that looks up the initial crank angle from an array.
Definition crank_angle_calculator.h:70
int16_t calculate(const int16_t toothAngles[]) const
Calculate the crank angle.
Definition crank_angle_calculator.cpp:51
uint16_t _toothCurrentCount
1-based tooth number
Definition crank_angle_calculator.h:71
A crank angle calculator that computes a revolution adjustment.
Definition crank_angle_calculator.h:106
int16_t calculate(const config4 &page4) const
Definition crank_angle_calculator.cpp:86
bool _revZeroOrOne
When calculating over 720°, tells the calculator if we are in the 1st revolution (false) or the 2nd (...
Definition crank_angle_calculator.h:107
Definition crank_angle_calculator.h:127
int16_t calculateCrankAngle(int16_t initialCrankAngle, uint32_t currMicros, const config4 &page4) const
Definition crank_angle_calculator.cpp:99
Definition decoder_state.h:17
volatile uint16_t secondaryToothCount
Definition decoder_state.h:41
volatile uint16_t triggerToothAngle
Definition decoder_state.h:45
uint16_t toothCurrentCount
Definition decoder_state.h:24
volatile bool revolutionOne
Definition decoder_state.h:39
volatile uint32_t toothLastToothTime
Definition decoder_state.h:27
A crank angle calculator that computes a temporal adjustment based on the gap between the 2 most rece...
Definition crank_angle_calculator.h:51
uint32_t _toothLastMinusOneToothTime
Time in µS that the tooth before the last tooth was detected.
Definition crank_angle_calculator.h:53
bool _toothAngleCorrect
Is _toothAngle valid.
Definition crank_angle_calculator.h:55
int16_t calculate(uint32_t currMicros) const
Definition crank_angle_calculator.cpp:32
uint16_t _toothAngle
Tooth angle (1-359°)
Definition crank_angle_calculator.h:54
uint32_t _toothLastToothTime
Time in µS that the current tooth was last detected.
Definition crank_angle_calculator.h:52
Definition crank_angle_calculator.h:147
int16_t calculateCrankAngle(uint32_t currMicros, const config4 &page4) const
Calculate the crank angle.
Definition crank_angle_calculator.cpp:129