Bug fix in CalculateDivTransitionTime( ), div. transition time stored in results, DiverterTestSeq calculates average transition time.

This commit is contained in:
Milan Hanajik
2021-04-13 23:34:06 +02:00
parent 8b8198e298
commit 39197ddd71
2 changed files with 37 additions and 8 deletions
+17 -7
View File
@@ -76,8 +76,15 @@ namespace TBF.Rig.ControlBoard.Uni
if (Diverter != null && StateMachine.Time <= DiverterAssociationValidUntil)
{
data.TransitionTime_ms = Const.DivTimeResolution * CalculateDivTransitionTime(data.Samples, Diverter.ThresholdLo, Diverter.ThresholdHi);
log.DebugFormat("{0} transition time = {1} ms", Diverter.Name, data.TransitionTime_ms);
log.InfoFormat("{0} transition time = {1} ms", Diverter.Name, data.TransitionTime_ms);
if (ToTank)
{
if (Diverter != null && Diverter.SwitchTimeStart != null) Diverter.SwitchTimeStart.Val = data.TransitionTime_ms / 1000.0f;
}
else
{
if (Diverter != null && Diverter.SwitchTimeEnd != null) Diverter.SwitchTimeEnd.Val = data.TransitionTime_ms / 1000.0f;
}
if (Plotter != null)
{
@@ -115,29 +122,29 @@ namespace TBF.Rig.ControlBoard.Uni
int transitionStartIdx = 0;
int transitionEndIdx = 0;
int level = samples[0];
int level = 4*samples[0];
for (int i = 1; i < SamplesCount; i++)
{
if (!startedRising && !startedFalling)
{
if (level <= thresholdLo && samples[i] > thresholdLo)
if (level <= thresholdLo && 4*samples[i] > thresholdLo)
{
transitionStartIdx = i;
startedRising = true;
}
else if (level >= thresholdHi && samples[i] < thresholdHi)
else if (level >= thresholdHi && 4*samples[i] < thresholdHi)
{
transitionStartIdx = i;
startedFalling = true;
}
}
else if (startedRising && !stopped && level < thresholdHi && samples[i] >= thresholdHi)
else if (startedRising && !stopped && level < thresholdHi && 4*samples[i] >= thresholdHi)
{
transitionEndIdx = i;
stopped = true;
break;
}
else if (startedFalling && !stopped && level > thresholdLo && samples[i] <= thresholdLo)
else if (startedFalling && !stopped && level > thresholdLo && 4*samples[i] <= thresholdLo)
{
transitionEndIdx = i;
stopped = true;
@@ -145,6 +152,9 @@ namespace TBF.Rig.ControlBoard.Uni
}
}
log.DebugFormat("CalculateDivTransitionTime() ... thresholdLo={0} thresholdHi={1} startIx={2} endIx={3} time = {4} ms",
thresholdLo, thresholdHi, transitionStartIdx, transitionEndIdx, 2 * (transitionEndIdx - transitionStartIdx));
return transitionEndIdx - transitionStartIdx;
}
}