Engine phase wrap around in log #3645

refactoring & docs
This commit is contained in:
rusefillc 2021-12-02 17:05:47 -05:00
parent 2476fae92a
commit 9ce37314c0
4 changed files with 12 additions and 4 deletions

View File

@ -13,8 +13,13 @@ void setAlgorithm(engine_load_mode_e algo);
void setFlatInjectorLag(float value);
#define fixAngle(angle, msg, code) fixAngle2(angle, msg, code, engine->engineCycle)
/**
* See also wrapVvt
* TODO: replace all usages of fixAngle with wrapAngle?
* Should we make this a nice method instead of that off macro which changes parameter value?
*/
#define fixAngle(angle, msg, code) wrapAngle2(angle, msg, code, engine->engineCycle)
#define wrapAngle(angle, msg, code) fixAngle(angle, msg, code)
/**
* @return time needed to rotate crankshaft by one degree, in milliseconds.

View File

@ -388,7 +388,7 @@ void findTriggerPosition(TriggerWaveform *triggerShape,
// convert engine cycle angle into trigger cycle angle
angle += triggerShape->tdcPosition + engineConfiguration->globalTriggerAngleOffset;
efiAssertVoid(CUSTOM_ERR_6577, !cisnan(angle), "findAngle#2");
fixAngle2(angle, "addFuel#2", CUSTOM_ERR_6555, getEngineCycle(triggerShape->getOperationMode()));
wrapAngle2(angle, "addFuel#2", CUSTOM_ERR_6555, getEngineCycle(triggerShape->getOperationMode()));
int triggerEventIndex = triggerShape->findAngleIndex(details, angle);
angle_t triggerEventAngle = details->eventAngles[triggerEventIndex];

View File

@ -29,7 +29,7 @@
* @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke
* I guess this implementation would be faster than 'angle % engineCycle'
*/
#define fixAngle2(angle, msg, code, engineCycle) \
#define wrapAngle2(angle, msg, code, engineCycle) \
{ \
if (cisnan(angle)) { \
firmwareError(CUSTOM_ERR_ANGLE, "aNaN%s", msg); \

View File

@ -160,6 +160,9 @@ static angle_t adjustCrankPhase(int camIndex) {
}
}
/**
* See also wrapAngle
*/
static angle_t wrapVvt(angle_t vvtPosition, int period) {
// Wrap VVT position in to the range [-360, 360)
while (vvtPosition < -period / 2) {