From dca4dc97a12aaeebf260e3b0787e0645c7e85f04 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-12PPI61\\boris.bozic" Date: Tue, 21 Jun 2016 02:16:22 +0200 Subject: [PATCH] Added RC rate yaw and prepared filters --- _locales/en/messages.json | 6 ++++++ js/fc.js | 2 +- js/msp.js | 11 ++++++++--- tabs/pid_tuning.html | 3 ++- tabs/pid_tuning.js | 27 ++++++++++++++++++++++++--- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index c998b532..5a57c21e 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -768,6 +768,12 @@ }, "pidTuningTPABreakPoint": { "message": "TPA Breakpoint" + }, + "pidTuningFilter": { + "message": "Filter" + }, + "pidTuningFilterFrequency": { + "message": "Frequency" }, "rcCurve": { "message": "RC Curve" diff --git a/js/fc.js b/js/fc.js index e5960afb..f26882ff 100644 --- a/js/fc.js +++ b/js/fc.js @@ -260,7 +260,7 @@ var FC = { }; TEMPORARY_COMMANDS = { - RC_YAW_RATE: 0 + RC_RATE_YAW: 0 }; RX_CONFIG = { diff --git a/js/msp.js b/js/msp.js index 2e8f46a8..f0dd8aaa 100755 --- a/js/msp.js +++ b/js/msp.js @@ -902,7 +902,7 @@ var MSP = { ADVANCED_TUNING.yaw_p_limit = data.getUint16(offset, 1); break; case MSP_codes.MSP_TEMPORARY_COMMANDS: - TEMPORARY_COMMANDS.RC_RATE_YAW = data.getUint8(0, 1); + TEMPORARY_COMMANDS.RC_RATE_YAW = parseFloat((data.getUint8(offset++) / 100).toFixed(2)); break; case MSP_codes.MSP_LED_STRIP_CONFIG: LED_STRIP = []; @@ -1407,8 +1407,13 @@ MSP.crunch = function (code) { buffer.push(lowByte(PID_ADVANCED_CONFIG.motor_pwm_rate)); buffer.push(highByte(PID_ADVANCED_CONFIG.motor_pwm_rate)); break; - case MSP_codes.MSP_TEMPORARY_COMMANDS: - buffer.push(TEMPORARY_COMMANDS.RC_RATE_YAW); + case MSP_codes.MSP_SET_FILTER_CONFIG: + buffer.push(FILTER_CONFIG.gyro_soft_lpf_hz); + buffer.push(FILTER_CONFIG.dterm_lpf_hz); + buffer.push(FILTER_CONFIG.yaw_lpf_hz); + break; + case MSP_codes.MSP_SET_TEMPORARY_COMMANDS: + buffer.push(Math.round(TEMPORARY_COMMANDS.RC_RATE_YAW * 100)); break; default: return false; diff --git a/tabs/pid_tuning.html b/tabs/pid_tuning.html index f83572bd..f3c3f119 100755 --- a/tabs/pid_tuning.html +++ b/tabs/pid_tuning.html @@ -49,7 +49,7 @@ - + @@ -69,6 +69,7 @@ + diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index ff679572..15a2f2a1 100755 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -185,6 +185,7 @@ TABS.pid_tuning.initialize = function (callback) { $('.pid_tuning input[name="yaw_rate"]').val(RC_tuning.yaw_rate.toFixed(2)); $('.pid_tuning input[name="rc_expo"]').val(RC_tuning.RC_EXPO.toFixed(2)); $('.pid_tuning input[name="rc_yaw_expo"]').val(RC_tuning.RC_YAW_EXPO.toFixed(2)); + $('.pid_tuning input[name="rc_rate_yaw"]').val(TEMPORARY_COMMANDS.RC_RATE_YAW.toFixed(2)); $('.tpa input[name="tpa"]').val(RC_tuning.dynamic_THR_PID.toFixed(2)); $('.tpa input[name="tpa-breakpoint"]').val(RC_tuning.dynamic_THR_breakpoint); @@ -193,8 +194,10 @@ TABS.pid_tuning.initialize = function (callback) { $('.pid_tuning input[name="rc_yaw_expo"]').hide(); $('.pid_tuning input[name="rc_expo"]').attr("rowspan", "3"); } - - + + $('.pid_tuning input[name="gyro_soft_lpf"]').val(FILTER_CONFIG.gyro_soft_lpf_hz); + $('.pid_tuning input[name="dterm_lpf"]').val(FILTER_CONFIG.dterm_lpf_hz); + $('.pid_tuning input[name="yaw_lpf"]').val(FILTER_CONFIG.yaw_lpf_hz); } @@ -258,9 +261,14 @@ TABS.pid_tuning.initialize = function (callback) { RC_tuning.yaw_rate = parseFloat($('.pid_tuning input[name="yaw_rate"]').val()); RC_tuning.RC_EXPO = parseFloat($('.pid_tuning input[name="rc_expo"]').val()); RC_tuning.RC_YAW_EXPO = parseFloat($('.pid_tuning input[name="rc_yaw_expo"]').val()); + TEMPORARY_COMMANDS.RC_RATE_YAW = parseFloat($('.pid_tuning input[name="rc_rate_yaw"]').val()); RC_tuning.dynamic_THR_PID = parseFloat($('.tpa input[name="tpa"]').val()); RC_tuning.dynamic_THR_breakpoint = parseInt($('.tpa input[name="tpa-breakpoint"]').val()); + + FILTER_CONFIG.gyro_soft_lpf_hz = parseInt($('.tpa input[name="gyro_soft_lpf"]').val()); + FILTER_CONFIG.dterm_lpf_hz = parseInt($('.tpa input[name="dterm_lpf"]').val()); + FILTER_CONFIG.yaw_lpf_hz = parseInt($('.tpa input[name="yaw_lpf"]').val()); } function hideUnusedPids(sensors_detected) { $('.tab-pid_tuning table.pid_tuning').hide(); @@ -436,10 +444,23 @@ TABS.pid_tuning.initialize = function (callback) { function send_pids() { if (!TABS.pid_tuning.controllerChanged) { - MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), false, send_rc_tuning_changes); + MSP.send_message(MSP_codes.MSP_SET_PID, MSP.crunch(MSP_codes.MSP_SET_PID), false, send_temporary); } } + function send_temporary() { + if (!TABS.pid_tuning.controllerChanged) { + MSP.send_message(MSP_codes.MSP_SET_TEMPORARY_COMMANDS, MSP.crunch(MSP_codes.MSP_SET_TEMPORARY_COMMANDS), false, send_rc_tuning_changes); + } + } + + /* Uncomment when HTML layout added + function send_filters() { + if (!TABS.pid_tuning.controllerChanged) { + MSP.send_message(MSP_codes.MSP_SET_FILTER_CONFIG, MSP.crunch(MSP_codes.MSP_SET_FILTER_CONFIG), 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); }