mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 17:55:24 +03:00
Merge pull request #674 from mikeller/fix_motors_tab
Fixed motor output values in motor tab.
This commit is contained in:
commit
d55f22bcdd
2 changed files with 240 additions and 251 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,6 @@
|
|||
.DS_store
|
||||
nbproject/
|
||||
.idea
|
||||
.project
|
||||
.settings/
|
||||
|
||||
|
|
121
tabs/motors.js
121
tabs/motors.js
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
TABS.motors = {
|
||||
allowTestMode: false,
|
||||
feature3DEnabled: false,
|
||||
feature3DSupported: false,
|
||||
escProtocolIsDshot: false,
|
||||
sensor: "gyro",
|
||||
sensorGyroRate: 20,
|
||||
|
@ -13,16 +11,18 @@ TABS.motors = {
|
|||
sensorSelectValues: {
|
||||
"gyroScale": {"50":50,"100":100,"200":200,"300":300,"400":400,"500":500,"1000":1000,"2000":2000},
|
||||
"accelScale": {"0.05":0.05,"0.1":0.1,"0.2":0.2,"0.3":0.3,"0.4":0.4,"0.5":0.5,"1":1,"2":2}
|
||||
}
|
||||
},
|
||||
// These are translated into proper Dshot values on the flight controller
|
||||
DSHOT_DISARMED_VALUE: 1000,
|
||||
DSHOT_MAX_VALUE: 2000,
|
||||
DSHOT_3D_NEUTRAL: 1500
|
||||
};
|
||||
|
||||
TABS.motors.initialize = function (callback) {
|
||||
var self = this;
|
||||
|
||||
self.armed = false;
|
||||
self.feature3DSupported = false;
|
||||
self.allowTestMode = true;
|
||||
self.feature3DSupported = true;
|
||||
self.escProtocolIsDshot = false;
|
||||
|
||||
if (GUI.active_tab != 'motors') {
|
||||
GUI.active_tab = 'motors';
|
||||
|
@ -204,10 +204,6 @@ TABS.motors.initialize = function (callback) {
|
|||
|
||||
self.feature3DEnabled = FEATURE_CONFIG.features.isEnabled('3D');
|
||||
|
||||
if (self.feature3DEnabled && !self.feature3DSupported) {
|
||||
self.allowTestMode = false;
|
||||
}
|
||||
|
||||
if (PID_ADVANCED_CONFIG.fast_pwm_protocol >= TABS.configuration.DSHOT_PROTOCOL_MIN_VALUE) {
|
||||
self.escProtocolIsDshot = true;
|
||||
} else {
|
||||
|
@ -398,7 +394,6 @@ TABS.motors.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
$('a.reset_max').click(function () {
|
||||
gyro_max_read = [0, 0, 0];
|
||||
accel_max_read = [0, 0, 0];
|
||||
|
@ -406,6 +401,20 @@ TABS.motors.initialize = function (callback) {
|
|||
});
|
||||
|
||||
var number_of_valid_outputs = (MOTOR_DATA.indexOf(0) > -1) ? MOTOR_DATA.indexOf(0) : 8;
|
||||
var rangeMin;
|
||||
var rangeMax;
|
||||
var neutral3d;
|
||||
if (self.escProtocolIsDshot) {
|
||||
rangeMin = self.DSHOT_DISARMED_VALUE;
|
||||
rangeMax = self.DSHOT_MAX_VALUE;
|
||||
neutral3d = self.DSHOT_3D_NEUTRAL;
|
||||
} else {
|
||||
rangeMin = MOTOR_CONFIG.mincommand;
|
||||
rangeMax = MOTOR_CONFIG.maxthrottle;
|
||||
//Arbitrary sanity checks
|
||||
//Note: values may need to be revisited
|
||||
neutral3d = (MOTOR_3D_CONFIG.neutral > 1575 || MOTOR_3D_CONFIG.neutral < 1425) ? 1500 : MOTOR_3D_CONFIG.neutral;
|
||||
}
|
||||
|
||||
var motors_wrapper = $('.motors .bar-wrapper'),
|
||||
servos_wrapper = $('.servos .bar-wrapper');
|
||||
|
@ -438,34 +447,47 @@ TABS.motors.initialize = function (callback) {
|
|||
');
|
||||
}
|
||||
|
||||
$('div.sliders input').prop('min', MOTOR_CONFIG.mincommand)
|
||||
.prop('max', MOTOR_CONFIG.maxthrottle);
|
||||
$('div.values li:not(:last)').text(MOTOR_CONFIG.mincommand);
|
||||
$('div.sliders input').prop('min', rangeMin)
|
||||
.prop('max', rangeMax);
|
||||
$('div.values li:not(:last)').text(rangeMin);
|
||||
|
||||
if(self.feature3DEnabled && self.feature3DSupported) {
|
||||
//Arbitrary sanity checks
|
||||
//Note: values may need to be revisited
|
||||
if(MOTOR_3D_CONFIG.neutral > 1575 || MOTOR_3D_CONFIG.neutral < 1425)
|
||||
MOTOR_3D_CONFIG.neutral = 1500;
|
||||
|
||||
$('div.sliders input').val(MOTOR_3D_CONFIG.neutral);
|
||||
// UI hooks
|
||||
function setSlidersDefault() {
|
||||
// change all values to default
|
||||
if (self.feature3DEnabled) {
|
||||
$('div.sliders input').val(neutral3d);
|
||||
} else {
|
||||
$('div.sliders input').val(MOTOR_CONFIG.mincommand);
|
||||
$('div.sliders input').val(rangeMin);
|
||||
}
|
||||
}
|
||||
|
||||
if(self.allowTestMode){
|
||||
// UI hooks
|
||||
setSlidersDefault();
|
||||
|
||||
$('#motorsEnableTestMode').change(function () {
|
||||
if ($(this).is(':checked')) {
|
||||
$('div.sliders input').slice(0, number_of_valid_outputs).prop('disabled', false);
|
||||
|
||||
// unlock master slider
|
||||
$('div.sliders input:last').prop('disabled', false);
|
||||
} else {
|
||||
setSlidersDefault();
|
||||
|
||||
// disable sliders / min max
|
||||
$('div.sliders input').prop('disabled', true);
|
||||
}
|
||||
|
||||
$('div.sliders input').trigger('input');
|
||||
}).change();
|
||||
|
||||
var buffering_set_motor = [],
|
||||
buffer_delay = false;
|
||||
$('div.sliders input:not(.master)').on('input', function () {
|
||||
|
||||
var index = $(this).index(),
|
||||
buffer = [],
|
||||
i;
|
||||
buffer = [];
|
||||
|
||||
$('div.values li').eq(index).text($(this).val());
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var val = parseInt($('div.sliders input').eq(i).val());
|
||||
buffer.push16(val);
|
||||
}
|
||||
|
@ -483,7 +505,6 @@ TABS.motors.initialize = function (callback) {
|
|||
}, 10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('div.sliders input.master').on('input', function () {
|
||||
var val = $(this).val();
|
||||
|
@ -493,33 +514,12 @@ TABS.motors.initialize = function (callback) {
|
|||
$('div.sliders input:not(:last):first').trigger('input');
|
||||
});
|
||||
|
||||
$('#motorsEnableTestMode').change(function () {
|
||||
if ($(this).is(':checked')) {
|
||||
$('div.sliders input').slice(0, number_of_valid_outputs).prop('disabled', false);
|
||||
|
||||
// unlock master slider
|
||||
$('div.sliders input:last').prop('disabled', false);
|
||||
} else {
|
||||
// disable sliders / min max
|
||||
$('div.sliders input').prop('disabled', true);
|
||||
|
||||
// change all values to default
|
||||
if (self.feature3DEnabled && self.feature3DSupported) {
|
||||
$('div.sliders input').val(MOTOR_3D_CONFIG.neutral);
|
||||
} else {
|
||||
$('div.sliders input').val(MOTOR_CONFIG.mincommand);
|
||||
}
|
||||
|
||||
$('div.sliders input').trigger('input');
|
||||
}
|
||||
});
|
||||
|
||||
// check if motors are already spinning
|
||||
var motors_running = false;
|
||||
|
||||
for (var i = 0; i < number_of_valid_outputs; i++) {
|
||||
if (!self.feature3DEnabled) {
|
||||
if (MOTOR_DATA[i] > MOTOR_CONFIG.mincommand) {
|
||||
if (MOTOR_DATA[i] > rangeMin) {
|
||||
motors_running = true;
|
||||
}
|
||||
} else {
|
||||
|
@ -530,7 +530,7 @@ TABS.motors.initialize = function (callback) {
|
|||
}
|
||||
|
||||
if (motors_running) {
|
||||
if (!self.armed && self.allowTestMode) {
|
||||
if (!self.armed) {
|
||||
$('#motorsEnableTestMode').prop('checked', true);
|
||||
}
|
||||
// motors are running adjust sliders to current values
|
||||
|
@ -558,8 +558,6 @@ TABS.motors.initialize = function (callback) {
|
|||
}
|
||||
}
|
||||
|
||||
$('#motorsEnableTestMode').change();
|
||||
|
||||
// data pulling functions used inside interval timer
|
||||
|
||||
function get_status() {
|
||||
|
@ -575,15 +573,7 @@ TABS.motors.initialize = function (callback) {
|
|||
MSP.send_message(MSPCodes.MSP_SERVO, false, false, update_ui);
|
||||
}
|
||||
|
||||
var full_block_scale;
|
||||
var motorOffset;
|
||||
if (self.escProtocolIsDshot) {
|
||||
full_block_scale = 1000;
|
||||
motorOffset = 1000;
|
||||
} else {
|
||||
full_block_scale = MOTOR_CONFIG.maxthrottle - MOTOR_CONFIG.mincommand;
|
||||
motorOffset = MOTOR_CONFIG.mincommand;
|
||||
}
|
||||
var full_block_scale = rangeMax - rangeMin;
|
||||
|
||||
function update_ui() {
|
||||
var previousArmState = self.armed;
|
||||
|
@ -591,7 +581,7 @@ TABS.motors.initialize = function (callback) {
|
|||
|
||||
for (var i = 0; i < MOTOR_DATA.length; i++) {
|
||||
var motorValue = MOTOR_DATA[i];
|
||||
var barHeight = motorValue - motorOffset,
|
||||
var barHeight = motorValue - rangeMin,
|
||||
margin_top = block_height - (barHeight * (block_height / full_block_scale)).clamp(0, block_height),
|
||||
height = (barHeight * (block_height / full_block_scale)).clamp(0, block_height),
|
||||
color = parseInt(barHeight * 0.009);
|
||||
|
@ -616,16 +606,13 @@ TABS.motors.initialize = function (callback) {
|
|||
}
|
||||
//keep the following here so at least we get a visual cue of our motor setup
|
||||
update_arm_status();
|
||||
if (!self.allowTestMode) return;
|
||||
|
||||
if (self.armed) {
|
||||
$('#motorsEnableTestMode').prop('disabled', true)
|
||||
.prop('checked', false);
|
||||
} else {
|
||||
if (self.allowTestMode) {
|
||||
$('#motorsEnableTestMode').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
if (previousArmState != self.armed) {
|
||||
console.log('arm state change detected');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue