From 8364abad02ad0435168fbb0c7d8e0baae1c02ba3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 12 Apr 2017 01:47:18 +0200 Subject: logic/tracker: no need for timeBeginPeriod There's jitter of up to 3 ms. Increasing timer resolution pessimizes overall performance. For Falcon BMS it costs about a dozen frames. --- logic/tracker.cpp | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'logic/tracker.cpp') diff --git a/logic/tracker.cpp b/logic/tracker.cpp index 4eba230c..95f7b38f 100644 --- a/logic/tracker.cpp +++ b/logic/tracker.cpp @@ -21,10 +21,6 @@ #include #include -#if defined(_WIN32) -# include -#endif - using namespace euler; using namespace gui_tracker_impl; @@ -269,7 +265,11 @@ void Tracker::logic() logger.write_pose(value); // "filtered" } + } + + nanp |= is_nan(value); + { euler_t neck, rel; if (s.neck_enable) @@ -335,10 +335,6 @@ void Tracker::logic() for (int i = 0; i < 3; i++) value(i) = map(value(i), m(i)); - nanp |= is_nan(value); - - logger.write_pose(value); // "mapped" - if (nanp) { QMutexLocker foo(&mtx); @@ -362,16 +358,14 @@ void Tracker::logic() output_pose = value; raw_6dof = raw; + logger.write_pose(value); // "mapped" + logger.reset_dt(); logger.next_line(); } void Tracker::run() { -#if defined(_WIN32) - (void) timeBeginPeriod(1); -#endif - setPriority(QThread::HighPriority); { @@ -390,9 +384,10 @@ void Tracker::run() logger.next_line(); } - t.start(); logger.reset_dt(); + t.start(); + while (!get(f_should_quit)) { Pose tmp; @@ -405,26 +400,20 @@ void Tracker::run() logic(); static constexpr long const_sleep_us = 4000; - - using std::max; - using std::min; - const long elapsed_usecs = t.elapsed_usecs(); + t.start(); backlog_time += elapsed_usecs - const_sleep_us; - if (std::fabs(backlog_time) > 10000l * 1000) + if (std::fabs(backlog_time) > 3000 * 1000) { qDebug() << "tracker: backlog interval overflow" << backlog_time; backlog_time = 0; } - const unsigned sleep_time = unsigned(std::round(clamp((const_sleep_us - backlog_time)/1000., 0., const_sleep_us*3/1000.))); + const unsigned sleep_time = unsigned(std::round(clamp((const_sleep_us - backlog_time)/1000., 0, const_sleep_us*2.5/1000))); - t.start(); - - if (sleep_time > 0) - portable::sleep(sleep_time); + portable::sleep(sleep_time); } { @@ -433,10 +422,6 @@ void Tracker::run() libs.pProtocol->pose(p); } -#if defined(_WIN32) - (void) timeEndPeriod(1); -#endif - for (int i = 0; i < 6; i++) { m(i).spline_main.set_tracking_active(false); -- cgit v1.2.3