From 18a00b2a6e6fb94e98ad15d3645c61c710f65aa0 Mon Sep 17 00:00:00 2001 From: Nolan Date: Tue, 19 Jul 2022 13:57:32 -0400 Subject: [PATCH] Added estimated record time field to both the IMU datalogging forms. This field uses the measured data ready frequency and the number of requested samples to estimate the capture duration --- src/IMUStreamingGUI.designer.vb | 45 +++++++++++++++++++------ src/IMUStreamingGUI.vb | 36 ++++++++++++++++++-- src/RegisterBulkReadGUI.designer.vb | 25 ++++++++++++++ src/RegisterBulkReadGUI.vb | 52 +++++++++++++++++++---------- 4 files changed, 128 insertions(+), 30 deletions(-) diff --git a/src/IMUStreamingGUI.designer.vb b/src/IMUStreamingGUI.designer.vb index 891c20f..3608f5d 100644 --- a/src/IMUStreamingGUI.designer.vb +++ b/src/IMUStreamingGUI.designer.vb @@ -43,6 +43,8 @@ Partial Class IMUStreamingGUI Me.radio_32bit = New System.Windows.Forms.RadioButton() Me.radio_16bit = New System.Windows.Forms.RadioButton() Me.check_checksum = New System.Windows.Forms.CheckBox() + Me.Label2 = New System.Windows.Forms.Label() + Me.lab_recTime = New System.Windows.Forms.Label() Me.group_config.SuspendLayout() Me.panel_dataformat.SuspendLayout() Me.panel_wordsize.SuspendLayout() @@ -94,14 +96,14 @@ Partial Class IMUStreamingGUI ' 'text_numSamples ' - Me.text_numSamples.Location = New System.Drawing.Point(93, 194) + Me.text_numSamples.Location = New System.Drawing.Point(97, 194) Me.text_numSamples.Name = "text_numSamples" - Me.text_numSamples.Size = New System.Drawing.Size(99, 20) + Me.text_numSamples.Size = New System.Drawing.Size(94, 20) Me.text_numSamples.TabIndex = 23 ' 'btn_cancel ' - Me.btn_cancel.Location = New System.Drawing.Point(106, 220) + Me.btn_cancel.Location = New System.Drawing.Point(106, 248) Me.btn_cancel.Name = "btn_cancel" Me.btn_cancel.Size = New System.Drawing.Size(86, 30) Me.btn_cancel.TabIndex = 22 @@ -110,7 +112,7 @@ Partial Class IMUStreamingGUI ' 'btn_start ' - Me.btn_start.Location = New System.Drawing.Point(12, 220) + Me.btn_start.Location = New System.Drawing.Point(12, 248) Me.btn_start.Name = "btn_start" Me.btn_start.Size = New System.Drawing.Size(86, 30) Me.btn_start.TabIndex = 21 @@ -121,7 +123,7 @@ Partial Class IMUStreamingGUI ' Me.burstRegList.Location = New System.Drawing.Point(201, 12) Me.burstRegList.Name = "burstRegList" - Me.burstRegList.Size = New System.Drawing.Size(207, 314) + Me.burstRegList.Size = New System.Drawing.Size(207, 342) Me.burstRegList.TabIndex = 20 Me.burstRegList.UseCompatibleStateImageBehavior = False ' @@ -130,7 +132,7 @@ Partial Class IMUStreamingGUI Me.statusLabel.BackColor = System.Drawing.SystemColors.ButtonHighlight Me.statusLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.statusLabel.ForeColor = System.Drawing.SystemColors.ControlText - Me.statusLabel.Location = New System.Drawing.Point(55, 262) + Me.statusLabel.Location = New System.Drawing.Point(55, 290) Me.statusLabel.Name = "statusLabel" Me.statusLabel.Size = New System.Drawing.Size(137, 20) Me.statusLabel.TabIndex = 30 @@ -140,7 +142,7 @@ Partial Class IMUStreamingGUI 'Label6 ' Me.Label6.AutoSize = True - Me.Label6.Location = New System.Drawing.Point(9, 266) + Me.Label6.Location = New System.Drawing.Point(9, 294) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(43, 13) Me.Label6.TabIndex = 29 @@ -149,7 +151,7 @@ Partial Class IMUStreamingGUI 'Label1 ' Me.Label1.AutoSize = True - Me.Label1.Location = New System.Drawing.Point(9, 292) + Me.Label1.Location = New System.Drawing.Point(9, 320) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(91, 13) Me.Label1.TabIndex = 32 @@ -157,7 +159,7 @@ Partial Class IMUStreamingGUI ' 'CaptureProgressBurst ' - Me.CaptureProgressBurst.Location = New System.Drawing.Point(12, 308) + Me.CaptureProgressBurst.Location = New System.Drawing.Point(12, 336) Me.CaptureProgressBurst.Name = "CaptureProgressBurst" Me.CaptureProgressBurst.Size = New System.Drawing.Size(180, 18) Me.CaptureProgressBurst.TabIndex = 31 @@ -256,11 +258,32 @@ Partial Class IMUStreamingGUI Me.check_checksum.Text = "Burst Checksum" Me.check_checksum.UseVisualStyleBackColor = True ' + 'Label2 + ' + Me.Label2.AutoSize = True + Me.Label2.Location = New System.Drawing.Point(9, 225) + Me.Label2.Name = "Label2" + Me.Label2.Size = New System.Drawing.Size(82, 13) + Me.Label2.TabIndex = 36 + Me.Label2.Text = "Rec. Time (est):" + ' + 'lab_recTime + ' + Me.lab_recTime.BackColor = System.Drawing.SystemColors.Window + Me.lab_recTime.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle + Me.lab_recTime.Location = New System.Drawing.Point(97, 221) + Me.lab_recTime.Name = "lab_recTime" + Me.lab_recTime.Size = New System.Drawing.Size(95, 20) + Me.lab_recTime.TabIndex = 37 + Me.lab_recTime.TextAlign = System.Drawing.ContentAlignment.MiddleLeft + ' 'IMUStreamingGUI ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(420, 338) + Me.ClientSize = New System.Drawing.Size(420, 362) + Me.Controls.Add(Me.lab_recTime) + Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.group_config) Me.Controls.Add(Me.check_drActive) Me.Controls.Add(Me.Label1) @@ -311,4 +334,6 @@ Partial Class IMUStreamingGUI Friend WithEvents radio_32bit As RadioButton Friend WithEvents panel_dataformat As Panel Friend WithEvents panel_wordsize As Panel + Friend WithEvents Label2 As Label + Friend WithEvents lab_recTime As Label End Class diff --git a/src/IMUStreamingGUI.vb b/src/IMUStreamingGUI.vb index b16173a..68618c2 100644 --- a/src/IMUStreamingGUI.vb +++ b/src/IMUStreamingGUI.vb @@ -14,6 +14,8 @@ Public Class IMUStreamingGUI Private WithEvents fileManager As Logger Private manager As BurstManager Private initialized As Boolean = False + Private totalDRCaptures As Integer = 0 + Private measuredDrFreq As Double = Double.PositiveInfinity ''' ''' Load the application @@ -136,7 +138,7 @@ Public Class IMUStreamingGUI fileManager.RegList = manager.BurstRegisters fileManager.FileBaseName = m_TopGUI.SelectedPersonality + "_Burst" + timeString fileManager.FilePath = savePath - fileManager.Buffers = Convert.ToUInt32(text_numSamples.Text) + fileManager.Buffers = totalDRCaptures fileManager.Captures = 1 'Number of times to read each register in the reg map fileManager.FileMaxDataRows = 1000000 'Keep this under 1M samples to open in Excel fileManager.BufferTimeoutSeconds = 10 'Timeout in seconds @@ -201,7 +203,7 @@ Public Class IMUStreamingGUI ''' ''' Private Sub MeasureDR_Click(sender As Object, e As EventArgs) Handles btn_measureDR.Click - label_measuredFreq.Text = FormatNumber(m_TopGUI.FX3.ReadDRFreq(m_TopGUI.FX3.DrPin, 1, 2000), 3).ToString + " Hz" + MeasureDrFreq(2000) End Sub ''' @@ -242,6 +244,11 @@ Public Class IMUStreamingGUI ''' Private Sub check_drActive_CheckedChanged(sender As Object, e As EventArgs) Handles check_drActive.CheckedChanged m_TopGUI.FX3.DrActive = check_drActive.Checked + If check_drActive.Checked Then + MeasureDrFreq(500) + Else + UpdateRecordTimeEstimate() + End If End Sub ''' @@ -252,11 +259,13 @@ Public Class IMUStreamingGUI Private Sub text_numSamples_TextChanged(sender As Object, e As EventArgs) Handles text_numSamples.TextChanged 'Check DR capture input Try - Convert.ToInt32(text_numSamples.Text) + totalDRCaptures = Convert.ToInt32(text_numSamples.Text) Catch ex As Exception MsgBox("ERROR: Invalid Input") text_numSamples.Text = "10000" + totalDRCaptures = 10000 End Try + UpdateRecordTimeEstimate() End Sub ''' @@ -269,6 +278,12 @@ Public Class IMUStreamingGUI #Region "Helper Functions" + Private Sub MeasureDrFreq(timeout As Integer) + measuredDrFreq = m_TopGUI.FX3.ReadDRFreq(m_TopGUI.FX3.DrPin, 1, 2000) + label_measuredFreq.Text = FormatNumber(measuredDrFreq, 3).ToString + " Hz" + UpdateRecordTimeEstimate() + End Sub + ''' ''' Clean up after a burst read capture has completed ''' @@ -322,6 +337,21 @@ Public Class IMUStreamingGUI Next End Sub + Private Sub UpdateRecordTimeEstimate() + If check_drActive.Checked Then + If Not Double.IsPositiveInfinity(measuredDrFreq) Then + Dim seconds As Integer = 0 + seconds = totalDRCaptures / measuredDrFreq + Dim span As TimeSpan = TimeSpan.FromSeconds(seconds) + lab_recTime.Text = New DateTime(span.Ticks).ToString("HH:mm:ss") + Else + lab_recTime.Text = "No data ready detected" + End If + Else + lab_recTime.Text = "Async Capture" + End If + End Sub + #End Region End Class \ No newline at end of file diff --git a/src/RegisterBulkReadGUI.designer.vb b/src/RegisterBulkReadGUI.designer.vb index 658bfcf..541c6c1 100644 --- a/src/RegisterBulkReadGUI.designer.vb +++ b/src/RegisterBulkReadGUI.designer.vb @@ -48,6 +48,8 @@ Partial Class RegisterBulkReadGUI Me.ValidateDR = New System.Windows.Forms.CheckBox() Me.Label4 = New System.Windows.Forms.Label() Me.fileBaseName = New System.Windows.Forms.TextBox() + Me.Label8 = New System.Windows.Forms.Label() + Me.label_recTime = New System.Windows.Forms.Label() Me.SuspendLayout() ' 'Label1 @@ -291,11 +293,32 @@ Partial Class RegisterBulkReadGUI Me.fileBaseName.TabIndex = 101 Me.fileBaseName.Text = "RegStream" ' + 'Label8 + ' + Me.Label8.AutoSize = True + Me.Label8.Location = New System.Drawing.Point(9, 341) + Me.Label8.Name = "Label8" + Me.Label8.Size = New System.Drawing.Size(104, 13) + Me.Label8.TabIndex = 103 + Me.Label8.Text = "# Record Time (est):" + ' + 'label_recTime + ' + Me.label_recTime.BackColor = System.Drawing.SystemColors.Window + Me.label_recTime.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle + Me.label_recTime.Location = New System.Drawing.Point(11, 356) + Me.label_recTime.Name = "label_recTime" + Me.label_recTime.Size = New System.Drawing.Size(111, 21) + Me.label_recTime.TabIndex = 104 + Me.label_recTime.TextAlign = System.Drawing.ContentAlignment.MiddleLeft + ' 'RegisterBulkReadGUI ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(444, 566) + Me.Controls.Add(Me.label_recTime) + Me.Controls.Add(Me.Label8) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.fileBaseName) Me.Controls.Add(Me.ValidateDR) @@ -356,4 +379,6 @@ Partial Class RegisterBulkReadGUI Friend WithEvents ValidateDR As CheckBox Friend WithEvents Label4 As Label Friend WithEvents fileBaseName As TextBox + Friend WithEvents Label8 As Label + Friend WithEvents label_recTime As Label End Class diff --git a/src/RegisterBulkReadGUI.vb b/src/RegisterBulkReadGUI.vb index 8f7fab5..74783ba 100644 --- a/src/RegisterBulkReadGUI.vb +++ b/src/RegisterBulkReadGUI.vb @@ -14,6 +14,7 @@ Public Class RegisterBulkReadGUI Private WithEvents fileManager As Logger Private totalDRCaptures As Integer = 0 + Private measuredDrFreq As Double = Double.PositiveInfinity Public Sub FormSetup() Handles Me.Load @@ -153,13 +154,9 @@ Public Class RegisterBulkReadGUI Private Sub MainButton_Click(sender As Object, e As EventArgs) Handles MainButton.Click Dim savePath As String - Dim MeasuredFreq As Double = Double.PositiveInfinity Dim timeString As String = "_" + DateTime.Now().ToString("s") timeString = timeString.Replace(":", "-") - 'Update the data ready pin and measurement - UpdateDRPin() - 'Check whether user selected registers to stream If selectedRegview.Items.Count <= 0 Then MessageBox.Show("Please select registers to stream before starting", "No registers selected!", MessageBoxButtons.OK) @@ -175,10 +172,9 @@ Public Class RegisterBulkReadGUI 'Check whether the measured DR is valid If m_TopGUI.FX3.DrActive And ValidateDR.Checked Then 'measure data ready frequency - MeasuredFreq = m_TopGUI.FX3.MeasurePinFreq(m_TopGUI.FX3.DrPin, 1, 10000, 2) - DrFreq.Text = FormatNumber(MeasuredFreq, 3).ToString() + "Hz" + MeasureDrFreq(10000) 'allow a freq up to 16KHz - If MeasuredFreq > 16000 Or MeasuredFreq = Double.PositiveInfinity Then + If measuredDrFreq > 16000 Or measuredDrFreq = Double.PositiveInfinity Then If MessageBox.Show("Data ready frequency measured invalid. Continue?", "Invalid Data Ready!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) <> DialogResult.OK Then Exit Sub End If @@ -193,7 +189,7 @@ Public Class RegisterBulkReadGUI 'Check the time it will take to capture each frame and ask the user if it exceeds the DR period If m_TopGUI.FX3.DrActive And ValidateDR.Checked Then - Dim drPeriod As Double = 1 / MeasuredFreq + Dim drPeriod As Double = 1 / measuredDrFreq Dim num16bitregs As Integer = 0 For Each reg In regList If reg.NumBytes = 1 Or reg.NumBytes = 2 Then @@ -306,8 +302,7 @@ Public Class RegisterBulkReadGUI End Sub Private Sub MeasureDR_Click(sender As Object, e As EventArgs) Handles MeasureDR.Click - UpdateDRPin() - DrFreq.Text = FormatNumber(m_TopGUI.FX3.MeasurePinFreq(m_TopGUI.FX3.DrPin, 1, 5000, 2), 3).ToString + " Hz" + MeasureDrFreq(5000) End Sub Private Sub UpdateDRPin() @@ -335,7 +330,7 @@ Public Class RegisterBulkReadGUI End If End Sub - Private Sub UpdateGUI() + Private Sub NumberDRToCapture_TextChanged(sender As Object, e As EventArgs) Handles NumberDRToCapture.TextChanged 'Check DR capture input If NumberDRToCapture.Text = "" Then NumberDRToCapture.Text = 0 @@ -346,17 +341,18 @@ Public Class RegisterBulkReadGUI MsgBox("ERROR: Invalid Input") Exit Sub End Try - End Sub - - Private Sub NumberDRToCapture_TextChanged(sender As Object, e As EventArgs) Handles NumberDRToCapture.TextChanged - UpdateGUI() + UpdateRecordTimeEstimate() End Sub Private Sub DrActiveBox_CheckedChanged(sender As Object, e As EventArgs) Handles DrActiveBox.CheckedChanged m_TopGUI.FX3.DrActive = DrActiveBox.Checked - MeasureDR.Enabled = m_TopGUI.FX3.DrActive - ValidateDR.Enabled = m_TopGUI.FX3.DrActive + MeasureDR.Enabled = DrActiveBox.Checked + ValidateDR.Enabled = DrActiveBox.Checked ValidateDR.Checked = DrActiveBox.Checked + If DrActiveBox.Checked Then + MeasureDrFreq(500) + End If + UpdateRecordTimeEstimate() End Sub Private Sub btn_loadregs_Click(sender As Object, e As EventArgs) Handles btn_loadregs.Click @@ -405,4 +401,26 @@ Public Class RegisterBulkReadGUI End Sub + Private Sub MeasureDrFreq(timeout As Integer) + UpdateDRPin() + measuredDrFreq = m_TopGUI.FX3.MeasurePinFreq(m_TopGUI.FX3.DrPin, 1, timeout, 2) + DrFreq.Text = FormatNumber(measuredDrFreq, 3).ToString + " Hz" + UpdateRecordTimeEstimate() + End Sub + + Private Sub UpdateRecordTimeEstimate() + If DrActiveBox.Checked Then + If Not Double.IsPositiveInfinity(measuredDrFreq) Then + Dim seconds As Integer = 0 + seconds = totalDRCaptures / measuredDrFreq + Dim span As TimeSpan = TimeSpan.FromSeconds(seconds) + label_recTime.Text = New DateTime(span.Ticks).ToString("HH:mm:ss") + Else + label_recTime.Text = "No data ready detected" + End If + Else + label_recTime.Text = "Async Capture" + End If + End Sub + End Class \ No newline at end of file