1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-17 21:35:33 +03:00

Cleanup for model/rates

This commit is contained in:
Anthony Dmitriyev 2016-07-07 00:55:15 +01:00
parent 51db1de165
commit 10b51a1b83
3 changed files with 42 additions and 37 deletions

26
main.js
View file

@ -34,7 +34,7 @@ $(document).ready(function () {
console.log('Application version expired');
GUI.log('You are using an old version of ' + chrome.runtime.getManifest().name + '. There may be a more recent version with improvements and fixes.');
}
chrome.storage.local.get('logopen', function (result) {
if (result.logopen) {
$("#showlog").trigger('click');
@ -58,20 +58,20 @@ $(document).ready(function () {
tabClass = $(self).parent().prop('class');
var tabRequiresConnection = $(self).parent().hasClass('mode-connected');
var tab = tabClass.substring(4);
var tabName = $(self).text();
if (tabRequiresConnection && !CONFIGURATOR.connectionValid) {
GUI.log(chrome.i18n.getMessage('tabSwitchConnectionRequired'));
return;
}
if (GUI.connect_lock) { // tab switching disabled while operation is in progress
GUI.log(chrome.i18n.getMessage('tabSwitchWaitForOperation'));
return;
}
if (GUI.allowedTabs.indexOf(tab) < 0) {
GUI.log(chrome.i18n.getMessage('tabSwitchUpgradeRequired', [tabName]));
return;
@ -300,7 +300,7 @@ $(document).ready(function () {
}
}
});
$("#showlog").on('click', function() {
var state = $(this).data('state');
if ( state ) {
@ -313,7 +313,7 @@ $(document).ready(function () {
$(".tab_container").removeClass('logopen');
$("#scrollicon").removeClass('active');
chrome.storage.local.set({'logopen': false});
state = false;
}else{
$("#log").animate({height: 111}, 200);
@ -327,11 +327,11 @@ $(document).ready(function () {
}
$(this).text(state ? 'Hide Log' : 'Show Log');
$(this).data('state', state);
});
var profile_e = $('select[name="profilechange"]');
profile_e.change(function () {
var profile = parseInt($(this).val());
MSP.send_message(MSP_codes.MSP_SELECT_SETTING, [profile], false, function () {
@ -353,6 +353,12 @@ function millitime() {
return now;
}
var DEGREE_TO_RADIAN_RATIO = Math.PI / 180;
function degToRad(degrees) {
return degrees * DEGREE_TO_RADIAN_RATIO;
}
function bytesToSize(bytes) {
if (bytes < 1024) {
bytes = bytes + ' Bytes';

View file

@ -8,7 +8,9 @@ var SUPEREXPO_FEATURE_BIT = 23;
TABS.pid_tuning.initialize = function (callback) {
var self = this;
if (GUI.active_tab != 'pid_tuning') { GUI.active_tab = 'pid_tuning'; }
if (GUI.active_tab != 'pid_tuning') {
GUI.active_tab = 'pid_tuning';
}
// requesting MSP_STATUS manually because it contains CONFIG.profile
MSP.promise(MSP_codes.MSP_STATUS).then(function() {
@ -383,13 +385,14 @@ TABS.pid_tuning.initialize = function (callback) {
// Local cache of current rates
self.currentRates = {
rateRoll: RC_tuning.roll_rate * 100,
ratePitch: RC_tuning.pitch_rate * 100,
rateYaw: RC_tuning.yaw_rate * 100,
rcRate: RC_tuning.RC_RATE * 100,
rcRateYaw: SPECIAL_PARAMETERS.RC_RATE_YAW * 100,
rcExpo: RC_tuning.RC_EXPO * 100,
rcExpoYaw: RC_tuning.RC_YAW_EXPO * 100
roll_rate: RC_tuning.roll_rate * 100,
pitch_rate: RC_tuning.pitch_rate * 100,
yaw_rate: RC_tuning.yaw_rate * 100,
rc_rate: RC_tuning.RC_RATE * 100,
rc_rate_yaw: SPECIAL_PARAMETERS.RC_RATE_YAW * 100,
rc_expo: RC_tuning.RC_EXPO * 100,
rc_yaw_expo: RC_tuning.RC_YAW_EXPO * 100,
superexpo: false
};
var showAllButton = $('#showAllPids');
@ -515,7 +518,7 @@ TABS.pid_tuning.initialize = function (callback) {
// UI Hooks
// curves
function redrawRateCurves() {
function redrawRateCurves(event) {
setTimeout(function () { // let global validation trigger and adjust the values first
var curveHeight = rcCurveElement.height;
var curveWidth = rcCurveElement.width;
@ -530,13 +533,14 @@ TABS.pid_tuning.initialize = function (callback) {
var rcExpo = checkInput(rcExpoElement);
var rcExpoYaw = checkInput(rcExpoYawElement);
self.currentRates.rateRoll = rateRoll * 100;
self.currentRates.ratePitch = ratePitch * 100;
self.currentRates.rateYaw = rateYaw * 100;
self.currentRates.rcRate = rcRate * 100;
self.currentRates.rcRateYaw = rcRateYaw * 100;
self.currentRates.rcExpo = rcExpo * 100;
self.currentRates.rcExpoYaw = rcExpoYaw * 100;
var targetElement = $(event.target),
targetValue = checkInput(targetElement);
if (self.currentRates.hasOwnProperty(targetElement.attr('name')) && targetValue) {
self.currentRates[targetElement.attr('name')] = targetValue * 100;
}
self.currentRates.superexpo = useSuperExpo;
var maxAngularVelRoll = self.rateCurve.getMaxAngularVel(rateRoll, rcRate, rcExpo, useSuperExpo);
maxAngularVelRollElement.text(maxAngularVelRoll);
@ -718,9 +722,6 @@ TABS.pid_tuning.initRatesPreview = function () {
this.keepRendering = true;
this.model = new Model($('.rates_preview'), $('.rates_preview canvas'));
this.$superExpo = $('.pid_tuning input[name="show_superexpo_rates"]');
this.degreeToRadianRatio = Math.PI / 180;
$(window).on('resize', $.proxy(this.model.resize, this.model));
};
@ -730,14 +731,13 @@ TABS.pid_tuning.renderModel = function () {
if (!this.clock) { this.clock = new THREE.Clock(); }
if (RC.channels[0] && RC.channels[1] && RC.channels[2]) {
var delta = this.clock.getDelta(),
useSuperExpo = this.$superExpo.is(':checked');
var delta = this.clock.getDelta();
var roll = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[0], this.currentRates.rateRoll, this.currentRates.rcRate, this.currentRates.rcExpo, useSuperExpo),
pitch = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[1], this.currentRates.ratePitch, this.currentRates.rcRate, this.currentRates.rcExpo, useSuperExpo),
yaw = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[2], this.currentRates.rateYaw, this.currentRates.rcRateYaw, this.currentRates.rcExpoYaw, useSuperExpo);
var roll = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[0], this.currentRates.roll_rate, this.currentRates.rc_rate, this.currentRates.rc_expo, this.currentRates.super_expo),
pitch = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[1], this.currentRates.pitch_rate, this.currentRates.rc_rate, this.currentRates.rc_expo, this.currentRates.super_expo),
yaw = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[2], this.currentRates.yaw_rate, this.currentRates.rc_rate_yaw, this.currentRates.rc_yaw_expo, this.currentRates.super_expo);
this.model.rotateBy(-pitch * this.degreeToRadianRatio, -yaw * this.degreeToRadianRatio, -roll * this.degreeToRadianRatio);
this.model.rotateBy(-degToRad(pitch), -degToRad(yaw), -degToRad(roll));
}
};

View file

@ -405,7 +405,6 @@ TABS.receiver.initModelPreview = function () {
}
this.rateCurve = new RateCurve(CONFIG.flightControllerIdentifier !== 'BTFL' || semver.lt(CONFIG.flightControllerVersion, '2.8.0'));
this.degreeToRadianRatio = Math.PI / 180;
$(window).on('resize', $.proxy(this.model.resize, this.model));
};
@ -422,7 +421,7 @@ TABS.receiver.renderModel = function () {
pitch = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[1], RC_tuning.pitch_rate * 100, RC_tuning.RC_RATE * 100, RC_tuning.RC_EXPO * 100, this.useSuperExpo),
yaw = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[2], RC_tuning.yaw_rate * 100, SPECIAL_PARAMETERS.RC_RATE_YAW * 100, RC_tuning.RC_YAW_EXPO * 100, this.useSuperExpo);
this.model.rotateBy(-pitch * this.degreeToRadianRatio, -yaw * this.degreeToRadianRatio, -roll * this.degreeToRadianRatio);
this.model.rotateBy(-degToRad(pitch), -degToRad(yaw), -degToRad(roll));
}
};