From 6d45b2c8783427a5e70030d7e5aa4585fc4b19a8 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 16 Jan 2017 15:51:34 +0100 Subject: [PATCH] RoiDetectionSeq modified, ready to be tested. --- .../BenchControl/GenericDevices/ICamera.cs | 6 + .../GenericDevices/{ICameraRoi.cs => IRoi.cs} | 6 +- .../Network/Adapter/NetadapterCfg.cs | 2 + .../BenchControl/Network/Camera/Roi/Roi.cs | 12 +- .../TestMethods/Adjustment/AdjustmentSeq.cs | 2 +- .../CombinedWithDetectionSeq.cs | 2 +- .../TestMethods/Endurance/EnduranceSeq.cs | 2 +- .../FixedStartAdvancedSeq.cs | 2 +- .../FixedStartMassCollectionSeq.cs | 2 +- .../TestMethods/FlyingStart/FlyingStartSeq.cs | 3 +- .../FlyingStartMassCollectionSeq.cs | 2 +- .../RoiDetection/RoiDetectionSeq.cs | 106 +++++++++++++----- .../Resources/Strings.Designer.cs | 9 ++ TestBenchFramework/Resources/Strings.de.resx | 3 + TestBenchFramework/Resources/Strings.resx | 3 + TestBenchFramework/TBF.csproj | 2 +- 16 files changed, 120 insertions(+), 44 deletions(-) rename TestBenchFramework/BenchControl/GenericDevices/{ICameraRoi.cs => IRoi.cs} (86%) diff --git a/TestBenchFramework/BenchControl/GenericDevices/ICamera.cs b/TestBenchFramework/BenchControl/GenericDevices/ICamera.cs index 9d2c8ac8c..8054f2622 100644 --- a/TestBenchFramework/BenchControl/GenericDevices/ICamera.cs +++ b/TestBenchFramework/BenchControl/GenericDevices/ICamera.cs @@ -23,5 +23,11 @@ namespace TBF.BenchControl.GenericDevices /// /// Reference to operation object instance IOperation LiveStreamOp(bool hiRes); + + /// + /// Watermeter wheel/arrow angle measurement process. + /// + /// Reference to operation object instance + IOperation MeasurementOp(); } } diff --git a/TestBenchFramework/BenchControl/GenericDevices/ICameraRoi.cs b/TestBenchFramework/BenchControl/GenericDevices/IRoi.cs similarity index 86% rename from TestBenchFramework/BenchControl/GenericDevices/ICameraRoi.cs rename to TestBenchFramework/BenchControl/GenericDevices/IRoi.cs index 6b75f61cc..4a739a094 100644 --- a/TestBenchFramework/BenchControl/GenericDevices/ICameraRoi.cs +++ b/TestBenchFramework/BenchControl/GenericDevices/IRoi.cs @@ -5,10 +5,12 @@ using TBF.BenchControl.Generic; namespace TBF.BenchControl.GenericDevices { - public interface ICameraRoi : IComponent, IRegisterReader + public interface IRoi : IComponent, IRegisterReader { GenericDevices.ICamera Camera { get; } - + + bool Detected { get; set; } + /// /// Watermeter wheel/arrow detection process. /// diff --git a/TestBenchFramework/BenchControl/Network/Adapter/NetadapterCfg.cs b/TestBenchFramework/BenchControl/Network/Adapter/NetadapterCfg.cs index b4563dfeb..819f70119 100644 --- a/TestBenchFramework/BenchControl/Network/Adapter/NetadapterCfg.cs +++ b/TestBenchFramework/BenchControl/Network/Adapter/NetadapterCfg.cs @@ -24,6 +24,8 @@ namespace TBF.BenchControl.Network.Adapter Name = name; Factory = factory; ParentName = string.Empty; + TftpServerEnabled = true; + TftpServerDirectory = "C:\\TBF\\TftpRoot"; } public string ToString(int i) diff --git a/TestBenchFramework/BenchControl/Network/Camera/Roi/Roi.cs b/TestBenchFramework/BenchControl/Network/Camera/Roi/Roi.cs index cbccdd8cf..4c18b5ff5 100644 --- a/TestBenchFramework/BenchControl/Network/Camera/Roi/Roi.cs +++ b/TestBenchFramework/BenchControl/Network/Camera/Roi/Roi.cs @@ -9,7 +9,7 @@ using Config.Entities; namespace TBF.BenchControl.Network.Camera.Roi { - public class Roi : ComponentBase, GenericDevices.ICameraRoi, IOperation + public class Roi : ComponentBase, GenericDevices.IRoi, IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(Roi)); public override string ToString() @@ -44,7 +44,13 @@ namespace TBF.BenchControl.Network.Camera.Roi /// /// Roi specific /// - public bool Detected; + public bool Detected + { + get { return Detected; } + set { Detected = value; } + } + bool detected; + /// public Boxes.IntBox RoiX; public Boxes.IntBox RoiY; public Boxes.IntBox RoiWid; @@ -65,7 +71,7 @@ namespace TBF.BenchControl.Network.Camera.Roi PreviousRoi = TbfComponents.FindComponent(roiCfg.PreviousRoi, components) as Roi; - Detected = false; + detected = false; RoiX = new Boxes.IntBox(); RoiY = new Boxes.IntBox(); RoiWid = new Boxes.IntBox(); diff --git a/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs b/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs index ed35ef1e3..8d330b62c 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs @@ -175,7 +175,7 @@ namespace TBF.BenchControl.TestMethods.Adjustment IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs index f6862f83a..2080f1865 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs @@ -180,7 +180,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/EnduranceSeq.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/EnduranceSeq.cs index e63722d5b..9185c60d5 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Endurance/EnduranceSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/EnduranceSeq.cs @@ -153,7 +153,7 @@ namespace TBF.BenchControl.TestMethods.Endurance IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs index a1e7f5915..0339ef8f2 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartAdvanced/FixedStartAdvancedSeq.cs @@ -212,7 +212,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartAdvanced IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs index 556c52762..ab0c1facc 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs @@ -287,7 +287,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs index b72d1c10f..50c14458c 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs @@ -157,7 +157,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStart if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } - } while (e.Contains(Event.ValvesBusy) || !e.Contains(Event.AllPositionsReached)); @@ -248,7 +247,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStart IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs index 2f5aad799..bdc26d414 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs @@ -348,7 +348,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection IList measureOperations = new List(); for (int i = 0; i < sensPath.RegisterReaders.Length; i++) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; + GenericDevices.IRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.IRoi; if (cameraRoi != null) measureOperations.Add(cameraRoi.MeasurementOp()); } diff --git a/TestBenchFramework/BenchControl/TestMethods/RoiDetection/RoiDetectionSeq.cs b/TestBenchFramework/BenchControl/TestMethods/RoiDetection/RoiDetectionSeq.cs index 65b21e375..c4ddc0f16 100644 --- a/TestBenchFramework/BenchControl/TestMethods/RoiDetection/RoiDetectionSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/RoiDetection/RoiDetectionSeq.cs @@ -27,12 +27,17 @@ namespace TBF.BenchControl.TestMethods.RoiDetection checkUiOp = new Operations.CheckUIOp(true); processDataLoggingOp = null; - //==================================== - /// Start the test, initialize test results - Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, 1, inPath, benchPath, outPath, sensPath, 0)); - TestResult tstRslt = new TestResult(test, 1, MetersKind.Single); - tstRslt.DoNotEvaluate = true; - tstRslt.DoNotPublish = true; + + /// LtrPerRefPulse and totalPulses are only to make time estimates + LtrPerRefPulse = outPath.FlowMeter.LtrPerPulse; /// [ltr/pulse], nominal flow in [m3/h] + /// Notes: + /// float timeHr = volumeLtr / (1000.0f * targetFlow); + /// float timeSec = 3600.0f * timeHr; + /// int refPulses = (int)(timeSec * (2000.0f * targetFlow / pOut.FlowMeter.NominalFlow)); + int totalPulses = (int)(test.Volume / LtrPerRefPulse + 0.5f); + + + int repetitionNr = outerLoopMode ? outerLoopCounter : 1; /// First test: repetitionNr=1 //==================================== @@ -40,26 +45,42 @@ namespace TBF.BenchControl.TestMethods.RoiDetection //==================================== switch (Transition(transitionBefore, TransitionContext.BeforeTest)) { - case Event.Error: { retVal = Event.Error; goto stopTest; } - case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } } + //==================== + // Start the test + //==================== + Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, totalPulses)); + string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); + TestStartTime = DateTime.Now; + TestProgressEventArgs.SetEstimatedTimes(new int[] { 1, 1, 1, 30, Convert.ToInt32(test.TstTime) + 15, 0, 0 }); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.JustStarted)); + //------------------------------------------------ - Bridge.OnActivity(this, Strings.Setting_the_flow); + Bridge.OnActivity(this, Strings.Starting_the_pump); //------------------------------------------------ + /// if (inPath.Pump is GenericDevices.IPumpFM) (inPath.Pump as GenericDevices.IPumpFM).TurnOn(test.PumpPower); State.Create("RoiDetection : Starting the pump") .AddOperation(checkUiOp) - .AddOperation(cBrd.SetValvesOp(inPath.Pump, null)) + .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) + .AddOperation(inPath.Pump != null ? cBrd.SetValvesOp(inPath.Pump, null) : null) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); - if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } - } - while (!e.Contains(Event.ValvesSet)); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); - //-------------------------------- + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } + } + while (e.Contains(Event.ValvesBusy)); + + //------------------------------------------------ + Bridge.OnActivity(this, Strings.Setting_the_flow); + //------------------------------------------------ State.Create("RoiDetection : Setting the flow") .AddOperation(checkUiOp) .AddOperation(outPath.RegulValve.SetFlowOp(outPath.FlowMeter, test.Qfrom, test.Qto, outPath.PidCoef, RefFlow, 600)) /// timeout = 10 min. @@ -67,9 +88,10 @@ namespace TBF.BenchControl.TestMethods.RoiDetection do { e = StateMachine.WaitRunDevsRunOps(); + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); - if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } - if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } + if (e.Contains(Event.OpArgumentError)) { retVal = Event.OpArgumentError; goto stopTest; } + if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } if (e.Contains(Event.RegulValveTimeOut)) { Bridge.OnError(this, Strings.Timeout); @@ -81,27 +103,36 @@ namespace TBF.BenchControl.TestMethods.RoiDetection while (!e.Contains(Event.FlowReached)); flow_set: + int time = StateMachine.Time; double currentFlow = RefFlow.Val; + foreach (var rr in sensPath.RegisterReaders) + { + if (rr is GenericDevices.IRoi) (rr as GenericDevices.IRoi).Detected = false; + } + + detection_loop: + //------------------------------------------------ Bridge.OnActivity(this, Strings.ROI_Detection_in_Progress); //------------------------------------------------ State detection = State.Create("RoiDetection : Detection of ROI-s") .AddOperation(checkUiOp); - /// Extract cameras from the current sensors path, add operations to the detection state - for (int i = 0; i < sensPath.RegisterReaders.Length; i++) + foreach (var rr in sensPath.RegisterReaders) { - GenericDevices.ICameraRoi cameraRoi = sensPath.RegisterReaders[i] as GenericDevices.ICameraRoi; - if (cameraRoi != null) - { - detection.AddOperation(cameraRoi.RoiDetectionOp()); - } - } + if (rr is GenericDevices.IRoi && !(rr as GenericDevices.IRoi).Detected) + { + detection.AddOperation((rr as GenericDevices.IRoi).RoiDetectionOp()); + } + } detection.EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Test)); + if (e.Contains(Event.Error)) { retVal = Event.Error; @@ -111,23 +142,36 @@ namespace TBF.BenchControl.TestMethods.RoiDetection } while (e.Contains(Event.CameraBusy)); - if (e.Contains(Event.CameraOpFailed)) + + if (e.Contains(Event.RoiDetectionPreviousFailed)) { retVal = Event.Error; Bridge.OnActivity(this, Strings.Camera_error); - goto stopTest; } else if (e.Contains(Event.RoiDetectionFailed)) { retVal = Event.Error; Bridge.OnActivity(this, Strings.Detection_failed); - goto stopTest; - } + State.Create("RoiDetection : Do you want to retry RoI detection?") + .AddOperation(checkUiOp) + .AddOperation(new Operations.AskYesNoOp(Strings.Do_you_want_to_retry_RoI_detection)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + + while (!e.Contains(Event.Yes)) goto detection_loop; + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopTest; } + } + while (!e.Contains(Event.No)); + } //------------------------------------------------ Bridge.OnActivity(this, Strings.Detection_completed); //------------------------------------------------ + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.TransitionAfter)); + stopTest: ///----------------------/// @@ -141,8 +185,8 @@ namespace TBF.BenchControl.TestMethods.RoiDetection do { e = StateMachine.WaitRunDevsRunOps(); - if (TestAndLogUiCmdStop(test,e)) { retVal = Event.UiCmdStop; goto stopTest; } - } + if (TestAndLogUiCmdStop(test, e)) { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } + } while (!e.Contains(Event.PreviousStopped)); /// Transition sequence at the end of test @@ -153,6 +197,8 @@ namespace TBF.BenchControl.TestMethods.RoiDetection case Event.UiCmdStop: { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } } + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed)); + /// Create a list with one item 'retVal' (default is Event.Done) and return it IList retList = new List(1); retList.Add(retVal); diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index e2cc21991..bc92ee20f 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -1032,6 +1032,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Do you want to retry RoI detection?. + /// + internal static string Do_you_want_to_retry_RoI_detection { + get { + return ResourceManager.GetString("Do_you_want_to_retry_RoI_detection", resourceCulture); + } + } + /// /// Looks up a localized string similar to Do you want to save changes?. /// diff --git a/TestBenchFramework/Resources/Strings.de.resx b/TestBenchFramework/Resources/Strings.de.resx index bc2b1e625..fde883d9d 100644 --- a/TestBenchFramework/Resources/Strings.de.resx +++ b/TestBenchFramework/Resources/Strings.de.resx @@ -1380,4 +1380,7 @@ Fehler beim Gerätstart {0}{1}{2} + + Möchten Sie die RoI-Erkennung erneut versuchen? + \ No newline at end of file diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index 6448eaa0e..c66b41908 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1630,4 +1630,7 @@ Failed to initialize component {0}\r\n{1} + + Do you want to retry RoI detection? + \ No newline at end of file diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index e091a0171..1546837eb 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -1032,7 +1032,7 @@ - +