Change lexical scope ratecurve

10.8-maintenance
Mark Haslinghuis 2020-12-08 20:02:50 +01:00
parent 317f937fd5
commit 7e40d36c26
1 changed files with 19 additions and 19 deletions

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
var minRc = 1000; const minRc = 1000;
var midRc = 1500; const midRc = 1500;
var maxRc = 2000; const maxRc = 2000;
var RateCurve = function (useLegacyCurve) { const RateCurve = function (useLegacyCurve) {
this.useLegacyCurve = useLegacyCurve; this.useLegacyCurve = useLegacyCurve;
this.maxAngularVel = null; this.maxAngularVel = null;
@ -13,9 +13,9 @@ var RateCurve = function (useLegacyCurve) {
}; };
this.rcCommand = function (rcData, rcRate, deadband) { this.rcCommand = function (rcData, rcRate, deadband) {
var tmp = Math.min(Math.max(Math.abs(rcData - midRc) - deadband, 0), 500); const tmp = Math.min(Math.max(Math.abs(rcData - midRc) - deadband, 0), 500);
var result = tmp * rcRate; let result = tmp * rcRate;
if (rcData < midRc) { if (rcData < midRc) {
result = -result; result = -result;
@ -25,15 +25,15 @@ var RateCurve = function (useLegacyCurve) {
}; };
this.drawRateCurve = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit, maxAngularVel, context, width, height) { this.drawRateCurve = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit, maxAngularVel, context, width, height) {
var canvasHeightScale = height / (2 * maxAngularVel); const canvasHeightScale = height / (2 * maxAngularVel);
var stepWidth = context.lineWidth; const stepWidth = context.lineWidth;
context.save(); context.save();
context.translate(width / 2, height / 2); context.translate(width / 2, height / 2);
context.beginPath(); context.beginPath();
var rcData = minRc; let rcData = minRc;
context.moveTo(-500, -canvasHeightScale * this.rcCommandRawToDegreesPerSecond(rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit)); context.moveTo(-500, -canvasHeightScale * this.rcCommandRawToDegreesPerSecond(rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit));
rcData = rcData + stepWidth; rcData = rcData + stepWidth;
while (rcData <= maxRc) { while (rcData <= maxRc) {
@ -48,7 +48,7 @@ var RateCurve = function (useLegacyCurve) {
this.drawLegacyRateCurve = function (rate, rcRate, rcExpo, context, width, height) { this.drawLegacyRateCurve = function (rate, rcRate, rcExpo, context, width, height) {
// math magic by englishman // math magic by englishman
var rateY = height * rcRate; let rateY = height * rcRate;
rateY = rateY + (1 / (1 - ((rateY / height) * rate))); rateY = rateY + (1 / (1 - ((rateY / height) * rate)));
// draw // draw
@ -63,7 +63,7 @@ var RateCurve = function (useLegacyCurve) {
const DEFAULT_SIZE = 60; // canvas units, relative size of the stick indicator (larger value is smaller indicator) const DEFAULT_SIZE = 60; // canvas units, relative size of the stick indicator (larger value is smaller indicator)
const rateScaling = (context.canvas.height / 2) / maxAngularVel; const rateScaling = (context.canvas.height / 2) / maxAngularVel;
var currentValue = this.rcCommandRawToDegreesPerSecond(rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit); const currentValue = this.rcCommandRawToDegreesPerSecond(rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit);
if(rcData!=undefined) { if(rcData!=undefined) {
context.save(); context.save();
@ -85,8 +85,8 @@ var RateCurve = function (useLegacyCurve) {
rcRate = rcRate + (rcRate - 2) * 14.54; rcRate = rcRate + (rcRate - 2) * 14.54;
} }
var expoPower; let expoPower;
var rcRateConstant; let rcRateConstant;
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
expoPower = 3; expoPower = 3;
@ -101,7 +101,7 @@ var RateCurve = function (useLegacyCurve) {
} }
if (superExpoActive) { if (superExpoActive) {
var rcFactor = 1 / this.constrain(1 - rcCommandfAbs * rate, 0.01, 1); const rcFactor = 1 / this.constrain(1 - rcCommandfAbs * rate, 0.01, 1);
angularVel = rcRateConstant * rcRate * rcCommandf; // 200 should be variable checked on version (older versions it's 205,9) angularVel = rcRateConstant * rcRate * rcCommandf; // 200 should be variable checked on version (older versions it's 205,9)
angularVel = angularVel * rcFactor; angularVel = angularVel * rcFactor;
} else { } else {
@ -153,7 +153,7 @@ var RateCurve = function (useLegacyCurve) {
}; };
RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit) { RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcRate, rcExpo, superExpoActive, deadband, limit) {
var angleRate; let angleRate;
if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) { if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) {
let rcCommandf = this.rcCommand(rcData, 1, deadband); let rcCommandf = this.rcCommand(rcData, 1, deadband);
@ -163,7 +163,7 @@ RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcR
rcCommandf = rcCommandf / 500; rcCommandf = rcCommandf / 500;
} }
var rcCommandfAbs = Math.abs(rcCommandf); const rcCommandfAbs = Math.abs(rcCommandf);
switch(TABS.pid_tuning.currentRatesType) { switch(TABS.pid_tuning.currentRatesType) {
case TABS.pid_tuning.RATES_TYPE.RACEFLIGHT: case TABS.pid_tuning.RATES_TYPE.RACEFLIGHT:
@ -198,7 +198,7 @@ RateCurve.prototype.rcCommandRawToDegreesPerSecond = function (rcData, rate, rcR
}; };
RateCurve.prototype.getMaxAngularVel = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit) { RateCurve.prototype.getMaxAngularVel = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit) {
var maxAngularVel; let maxAngularVel;
if (!this.useLegacyCurve) { if (!this.useLegacyCurve) {
maxAngularVel = this.rcCommandRawToDegreesPerSecond(maxRc, rate, rcRate, rcExpo, superExpoActive, deadband, limit); maxAngularVel = this.rcCommandRawToDegreesPerSecond(maxRc, rate, rcRate, rcExpo, superExpoActive, deadband, limit);
} }
@ -214,8 +214,8 @@ RateCurve.prototype.setMaxAngularVel = function (value) {
RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit, maxAngularVel, context) { RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, deadband, limit, maxAngularVel, context) {
if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) { if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined) {
var height = context.canvas.height; const height = context.canvas.height;
var width = context.canvas.width; const width = context.canvas.width;
if (this.useLegacyCurve) { if (this.useLegacyCurve) {
this.drawLegacyRateCurve(rate, rcRate, rcExpo, context, width, height); this.drawLegacyRateCurve(rate, rcRate, rcExpo, context, width, height);