From d4cd63839701fdba0f7c6a0d4e4527c31e51151f Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 15 Sep 2019 21:43:11 +0200 Subject: Outputs tab rework part 1 --- _locales/en/messages.json | 7 +- main.html | 18 +-- src/css/tabs/motors.css | 157 +++++++++++++++++++--- src/css/tabs/servos.css | 143 -------------------- tabs/motors.html | 138 ++++++++----------- tabs/motors.js | 332 +++++++++++++++++++++++----------------------- tabs/servos.html | 7 +- tabs/servos.js | 80 +++-------- 8 files changed, 401 insertions(+), 481 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 3d811dec..ce5b3df5 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1432,7 +1432,12 @@ "gpsSignalStr": { "message": "Signal Strength" }, - + "motors": { + "message": "Motors" + }, + "servos": { + "message": "Servos" + }, "motorsMaster": { "message": "Master" }, diff --git a/main.html b/main.html index 94b37271..19518622 100755 --- a/main.html +++ b/main.html @@ -161,8 +161,7 @@
    -
  • +
  • @@ -173,6 +172,7 @@
  • +
  • @@ -184,18 +184,12 @@ title="PID Tuning">
  • -
  • -
  • -
  • -
  • -
  • -
  • +
  • +
  • +
  • +
  • -
  • +
    Motors
    -
    - -
    -
    -
    -
    - -
    - - - - - - - -
    -
    - Accelerometer - [Reset] -
    -
    -
    -
    - -
    -
    -
    - -
    -
    X:
    -
    0
    -
    Y:
    -
    0
    -
    Z:
    -
    0
    -
    RMS:
    -
    0
    -
    -
    +
    +
    +
    -
    -
    -
    Motors
    -
    +
    +
    +
    +
    +
      +
      +
      -
      -

      - -
      -
      -
      -
      -
      - -
      -
      -
        - -
      +
      +
      +
      +
      -
      +
      + + + + + +
      Acc. noise RMS
      +
      +
      +
      +

      + +
      +
      +
      -
      +
      +
      +
      +
      -
      Servos
      • 15
      • @@ -115,6 +70,29 @@
      +
      + + + + + + + + + + +
      +
      + +
      +
      +
      +
      +
      +
      + +
      +
      diff --git a/tabs/motors.js b/tabs/motors.js index f6994a60..3f891a84 100644 --- a/tabs/motors.js +++ b/tabs/motors.js @@ -28,7 +28,11 @@ TABS.motors.initialize = function (callback) { mspHelper.loadMotors, mspHelper.loadMotorMixRules, mspHelper.loadServoMixRules, - mspHelper.loadMixerConfig + mspHelper.loadMixerConfig, + mspHelper.loadServoMixRules, + mspHelper.loadServoConfiguration, + mspHelper.loadOutputMapping, + mspHelper.loadRcData, ]); loadChainer.setExitPoint(load_html); loadChainer.execute(); @@ -37,7 +41,7 @@ TABS.motors.initialize = function (callback) { var saveChainer = new MSPChainerClass(); saveChainer.setChain([ - mspHelper.sendMotorMixer, + mspHelper.sendServoConfigurations, mspHelper.saveToEeprom ]); saveChainer.setExitPoint(function () { @@ -46,9 +50,15 @@ TABS.motors.initialize = function (callback) { }); function load_html() { - $('#content').load("./tabs/motors.html", process_html); + $('#content').load("./tabs/motors.html", onLoad); } + function onLoad() { + process_motors(); + process_servos(); + finalize(); + } + function update_arm_status() { self.armed = FC.isModeEnabled('ARM'); } @@ -80,7 +90,7 @@ TABS.motors.initialize = function (callback) { data[i].max = dataPoint; } } - while (data[0].length > 300) { + while (data[0].length > 40) { for (i = 0; i < data.length; i++) { data[i].shift(); } @@ -88,97 +98,141 @@ TABS.motors.initialize = function (callback) { return sampleNumber + 1; } - var margin = {top: 20, right: 30, bottom: 10, left: 20}; - function updateGraphHelperSize(helpers) { - helpers.width = helpers.targetElement.width() - margin.left - margin.right; - helpers.height = helpers.targetElement.height() - margin.top - margin.bottom; - - helpers.widthScale.range([0, helpers.width]); - helpers.heightScale.range([helpers.height, 0]); + function update_model(val) { + if (MIXER_CONFIG.appliedMixerPreset == -1) return; - helpers.xGrid.tickSize(-helpers.height, 0, 0); - helpers.yGrid.tickSize(-helpers.width, 0, 0); + $('.mixerPreview img').attr('src', './resources/motor_order/' + + helper.mixer.getById(val).image + '.svg'); } - function initGraphHelpers(selector, sampleNumber, heightDomain) { - var helpers = {selector: selector, targetElement: $(selector), dynamicHeightDomain: !heightDomain}; + function process_servos() { + + let $tabServos = $(".tab-servos"), + $servoEmptyTableInfo = $('#servoEmptyTableInfo'), + $servoConfigTableContainer = $('#servo-config-table-container'), + $servoConfigTable = $('#servo-config-table'); - helpers.widthScale = d3.scale.linear() - .clamp(true) - .domain([(sampleNumber - 299), sampleNumber]); + if (SERVO_CONFIG.length == 0) { + $tabServos.addClass("is-hidden"); + return; + } - helpers.heightScale = d3.scale.linear() - .clamp(true) - .domain(heightDomain || [1, -1]); + function renderServos(name, alternate, obj) { + + $servoConfigTable.append('\ + \ + ' + name + '\ + \ + \ + \ + \ + \ + \ + \ + '); - helpers.xGrid = d3.svg.axis(); - helpers.yGrid = d3.svg.axis(); + let $currentRow = $servoConfigTable.find('tr:last'); - updateGraphHelperSize(helpers); + //This routine is pre 2.0 only + if (SERVO_CONFIG[obj].indexOfChannelToForward >= 0) { + $currentRow.find('td.channel input').eq(SERVO_CONFIG[obj].indexOfChannelToForward).prop('checked', true); + } - helpers.xGrid - .scale(helpers.widthScale) - .orient("bottom") - .ticks(5) - .tickFormat(""); + // adding select box and generating options + $currentRow.find('td.rate').append( + '' + ); - helpers.yGrid - .scale(helpers.heightScale) - .orient("left") - .ticks(5) - .tickFormat(""); + $currentRow.find('td.reverse').append( + '' + ); - helpers.xAxis = d3.svg.axis() - .scale(helpers.widthScale) - .ticks(5) - .orient("bottom") - .tickFormat(function (d) {return d;}); + $currentRow.data('info', { 'obj': obj }); - helpers.yAxis = d3.svg.axis() - .scale(helpers.heightScale) - .ticks(5) - .orient("left") - .tickFormat(function (d) {return d;}); + $currentRow.append(''); - helpers.line = d3.svg.line() - .x(function (d) { return helpers.widthScale(d[0]); }) - .y(function (d) { return helpers.heightScale(d[1]); }); + let output, + outputString; - return helpers; - } + if (MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER) { + output = OUTPUT_MAPPING.getMrServoOutput(usedServoIndex); + } else { + output = OUTPUT_MAPPING.getFwServoOutput(usedServoIndex); + } + + if (output === null) { + outputString = "-"; + } else { + outputString = "S" + output; + } + + $currentRow.find('.output').html(outputString); + //For 2.0 and above hide a row when servo is not configured + if (!SERVO_RULES.isServoConfigured(obj)) { + $currentRow.hide(); + } else { + usedServoIndex++; + } + } + + function servos_update(save_configuration_to_eeprom) { + $servoConfigTable.find('tr:not(".main")').each(function () { + var info = $(this).data('info'); + + var selection = $('.channel input', this); + var channelIndex = parseInt(selection.index(selection.filter(':checked'))); + if (channelIndex == -1) { + channelIndex = undefined; + } - function drawGraph(graphHelpers, data, sampleNumber) { - var svg = d3.select(graphHelpers.selector); + SERVO_CONFIG[info.obj].indexOfChannelToForward = channelIndex; - if (graphHelpers.dynamicHeightDomain) { - var limits = []; - $.each(data, function (idx, datum) { - limits.push(datum.min); - limits.push(datum.max); + SERVO_CONFIG[info.obj].middle = parseInt($('.middle input', this).val()); + SERVO_CONFIG[info.obj].min = parseInt($('.min input', this).val()); + SERVO_CONFIG[info.obj].max = parseInt($('.max input', this).val()); + var rate = parseInt($('.rate-input', this).val()); + if ($('.reverse-input', this).is(':checked')) { + rate = -rate; + } + SERVO_CONFIG[info.obj].rate = rate; }); - graphHelpers.heightScale.domain(d3.extent(limits)); + + //Save configuration to FC + saveChainer.execute(); } - graphHelpers.widthScale.domain([(sampleNumber - 299), sampleNumber]); - svg.select(".x.grid").call(graphHelpers.xGrid); - svg.select(".y.grid").call(graphHelpers.yGrid); - svg.select(".x.axis").call(graphHelpers.xAxis); - svg.select(".y.axis").call(graphHelpers.yAxis); + // drop previous table + $servoConfigTable.find('tr:not(:first)').remove(); - var group = svg.select("g.data"); - var lines = group.selectAll("path").data(data, function (d, i) {return i;}); - lines.enter().append("path").attr("class", "line"); - lines.attr('d', graphHelpers.line); - } + let usedServoIndex = 0; - function update_model(val) { - if (MIXER_CONFIG.appliedMixerPreset == -1) return; + for (let servoIndex = 0; servoIndex < SERVO_RULES.getServoCount(); servoIndex++) { + renderServos('Servo ' + servoIndex, '', servoIndex); + } + if (usedServoIndex == 0) { + // No servos configured + $servoEmptyTableInfo.show(); + $servoConfigTableContainer.hide(); + } else { + $servoEmptyTableInfo.hide(); + $servoConfigTableContainer.show(); + } + + // UI hooks for dynamically generated elements + $('table.directions select, table.directions input, #servo-config-table select, #servo-config-table input').change(function () { + if ($('div.live input').is(':checked')) { + // apply small delay as there seems to be some funky update business going wrong + helper.timeout.add('servos_update', servos_update, 10); + } + }); + + $('a.update').click(function () { + servos_update(true); + }); - $('.mixerPreview img').attr('src', './resources/motor_order/' - + helper.mixer.getById(val).image + '.svg'); } - function process_html() { + function process_motors() { $motorsEnableTestMode = $('#motorsEnableTestMode'); self.feature3DEnabled = bit_check(BF_CONFIG.features, 12); @@ -202,114 +256,62 @@ TABS.motors.initialize = function (callback) { // Setup variables var samples_accel_i = 0, accel_data = initDataArray(3), - accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-2, 2]), accel_max_read = [0, 0, 0], accel_offset = [0, 0, 0], accel_offset_established = false; - var raw_data_text_ements = { - x: [], - y: [], - z: [], - rms: [] - }; - - $('.plot_control .x, .plot_control .y, .plot_control .z, .plot_control .rms').each(function () { - var el = $(this); - if (el.hasClass('x')) { - raw_data_text_ements.x.push(el); - } else if (el.hasClass('y')) { - raw_data_text_ements.y.push(el); - } else if (el.hasClass('z')) { - raw_data_text_ements.z.push(el); - } else if (el.hasClass('rms')) { - raw_data_text_ements.rms.push(el); - } - }); - - // set refresh speeds according to configuration saved in storage - chrome.storage.local.get('motors_tab_accel_settings', function (result) { - if (result.motors_tab_accel_settings) { - $('.tab-motors select[name="accel_refresh_rate"]').val(result.motors_tab_accel_settings.rate); - $('.tab-motors select[name="accel_scale"]').val(result.motors_tab_accel_settings.scale); - - // start polling data by triggering refresh rate change event - $('.tab-motors .rate select:first').change(); - } else { - // start polling immediatly (as there is no configuration saved in the storage) - $('.tab-motors .rate select:first').change(); - } - }); + let $rmsHelper = $(".acc-rms"); - $('.tab-motors .rate select, .tab-motors .scale select').change(function () { - var rate = parseInt($('.tab-motors select[name="accel_refresh_rate"]').val(), 10); - var scale = parseFloat($('.tab-motors select[name="accel_scale"]').val()); + // timer initialization + helper.interval.killAll(['motor_and_status_pull', 'global_data_refresh', 'msp-load-update']); + helper.mspBalancedInterval.flush(); - // store current/latest refresh rates in the storage - chrome.storage.local.set({'motors_tab_accel_settings': {'rate': rate, 'scale': scale}}); + helper.interval.add('IMU_pull', function imu_data_pull() { - accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-scale, scale]); + /* + * Enable balancer + */ + if (helper.mspQueue.shouldDrop()) { + update_accel_graph(); + return; + } - // timer initialization - helper.interval.killAll(['motor_and_status_pull', 'global_data_refresh', 'msp-load-update']); - helper.mspBalancedInterval.flush(); + MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_accel_graph); + }, 25, true); - helper.interval.add('IMU_pull', function imu_data_pull() { + function update_accel_graph() { - /* - * Enable balancer - */ - if (helper.mspQueue.shouldDrop()) { - update_accel_graph(); - return; + if (!accel_offset_established) { + for (var i = 0; i < 3; i++) { + accel_offset[i] = SENSOR_DATA.accelerometer[i] * -1; } - MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_accel_graph); - }, rate, true); + accel_offset_established = true; + } - function update_accel_graph() { - if (!accel_offset_established) { - for (var i = 0; i < 3; i++) { - accel_offset[i] = SENSOR_DATA.accelerometer[i] * -1; - } + var accel_with_offset = [ + accel_offset[0] + SENSOR_DATA.accelerometer[0], + accel_offset[1] + SENSOR_DATA.accelerometer[1], + accel_offset[2] + SENSOR_DATA.accelerometer[2] + ]; - accel_offset_established = true; - } + samples_accel_i = addSampleToData(accel_data, samples_accel_i, accel_with_offset); - var accel_with_offset = [ - accel_offset[0] + SENSOR_DATA.accelerometer[0], - accel_offset[1] + SENSOR_DATA.accelerometer[1], - accel_offset[2] + SENSOR_DATA.accelerometer[2] - ]; - - updateGraphHelperSize(accelHelpers); - samples_accel_i = addSampleToData(accel_data, samples_accel_i, accel_with_offset); - drawGraph(accelHelpers, accel_data, samples_accel_i); - - // Compute RMS of acceleration in displayed period of time - // This is particularly useful for motor balancing as it - // eliminates the need for external tools - var sum = 0.0; - for (var j = 0; j < accel_data.length; j++) - for (var k = 0; k < accel_data[j].length; k++) - sum += accel_data[j][k][1]*accel_data[j][k][1]; - var rms = Math.sqrt(sum/(accel_data[0].length+accel_data[1].length+accel_data[2].length)); - - raw_data_text_ements.x[0].text(accel_with_offset[0].toFixed(2) + ' (' + accel_max_read[0].toFixed(2) + ')'); - raw_data_text_ements.y[0].text(accel_with_offset[1].toFixed(2) + ' (' + accel_max_read[1].toFixed(2) + ')'); - raw_data_text_ements.z[0].text(accel_with_offset[2].toFixed(2) + ' (' + accel_max_read[2].toFixed(2) + ')'); - raw_data_text_ements.rms[0].text(rms.toFixed(4)); + // Compute RMS of acceleration in displayed period of time + // This is particularly useful for motor balancing as it + // eliminates the need for external tools + var sum = 0.0; + for (var j = 0; j < accel_data.length; j++) + for (var k = 0; k < accel_data[j].length; k++) + sum += accel_data[j][k][1]*accel_data[j][k][1]; - for (var i = 0; i < 3; i++) { - if (Math.abs(accel_with_offset[i]) > Math.abs(accel_max_read[i])) accel_max_read[i] = accel_with_offset[i]; - } - } - }); + let rms = Math.sqrt(sum/(accel_data[0].length+accel_data[1].length+accel_data[2].length)); + $rmsHelper.text(rms.toFixed(4)); - $('a.reset_accel_max').click(function () { - accel_max_read = [0, 0, 0]; - accel_offset_established = false; - }); + for (var i = 0; i < 3; i++) { + if (Math.abs(accel_with_offset[i]) > Math.abs(accel_max_read[i])) accel_max_read[i] = accel_with_offset[i]; + } + } let motors_wrapper = $('.motors .bar-wrapper'), servos_wrapper = $('.servos .bar-wrapper'), @@ -559,11 +561,13 @@ TABS.motors.initialize = function (callback) { // enable Status and Motor data pulling helper.interval.add('motor_and_status_pull', getPeriodicMotorOutput, 75, true); + } + function finalize() { localize(); - GUI.content_ready(callback); } + }; TABS.motors.cleanup = function (callback) { diff --git a/tabs/servos.html b/tabs/servos.html index 66d94962..0cfae5af 100755 --- a/tabs/servos.html +++ b/tabs/servos.html @@ -13,10 +13,9 @@ - CH1 - CH2 - CH3 - CH4 + + +
      diff --git a/tabs/servos.js b/tabs/servos.js index 202cb85a..6a9bd03d 100755 --- a/tabs/servos.js +++ b/tabs/servos.js @@ -44,43 +44,14 @@ TABS.servos.initialize = function (callback) { $tabServos = $(".tab-servos"), $servoEmptyTableInfo = $('#servoEmptyTableInfo'), $servoConfigTableContainer = $('#servo-config-table-container'), - $servoConfigTable = $('#servo-config-table'), - $servoMixTable = $('#servo-mix-table'), - $servoMixTableBody = $servoMixTable.find('tbody'); + $servoConfigTable = $('#servo-config-table'); if (SERVO_CONFIG.length == 0) { $tabServos.addClass("is-hidden"); return; } - let servoCheckbox = '', - servoHeader = ''; - - if (semver.lt(CONFIG.flightControllerVersion, "2.0.0")) { - - $servoEmptyTableInfo.hide(); - - for (i = 0; i < RC.active_channels - 4; i++) { - servoHeader = servoHeader + 'CH' + (i + 5) + ''; - } - servoHeader = servoHeader + ''; - - for (i = 0; i < RC.active_channels; i++) { - servoCheckbox = servoCheckbox + ''; - } - - $servoConfigTable.find('tr.main').append(servoHeader); - } else { - $servoConfigTable.find('tr.main').html('\ - \ - \ - \ - \ - \ - \ - \ - '); - } + let servoCheckbox = ''; function process_servos(name, alternate, obj) { @@ -115,39 +86,30 @@ TABS.servos.initialize = function (callback) { $currentRow.data('info', { 'obj': obj }); - if (semver.lt(CONFIG.flightControllerVersion, "2.0.0")) { - // only one checkbox for indicating a channel to forward can be selected at a time, perhaps a radio group would be best here. - $currentRow.find('td.channel input').click(function () { - if ($(this).is(':checked')) { - $(this).parent().parent().find('.channel input').not($(this)).prop('checked', false); - } - }); - } else { - $currentRow.append(''); + $currentRow.append(''); - let output, - outputString; + let output, + outputString; - if (MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER) { - output = OUTPUT_MAPPING.getMrServoOutput(usedServoIndex); - } else { - output = OUTPUT_MAPPING.getFwServoOutput(usedServoIndex); - } + if (MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER) { + output = OUTPUT_MAPPING.getMrServoOutput(usedServoIndex); + } else { + output = OUTPUT_MAPPING.getFwServoOutput(usedServoIndex); + } - if (output === null) { - outputString = "-"; - } else { - outputString = "S" + output; - } + if (output === null) { + outputString = "-"; + } else { + outputString = "S" + output; + } - $currentRow.find('.output').html(outputString); - //For 2.0 and above hide a row when servo is not configured - if (!SERVO_RULES.isServoConfigured(obj)) { - $currentRow.hide(); - } else { - usedServoIndex++; - } + $currentRow.find('.output').html(outputString); + //For 2.0 and above hide a row when servo is not configured + if (!SERVO_RULES.isServoConfigured(obj)) { + $currentRow.hide(); + } else { + usedServoIndex++; } } -- cgit v1.2.3