From 35200e5a36dd96b6f21c02027c1801d345570d23 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Thu, 29 Jan 2015 18:27:50 +0100 Subject: [PATCH] Support changing PID controller in the GUI. --- _locales/en/messages.json | 6 ++++++ changelog.html | 9 +++++---- js/backup_restore.js | 25 +++++++++++++++++++++--- js/data_storage.js | 8 ++++++-- js/msp.js | 12 ++++++++++++ js/serial_backend.js | 2 ++ manifest.json | 2 +- tabs/pid_tuning.css | 24 +++++++++++++++++++++++ tabs/pid_tuning.html | 13 +++++++++++++ tabs/pid_tuning.js | 41 +++++++++++++++++++++++++++++++++++---- 10 files changed, 128 insertions(+), 14 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 1b06dbf7..f38f80d8 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -508,6 +508,9 @@ "message": "Save and Reboot" }, + "pidTuningUpgradeFirmwareToChangePidController": { + "message": "Changing PID controller disabled - you can change it via the CLI. You have firmware with API version $1, but this functionality requires requires $2." + }, "pidTuningName": { "message": "Name" }, @@ -538,6 +541,9 @@ "pidTuningProfileHead": { "message": "Profile" }, + "pidTuningControllerHead": { + "message": "PID Controller" + }, "pidTuningLoadedProfile": { "message": "Loaded Profile: $1" }, diff --git a/changelog.html b/changelog.html index 29b834e1..e4c10c04 100644 --- a/changelog.html +++ b/changelog.html @@ -1,12 +1,13 @@ -2015.01.19 - 0.60.1 - cleanflight +2015.01.19 - 0.61.0 - cleanflight

- - Add support for backup and restore of LED strip configuration.
- - Update presentation of LEDs that have multiple functions.
+ - Support changing PID controller - there new PID controllers in 1.7.0 firmware.
- Support for LED thrust ring.
- Support for LED colors.
- Support for displaying sonar sensor reading on the sensors tab.
- UI cleanup - 'Welcome' and 'Firmware flasher' are now tabs.
- - Added Documentation and Support panels to welcome tab.
+ - Update presentation of LEDs that have multiple functions.
+ - Added Documentation and Support panels to welcome tab.
+ - Add support for backup and restore of LED strip configuration.
- Fix for disappearing tabs in chrome 41 beta.

