iPerlHead : iPerl flow direction detection fine tuning, ver. 2.18.1086

This commit is contained in:
Milan Hanajik 2018-12-04 10:06:10 +01:00
parent 0e37e7217d
commit 70f3dbbf5d
3 changed files with 18 additions and 20 deletions

View File

@ -8,14 +8,16 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
{
public class FlowDirectionDetection
{
readonly int fifoSize;
const int FIFO_SIZE = 64; /// 8 sec. @ 8Hz
const double MAX_OPTO_DROPOUT = 4.5; /// sec.
Int64[] volumeRawFifo; /// Volume FIFO buffer
Int64[] timestampFifo; /// Timestamp FIFO buffer
int fifoCount; /// Number of valid FIFO items
int fifoIx; /// Index of the next FIFO item
DateTime lastFifoWriteTime; /// Time of the last write to FIFO
Int64[] volumeRawFifo; /// Volume FIFO buffer
Int64[] timestampFifo; /// Timestamp FIFO buffer
int fifoCount; /// Number of valid FIFO items
int fifoIx; /// Index of the next FIFO item
DateTime lastFifoWriteTime; /// Time of the last write to FIFO
///
/// Sums for linear regression calculation
@ -26,11 +28,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
decimal sumY;
decimal N;
public FlowDirectionDetection(int fifoSize)
public FlowDirectionDetection()
{
this.fifoSize = fifoSize;
volumeRawFifo = new Int64[fifoSize];
timestampFifo = new Int64[fifoSize];
volumeRawFifo = new Int64[FIFO_SIZE];
timestampFifo = new Int64[FIFO_SIZE];
ClearFifo();
}
@ -62,7 +63,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
///
/// Update sums for linear regression calculation
///
if (fifoCount == fifoSize)
if (fifoCount == FIFO_SIZE)
{
/// Buffer is already full, the oldest item will be re-written
sumXX -= timestampFifo[fifoIx] * timestampFifo[fifoIx];
@ -82,8 +83,8 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
///
volumeRawFifo[fifoIx] = volumeRaw;
timestampFifo[fifoIx] = timestamp;
fifoIx = (fifoIx + 1) % fifoSize;
fifoCount = Math.Min(fifoCount + 1, fifoSize);
fifoIx = (fifoIx + 1) % FIFO_SIZE;
fifoCount = Math.Min(fifoCount + 1, FIFO_SIZE);
lastFifoWriteTime = DateTime.Now;
}
@ -94,7 +95,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
/// <returns>true when data valid</returns>
public bool AreFifoDataValid()
{
return (DateTime.Now.Subtract(lastFifoWriteTime).TotalSeconds <= 2.5) && (fifoCount == fifoSize);
return (DateTime.Now.Subtract(lastFifoWriteTime).TotalSeconds <= MAX_OPTO_DROPOUT) && (fifoCount == FIFO_SIZE);
}

View File

@ -24,8 +24,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
private static readonly ILog log = LogManager.GetLogger(typeof(IperlHead));
public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); }
const int FifoSize = 32; /// 4s @ 8Hz
readonly IperlHeadCfg iperlHeadCfg;
public int RfidComPortNr { get { return iperlHeadCfg.RfidComPortNr; } }
@ -354,7 +352,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
///
/// Timestamp from the opto telegram
///
bool lastTimestampValid;
private Int64 lastTimestamp;
private double timestampSec;
private double timestampSec0;
@ -393,7 +390,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
public IperlHead(Generic.IComponentCfg cfg)
: base(cfg)
{
flowDirectionDetection = new FlowDirectionDetection(FifoSize);
flowDirectionDetection = new FlowDirectionDetection();
ClearData();

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.18.1085.0")]
[assembly: AssemblyFileVersion("2.18.1085.0")]
[assembly: AssemblyVersion("2.18.1086.0")]
[assembly: AssemblyFileVersion("2.18.1086.0")]