Cleaned up rates calculation and display a bunch.

10.3.x-maintenance
mikeller 2016-07-08 00:12:09 +12:00
parent 3cc363cbcb
commit b398c271c4
2 changed files with 82 additions and 91 deletions

View File

@ -40,10 +40,6 @@ var RateCurve = function (useLegacyCurve) {
}; };
this.drawRateCurve = function (rate, rcRate, rcExpo, superExpoActive, maxAngularVel, context, width, height) { this.drawRateCurve = function (rate, rcRate, rcExpo, superExpoActive, maxAngularVel, context, width, height) {
rate = rate * 100;
rcRate = rcRate * 100;
rcExpo = rcExpo * 100;
var canvasHeightScale = height / (2 * maxAngularVel); var canvasHeightScale = height / (2 * maxAngularVel);
var stepWidth = context.lineWidth; var stepWidth = context.lineWidth;
@ -66,6 +62,10 @@ var RateCurve = function (useLegacyCurve) {
} }
this.drawLegacyRateCurve = function (rate, rcRate, rcExpo, context, width, height) { this.drawLegacyRateCurve = function (rate, rcRate, rcExpo, context, width, height) {
rate = rate / 100;
rcRate = rcRate / 100;
rcExpo = rcExpo / 100;
// math magic by englishman // math magic by englishman
var rateY = height * rcRate; var rateY = height * rcRate;
rateY = rateY + (1 / (1 - ((rateY / height) * rate))) rateY = rateY + (1 / (1 - ((rateY / height) * rate)))
@ -82,10 +82,6 @@ RateCurve.prototype.getMaxAngularVel = function (rate, rcRate, rcExpo, superExpo
var maxAngularVel; var maxAngularVel;
if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined if (rate !== undefined && rcRate !== undefined && rcExpo !== undefined
&& !this.useLegacyCurve) { && !this.useLegacyCurve) {
rate = rate * 100;
rcRate = rcRate * 100;
rcExpo = rcExpo * 100;
maxAngularVel = this.rcCommandRawToDegreesPerSecond(maxRc, rate, rcRate, rcExpo, superExpoActive); maxAngularVel = this.rcCommandRawToDegreesPerSecond(maxRc, rate, rcRate, rcExpo, superExpoActive);
} }

View File

@ -337,6 +337,20 @@ TABS.pid_tuning.initialize = function (callback) {
} }
} }
var showAllButton = $('#showAllPids');
function updatePidDisplay() {
if (!TABS.pid_tuning.showAllPids) {
hideUnusedPids();
showAllButton.text(chrome.i18n.getMessage("pidTuningShowAllPids"));
} else {
showAllPids();
showAllButton.text(chrome.i18n.getMessage("pidTuningHideUnusedPids"));
}
}
function drawAxes(curveContext, width, height, scaleHeight) { function drawAxes(curveContext, width, height, scaleHeight) {
curveContext.strokeStyle = '#000000'; curveContext.strokeStyle = '#000000';
curveContext.lineWidth = 4; curveContext.lineWidth = 4;
@ -354,8 +368,8 @@ TABS.pid_tuning.initialize = function (callback) {
curveContext.stroke(); curveContext.stroke();
if (scaleHeight <= height / 2) { if (scaleHeight <= height / 2) {
curveContext.strokeStyle = '#202020'; curveContext.strokeStyle = '#c0c0c0';
curveContext.lineWidth = 1; curveContext.lineWidth = 4;
curveContext.beginPath(); curveContext.beginPath();
curveContext.moveTo(0, height / 2 + scaleHeight); curveContext.moveTo(0, height / 2 + scaleHeight);
@ -379,6 +393,28 @@ TABS.pid_tuning.initialize = function (callback) {
return value; return value;
} }
var useLegacyCurve = false;
if (CONFIG.flightControllerIdentifier !== "BTFL" || semver.lt(CONFIG.flightControllerVersion, "2.8.0")) {
useLegacyCurve = true;
}
self.rateCurve = new RateCurve(useLegacyCurve);
function printMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, maxAngularVelElement) {
var maxAngularVel = self.rateCurve.getMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo);
maxAngularVelElement.text(maxAngularVel);
return maxAngularVel;
}
function drawCurve(rate, rcRate, rcExpo, useSuperExpo, maxAngularVel, colour, yOffset, context) {
context.save();
context.strokeStyle = colour;
context.translate(0, yOffset);
self.rateCurve.draw(rate, rcRate, rcExpo, useSuperExpo, maxAngularVel, context);
context.restore();
}
function process_html() { function process_html() {
// translate to user-selected language // translate to user-selected language
localize(); localize();
@ -392,23 +428,16 @@ TABS.pid_tuning.initialize = function (callback) {
rc_rate_yaw: SPECIAL_PARAMETERS.RC_RATE_YAW * 100, rc_rate_yaw: SPECIAL_PARAMETERS.RC_RATE_YAW * 100,
rc_expo: RC_tuning.RC_EXPO * 100, rc_expo: RC_tuning.RC_EXPO * 100,
rc_yaw_expo: RC_tuning.RC_YAW_EXPO * 100, rc_yaw_expo: RC_tuning.RC_YAW_EXPO * 100,
superexpo: false superexpo: bit_check(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT)
}; };
var showAllButton = $('#showAllPids'); if (CONFIG.flightControllerIdentifier !== "BTFL" || semver.lt(CONFIG.flightControllerVersion, "2.8.1")) {
var showAllMsg = chrome.i18n.getMessage("pidTuningShowAllPids"); self.currentRates.rc_rate_yaw = self.currentRates.rc_rate;
var hideUnusedMsg = chrome.i18n.getMessage("pidTuningHideUnusedPids");
function updatePidDisplay() {
if (!TABS.pid_tuning.showAllPids) {
hideUnusedPids();
showAllButton.text(showAllMsg);
} else {
showAllPids();
showAllButton.text(hideUnusedMsg);
} }
if (semver.lt(CONFIG.apiVersion, "1.7.0")) {
self.currentRates.roll_rate = RC_tuning.roll_pitch_rate * 100;
self.currentRates.pitch_rate = RC_tuning.roll_pitch_rate * 100;
} }
updatePidDisplay(); updatePidDisplay();
@ -481,22 +510,11 @@ TABS.pid_tuning.initialize = function (callback) {
$('.pid_tuning .roll_pitch_rate').hide(); $('.pid_tuning .roll_pitch_rate').hide();
} }
// Getting the DOM elements for curve display if (useLegacyCurve) {
var rcRateElement = $('.pid_tuning input[name="rc_rate"]'); $('.new_rates').hide();
var rcRateYawElement;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "2.8.1")) {
rcRateYawElement = $('.pid_tuning input[name="rc_rate_yaw"]');
} else {
rcRateYawElement = rcRateElement;
} }
var rateRollElement = $('.pid_tuning input[name="roll_rate"]'); // Getting the DOM elements for curve display
var ratePitchElement = $('.pid_tuning input[name="pitch_rate"]');
var rateYawElement = $('.pid_tuning input[name="yaw_rate"]');
var rcExpoElement = $('.pid_tuning input[name="rc_expo"]');
var rcExpoYawElement = $('.pid_tuning input[name="rc_yaw_expo"]');
var rcCurveElement = $('.rate_curve canvas').get(0); var rcCurveElement = $('.rate_curve canvas').get(0);
var curveContext = rcCurveElement.getContext("2d"); var curveContext = rcCurveElement.getContext("2d");
rcCurveElement.width = 1000; rcCurveElement.width = 1000;
@ -506,33 +524,8 @@ TABS.pid_tuning.initialize = function (callback) {
var maxAngularVelPitchElement = $('.rc_curve .maxAngularVelPitch'); var maxAngularVelPitchElement = $('.rc_curve .maxAngularVelPitch');
var maxAngularVelYawElement = $('.rc_curve .maxAngularVelYaw'); var maxAngularVelYawElement = $('.rc_curve .maxAngularVelYaw');
var superExpoElement = $('.pid_tuning input[name="show_superexpo_rates"]'); function updateRates(event) {
var useLegacyCurve = false;
if (CONFIG.flightControllerIdentifier !== "BTFL" || semver.lt(CONFIG.flightControllerVersion, "2.8.0")) {
$('.new_rates').hide();
useLegacyCurve = true;
}
self.rateCurve = new RateCurve(useLegacyCurve);
// UI Hooks
// curves
function redrawRateCurves(event) {
setTimeout(function () { // let global validation trigger and adjust the values first setTimeout(function () { // let global validation trigger and adjust the values first
var curveHeight = rcCurveElement.height;
var curveWidth = rcCurveElement.width;
var useSuperExpo = superExpoElement.is(':checked');
var rateRoll = checkInput(rateRollElement);
var ratePitch = checkInput(ratePitchElement);
var rateYaw = checkInput(rateYawElement);
var rcRate = checkInput(rcRateElement);
var rcRateYaw = checkInput(rcRateYawElement);
var rcExpo = checkInput(rcExpoElement);
var rcExpoYaw = checkInput(rcExpoYawElement);
var targetElement = $(event.target), var targetElement = $(event.target),
targetValue = checkInput(targetElement); targetValue = checkInput(targetElement);
@ -540,15 +533,26 @@ TABS.pid_tuning.initialize = function (callback) {
self.currentRates[targetElement.attr('name')] = targetValue * 100; self.currentRates[targetElement.attr('name')] = targetValue * 100;
} }
self.currentRates.superexpo = useSuperExpo; if (targetElement.attr('name') === 'rc_rate' && CONFIG.flightControllerIdentifier !== "BTFL" || semver.lt(CONFIG.flightControllerVersion, "2.8.1")) {
self.currentRates.rc_rate_yaw = targetValue * 100;
}
var maxAngularVelRoll = self.rateCurve.getMaxAngularVel(rateRoll, rcRate, rcExpo, useSuperExpo); if (targetElement.attr('name') === 'roll_pitch_rate' && semver.lt(CONFIG.apiVersion, "1.7.0")) {
maxAngularVelRollElement.text(maxAngularVelRoll); self.currentRates.roll_rate = targetValue * 100;
var maxAngularVelPitch = self.rateCurve.getMaxAngularVel(ratePitch, rcRate, rcExpo, useSuperExpo); self.currentRates.pitch_rate = targetValue * 100;
maxAngularVelPitchElement.text(maxAngularVelPitch); }
var maxAngularVelYaw = self.rateCurve.getMaxAngularVel(rateYaw, rcRateYaw, rcExpoYaw, useSuperExpo);
maxAngularVelYawElement.text(maxAngularVelYaw); if (targetElement.attr('name') === 'show_superexpo_rates') {
var maxAngularVel = Math.max(maxAngularVelRoll, maxAngularVelPitch, maxAngularVelYaw); self.currentRates.superexpo = targetElement.is(':checked');
}
var curveHeight = rcCurveElement.height;
var curveWidth = rcCurveElement.width;
var maxAngularVel = Math.max(
printMaxAngularVel(self.currentRates.roll_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, maxAngularVelRollElement),
printMaxAngularVel(self.currentRates.pitch_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, maxAngularVelPitchElement),
printMaxAngularVel(self.currentRates.yaw_rate, self.currentRates.rc_rate_yaw, self.currentRates.rc_yaw_expo, self.currentRates.superexpo, maxAngularVelYawElement));
curveContext.clearRect(0, 0, curveWidth, curveHeight); curveContext.clearRect(0, 0, curveWidth, curveHeight);
@ -558,27 +562,18 @@ TABS.pid_tuning.initialize = function (callback) {
curveContext.lineWidth = 4; curveContext.lineWidth = 4;
curveContext.save(); drawCurve(self.currentRates.roll_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, maxAngularVel, '#ff0000', 0, curveContext);
curveContext.strokeStyle = '#ff0000';
self.rateCurve.draw(rateRoll, rcRate, rcExpo, useSuperExpo, maxAngularVel, curveContext);
curveContext.restore();
curveContext.save(); drawCurve(self.currentRates.pitch_rate, self.currentRates.rc_rate, self.currentRates.rc_expo, self.currentRates.superexpo, maxAngularVel, '#00ff00', -4, curveContext);
curveContext.translate(0, -4);
curveContext.strokeStyle = '#00ff00';
self.rateCurve.draw(ratePitch, rcRate, rcExpo, useSuperExpo, maxAngularVel, curveContext);
curveContext.restore();
curveContext.save(); drawCurve(self.currentRates.yaw_rate, self.currentRates.rc_rate_yaw, self.currentRates.rc_yaw_expo, self.currentRates.superexpo, maxAngularVel, '#0000ff', 4, curveContext);
curveContext.strokeStyle = '#0000ff';
curveContext.translate(0, 4);
self.rateCurve.draw(rateYaw, rcRateYaw, rcExpoYaw, useSuperExpo, maxAngularVel, curveContext);
curveContext.restore();
}, 0); }, 0);
}; };
$('.pid_tuning').on('input change', redrawRateCurves).trigger('input'); // UI Hooks
$('.super_expo_checkbox').on('input change', redrawRateCurves).trigger('input'); // curves
$('.pid_tuning').on('input change', updateRates);
$('.super_expo_checkbox').on('input change', updateRates).trigger('input');
$('.throttle input').on('input change', function () { $('.throttle input').on('input change', function () {
setTimeout(function () { // let global validation trigger and adjust the values first setTimeout(function () { // let global validation trigger and adjust the values first