Skip to content

Commit

Permalink
Mitsubishi 4G93 Trigger issues #4918
Browse files Browse the repository at this point in the history
adding more info on the trigger images
  • Loading branch information
rusefillc committed Jan 3, 2023
1 parent 1ddd871 commit def809a
Show file tree
Hide file tree
Showing 5 changed files with 4,496 additions and 4,391 deletions.
7 changes: 7 additions & 0 deletions firmware/controllers/trigger/trigger_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ expected<TriggerDecodeResult> TriggerDecoderBase::decodeTriggerEvent(
}

toothed_previous_time = nowNt;

#if EFI_UNIT_TEST
if (wasSynchronized) {
int uiGapIndex = (currentCycle.current_index) % triggerShape.getLength();
gapRatio[uiGapIndex] = triggerSyncGapRatio;
}
#endif // EFI_UNIT_TEST
}

if (getShaftSynchronized() && !isValidIndex(triggerShape)) {
Expand Down
7 changes: 7 additions & 0 deletions firmware/controllers/trigger/trigger_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class TriggerDecoderBase : public trigger_state_s {
*/
void incrementShaftSynchronizationCounter();

#if EFI_UNIT_TEST
/**
* used for trigger export only
*/
float gapRatio[PWM_PHASE_MAX_COUNT * 6];
#endif // EFI_UNIT_TEST

int64_t getTotalEventCounter() const;

expected<TriggerDecodeResult> decodeTriggerEvent(
Expand Down
1 change: 1 addition & 0 deletions firmware/integration/rusefi_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ struct_no_prefix engine_configuration_s
#define TRIGGER_GAPS_COUNT "gapsCount"
#define TRIGGER_GAP_FROM "gapFrom"
#define TRIGGER_GAP_TO "gapTo"
#define TRIGGER_WITH_SYNC "isSynchronizationNeeded"

!
! all the xxx_PACKING_xxx constants are about persisting tables in compact for, for example packing RPM with 50 increment in a byte
Expand Down
22 changes: 19 additions & 3 deletions unit_tests/tests/trigger/test_all_triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
*/
#include "pch.h"

// uncomment to test starting from specific trigger
//#define TEST_FROM_TRIGGER_ID ((int)TT_MAZDA_MIATA_NA)
// uncomment to test only newest trigger
//#define TEST_FROM_TRIGGER_ID ((int)TT_UNUSED - 1)
#define TEST_FROM_TRIGGER_ID 1

#define TEST_TO_TRIGGER_ID TT_UNUSED
// uncomment to test only one trigger
//#define TEST_TO_TRIGGER_ID (TEST_FROM_TRIGGER_ID + 1)

struct TriggerExportHelper
{
FILE* fp;
Expand Down Expand Up @@ -35,7 +41,7 @@ INSTANTIATE_TEST_SUITE_P(
AllTriggersFixture,
// Test all triggers from the first valid trigger thru the last
// (Skip index 0, that's custom toothed wheel which is covered by others)
::testing::Range((trigger_type_e)TEST_FROM_TRIGGER_ID, TT_UNUSED)
::testing::Range((trigger_type_e)TEST_FROM_TRIGGER_ID, (trigger_type_e)TEST_TO_TRIGGER_ID)
);

extern bool printTriggerDebug;
Expand All @@ -57,6 +63,13 @@ TEST_P(AllTriggersFixture, TestTrigger) {
Engine* engine = &e;
EngineTestHelperBase base(engine, &pc.engineConfiguration, &pc);

#if EFI_UNIT_TEST
extern TriggerDecoderBase initState;
for (size_t i = 0;i<efi::size(initState.gapRatio);i++) {
initState.gapRatio[i] = -1;
}
#endif // EFI_UNIT_TEST

engineConfiguration->trigger.type = tt;
setCamOperationMode();

Expand All @@ -75,6 +88,7 @@ TEST_P(AllTriggersFixture, TestTrigger) {
fprintf(fp, "%s=%s\n", TRIGGER_IS_SECOND_WHEEL_CAM, shape->isSecondWheelCam ? "true" : "false");
fprintf(fp, "%s=%d\n", TRIGGER_CYCLE_DURATION, (int)shape->getCycleDuration());
fprintf(fp, "%s=%d\n", TRIGGER_GAPS_COUNT, shape->gapTrackingLength);
fprintf(fp, "%s=%d\n", "isSynchronizationNeeded", shape->isSynchronizationNeeded);
for (int i = 0; i < shape->gapTrackingLength; i++) {
fprintf(fp, "%s.%d=%f\n", TRIGGER_GAP_FROM, i, shape->syncronizationRatioFrom[i]);
fprintf(fp, "%s.%d=%f\n", TRIGGER_GAP_TO, i, shape->syncronizationRatioTo[i]);
Expand All @@ -84,10 +98,12 @@ TEST_P(AllTriggersFixture, TestTrigger) {
for (size_t i = 0; i < shape->getLength(); i++) {
int triggerDefinitionCoordinate = (shape->getTriggerWaveformSynchPointIndex() + i) % shape->getSize();

fprintf(fp, "event %d %d %d %.2f\n",
fprintf(fp, "event %d %d %d %.2f %f\n",
i,
shape->triggerSignalIndeces[triggerDefinitionCoordinate],
shape->triggerSignalStates[triggerDefinitionCoordinate],
triggerFormDetails->eventAngles[i]);
triggerFormDetails->eventAngles[i],
initState.gapRatio[i]
);
}
}
Loading

0 comments on commit def809a

Please sign in to comment.