2015.01.08 - 0.60.0 - cleanflight diff --git a/js/backup_restore.js b/js/backup_restore.js index 3d3d8ef8..ae536b11 100644 --- a/js/backup_restore.js +++ b/js/backup_restore.js @@ -25,6 +25,7 @@ function configuration_backup(callback) { } var profileSpecificData = [ + MSP_codes.MSP_PID_CONTROLLER, MSP_codes.MSP_PID, MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_ACC_TRIM, @@ -47,7 +48,8 @@ function configuration_backup(callback) { fetch_specific_data_item(); } else { configuration.profiles.push({ - 'PID': jQuery.extend(true, [], PIDs), + 'PID': jQuery.extend(true, [], PID), + 'PIDs': jQuery.extend(true, [], PIDs), 'RC': jQuery.extend(true, {}, RC_tuning), 'AccTrim': jQuery.extend(true, [], CONFIG.accelerometerTrims), 'ServoConfig': jQuery.extend(true, [], SERVO_CONFIG), @@ -312,7 +314,22 @@ function configuration_restore(callback) { GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } - + + if (!compareVersions(migratedVersion, '0.61.0')) { + + // Changing PID controller via UI was added. + if (!configuration.PIDs && configuration.PID) { + configuration.PIDs = configuration.PID; + configuration.PID = { + controller: 0 // assume pid controller 0 was used. + }; + } + + migratedVersion = '0.61.0'; + GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion])); + appliedMigrationsCount++; + } + GUI.log(chrome.i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount])); return true; } @@ -323,6 +340,7 @@ function configuration_restore(callback) { profilesN = 3; var profileSpecificData = [ + MSP_codes.MSP_SET_PID_CONTROLLER, MSP_codes.MSP_SET_PID, MSP_codes.MSP_SET_RC_TUNING, MSP_codes.MSP_SET_ACC_TRIM, @@ -348,7 +366,8 @@ function configuration_restore(callback) { codeKey = 0; function load_objects(profile) { - PIDs = configuration.profiles[profile].PID; + PID = configuration.profiles[profile].PID; + PIDs = configuration.profiles[profile].PIDs; RC_tuning = configuration.profiles[profile].RC; CONFIG.accelerometerTrims = configuration.profiles[profile].AccTrim; SERVO_CONFIG = configuration.profiles[profile].ServoConfig; diff --git a/js/data_storage.js b/js/data_storage.js index cd8d28e1..7d3f4bcb 100755 --- a/js/data_storage.js +++ b/js/data_storage.js @@ -1,9 +1,10 @@ 'use strict'; var CONFIGURATOR = { - 'releaseDate': 1421431075334, // new Date().getTime() - 2015.01.16 + 'releaseDate': 1422552160231, // new Date().getTime() - 2015.01.29 'apiVersionAccepted': 1.2, - 'backupRestoreMinApiVersionAccepted': 1.4, + 'backupRestoreMinApiVersionAccepted': 1.5, + 'pidControllerChangeMinApiVersion': 1.5, 'backupFileMinVersionAccepted': '0.55', // chrome.runtime.getManifest().version is stored as string, so does this one 'connectionValid': false, 'connectionValidCliOnly': false, @@ -42,6 +43,9 @@ var BF_CONFIG = { var LED_STRIP = []; +var PID = { + controller: 0 +}; var PID_names = []; var PIDs = new Array(10); diff --git a/js/msp.js b/js/msp.js index 4bbd7636..5d38c092 100644 --- a/js/msp.js +++ b/js/msp.js @@ -20,6 +20,8 @@ var MSP_codes = { MSP_CF_SERIAL_CONFIG: 54, MSP_SET_CF_SERIAL_CONFIG: 55, MSP_SONAR: 58, + MSP_PID_CONTROLLER: 59, + MSP_SET_PID_CONTROLLER: 60, // Multiwii MSP commands MSP_IDENT: 100, @@ -673,6 +675,13 @@ var MSP = { console.log('Adjustment range saved'); break; + case MSP_codes.MSP_PID_CONTROLLER: + PID.controller = data.getUint8(0, 1); + break; + case MSP_codes.MSP_SET_PID_CONTROLLER: + console.log('PID controller changed'); + break; + default: console.log('Unknown code detected: ' + code); @@ -806,6 +815,9 @@ MSP.crunch = function (code) { buffer.push(lowByte(BF_CONFIG.currentoffset)); buffer.push(highByte(BF_CONFIG.currentoffset)); break; + case MSP_codes.MSP_SET_PID_CONTROLLER: + buffer.push(PID.controller); + break; case MSP_codes.MSP_SET_PID: for (var i = 0; i < PIDs.length; i++) { switch (i) { diff --git a/js/serial_backend.js b/js/serial_backend.js index 16bdf42c..e522b6a9 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -171,6 +171,8 @@ function onOpen(openInfo) { GUI.allowedTabs.splice(GUI.allowedTabs.indexOf('led_strip'), 1); } + GUI.canChangePidController = CONFIG.apiVersion >= CONFIGURATOR.pidControllerChangeMinApiVersion; + onConnect(); $('#tabs ul.mode-connected .tab_setup a').click(); diff --git a/manifest.json b/manifest.json index fe6d3895..6fccb3e3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "minimum_chrome_version": "38", - "version": "0.60.1", + "version": "0.61.0", "author": "Hydra", "name": "Cleanflight - Configurator", "short_name": "cleanflight", diff --git a/tabs/pid_tuning.css b/tabs/pid_tuning.css index d95940b9..106adf25 100644 --- a/tabs/pid_tuning.css +++ b/tabs/pid_tuning.css @@ -34,6 +34,30 @@ text-align: right; } +.tab-pid_tuning .controller { + float: left; + + width: calc(18% - 2px); /* - border*/ + + margin-bottom: 10px; + border: 1px solid #8b8b8b; +} +.tab-pid_tuning .controller .head { + display: block; + + text-align: center; + line-height: 20px; + font-weight: bold; + + border-bottom: 1px solid #8b8b8b; + background-color: #ececec; +} +.tab-pid_tuning .controller select { + width: 100%; + padding-left: calc(100% - 35px); + height: 20px; + line-height: 20px; +} .tab-pid_tuning .profile { float: left; diff --git a/tabs/pid_tuning.html b/tabs/pid_tuning.html index 689ec78b..e411f67c 100644 --- a/tabs/pid_tuning.html +++ b/tabs/pid_tuning.html @@ -1,4 +1,17 @@
+
+ + +
+
+ diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index 1ea32c42..8b611d1a 100644 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -3,12 +3,20 @@ TABS.pid_tuning = {}; TABS.pid_tuning.initialize = function (callback) { var self = this; - + if (GUI.active_tab != 'pid_tuning') { GUI.active_tab = 'pid_tuning'; googleAnalytics.sendAppView('PID Tuning'); } + function get_pid_controller() { + if (GUI.canChangePidController) { + MSP.send_message(MSP_codes.MSP_PID_CONTROLLER, false, false, get_pid_names); + } else { + get_pid_names(); + } + } + function get_pid_names() { MSP.send_message(MSP_codes.MSP_PIDNAMES, false, false, get_pid_data); } @@ -26,12 +34,12 @@ TABS.pid_tuning.initialize = function (callback) { } // requesting MSP_STATUS manually because it contains CONFIG.profile - MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_pid_names); + MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_pid_controller); function process_html() { // translate to user-selected language localize(); - + // Fill in the names from PID_names array // this needs to be reworked, but will do for now $('.pid_tuning tr:eq(1) td:first').text(PID_names[0]); @@ -181,6 +189,20 @@ TABS.pid_tuning.initialize = function (callback) { $('.rate-tpa input[name="yaw"]').val(RC_tuning.yaw_rate.toFixed(2)); $('.rate-tpa input[name="tpa"]').val(RC_tuning.dynamic_THR_PID.toFixed(2)); + var pidController_e = $('select[name="controller"]'); + + if (GUI.canChangePidController) { + pidController_e.val(PID.controller); + } else { + GUI.log(chrome.i18n.getMessage('pidTuningUpgradeFirmwareToChangePidController', [CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion])); + + pidController_e.empty(); + pidController_e.append(''); + + pidController_e.prop('disabled', true); + } + + // Fill in currently selected profile $('select[name="profile"]').val(CONFIG.profile); @@ -261,6 +283,12 @@ TABS.pid_tuning.initialize = function (callback) { RC_tuning.yaw_rate = parseFloat($('.rate-tpa input[name="yaw"]').val()); RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val()); + var pidController_e = $('select[name="controller"]'); + + function send_pids() { + MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), false, send_rc_tuning_changes); + } + function send_rc_tuning_changes() { MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_to_eeprom); } @@ -271,7 +299,12 @@ TABS.pid_tuning.initialize = function (callback) { }); } - MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), false, send_rc_tuning_changes); + if (GUI.canChangePidController) { + PID.controller = pidController_e.val(); + MSP.send_message(MSP_codes.MSP_SET_PID_CONTROLLER, MSP.crunch(MSP_codes.MSP_SET_PID_CONTROLLER), false, send_pids); + } else { + send_pids(); + } }); // status data pulled via separate timer with static speed