From 93bb0eba4fc1256e9d533247d6986e79d94b18dc Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 12:05:17 +0200 Subject: [PATCH 01/11] Deduplicatrion of the queue and delayed release of hard lock --- js/msp.js | 8 +++++++- js/serial_backend.js | 2 ++ js/serial_queue.js | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/js/msp.js b/js/msp.js index d8553f0d2..85a51a5e5 100644 --- a/js/msp.js +++ b/js/msp.js @@ -2,6 +2,8 @@ const MSPCodes = require('./msp/MSPCodes') const mspQueue = require('./serial_queue'); +const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer'); +const timeout = require('./timeouts'); /** * @@ -265,7 +267,9 @@ var MSP = { /* * Free port */ - mspQueue.freeHardLock(); + timeout.add('delayedFreeHardLock', function() { + mspQueue.freeHardLock(); + }, 50); // Reset variables this.message_length_received = 0; @@ -301,6 +305,8 @@ var MSP = { var checksum; var ii; + eventFrequencyAnalyzer.put('MPS ' + code); + if (!protocolVersion) { protocolVersion = this.protocolVersion; } diff --git a/js/serial_backend.js b/js/serial_backend.js index 3589ed920..554110753 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -35,6 +35,8 @@ var SerialBackend = (function () { privateScope.isDemoRunning = false; + privateScope.isWirelessMode = false; + /* * Handle "Wireless" mode with strict queueing of messages */ diff --git a/js/serial_queue.js b/js/serial_queue.js index 3f2a1df96..7ad0af2df 100644 --- a/js/serial_queue.js +++ b/js/serial_queue.js @@ -59,6 +59,15 @@ var mspQueue = function () { privateScope.queueLocked = false; + privateScope.isMessageInQueue = function (code) { + for (var i = 0; i < privateScope.queue.length; i++) { + if (privateScope.queue[i].code == code) { + return true; + } + } + return false; + }; + publicScope.setremoveCallback = function(cb) { privateScope.removeCallback = cb; } @@ -86,6 +95,10 @@ var mspQueue = function () { privateScope.lockMethod = method; }; + publicScope.getLockMethod = function () { + return privateScope.lockMethod; + }; + publicScope.setSoftLock = function () { privateScope.softLock = new Date().getTime(); }; @@ -223,6 +236,12 @@ var mspQueue = function () { */ publicScope.put = function (mspRequest) { + console.log(mspRequest.code); + if (privateScope.isMessageInQueue(mspRequest.code)) { + console.log('Message already in queue: ' + mspRequest.code); + return false; + } + if (privateScope.queueLocked === true) { return false; } @@ -317,6 +336,10 @@ var mspQueue = function () { } }; + publicScope.getQueue = function () { + return privateScope.queue; + }; + setInterval(publicScope.executor, Math.round(1000 / privateScope.handlerFrequency)); setInterval(publicScope.balancer, Math.round(1000 / privateScope.balancerFrequency)); From 2156090a0d70366baf9198230434782ab2fbfb8b Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 12:38:28 +0200 Subject: [PATCH 02/11] Run message deduplication based on full roundtrip, not only input queue --- js/msp/MSPHelper.js | 3 +++ js/serial_backend.js | 2 ++ js/serial_queue.js | 51 +++++++++++++++++++++++++++++++--------- tabs/cli.js | 1 + tabs/firmware_flasher.js | 1 + 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 61a17cb4c..d96dc2054 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -1621,6 +1621,9 @@ var mspHelper = (function () { mspQueue.putHardwareRoundtrip(new Date().getTime() - dataHandler.callbacks[i].sentOn); } + //remove message from queue as received + mspQueue.removeMessage(dataHandler.code); + // remove object from array dataHandler.callbacks.splice(i, 1); diff --git a/js/serial_backend.js b/js/serial_backend.js index 554110753..73ed68df4 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -239,6 +239,7 @@ var SerialBackend = (function () { mspQueue.flush(); mspQueue.freeHardLock(); mspQueue.freeSoftLock(); + mspQueue.flushMessages(); CONFIGURATOR.connection.disconnect(privateScope.onClosed); MSP.disconnect_cleanup(); @@ -376,6 +377,7 @@ var SerialBackend = (function () { mspQueue.flush(); mspQueue.freeHardLock(); mspQueue.freeSoftLock(); + mspQueue.flushMessages(); CONFIGURATOR.connection.emptyOutputBuffer(); $('div.connect_controls a').click(); // disconnect diff --git a/js/serial_queue.js b/js/serial_queue.js index 7ad0af2df..dc3979b88 100644 --- a/js/serial_queue.js +++ b/js/serial_queue.js @@ -42,6 +42,38 @@ var mspQueue = function () { privateScope.removeCallback = null; privateScope.putCallback = null; + /** + * This is the list of all messages that are currently in queue, including being already dispatched via radio and waiting for response + */ + privateScope.messagesInQueue = []; + + //Store new code in the queue + publicScope.storeMessage = function (code) { + privateScope.messagesInQueue.push(code); + }; + + //Remove code from the queue + publicScope.removeMessage = function (code) { + var index = privateScope.messagesInQueue.indexOf(code); + if (index > -1) { + privateScope.messagesInQueue.splice(index, 1); + } + }; + + //List all messages in the queue + publicScope.getMessages = function () { + return privateScope.messagesInQueue; + }; + + //Check if message is in the queue + publicScope.isMessageInQueue = function (code) { + return privateScope.messagesInQueue.indexOf(code) > -1; + }; + + publicScope.flushMessages = function () { + privateScope.messagesInQueue = []; + }; + publicScope.computeDropRatio = function () { privateScope.dropRatio = privateScope.loadPidController.run(publicScope.getLoad()); }; @@ -59,15 +91,6 @@ var mspQueue = function () { privateScope.queueLocked = false; - privateScope.isMessageInQueue = function (code) { - for (var i = 0; i < privateScope.queue.length; i++) { - if (privateScope.queue[i].code == code) { - return true; - } - } - return false; - }; - publicScope.setremoveCallback = function(cb) { privateScope.removeCallback = cb; } @@ -173,6 +196,7 @@ var mspQueue = function () { request.timer = setTimeout(function () { console.log('MSP data request timed-out: ' + request.code); + publicScope.removeMessage(request.code); /* * Remove current callback */ @@ -236,12 +260,17 @@ var mspQueue = function () { */ publicScope.put = function (mspRequest) { - console.log(mspRequest.code); - if (privateScope.isMessageInQueue(mspRequest.code)) { + console.log('Received message ', mspRequest.code); + + const isMessageInQueue = publicScope.isMessageInQueue(mspRequest.code); + + if (isMessageInQueue) { console.log('Message already in queue: ' + mspRequest.code); return false; } + publicScope.storeMessage(mspRequest.code); + if (privateScope.queueLocked === true) { return false; } diff --git a/tabs/cli.js b/tabs/cli.js index abde85033..310906b6e 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -94,6 +94,7 @@ TABS.cli.initialize = function (callback) { // Flush MSP queue as well as all MSP registered callbacks mspQueue.flush(); + mspQueue.flushMessages(); MSP.callbacks_cleanup(); self.outputHistory = ""; diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index bcd4a4834..cb34094fe 100755 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -780,6 +780,7 @@ TABS.firmware_flasher.closeTempConnection = function() { mspQueue.flush(); mspQueue.freeHardLock(); mspQueue.freeSoftLock(); + mspQueue.flushMessages(); CONFIGURATOR.connection.emptyOutputBuffer(); CONFIGURATOR.connectionValid = false; From 040b0cec529ee19992ed5617c1434f77871901bd Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 13:10:29 +0200 Subject: [PATCH 03/11] Extract mspDeduplicationQueue to separate file --- js/msp/MSPHelper.js | 3 ++- js/msp/mspDeduplicationQueue.js | 41 +++++++++++++++++++++++++++++++++ js/serial_backend.js | 5 ++-- js/serial_queue.js | 41 ++++----------------------------- tabs/cli.js | 3 ++- tabs/firmware_flasher.js | 3 ++- 6 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 js/msp/mspDeduplicationQueue.js diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index d96dc2054..60ac4ef0f 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -18,6 +18,7 @@ const ProgrammingPid = require('./../programmingPid'); const Safehome = require('./../safehome'); const { FwApproach } = require('./../fwApproach'); const Waypoint = require('./../waypoint'); +const mspDeduplicationQueue = require('./mspDeduplicationQueue'); var mspHelper = (function () { var self = {}; @@ -1622,7 +1623,7 @@ var mspHelper = (function () { } //remove message from queue as received - mspQueue.removeMessage(dataHandler.code); + mspDeduplicationQueue.remove(dataHandler.code); // remove object from array dataHandler.callbacks.splice(i, 1); diff --git a/js/msp/mspDeduplicationQueue.js b/js/msp/mspDeduplicationQueue.js new file mode 100644 index 000000000..4ea151692 --- /dev/null +++ b/js/msp/mspDeduplicationQueue.js @@ -0,0 +1,41 @@ +'use strict'; + +/** + * This module is a queue for deduplication of MSP requests. + * We do not want to process the same request multiple times unless response is received. + * This improves wireless handling and lower amount of data that is put on the air + */ +var mspDeduplicationQueue = function() { + + let publicScope = {}, + privateScope = {}; + + privateScope.queue = []; + + publicScope.put = function(item) { + privateScope.queue.push(item); + }; + + publicScope.remove = function(item) { + const index = privateScope.queue.indexOf(item); + if (index > -1) { + privateScope.queue.splice(index, 1); + } + }; + + publicScope.check = function(item) { + return privateScope.queue.includes(item); + }; + + publicScope.flush = function() { + privateScope.queue = []; + }; + + publicScope.get = function() { + return privateScope.queue; + }; + + return publicScope; +}(); + +module.exports = mspDeduplicationQueue; \ No newline at end of file diff --git a/js/serial_backend.js b/js/serial_backend.js index 73ed68df4..942d09b6a 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -27,6 +27,7 @@ const BOARD = require('./boards'); const jBox = require('./libraries/jBox/jBox.min'); const groundstation = require('./groundstation'); const ltmDecoder = require('./ltmDecoder'); +const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue'); var SerialBackend = (function () { @@ -239,7 +240,7 @@ var SerialBackend = (function () { mspQueue.flush(); mspQueue.freeHardLock(); mspQueue.freeSoftLock(); - mspQueue.flushMessages(); + mspDeduplicationQueue.flush(); CONFIGURATOR.connection.disconnect(privateScope.onClosed); MSP.disconnect_cleanup(); @@ -377,7 +378,7 @@ var SerialBackend = (function () { mspQueue.flush(); mspQueue.freeHardLock(); mspQueue.freeSoftLock(); - mspQueue.flushMessages(); + mspDeduplicationQueue.flush(); CONFIGURATOR.connection.emptyOutputBuffer(); $('div.connect_controls a').click(); // disconnect diff --git a/js/serial_queue.js b/js/serial_queue.js index dc3979b88..8cf22edf4 100644 --- a/js/serial_queue.js +++ b/js/serial_queue.js @@ -5,6 +5,7 @@ const MSPCodes = require('./msp/MSPCodes'); const SimpleSmoothFilter = require('./simple_smooth_filter'); const PidController = require('./pid_controller'); const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer'); +const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue'); var mspQueue = function () { @@ -42,38 +43,6 @@ var mspQueue = function () { privateScope.removeCallback = null; privateScope.putCallback = null; - /** - * This is the list of all messages that are currently in queue, including being already dispatched via radio and waiting for response - */ - privateScope.messagesInQueue = []; - - //Store new code in the queue - publicScope.storeMessage = function (code) { - privateScope.messagesInQueue.push(code); - }; - - //Remove code from the queue - publicScope.removeMessage = function (code) { - var index = privateScope.messagesInQueue.indexOf(code); - if (index > -1) { - privateScope.messagesInQueue.splice(index, 1); - } - }; - - //List all messages in the queue - publicScope.getMessages = function () { - return privateScope.messagesInQueue; - }; - - //Check if message is in the queue - publicScope.isMessageInQueue = function (code) { - return privateScope.messagesInQueue.indexOf(code) > -1; - }; - - publicScope.flushMessages = function () { - privateScope.messagesInQueue = []; - }; - publicScope.computeDropRatio = function () { privateScope.dropRatio = privateScope.loadPidController.run(publicScope.getLoad()); }; @@ -196,7 +165,7 @@ var mspQueue = function () { request.timer = setTimeout(function () { console.log('MSP data request timed-out: ' + request.code); - publicScope.removeMessage(request.code); + mspDeduplicationQueue.remove(request.code); /* * Remove current callback */ @@ -262,19 +231,19 @@ var mspQueue = function () { console.log('Received message ', mspRequest.code); - const isMessageInQueue = publicScope.isMessageInQueue(mspRequest.code); + const isMessageInQueue = mspDeduplicationQueue.check(mspRequest.code); if (isMessageInQueue) { console.log('Message already in queue: ' + mspRequest.code); return false; } - publicScope.storeMessage(mspRequest.code); - if (privateScope.queueLocked === true) { return false; } + mspDeduplicationQueue.put(mspRequest.code); + privateScope.queue.push(mspRequest); return true; }; diff --git a/tabs/cli.js b/tabs/cli.js index 310906b6e..eef500134 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -13,6 +13,7 @@ const { globalSettings } = require('./../js/globalSettings'); const CliAutoComplete = require('./../js/CliAutoComplete'); const { ConnectionType } = require('./../js/connection/connection'); const jBox = require('./../js/libraries/jBox/jBox.min'); +const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue'); TABS.cli = { lineDelayMs: 50, @@ -94,7 +95,7 @@ TABS.cli.initialize = function (callback) { // Flush MSP queue as well as all MSP registered callbacks mspQueue.flush(); - mspQueue.flushMessages(); + mspDeduplicationQueue.flush(); MSP.callbacks_cleanup(); self.outputHistory = ""; diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index cb34094fe..68363ab9e 100755 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -22,6 +22,7 @@ const mspQueue = require('./../js/serial_queue'); const mspHelper = require('./../js/msp/MSPHelper'); const STM32 = require('./../js/protocols/stm32'); const STM32DFU = require('./../js/protocols/stm32usbdfu'); +const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue'); TABS.firmware_flasher = {}; TABS.firmware_flasher.initialize = function (callback) { @@ -780,7 +781,7 @@ TABS.firmware_flasher.closeTempConnection = function() { mspQueue.flush(); mspQueue.freeHardLock(); mspQueue.freeSoftLock(); - mspQueue.flushMessages(); + mspDeduplicationQueue.flush(); CONFIGURATOR.connection.emptyOutputBuffer(); CONFIGURATOR.connectionValid = false; From 3e637c1c5486dd4cb770509350497112521aa7dc Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 14:14:22 +0200 Subject: [PATCH 04/11] Fix forced lock removal and add frame mspStatistics --- js/connection/connection.js | 4 +++- js/msp/MSPHelper.js | 9 ++++++++- js/msp/mspStatistics.js | 37 +++++++++++++++++++++++++++++++++++++ js/serial_queue.js | 10 +++++++--- 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 js/msp/mspStatistics.js diff --git a/js/connection/connection.js b/js/connection/connection.js index 157f239a2..cffaf41c9 100644 --- a/js/connection/connection.js +++ b/js/connection/connection.js @@ -255,8 +255,10 @@ class Connection { getTimeout() { if (this._bitrate >= 57600) { return 3000; - } else { + } if (this._bitrate >= 19200) { return 4000; + } else { + return 6000; } } } diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 60ac4ef0f..6f14254db 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -19,6 +19,7 @@ const Safehome = require('./../safehome'); const { FwApproach } = require('./../fwApproach'); const Waypoint = require('./../waypoint'); const mspDeduplicationQueue = require('./mspDeduplicationQueue'); +const mspStatistics = require('./mspStatistics'); var mspHelper = (function () { var self = {}; @@ -1619,7 +1620,12 @@ var mspHelper = (function () { */ if (dataHandler.callbacks[i]) { mspQueue.putRoundtrip(new Date().getTime() - dataHandler.callbacks[i].createdOn); - mspQueue.putHardwareRoundtrip(new Date().getTime() - dataHandler.callbacks[i].sentOn); + + const hardwareRountrip = new Date().getTime() - dataHandler.callbacks[i].sentOn; + + mspQueue.putHardwareRoundtrip(hardwareRountrip); + + mspStatistics.add(dataHandler.code, hardwareRountrip); } //remove message from queue as received @@ -3069,6 +3075,7 @@ var mspHelper = (function () { }; self._getSetting = function (name) { + console.log("Getting setting " + name); if (FC.SETTINGS[name]) { return Promise.resolve(FC.SETTINGS[name]); } diff --git a/js/msp/mspStatistics.js b/js/msp/mspStatistics.js new file mode 100644 index 000000000..c86e598ff --- /dev/null +++ b/js/msp/mspStatistics.js @@ -0,0 +1,37 @@ +'use strict'; + +var mspStatistics = function() { + + let publicScope = {}, + privateScope = {}; + + privateScope.statistics = {}; + + + publicScope.add = function(code, duration) { + if (!privateScope.statistics[code]) { + privateScope.statistics[code] = { + ctime: new Date().getTime(), + count: 0, + duration: 0, + average: 0 + }; + } + privateScope.statistics[code].count++; + privateScope.statistics[code].duration += duration; + privateScope.statistics[code].average = privateScope.statistics[code].duration / privateScope.statistics[code].count; + }; + + publicScope.get = function() { + return privateScope.statistics; + }; + + publicScope.reset = function() { + privateScope.statistics = {}; + }; + + return publicScope; + +}(); + +module.exports = mspStatistics; \ No newline at end of file diff --git a/js/serial_queue.js b/js/serial_queue.js index 8cf22edf4..c01e8b8f6 100644 --- a/js/serial_queue.js +++ b/js/serial_queue.js @@ -294,16 +294,20 @@ var mspQueue = function () { var currentTimestamp = new Date().getTime(), threshold = publicScope.getHardwareRoundtrip() * 3; - if (threshold > 1000) { + if (threshold > 5000) { + threshold = 5000; + } + if (threshold < 1000) { threshold = 1000; } if (privateScope.softLock !== false && currentTimestamp - privateScope.softLock > threshold) { - privateScope.softLock = false; + publicScope.freeSoftLock(); eventFrequencyAnalyzer.put('force free soft lock'); } if (privateScope.hardLock !== false && currentTimestamp - privateScope.hardLock > threshold) { - privateScope.hardLock = false; + console.log('Force free hard lock'); + publicScope.freeHardLock(); eventFrequencyAnalyzer.put('force free hard lock'); } From aa9457a96ac663726a00d23e87849ddb6b30e391 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 14:19:27 +0200 Subject: [PATCH 05/11] Add calls per second to the msp statistics page --- js/msp/mspStatistics.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/msp/mspStatistics.js b/js/msp/mspStatistics.js index c86e598ff..a2dc18489 100644 --- a/js/msp/mspStatistics.js +++ b/js/msp/mspStatistics.js @@ -14,12 +14,14 @@ var mspStatistics = function() { ctime: new Date().getTime(), count: 0, duration: 0, - average: 0 + average: 0, + callsPerSecond: 0 }; } privateScope.statistics[code].count++; privateScope.statistics[code].duration += duration; privateScope.statistics[code].average = privateScope.statistics[code].duration / privateScope.statistics[code].count; + privateScope.statistics[code].callsPerSecond = privateScope.statistics[code].count / ((new Date().getTime() - privateScope.statistics[code].ctime) / 1000); }; publicScope.get = function() { From 94cc87d3845fb2884900ff611f636628b8082512 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 14:27:13 +0200 Subject: [PATCH 06/11] Replace status balanced interval with simple deduplication --- tabs/setup.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tabs/setup.js b/tabs/setup.js index f8a56199f..3656e80f2 100755 --- a/tabs/setup.js +++ b/tabs/setup.js @@ -123,9 +123,9 @@ TABS.setup.initialize = function (callback) { /* * Enable balancer */ - if (mspQueue.shouldDrop()) { - return; - } + // if (mspQueue.shouldDrop()) { + // return; + // } MSP.send_message(MSPCodes.MSP_RAW_GPS, false, false, function () { var gpsFixType = i18n.getMessage('gpsFixNone'); @@ -146,9 +146,9 @@ TABS.setup.initialize = function (callback) { /* * Enable balancer */ - if (mspQueue.shouldDrop()) { - return; - } + // if (mspQueue.shouldDrop()) { + // return; + // } MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, function () { roll_e.text(i18n.getMessage('initialSetupAttitude', [FC.SENSOR_DATA.kinematics[0]])); @@ -159,9 +159,10 @@ TABS.setup.initialize = function (callback) { }); } - mspBalancedInterval.add('setup_data_pull_fast', 40, 1, get_fast_data); mspBalancedInterval.add('setup_data_pull_slow', 250, 1, get_slow_data); + interval.add('setup_data_pull_fast', get_fast_data, 50); + interval.add('gui_analog_update', function () { bat_cells_e.text(i18n.getMessage('initialSetupBatteryDetectedCellsValue', [FC.ANALOG.cell_count])); bat_voltage_e.text(i18n.getMessage('initialSetupBatteryVoltageValue', [FC.ANALOG.voltage])); From 6b5440f437d92b95ecfe6f948241518516e9a13a Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 20:46:31 +0200 Subject: [PATCH 07/11] remove msp_balanced_interval --- js/gui.js | 2 - js/msp_balanced_interval.js | 75 ------------------------------------- js/serial_backend.js | 2 - tabs/adjustments.js | 11 +----- tabs/auxiliary.js | 11 +----- tabs/firmware_flasher.js | 2 - tabs/gps.js | 12 ++---- tabs/logging.js | 2 - tabs/magnetometer.js | 8 +--- tabs/mission_control.js | 6 +-- tabs/mixer.js | 6 +-- tabs/outputs.js | 2 - tabs/programming.js | 7 ++-- tabs/receiver.js | 16 +------- tabs/setup.js | 21 +---------- 15 files changed, 21 insertions(+), 162 deletions(-) delete mode 100644 js/msp_balanced_interval.js diff --git a/js/gui.js b/js/gui.js index b388a9c3a..445a05aae 100644 --- a/js/gui.js +++ b/js/gui.js @@ -5,7 +5,6 @@ const Switchery = require('./libraries/switchery/switchery') const MSP = require('./msp'); const FC = require('./fc'); const interval = require('./intervals'); -const mspBalancedInterval = require('./msp_balanced_interval'); const { scaleRangeInt } = require('./helpers'); const i18n = require('./localization'); @@ -92,7 +91,6 @@ GUI_control.prototype.tab_switch_cleanup = function (callback) { MSP.callbacks_cleanup(); // we don't care about any old data that might or might not arrive interval.killAll(['global_data_refresh', 'msp-load-update', 'ltm-connection-check']); - mspBalancedInterval.flush(); if (this.active_tab) { TABS[this.active_tab].cleanup(callback); diff --git a/js/msp_balanced_interval.js b/js/msp_balanced_interval.js deleted file mode 100644 index a0d0aef68..000000000 --- a/js/msp_balanced_interval.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -const mspQueue = require('./serial_queue'); -const interval = require('./intervals'); - -var mspBalancedInterval = (function (mspQueue, intervalHandler) { - - var publicScope = {}, - privateScope = {}; - - /** - * How often balancing should be executed [Hz] - * @type {number} - */ - privateScope.balancingFrequency = 0.5; - - privateScope.intervals = []; - - /** - * - * @param {string} name - * @param {number} requestedInterval - * @param {number} messagesInInterval - * @param {function} code - */ - publicScope.add = function (name, requestedInterval, messagesInInterval, code) { - privateScope.intervals.push({ - name: name, - requestedInterval: requestedInterval, - messagesInInterval: messagesInInterval, - code: code - }); - - intervalHandler.add(name, code, mspQueue.getIntervalPrediction(requestedInterval, messagesInInterval)); - }; - - /** - * Periodically executed balancing handler - */ - publicScope.balancer = function () { - - var interval; - - for (var i in privateScope.intervals) { - if (privateScope.intervals.hasOwnProperty(i)) { - interval = privateScope.intervals[i]; - - intervalHandler.remove(interval.name); - intervalHandler.add( - interval.name, - interval.code, - mspQueue.getIntervalPrediction( - interval.requestedInterval, - interval.messagesInInterval - ) - ); - } - } - - }; - - /** - * Real interval cleaning happens win interval.killAll method - * both methods have to be executed - */ - publicScope.flush = function () { - privateScope.intervals = []; - }; - - setInterval(publicScope.balancer, Math.round(1000 / privateScope.balancingFrequency)); - - return publicScope; -})(mspQueue, interval); - -module.exports = mspBalancedInterval; diff --git a/js/serial_backend.js b/js/serial_backend.js index 942d09b6a..04eb60a99 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -18,7 +18,6 @@ const interval = require('./intervals'); const periodicStatusUpdater = require('./periodicStatusUpdater'); const mspQueue = require('./serial_queue'); const timeout = require('./timeouts'); -const mspBalancedInterval = require('./msp_balanced_interval'); const defaultsDialog = require('./defaults_dialog'); const { SITLProcess } = require('./sitl'); const update = require('./globalUpdates'); @@ -218,7 +217,6 @@ var SerialBackend = (function () { timeout.killAll(); interval.killAll(['global_data_refresh', 'msp-load-update']); - mspBalancedInterval.flush(); if (CONFIGURATOR.cliActive) { GUI.tab_switch_cleanup(finishDisconnect); diff --git a/tabs/adjustments.js b/tabs/adjustments.js index 164bb6ee2..c8dcc1ce4 100644 --- a/tabs/adjustments.js +++ b/tabs/adjustments.js @@ -6,12 +6,10 @@ const wNumb = require('wnumb/wNumb') const mspHelper = require('./../js/msp/MSPHelper'); const MSPCodes = require('./../js/msp/MSPCodes'); const MSP = require('./../js/msp'); -const mspQueue = require('./../js/serial_queue'); const { GUI, TABS } = require('./../js/gui'); const FC = require('./../js/fc'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const i18n = require('./../js/localization'); - +const interval = require('./../js/intervals'); TABS.adjustments = {}; @@ -260,11 +258,6 @@ TABS.adjustments.initialize = function (callback) { // data pulling functions used inside interval timer function get_rc_data() { - - if (mspQueue.shouldDrop()) { - return; - } - MSP.send_message(MSPCodes.MSP_RC, false, false, update_ui); } @@ -280,7 +273,7 @@ TABS.adjustments.initialize = function (callback) { update_ui(); // enable data pulling - mspBalancedInterval.add('aux_data_pull', 50, 1, get_rc_data); + interval.add('aux_data_pull', get_rc_data, 50); GUI.content_ready(callback); } diff --git a/tabs/auxiliary.js b/tabs/auxiliary.js index 7fd39225a..7d66e3897 100644 --- a/tabs/auxiliary.js +++ b/tabs/auxiliary.js @@ -9,13 +9,11 @@ const store = new Store(); const mspHelper = require('./../js/msp/MSPHelper'); const MSPCodes = require('./../js/msp/MSPCodes'); const MSP = require('./../js/msp'); -const mspQueue = require('./../js/serial_queue'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const { GUI, TABS } = require('./../js/gui'); const FC = require('./../js/fc'); const adjustBoxNameIfPeripheralWithModeID = require('./../js/peripherals'); const i18n = require('./../js/localization'); - +const interval = require('./../js/intervals'); var ORIG_AUX_CONFIG_IDS = []; @@ -375,11 +373,6 @@ TABS.auxiliary.initialize = function (callback) { // data pulling functions used inside interval timer function get_rc_data() { - - if (mspQueue.shouldDrop()) { - return; - } - MSP.send_message(MSPCodes.MSP_RC, false, false, update_ui); } @@ -516,7 +509,7 @@ TABS.auxiliary.initialize = function (callback) { update_ui(); // enable data pulling - mspBalancedInterval.add('aux_data_pull', 50, 1, get_rc_data); + interval.add('aux_data_pull', get_rc_data, 50); $(".tab-auxiliary .acroEnabled").width($("#mode-0 .info").width()); diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index 68363ab9e..5c88263c3 100755 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -17,7 +17,6 @@ const CONFIGURATOR = require('./../js/data_storage'); const SerialBackend = require('./../js/serial_backend'); const timeout = require('./../js/timeouts'); const interval = require('./../js/intervals'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const mspQueue = require('./../js/serial_queue'); const mspHelper = require('./../js/msp/MSPHelper'); const STM32 = require('./../js/protocols/stm32'); @@ -776,7 +775,6 @@ TABS.firmware_flasher.onValidFirmware = function() { TABS.firmware_flasher.closeTempConnection = function() { timeout.killAll(); interval.killAll(['global_data_refresh', 'msp-load-update', 'ltm-connection-check']); - mspBalancedInterval.flush(); mspQueue.flush(); mspQueue.freeHardLock(); diff --git a/tabs/gps.js b/tabs/gps.js index f77d9dd1c..3362f3b9b 100644 --- a/tabs/gps.js +++ b/tabs/gps.js @@ -8,8 +8,7 @@ const MSPChainerClass = require('./../js/msp/MSPchainer'); const mspHelper = require('./../js/msp/MSPHelper'); const MSPCodes = require('./../js/msp/MSPCodes'); const MSP = require('./../js/msp'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); -const mspQueue = require('./../js/serial_queue'); +const interval = require('./../js/intervals'); const { GUI, TABS } = require('./../js/gui'); const FC = require('./../js/fc'); const i18n = require('./../js/localization'); @@ -262,7 +261,6 @@ TABS.gps.initialize = function (callback) { } function update_ui() { - let lat = FC.GPS_DATA.lat / 10000000; let lon = FC.GPS_DATA.lon / 10000000; @@ -400,19 +398,15 @@ TABS.gps.initialize = function (callback) { * enable data pulling * GPS is usually refreshed at 5Hz, there is no reason to pull it much more often, really... */ - mspBalancedInterval.add('gps_pull', 200, 3, function gps_update() { + interval.add('gps_pull', function gps_update() { // avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support. if (!SerialBackend.have_sensor(FC.CONFIG.activeSensors, 'gps')) { update_ui(); return; } - if (mspQueue.shouldDrop()) { - return; - } - get_raw_gps_data(); - }); + }, 200); $('a.save').on('click', function () { diff --git a/tabs/logging.js b/tabs/logging.js index 43de37094..6f515658b 100644 --- a/tabs/logging.js +++ b/tabs/logging.js @@ -7,7 +7,6 @@ const store = new Store(); const MSPCodes = require('./../js/msp/MSPCodes'); const MSP = require('./../js/msp'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const { GUI, TABS } = require('./../js/gui'); const FC = require('./../js/fc'); const CONFIGURATOR = require('./../js/data_storage'); @@ -106,7 +105,6 @@ TABS.logging.initialize = function (callback) { } } else { interval.killAll(['global_data_refresh', 'msp-load-update', 'ltm-connection-check']); - mspBalancedInterval.flush(); $('.speed').prop('disabled', false); $(this).text(i18n.getMessage('loggingStart')); diff --git a/tabs/magnetometer.js b/tabs/magnetometer.js index 586798fd1..ec9d27cd7 100644 --- a/tabs/magnetometer.js +++ b/tabs/magnetometer.js @@ -6,12 +6,11 @@ const MSPChainerClass = require('./../js/msp/MSPchainer'); const MSP = require('./../js/msp'); const MSPCodes = require('./../js/msp/MSPCodes'); const mspHelper = require('./../js/msp/MSPHelper'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); -const mspQueue = require('./../js/serial_queue'); const FC = require('./../js/fc'); const { GUI, TABS } = require('./../js/gui'); const i18n = require('./../js/localization'); const { mixer } = require('./../js/model'); +const interval = require('./../js/intervals'); TABS.magnetometer = {}; @@ -524,9 +523,6 @@ TABS.magnetometer.initialize = function (callback) { }); function get_fast_data() { - if (mspQueue.shouldDrop()) { - return; - } MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, function () { self.roll_e.text(i18n.getMessage('initialSetupAttitude', [FC.SENSOR_DATA.kinematics[0]])); @@ -536,7 +532,7 @@ TABS.magnetometer.initialize = function (callback) { }); } - mspBalancedInterval.add('setup_data_pull_fast', 40, 1, get_fast_data); + interval.add('setup_data_pull_fast', get_fast_data, 40); GUI.content_ready(callback); } diff --git a/tabs/mission_control.js b/tabs/mission_control.js index d07ecd57c..27b181836 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -10,7 +10,6 @@ const MSPChainerClass = require('./../js/msp/MSPchainer'); const mspHelper = require('./../js/msp/MSPHelper'); const MSPCodes = require('./../js/msp/MSPCodes'); const MSP = require('./../js/msp'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const mspQueue = require('./../js/serial_queue'); const { GUI, TABS } = require('./../js/gui'); const FC = require('./../js/fc'); @@ -27,6 +26,7 @@ const FwApproachCollection = require('./../js/fwApproachCollection'); const SerialBackend = require('./../js/serial_backend'); const { distanceOnLine, wrap_360, calculate_new_cooridatnes } = require('./../js/helpers'); const Plotly = require('./../js/libraries/plotly-latest.min'); +const interval = require('./../js/intervals'); var MAX_NEG_FW_LAND_ALT = -2000; // cm @@ -334,7 +334,7 @@ TABS.mission_control.initialize = function (callback) { */ if(!isOffline) { - mspBalancedInterval.add('gps_pull', 200, 3, function gps_update() { + interval.add('gps_pull', function gps_update() { // avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support. if (!SerialBackend.have_sensor(FC.CONFIG.activeSensors, 'gps')) { update_gpsTrack(); @@ -346,7 +346,7 @@ TABS.mission_control.initialize = function (callback) { } get_raw_gps_data(); - }); + }, 200); } GUI.content_ready(callback); diff --git a/tabs/mixer.js b/tabs/mixer.js index a6ccebe87..a5ac2a83d 100644 --- a/tabs/mixer.js +++ b/tabs/mixer.js @@ -11,8 +11,8 @@ const FC = require('./../js/fc'); const i18n = require('./../js/localization'); const { mixer, platform, PLATFORM, INPUT, STABILIZED } = require('./../js/model'); const Settings = require('./../js/settings'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const jBox = require('../js/libraries/jBox/jBox.min'); +const interval = require('./../js/intervals'); TABS.mixer = {}; @@ -823,9 +823,9 @@ TABS.mixer.initialize = function (callback, scrollPosition) { FC.LOGIC_CONDITIONS.init($('#logic-wrapper')); - i18n.localize();; + i18n.localize();; - mspBalancedInterval.add('logic_conditions_pull', 350, 1, getLogicConditionsStatus); + interval.add('logic_conditions_pull', getLogicConditionsStatus, 350); GUI.content_ready(callback); } diff --git a/tabs/outputs.js b/tabs/outputs.js index e868f4fef..72269f72c 100644 --- a/tabs/outputs.js +++ b/tabs/outputs.js @@ -5,7 +5,6 @@ const path = require('path'); const MSPChainerClass = require('./../js/msp/MSPchainer'); const mspHelper = require('./../js/msp/MSPHelper'); const MSPCodes = require('./../js/msp/MSPCodes'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const mspQueue = require('./../js/serial_queue') const MSP = require('./../js/msp'); const { GUI, TABS } = require('./../js/gui'); @@ -430,7 +429,6 @@ TABS.outputs.initialize = function (callback) { // timer initialization interval.killAll(['motor_and_status_pull', 'global_data_refresh', 'msp-load-update', 'ltm-connection-check']); - mspBalancedInterval.flush(); interval.add('IMU_pull', function () { diff --git a/tabs/programming.js b/tabs/programming.js index 8ca1ca587..fe59c1b55 100644 --- a/tabs/programming.js +++ b/tabs/programming.js @@ -3,13 +3,12 @@ const path = require('path'); const MSPChainerClass = require('./../js/msp/MSPchainer'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const mspHelper = require('./../js/msp/MSPHelper'); const { GUI, TABS } = require('./../js/gui'); const FC = require('./../js/fc'); const tabs = require('./../js/tabs'); const i18n = require('./../js/localization'); - +const interval = require('./../js/intervals'); TABS.programming = {}; @@ -68,9 +67,9 @@ TABS.programming.initialize = function (callback, scrollPosition) { GUI.log(i18n.getMessage('programmingEepromSaved')); }); - mspBalancedInterval.add('logic_conditions_pull', 100, 1, function () { + interval.add('logic_conditions_pull', function () { statusChainer.execute(); - }); + }, 100); GUI.content_ready(callback); } diff --git a/tabs/receiver.js b/tabs/receiver.js index 0d1c36965..f1eb46168 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -4,8 +4,6 @@ const path = require('path'); const MSPChainerClass = require('./../js/msp/MSPchainer'); const mspHelper = require('./../js/msp/MSPHelper'); -const mspQueue = require('./../js/serial_queue'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const MSPCodes = require('./../js/msp/MSPCodes'); const MSP = require('./../js/msp'); const { GUI, TABS } = require('./../js/gui'); @@ -13,6 +11,7 @@ const FC = require('./../js/fc'); const CONFIGURATOR = require('./../js/data_storage'); const Settings = require('./../js/settings'); const i18n = require('./../js/localization'); +const interval = require('./../js/intervals'); TABS.receiver = { rateChartHeight: 117 @@ -370,21 +369,10 @@ TABS.receiver.initialize = function (callback) { }); function get_rc_data() { - - /* - * Throttling - */ - if (mspQueue.shouldDrop()) { - update_ui(); - return; - } - MSP.send_message(MSPCodes.MSP_RC, false, false, update_ui); } function update_ui() { - var i; - // update bars with latest data for (let i = 0; i < FC.RC.active_channels; i++) { meter_fill_array[i].css('width', ((FC.RC.channels[i] - meter_scale.min) / (meter_scale.max - meter_scale.min) * 100).clamp(0, 100) + '%'); @@ -393,7 +381,7 @@ TABS.receiver.initialize = function (callback) { } - mspBalancedInterval.add('receiver_pull', 35, 1, get_rc_data); + interval.add('receiver_pull', get_rc_data, 25); GUI.content_ready(callback); } diff --git a/tabs/setup.js b/tabs/setup.js index 3656e80f2..7579998fb 100755 --- a/tabs/setup.js +++ b/tabs/setup.js @@ -9,9 +9,7 @@ const MSP = require('./../js/msp'); const MSPCodes = require('./../js/msp/MSPCodes'); const i18n = require('./../js/localization'); const mspHelper = require('./../js/msp/MSPHelper'); -const mspBalancedInterval = require('./../js/msp_balanced_interval'); const interval = require('./../js/intervals'); -const mspQueue = require('./../js/serial_queue'); const SerialBackend = require('./../js/serial_backend'); const { mixer } = require('./../js/model'); const BitHelper = require('./../js/bitHelper') @@ -119,14 +117,6 @@ TABS.setup.initialize = function (callback) { function get_slow_data() { if (SerialBackend.have_sensor(FC.CONFIG.activeSensors, 'gps')) { - - /* - * Enable balancer - */ - // if (mspQueue.shouldDrop()) { - // return; - // } - MSP.send_message(MSPCodes.MSP_RAW_GPS, false, false, function () { var gpsFixType = i18n.getMessage('gpsFixNone'); if (FC.GPS_DATA.fix >= 2) @@ -142,14 +132,6 @@ TABS.setup.initialize = function (callback) { } function get_fast_data() { - - /* - * Enable balancer - */ - // if (mspQueue.shouldDrop()) { - // return; - // } - MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, function () { roll_e.text(i18n.getMessage('initialSetupAttitude', [FC.SENSOR_DATA.kinematics[0]])); pitch_e.text(i18n.getMessage('initialSetupAttitude', [FC.SENSOR_DATA.kinematics[1]])); @@ -159,9 +141,8 @@ TABS.setup.initialize = function (callback) { }); } - mspBalancedInterval.add('setup_data_pull_slow', 250, 1, get_slow_data); - interval.add('setup_data_pull_fast', get_fast_data, 50); + interval.add('setup_data_pull_slow', get_slow_data, 250); interval.add('gui_analog_update', function () { bat_cells_e.text(i18n.getMessage('initialSetupBatteryDetectedCellsValue', [FC.ANALOG.cell_count])); From 20e36b9b65f21d85bbd2795689a516322ec62881 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 21:36:02 +0200 Subject: [PATCH 08/11] Status updated changes --- js/msp.js | 2 +- js/periodicStatusUpdater.js | 5 ----- js/serial_queue.js | 8 -------- tabs/mission_control.js | 4 ---- 4 files changed, 1 insertion(+), 18 deletions(-) diff --git a/js/msp.js b/js/msp.js index 85a51a5e5..820b7d55c 100644 --- a/js/msp.js +++ b/js/msp.js @@ -269,7 +269,7 @@ var MSP = { */ timeout.add('delayedFreeHardLock', function() { mspQueue.freeHardLock(); - }, 50); + }, 10); // Reset variables this.message_length_received = 0; diff --git a/js/periodicStatusUpdater.js b/js/periodicStatusUpdater.js index e28959509..084da4a2a 100644 --- a/js/periodicStatusUpdater.js +++ b/js/periodicStatusUpdater.js @@ -104,11 +104,6 @@ const mspQueue = require('./serial_queue'); if (!stoppped && GUI.active_tab != 'cli') { - if (mspQueue.shouldDropStatus()) { - return; - } - - MSP.send_message(MSPCodes.MSP_SENSOR_STATUS, false, false); MSP.send_message(MSPCodes.MSPV2_INAV_STATUS, false, false); MSP.send_message(MSPCodes.MSP_ACTIVEBOXES, false, false); diff --git a/js/serial_queue.js b/js/serial_queue.js index c01e8b8f6..f4cf1bc19 100644 --- a/js/serial_queue.js +++ b/js/serial_queue.js @@ -313,14 +313,6 @@ var mspQueue = function () { }; - publicScope.shouldDrop = function () { - return (Math.round(Math.random()*100) < privateScope.dropRatio); - }; - - publicScope.shouldDropStatus = function () { - return (Math.round(Math.random()*100) < (privateScope.dropRatio * privateScope.statusDropFactor)); - }; - /** * This method return periodic for polling interval that should populate queue in 80% or less * @param {number} requestedInterval diff --git a/tabs/mission_control.js b/tabs/mission_control.js index 27b181836..19c377860 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -341,10 +341,6 @@ TABS.mission_control.initialize = function (callback) { return; } - if (mspQueue.shouldDrop()) { - return; - } - get_raw_gps_data(); }, 200); } From 9f9aa84170512bfc9aad39607c16938583c47a01 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 21:46:57 +0200 Subject: [PATCH 09/11] On connect load in series, not in parallel --- js/serial_backend.js | 51 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/js/serial_backend.js b/js/serial_backend.js index 04eb60a99..2fb26e803 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -454,35 +454,36 @@ var SerialBackend = (function () { $('.mode-disconnected').hide(); $('.mode-connected').show(); - MSP.send_message(MSPCodes.MSP_DATAFLASH_SUMMARY, false, false); - - $('#sensor-status').show(); - $('#portsinput').hide(); - $('#dataflash_wrapper_global').show(); - - /* - * Get BOXNAMES since it is used for some reason.... - */ - MSP.send_message(MSPCodes.MSP_BOXNAMES, false, false); + MSP.send_message(MSPCodes.MSP_DATAFLASH_SUMMARY, false, false, function () { + $('#sensor-status').show(); + $('#portsinput').hide(); + $('#dataflash_wrapper_global').show(); + + /* + * Get BOXNAMES since it is used for some reason.... + */ + MSP.send_message(MSPCodes.MSP_BOXNAMES, false, false, function () { + /* + * Init PIDs bank with a length that depends on the version + */ + let pidCount = 11; - /* - * Init PIDs bank with a length that depends on the version - */ - let pidCount = 11; + for (let i = 0; i < pidCount; i++) { + FC.PIDs.push(new Array(4)); + } - for (let i = 0; i < pidCount; i++) { - FC.PIDs.push(new Array(4)); - } + interval.add('msp-load-update', function () { + $('#msp-version').text("MSP version: " + MSP.protocolVersion.toFixed(0)); + $('#msp-load').text("MSP load: " + mspQueue.getLoad().toFixed(1)); + $('#msp-roundtrip').text("MSP round trip: " + mspQueue.getRoundtrip().toFixed(0)); + $('#hardware-roundtrip').text("HW round trip: " + mspQueue.getHardwareRoundtrip().toFixed(0)); + $('#drop-rate').text("Drop ratio: " + mspQueue.getDropRatio().toFixed(0) + "%"); + }, 100); - interval.add('msp-load-update', function () { - $('#msp-version').text("MSP version: " + MSP.protocolVersion.toFixed(0)); - $('#msp-load').text("MSP load: " + mspQueue.getLoad().toFixed(1)); - $('#msp-roundtrip').text("MSP round trip: " + mspQueue.getRoundtrip().toFixed(0)); - $('#hardware-roundtrip').text("HW round trip: " + mspQueue.getHardwareRoundtrip().toFixed(0)); - $('#drop-rate').text("Drop ratio: " + mspQueue.getDropRatio().toFixed(0) + "%"); - }, 100); + interval.add('global_data_refresh', periodicStatusUpdater.run, periodicStatusUpdater.getUpdateInterval(CONFIGURATOR.connection.bitrate), false); + }); + }); - interval.add('global_data_refresh', periodicStatusUpdater.run, periodicStatusUpdater.getUpdateInterval(CONFIGURATOR.connection.bitrate), false); } privateScope.onClosed = function (result) { From c50c28919b934e81a66df5dc1777aee43fb34ffa Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Fri, 26 Apr 2024 22:20:41 +0200 Subject: [PATCH 10/11] get rid of drop ratio and PID controller --- index.html | 3 - js/pid_controller.js | 130 ------------------------------------------- js/serial_backend.js | 1 - js/serial_queue.js | 26 +-------- 4 files changed, 1 insertion(+), 159 deletions(-) delete mode 100644 js/pid_controller.js diff --git a/index.html b/index.html index 0ac68c831..4b0d8aec5 100644 --- a/index.html +++ b/index.html @@ -339,9 +339,6 @@

-
- -
-
diff --git a/js/pid_controller.js b/js/pid_controller.js deleted file mode 100644 index b1df68709..000000000 --- a/js/pid_controller.js +++ /dev/null @@ -1,130 +0,0 @@ -'use strict'; - - -var PidController = function () { - - var self = {}, - privateScope = {}; - - /** - * - * @type {number} - */ - privateScope.target = null; - - /** - * - * @type {{P: null, I: null, D: null}} - */ - privateScope.gains = { - P: null, - I: null, - D: null - }; - - /** - * - * @type {number} - */ - privateScope.Iterm = 0; - - /** - * - * @type {{min: number, max: number}} - */ - privateScope.ItermLimit = { - min: -1000, - max: 1000 - }; - - /** - * - * @type {number} - */ - privateScope.previousError = 0; - - /** - * - * @type {{min: number, max: number, minThreshold: number}} - */ - privateScope.output = { - min: null, - max: null, - minThreshold: null - }; - - /** - * - * @param {number} value - */ - self.setTarget = function (value) { - privateScope.target = value; - }; - - /** - * @param {number} Pgain - * @param {number} Igain - * @param {number} Dgain - */ - self.setGains = function (Pgain, Igain, Dgain) { - privateScope.gains.P = Pgain; - privateScope.gains.I = Igain; - privateScope.gains.D = Dgain; - }; - - /** - * Sets min and max value for output - * @param {number} min - * @param {number} max - * @param {number} minThreshold if output is below this value, [min] is returned - */ - self.setOutput = function (min, max, minThreshold) { - privateScope.output.min = min; - privateScope.output.max = max; - privateScope.output.minThreshold = minThreshold; - }; - - /** - * Sets upper and lower limit for Iterm accumulator - * @param {number} min - * @param {number} max - */ - self.setItermLimit = function (min, max) { - privateScope.ItermLimit.min = min; - privateScope.ItermLimit.max = max; - }; - - /** - * Executes PID controller based on current value and target - * @param {number} current - * @returns {number} - */ - self.run = function (current) { - var error = current - privateScope.target, - Pterm = error * privateScope.gains.P, - Dterm = (error - privateScope.previousError) * privateScope.gains.D, - output; - - privateScope.previousError = error; - - privateScope.Iterm += error * privateScope.gains.I; - if (privateScope.Iterm > privateScope.ItermLimit.max) { - privateScope.Iterm = privateScope.ItermLimit.max; - } else if (privateScope.Iterm < privateScope.ItermLimit.min) { - privateScope.Iterm = privateScope.ItermLimit.min; - } - - output = Pterm + privateScope.Iterm + Dterm; - if (output < privateScope.output.minThreshold) { - output = privateScope.output.min; - } else if (output > privateScope.output.max) { - output = privateScope.output.max; - } - - return output; - }; - - return self; -}; - -module.exports = PidController; \ No newline at end of file diff --git a/js/serial_backend.js b/js/serial_backend.js index 2fb26e803..8f053ca90 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -477,7 +477,6 @@ var SerialBackend = (function () { $('#msp-load').text("MSP load: " + mspQueue.getLoad().toFixed(1)); $('#msp-roundtrip').text("MSP round trip: " + mspQueue.getRoundtrip().toFixed(0)); $('#hardware-roundtrip').text("HW round trip: " + mspQueue.getHardwareRoundtrip().toFixed(0)); - $('#drop-rate').text("Drop ratio: " + mspQueue.getDropRatio().toFixed(0) + "%"); }, 100); interval.add('global_data_refresh', periodicStatusUpdater.run, periodicStatusUpdater.getUpdateInterval(CONFIGURATOR.connection.bitrate), false); diff --git a/js/serial_queue.js b/js/serial_queue.js index f4cf1bc19..7dbf492b0 100644 --- a/js/serial_queue.js +++ b/js/serial_queue.js @@ -3,7 +3,6 @@ const CONFIGURATOR = require('./data_storage'); const MSPCodes = require('./msp/MSPCodes'); const SimpleSmoothFilter = require('./simple_smooth_filter'); -const PidController = require('./pid_controller'); const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer'); const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue'); @@ -28,29 +27,9 @@ var mspQueue = function () { privateScope.currentLoad = 0; - /** - * PID controller used to perform throttling - * @type {PidController} - */ - privateScope.loadPidController = new PidController(); - privateScope.loadPidController.setTarget(privateScope.targetLoad); - privateScope.loadPidController.setOutput(0, 99, 0); - privateScope.loadPidController.setGains(5, 6, 3); - privateScope.loadPidController.setItermLimit(0, 90); - - privateScope.dropRatio = 0; - privateScope.removeCallback = null; privateScope.putCallback = null; - publicScope.computeDropRatio = function () { - privateScope.dropRatio = privateScope.loadPidController.run(publicScope.getLoad()); - }; - - publicScope.getDropRatio = function () { - return privateScope.dropRatio; - }; - privateScope.queue = []; privateScope.softLock = false; @@ -229,12 +208,10 @@ var mspQueue = function () { */ publicScope.put = function (mspRequest) { - console.log('Received message ', mspRequest.code); - const isMessageInQueue = mspDeduplicationQueue.check(mspRequest.code); if (isMessageInQueue) { - console.log('Message already in queue: ' + mspRequest.code); + eventFrequencyAnalyzer.put('MSP Duplicate ' + mspRequest.code); return false; } @@ -286,7 +263,6 @@ var mspQueue = function () { publicScope.balancer = function () { privateScope.currentLoad = privateScope.loadFilter.get(); - publicScope.computeDropRatio(); /* * Also, check if port lock if hanging. Free is so From 7ed032ad2e1c39423cabd030b3613262cea5e12b Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sat, 27 Apr 2024 20:38:41 +0200 Subject: [PATCH 11/11] Fix additional tabs --- tabs/outputs.js | 20 ------------------ tabs/sensors.js | 54 ------------------------------------------------- 2 files changed, 74 deletions(-) diff --git a/tabs/outputs.js b/tabs/outputs.js index 72269f72c..c45d6bfa4 100644 --- a/tabs/outputs.js +++ b/tabs/outputs.js @@ -431,15 +431,6 @@ TABS.outputs.initialize = function (callback) { interval.killAll(['motor_and_status_pull', 'global_data_refresh', 'msp-load-update', 'ltm-connection-check']); interval.add('IMU_pull', function () { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_accel_graph(); - return; - } - MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_accel_graph); }, 25, true); @@ -660,21 +651,10 @@ TABS.outputs.initialize = function (callback) { $motorsEnableTestMode.trigger('change'); function getPeriodicMotorOutput() { - - if (mspQueue.shouldDrop()) { - getPeriodicServoOutput(); - return; - } - MSP.send_message(MSPCodes.MSP_MOTOR, false, false, getPeriodicServoOutput); } function getPeriodicServoOutput() { - if (mspQueue.shouldDrop()) { - update_ui(); - return; - } - MSP.send_message(MSPCodes.MSP_SERVO, false, false, update_ui); } diff --git a/tabs/sensors.js b/tabs/sensors.js index 013bb6840..a909feebe 100644 --- a/tabs/sensors.js +++ b/tabs/sensors.js @@ -442,90 +442,36 @@ TABS.sensors.initialize = function (callback) { // data pulling timers if (checkboxes[0] || checkboxes[1] || checkboxes[2]) { interval.add('IMU_pull', function () { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_imu_graphs(); - return; - } - MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_imu_graphs); }, fastest, true); } if (checkboxes[3]) { interval.add('altitude_pull', function altitude_data_pull() { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_altitude_graph(); - return; - } - MSP.send_message(MSPCodes.MSP_ALTITUDE, false, false, update_altitude_graph); }, rates.baro, true); } if (checkboxes[4]) { interval.add('sonar_pull', function sonar_data_pull() { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_sonar_graphs(); - return; - } - MSP.send_message(MSPCodes.MSP_SONAR, false, false, update_sonar_graphs); }, rates.sonar, true); } if (checkboxes[5]) { interval.add('airspeed_pull', function airspeed_data_pull() { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_airspeed_graphs(); - return; - } - MSP.send_message(MSPCodes.MSPV2_INAV_AIR_SPEED, false, false, update_airspeed_graphs); }, rates.airspeed, true); } if (checkboxes[6]) { interval.add('temperature_pull', function temperature_data_pull() { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_temperature_graphs(); - return; - } - MSP.send_message(MSPCodes.MSP2_INAV_TEMPERATURES, false, false, update_temperature_graphs); }, 1000, true); } if (checkboxes[7]) { interval.add('debug_pull', function debug_data_pull() { - - /* - * Enable balancer - */ - if (mspQueue.shouldDrop()) { - update_debug_graphs(); - return; - } - MSP.send_message(MSPCodes.MSP2_INAV_DEBUG, false, false, update_debug_graphs); }, rates.debug, true); }