3D model to respect rates

10.3.x-maintenance
Anthony Dmitriyev 2016-07-06 23:13:07 +01:00
parent 53c4ee43d3
commit 86352b2a61
2 changed files with 56 additions and 29 deletions

View File

@ -8,9 +8,7 @@ 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,6 +381,17 @@ TABS.pid_tuning.initialize = function (callback) {
// translate to user-selected language
localize();
// 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
};
var showAllButton = $('#showAllPids');
var showAllMsg = chrome.i18n.getMessage("pidTuningShowAllPids");
var hideUnusedMsg = chrome.i18n.getMessage("pidTuningHideUnusedPids");
@ -502,7 +511,7 @@ TABS.pid_tuning.initialize = function (callback) {
useLegacyCurve = true;
}
var rateCurve = new RateCurve(useLegacyCurve);
self.rateCurve = new RateCurve(useLegacyCurve);
// UI Hooks
// curves
@ -521,11 +530,19 @@ TABS.pid_tuning.initialize = function (callback) {
var rcExpo = checkInput(rcExpoElement);
var rcExpoYaw = checkInput(rcExpoYawElement);
var maxAngularVelRoll = rateCurve.getMaxAngularVel(rateRoll, rcRate, rcExpo, useSuperExpo);
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 maxAngularVelRoll = self.rateCurve.getMaxAngularVel(rateRoll, rcRate, rcExpo, useSuperExpo);
maxAngularVelRollElement.text(maxAngularVelRoll);
var maxAngularVelPitch = rateCurve.getMaxAngularVel(ratePitch, rcRate, rcExpo, useSuperExpo);
var maxAngularVelPitch = self.rateCurve.getMaxAngularVel(ratePitch, rcRate, rcExpo, useSuperExpo);
maxAngularVelPitchElement.text(maxAngularVelPitch);
var maxAngularVelYaw = rateCurve.getMaxAngularVel(rateYaw, rcRateYaw, rcExpoYaw, useSuperExpo);
var maxAngularVelYaw = self.rateCurve.getMaxAngularVel(rateYaw, rcRateYaw, rcExpoYaw, useSuperExpo);
maxAngularVelYawElement.text(maxAngularVelYaw);
var maxAngularVel = Math.max(maxAngularVelRoll, maxAngularVelPitch, maxAngularVelYaw);
@ -539,19 +556,19 @@ TABS.pid_tuning.initialize = function (callback) {
curveContext.save();
curveContext.strokeStyle = '#ff0000';
rateCurve.draw(rateRoll, rcRate, rcExpo, useSuperExpo, maxAngularVel, curveContext);
self.rateCurve.draw(rateRoll, rcRate, rcExpo, useSuperExpo, maxAngularVel, curveContext);
curveContext.restore();
curveContext.save();
curveContext.translate(0, -4);
curveContext.strokeStyle = '#00ff00';
rateCurve.draw(ratePitch, rcRate, rcExpo, useSuperExpo, maxAngularVel, curveContext);
self.rateCurve.draw(ratePitch, rcRate, rcExpo, useSuperExpo, maxAngularVel, curveContext);
curveContext.restore();
curveContext.save();
curveContext.strokeStyle = '#0000ff';
curveContext.translate(0, 4);
rateCurve.draw(rateYaw, rcRateYaw, rcExpoYaw, useSuperExpo, maxAngularVel, curveContext);
self.rateCurve.draw(rateYaw, rcRateYaw, rcExpoYaw, useSuperExpo, maxAngularVel, curveContext);
curveContext.restore();
}, 0);
};
@ -701,11 +718,8 @@ TABS.pid_tuning.initRatesPreview = function () {
this.keepRendering = true;
this.model = new Model($('.rates_preview'), $('.rates_preview canvas'));
var scale = d3.scale.linear().domain([900, 2100]);
this.rollScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.pitchScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.yawScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.$superExpo = $('.pid_tuning input[name="show_superexpo_rates"]');
this.degreeToRadianRatio = Math.PI / 180;
$(window).on('resize', $.proxy(this.model.resize, this.model));
};
@ -717,11 +731,13 @@ TABS.pid_tuning.renderModel = function () {
if (RC.channels[0] && RC.channels[1] && RC.channels[2]) {
var delta = this.clock.getDelta(),
roll = delta * this.rollScale(RC.channels[0]),
pitch = delta * this.pitchScale(RC.channels[1]),
yaw = delta * this.yawScale(RC.channels[2]);
useSuperExpo = this.$superExpo.is(':checked');
this.model.rotateBy(pitch, yaw, roll);
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);
this.model.rotateBy(-pitch * this.degreeToRadianRatio, -yaw * this.degreeToRadianRatio, -roll * this.degreeToRadianRatio);
}
};

View File

@ -12,7 +12,15 @@ TABS.receiver.initialize = function (callback) {
}
function get_rc_data() {
MSP.send_message(MSP_codes.MSP_RC, false, false, get_rc_map);
MSP.send_message(MSP_codes.MSP_RC, false, false, get_rc_tuning_data);
}
function get_rc_tuning_data() {
MSP.send_message(MSP_codes.MSP_RC_TUNING, false, false, get_bt_config_data);
}
function get_bt_config_data() {
MSP.send_message(MSP_codes.MSP_BF_CONFIG, false, false, get_rc_map);
}
function get_rc_map() {
@ -391,11 +399,13 @@ TABS.receiver.initModelPreview = function () {
this.keepRendering = true;
this.model = new Model($('.model_preview'), $('.model_preview canvas'));
var scale = d3.scale.linear().domain([900, 2100]);
this.useSuperExpo = false;
if (CONFIG.flightControllerIdentifier === 'BTFL' && semver.gte(CONFIG.flightControllerVersion, '2.8.0')) {
this.useSuperExpo = bit_check(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT);
}
this.rollScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.pitchScale = scale.range([Math.PI * 2, -Math.PI * 2]);
this.yawScale = scale.range([Math.PI * 2, -Math.PI * 2]);
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));
};
@ -406,12 +416,13 @@ TABS.receiver.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(),
roll = delta * this.rollScale(RC.channels[0]),
pitch = delta * this.pitchScale(RC.channels[1]),
yaw = delta * this.yawScale(RC.channels[2]);
var delta = this.clock.getDelta();
this.model.rotateBy(pitch, yaw, roll);
var roll = delta * this.rateCurve.rcCommandRawToDegreesPerSecond(RC.channels[0], RC_tuning.roll_rate * 100, RC_tuning.RC_RATE * 100, RC_tuning.RC_EXPO * 100, this.useSuperExpo),
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);
}
};