mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 19:40:22 +03:00
get rid of drop ratio and PID controller
This commit is contained in:
parent
9f9aa84170
commit
c50c28919b
4 changed files with 1 additions and 159 deletions
|
@ -339,9 +339,6 @@
|
||||||
<div>
|
<div>
|
||||||
<span id="hardware-roundtrip"> </span>
|
<span id="hardware-roundtrip"> </span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<span id="drop-rate"> </span>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<span data-i18n="statusbar_arming_flags"></span> <span class="arming-flags">-</span>
|
<span data-i18n="statusbar_arming_flags"></span> <span class="arming-flags">-</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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;
|
|
|
@ -477,7 +477,6 @@ var SerialBackend = (function () {
|
||||||
$('#msp-load').text("MSP load: " + mspQueue.getLoad().toFixed(1));
|
$('#msp-load').text("MSP load: " + mspQueue.getLoad().toFixed(1));
|
||||||
$('#msp-roundtrip').text("MSP round trip: " + mspQueue.getRoundtrip().toFixed(0));
|
$('#msp-roundtrip').text("MSP round trip: " + mspQueue.getRoundtrip().toFixed(0));
|
||||||
$('#hardware-roundtrip').text("HW round trip: " + mspQueue.getHardwareRoundtrip().toFixed(0));
|
$('#hardware-roundtrip').text("HW round trip: " + mspQueue.getHardwareRoundtrip().toFixed(0));
|
||||||
$('#drop-rate').text("Drop ratio: " + mspQueue.getDropRatio().toFixed(0) + "%");
|
|
||||||
}, 100);
|
}, 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);
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
const CONFIGURATOR = require('./data_storage');
|
const CONFIGURATOR = require('./data_storage');
|
||||||
const MSPCodes = require('./msp/MSPCodes');
|
const MSPCodes = require('./msp/MSPCodes');
|
||||||
const SimpleSmoothFilter = require('./simple_smooth_filter');
|
const SimpleSmoothFilter = require('./simple_smooth_filter');
|
||||||
const PidController = require('./pid_controller');
|
|
||||||
const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer');
|
const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer');
|
||||||
const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue');
|
const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue');
|
||||||
|
|
||||||
|
@ -28,29 +27,9 @@ var mspQueue = function () {
|
||||||
|
|
||||||
privateScope.currentLoad = 0;
|
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.removeCallback = null;
|
||||||
privateScope.putCallback = null;
|
privateScope.putCallback = null;
|
||||||
|
|
||||||
publicScope.computeDropRatio = function () {
|
|
||||||
privateScope.dropRatio = privateScope.loadPidController.run(publicScope.getLoad());
|
|
||||||
};
|
|
||||||
|
|
||||||
publicScope.getDropRatio = function () {
|
|
||||||
return privateScope.dropRatio;
|
|
||||||
};
|
|
||||||
|
|
||||||
privateScope.queue = [];
|
privateScope.queue = [];
|
||||||
|
|
||||||
privateScope.softLock = false;
|
privateScope.softLock = false;
|
||||||
|
@ -229,12 +208,10 @@ var mspQueue = function () {
|
||||||
*/
|
*/
|
||||||
publicScope.put = function (mspRequest) {
|
publicScope.put = function (mspRequest) {
|
||||||
|
|
||||||
console.log('Received message ', mspRequest.code);
|
|
||||||
|
|
||||||
const isMessageInQueue = mspDeduplicationQueue.check(mspRequest.code);
|
const isMessageInQueue = mspDeduplicationQueue.check(mspRequest.code);
|
||||||
|
|
||||||
if (isMessageInQueue) {
|
if (isMessageInQueue) {
|
||||||
console.log('Message already in queue: ' + mspRequest.code);
|
eventFrequencyAnalyzer.put('MSP Duplicate ' + mspRequest.code);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +263,6 @@ var mspQueue = function () {
|
||||||
|
|
||||||
publicScope.balancer = function () {
|
publicScope.balancer = function () {
|
||||||
privateScope.currentLoad = privateScope.loadFilter.get();
|
privateScope.currentLoad = privateScope.loadFilter.get();
|
||||||
publicScope.computeDropRatio();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Also, check if port lock if hanging. Free is so
|
* Also, check if port lock if hanging. Free is so
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue