From 0f6a37f0f7de9223419eb4d7954bb5b7b7367388 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 20 Nov 2015 09:49:14 -0800 Subject: [PATCH] remainder->fmod! --- interface/src/Application.cpp | 3 ++- interface/src/avatar/AvatarManager.cpp | 11 +++++++---- interface/src/avatar/AvatarManager.h | 2 +- libraries/shared/src/PIDController.h | 7 ++++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1e970828ec..5640827982 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1112,7 +1112,8 @@ void Application::paintGL() { // the key part (and not an exagerated part) of _lastPaintWait is accounted for. const float targetPeriod = getTargetFramePeriod(); if (_lastPaintWait > EPSILON && actualPeriod > targetPeriod) { - deducedNonVSyncPeriod += remainder(actualPeriod, _lastPaintWait); + // Don't use C++ remainder(). It's authors are mathematically insane. + deducedNonVSyncPeriod += fmod(actualPeriod, _lastPaintWait); } _lastDeducedNonVSyncFps = 1.0f / deducedNonVSyncPeriod; _lastInstantaneousFps = instantaneousFps; diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 6c1097a42b..789865679d 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -93,16 +93,15 @@ void AvatarManager::init() { const float target_fps = 1.0f / qApp->getTargetFramePeriod(); _renderDistanceController.setMeasuredValueSetpoint(target_fps); - const float TREE_SCALE = 32768.0f; // Not in shared library, alas. const float SMALLEST_REASONABLE_HORIZON = 5.0f; // meters _renderDistanceController.setControlledValueHighLimit(1.0f / SMALLEST_REASONABLE_HORIZON); - _renderDistanceController.setControlledValueLowLimit(1.0f / TREE_SCALE); + _renderDistanceController.setControlledValueLowLimit(1.0f / (float) TREE_SCALE); // Advice for tuning parameters: - // See PIDController.h. There's a sectionon tuning in the reference. + // See PIDController.h. There's a section on tuning in the reference. // Turn on logging with the following (or from js with AvatarList.setRenderDistanceControllerHistory("avatar render", 300)) //_renderDistanceController.setHistorySize("avatar render", target_fps * 4); // Note that extra logging/hysteresis is turned off in Avatar.cpp when the above logging is on. - _renderDistanceController.setKP(0.0005f); // Usually about 0.6 of largest that doesn't oscillate when other constants 0. + _renderDistanceController.setKP(0.0005f); // Usually about 0.6 of largest that doesn't oscillate when other parameters 0. _renderDistanceController.setKI(0.0004f); // Big enough to bring us to target with the above KP. _renderDistanceController.setKD(0.00001f); // A touch of kd increases the speed by which we get there. @@ -136,6 +135,10 @@ void AvatarManager::updateOtherAvatars(float deltaTime) { const float fps = qApp->getLastInstanteousFps(); const float paintWait = qApp->getLastPaintWait(); + // The PID controller raises the controlled value when the measured value goes up. + // The measured value is frame rate. When the controlled value (1 / render cutoff distance) + // goes up, the render cutoff distance gets closer, the number of rendered avatars is less, and frame rate + // goes up. const float deduced = qApp->getLastDeducedNonVSyncFps(); const float distance = 1.0f / _renderDistanceController.update(deduced, deltaTime, false, fps, paintWait); _renderDistanceAverage.updateAverage(distance); diff --git a/interface/src/avatar/AvatarManager.h b/interface/src/avatar/AvatarManager.h index 9f8b6dc646..f17a34da35 100644 --- a/interface/src/avatar/AvatarManager.h +++ b/interface/src/avatar/AvatarManager.h @@ -102,7 +102,7 @@ private: QVector _localLights; bool _shouldShowReceiveStats = false; - float _renderDistance { 40.0f }; + float _renderDistance { (float) TREE_SCALE }; int _renderedAvatarCount {0}; PIDController _renderDistanceController {}; SimpleMovingAverage _renderDistanceAverage {10}; diff --git a/libraries/shared/src/PIDController.h b/libraries/shared/src/PIDController.h index 7c63206406..55519063bc 100644 --- a/libraries/shared/src/PIDController.h +++ b/libraries/shared/src/PIDController.h @@ -21,12 +21,12 @@ #include #include -// Although our coding standard shuns abbreviations, the control systems literature pretty uniformly uses p, i, d, and dt rather than +// Although our coding standard shuns abbreviations, the control systems literature uniformly uses p, i, d, and dt rather than // proportionalTerm, integralTerm, derivativeTerm, and deltaTime. Here we will be consistent with the literature. class PIDController { public: - // These four the main interface: + // These are the main interfaces: void setMeasuredValueSetpoint(float newValue) { _measuredValueSetpoint = newValue; } float update(float measuredValue, float dt, bool resetAccumulator = false, float FIXME1 = 0.0f, float FIXME2 = 0.0f); // returns the new computedValue void setHistorySize(QString label = QString(""), int size = 0) { _history.reserve(size); _history.resize(0); _label = label; } // non-empty does logging @@ -78,9 +78,10 @@ protected: float _ki { 0.0f }; float _kd { 0.0f }; - // Controller state + // Controller operating state float _lastError{ 0.0f }; float _lastAccumulation{ 0.0f }; + // reporting QVector _history{}; QString _label{ "" };