From bc5579bd6fd1765c01c2b9b9433c91ec6ae262c1 Mon Sep 17 00:00:00 2001 From: doluk <69309597+doluk@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:15:56 +0100 Subject: [PATCH 1/3] Ensure more accurate speedsteps for complex data Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> --- utils/us_simparms.cpp | 81 ++++++++++--------------------------------- 1 file changed, 18 insertions(+), 63 deletions(-) diff --git a/utils/us_simparms.cpp b/utils/us_simparms.cpp index 53bc7d1c7..d3c910317 100644 --- a/utils/us_simparms.cpp +++ b/utils/us_simparms.cpp @@ -597,74 +597,29 @@ void US_SimulationParameters::computeSpeedSteps( computeSpeedSteps( &allrData[ 0 ].scanData, speedsteps ); return; } - - // Get indexes to low and high step scan - int ndx1 = -1; - int ndx2 = -1; - double timel = 1e+20; - double timeh = -1e+20; - - for ( int ii = 0; ii < allrData.count(); ii++ ) - { - int ls = allrData[ ii ].scanCount() - 1; - double time1 = allrData[ ii ].scanData[ 0 ].seconds; - double time2 = allrData[ ii ].scanData[ ls ].seconds; - - if ( time1 < timel ) - { // Accumulate low scan time - timel = time1; // Lowest scan time - ndx1 = ii; // Triple to which it belongs - } - - if ( time2 > timeh ) - { // Accumulate high scan time - timeh = time2; // High scan time - ndx2 = ii; // Triple to which it belongs + QVector scans; + QVector times; + + for ( int ii = 0; ii < allrData.count(); ii++ ) { + for ( int jj = 0; jj < allrData[ii].scanCount(); jj++ ) { + if ( !times.contains(allrData[ii].scanData[jj].seconds) ) { + scans << allrData[ii].scanData[jj]; + times << allrData[ii].scanData[jj].seconds; + } } } + times.clear(); - // Compute time steps for two triples at the extreme - QVector< SpeedProfile > speedstps2; - computeSpeedSteps( &allrData[ ndx1 ].scanData, speedsteps ); - computeSpeedSteps( &allrData[ ndx2 ].scanData, speedstps2 ); - - // Merge them so step time ranges cover all triples' time ranges - for ( int ii = 0; ii < speedsteps.count(); ii++ ) - { - SpeedProfile sp1 = speedsteps[ ii ]; - SpeedProfile sp2 = speedstps2[ ii ]; - double time1 = sp1.time_first; - double time2 = sp2.time_last; - double w2t1 = sp1.w2t_first; - double w2t2 = sp2.w2t_last; - double delay_secs = sp1.delay_hours * 3600.0 + - sp1.delay_minutes * 60.0; - - if ( sp2.time_first < sp1.time_first ) - { // Low time in the step and its corresponding omega2t - time1 = sp2.time_first; - w2t1 = sp2.w2t_first; - } - - if ( sp1.time_last > sp2.time_last ) - { // High time in the step and its corresponding omega2t - time2 = sp1.time_last; - w2t2 = sp1.w2t_last; + struct SortBySeconds { + bool operator()(const US_DataIO::Scan& a, const US_DataIO::Scan& b) const { + return a.seconds < b.seconds; } + }; + // Sort the scans by their respective attribute seconds + std::sort(scans.begin(), scans.end(), SortBySeconds()); - // Reset, recompute time and omega2t values for step - double step_secs = time2 - time1 + delay_secs; - sp1.duration_hours = (int)( step_secs / 3600.0 ); - sp1.duration_minutes = ( step_secs / 60.0 ) - - ( (double)sp1.duration_hours * 60.0 ); - sp1.w2t_first = w2t1; - sp1.w2t_last = w2t2; - sp1.time_first = qRound( time1 ); - sp1.time_last = qRound( time2 ); - sp1.avg_speed = ( sp1.avg_speed + sp2.avg_speed ) * 0.5; - - speedsteps[ ii ] = sp1; // Save merged speed step - } + // Compute time steps for two triples at the extreme + computeSpeedSteps( &scans, speedsteps ); } // Set parameters from hardware files, related to rotor and centerpiece From 64224c4de16c80ac4b4120a62bc0607708343240 Mon Sep 17 00:00:00 2001 From: doluk <69309597+doluk@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:16:20 +0100 Subject: [PATCH 2/3] Prevent race condition Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> --- programs/us_edit/us_edit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/us_edit/us_edit.cpp b/programs/us_edit/us_edit.cpp index a7a5246d4..98294a295 100644 --- a/programs/us_edit/us_edit.cpp +++ b/programs/us_edit/us_edit.cpp @@ -5296,7 +5296,7 @@ void US_Edit::set_data_over_lamda() { trx_b = trx; int min_xval = -100000000; int max_xval = 100000000; - int dx = -1000; + int dx = 1; for ( int jwx = 0; jwx < nwaveln; jwx++ ) { edata = &allData[ trx ]; // Triple data From 7b8ba3f8020f639727b4c94294cb423e7d7cde70 Mon Sep 17 00:00:00 2001 From: doluk <69309597+doluk@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:24:25 +0100 Subject: [PATCH 3/3] Document change Signed-off-by: doluk <69309597+doluk@users.noreply.github.com> --- programs/us_edit/us_edit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/us_edit/us_edit.cpp b/programs/us_edit/us_edit.cpp index 98294a295..46b920af2 100644 --- a/programs/us_edit/us_edit.cpp +++ b/programs/us_edit/us_edit.cpp @@ -5296,7 +5296,7 @@ void US_Edit::set_data_over_lamda() { trx_b = trx; int min_xval = -100000000; int max_xval = 100000000; - int dx = 1; + int dx = 1; // preventing that dx becomes 0 and causing an infinite loop for ( int jwx = 0; jwx < nwaveln; jwx++ ) { edata = &allData[ trx ]; // Triple data