Merge pull request #989 from iNavFlight/dzikuvx-presets-overhaul

Simplify Preset handling
pull/992/head
Paweł Spychalski 4 years ago committed by GitHub
commit 48b75539a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,43 +11,10 @@ presets.elementHelper = function (group, field, value) {
};
presets.defaultValues = {
PIDs: {
mr: [
[40, 30, 23, 0], //PID_ROLL
[40, 30, 23, 0], //PID_PITCH
[85, 45, 0, 0], //PID_YAW
[50, 0, 0, 0], //PID_POS_Z
[65, 120, 10, 0], //PID_POS_XY
[40, 15, 100, 40], //PID_VEL_XY
[0, 0, 0, 0], //PID_SURFACE
[20, 15, 75, 0], //PID_LEVEL
[60, 0, 0, 0], //PID_HEADING
[100, 50, 10, 0] //PID_VEL_Z
],
fw: [
[5, 7, 0, 50], //PID_ROLL
[5, 7, 0, 50], //PID_PITCH
[6, 10, 0, 60], //PID_YAW
[40, 5, 10, 0], //PID_POS_Z
[75, 5, 8, 0], //PID_POS_XY
[0, 0, 0, 0], //PID_VEL_XY
[0, 0, 0, 0], //PID_SURFACE
[20, 5, 75, 0], //PID_LEVEL
[60, 0, 0, 0], //PID_HEADING
[0, 0, 0, 0] //PID_VEL_Z
]},
INAV_PID_CONFIG: {"asynchronousMode": "0", "accelerometerTaskFrequency": 500, "attitudeTaskFrequency": 250, "magHoldRateLimit": 90, "magHoldErrorLpfFrequency": 2, "yawJumpPreventionLimit": 200, "gyroscopeLpf": "3", "accSoftLpfHz": 15},
ADVANCED_CONFIG: {"gyroSyncDenominator": 2, "pidProcessDenom": 1, "useUnsyncedPwm": 1, "motorPwmProtocol": 0, "motorPwmRate": 400, "servoPwmRate": 50, "gyroSync": 1},
RC_tuning: {"RC_RATE": 1, "RC_EXPO": 0.7, "roll_pitch_rate": 0, "roll_rate": 200, "pitch_rate": 200, "yaw_rate": 200, "dynamic_THR_PID": 0, "throttle_MID": 0.5, "throttle_EXPO": 0, "dynamic_THR_breakpoint": 1500, "RC_YAW_EXPO": 0.2},
PID_ADVANCED: {"rollPitchItermIgnoreRate": 200, "yawItermIgnoreRate": 50, "yawPLimit": 300, "axisAccelerationLimitRollPitch": 0, "axisAccelerationLimitYaw": 1000},
FILTER_CONFIG: {"gyroSoftLpfHz": 60, "dtermLpfHz": 40, "yawLpfHz": 30, "gyroNotchHz1": 0, "gyroNotchCutoff1": 0, "dtermNotchHz": 0, "dtermNotchCutoff": 0, "gyroNotchHz2": 0, "gyroNotchCutoff2": 0, "accNotchHz": 0, "accNotchCutoff": 0, "gyroStage2LowpassHz": 0},
FC_CONFIG: {"loopTime": 1000},
MIXER_CONFIG: {
"yawMotorDirection": 1,
"yawJumpPreventionLimit": 200,
"platformType": 0,
"hasFlaps": false
}
FILTER_CONFIG: {"gyroSoftLpfHz": 60, "dtermLpfHz": 40, "yawLpfHz": 30, "gyroNotchHz1": 0, "gyroNotchCutoff1": 0, "dtermNotchHz": 0, "dtermNotchCutoff": 0, "gyroNotchHz2": 0, "gyroNotchCutoff2": 0, "accNotchHz": 0, "accNotchCutoff": 0, "gyroStage2LowpassHz": 0}
};
presets.settings = {
@ -72,11 +39,6 @@ presets.settings = {
}
/**
* When defining a preset, following fields are required:
*
* BF_CONFIG::mixerConfiguration
* MIXER_CONFIG::platformType
*
* @type {{name: string, description: string, features: string[], applyDefaults: string[], settingsMSP: *[], type: string}[]}
*/
presets.presets = [
@ -84,12 +46,13 @@ presets.presets = [
name: '3-inch Multirotor Preset',
description: "INAV Quad X configuration, 3-inch propellers. F4/F7 CPU.",
features: ["DSHOT600", "4k mode", "Matrix Filter", "Improved mechanics", "Optimized filtering", "Optimized rates"],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -253,12 +216,13 @@ presets.presets = [
name: 'MegaBee Cinewoop',
description: "iFlight MegaBee Preset",
features: ["DSHOT600", "4k mode", "Matrix Filter", "Improved mechanics", "Optimized filtering", "Optimized rates"],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -430,12 +394,13 @@ presets.presets = [
name: '5-inch Multirotor Preset',
description: "INAV Quad X configuration, 5-inch propellers. F4/F7 CPU. GPS and Magnetometer are optional",
features: ["DSHOT600", "2k mode", "Matrix Filter", "Improved mechanics", "Optimized filtering", "Optimized rates"],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -546,7 +511,7 @@ presets.presets = [
},
{
key: "mc_d_roll",
value: 25
value: 23
},
{
key: "mc_p_yaw",
@ -591,12 +556,13 @@ presets.presets = [
name: '5-inch, 2208 2450KV motors',
description: "Overpowered freestyle kwad. 5-inch, 3 bladed propellers like HQProp S4, Nepal N1, 2208 2450KV motors, 4S, DSHOT600 ESC protocol. Optimized for smooth, freestyle or acrobatic flight.",
features: ["DSHOT600", "4k mode", "Matrix Filter", "Improved mechanics", "Optimized filtering", "Optimized rates"],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -619,7 +585,7 @@ presets.presets = [
},
{
key: "gyro_stage2_lowpass_hz",
value: 250
value: 0
},
{
key: "gyro_stage2_lowpass_type",
@ -635,7 +601,7 @@ presets.presets = [
},
{
key: "dterm_lpf2_hz",
value: 250
value: 170
},
{
key: "dterm_lpf2_type",
@ -703,7 +669,7 @@ presets.presets = [
},
{
key: "mc_d_pitch",
value: 30
value: 28
},
{
key: "mc_p_roll",
@ -715,7 +681,7 @@ presets.presets = [
},
{
key: "mc_d_roll",
value: 26
value: 24
},
{
key: "mc_p_yaw",
@ -760,12 +726,13 @@ presets.presets = [
name: '6-inch, 2207 1700KV motors',
description: "6-inch, 3 bladed propellers, 2207 1700KV motors, 4S, DSHOT600 ESC protocol. Optimized for smooth, freestyle or acrobatic flight with GPS or not.",
features: ["DSHOT600", "2k mode", "Matrix Filter", "Improved mechanics", "Optimized filtering", "Optimized rates"],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -929,12 +896,13 @@ presets.presets = [
name: '7-inch Multirotor Preset',
description: "General configuration for 7-inch propellers. Adjusted rates and filtering.",
features: ["DSHOT600", "2k mode", "Matrix Filter", "Improved mechanics", "Optimized filtering", "Optimized rates"],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -1103,12 +1071,13 @@ presets.presets = [
"Improved PID defaults",
"Adjusted filtering"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 3),
presets.elementHelper("MIXER_CONFIG", "platformType", 0)
],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [],
settings: [
{
key: "platform_type",
value: "MULTIROTOR"
},
{
key: "motor_pwm_protocol",
value: "DSHOT600"
@ -1280,15 +1249,19 @@ presets.presets = [
"Adjusted PIDs",
"Adjusted rates"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 14),
presets.elementHelper("MIXER_CONFIG", "platformType", 1),
presets.elementHelper("RC_tuning", "roll_rate", 200),
presets.elementHelper("RC_tuning", "pitch_rate", 150),
presets.elementHelper("RC_tuning", "yaw_rate", 90),
presets.elementHelper("INAV_PID_CONFIG", "gyroscopeLpf", 1)
],
settings: [
{
key: "platform_type",
value: "AIRPLANE"
}
],
type: 'airplane'
},
{
@ -1300,19 +1273,44 @@ presets.presets = [
"Adjusted PIDs",
"Adjusted rates"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 8),
presets.elementHelper("MIXER_CONFIG", "platformType", 1),
presets.elementHelper("PIDs", 0, [2, 15, 0, 30]), //ROLL PIDs
presets.elementHelper("PIDs", 1, [2, 15, 0, 70]), //PITCH PIDs
presets.elementHelper("PIDs", 7, [10, 15, 75, 0]), //LEVEL PIDs
presets.elementHelper("RC_tuning", "roll_rate", 350),
presets.elementHelper("RC_tuning", "pitch_rate", 90),
presets.elementHelper("RC_tuning", "dynamic_THR_PID", 33),
presets.elementHelper("RC_tuning", "dynamic_THR_breakpoint", 1300),
presets.elementHelper("INAV_PID_CONFIG", "gyroscopeLpf", 4)
],
settings: [
{
key: "platform_type",
value: "AIRPLANE"
},
{
key: "fw_p_pitch",
value: 2
},
{
key: "fw_i_pitch",
value: 15
},
{
key: "fw_ff_pitch",
value: 70
},
{
key: "fw_p_roll",
value: 2
},
{
key: "fw_i_roll",
value: 15
},
{
key: "fw_ff_roll",
value: 30
}
],
type: 'flyingwing'
},
{
@ -1323,12 +1321,8 @@ presets.presets = [
"Adjusted PIDs",
"Adjusted rates"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 8),
presets.elementHelper("MIXER_CONFIG", "platformType", 1),
presets.elementHelper("PIDs", 0, [6, 6, 0, 49]), //ROLL PIDs
presets.elementHelper("PIDs", 1, [6, 9, 0, 52]), //PITCH PIDs
presets.elementHelper("INAV_PID_CONFIG", "gyroscopeLpf", 0),
presets.elementHelper("FILTER_CONFIG", "gyroSoftLpfHz", 40),
presets.elementHelper("RC_tuning", "roll_rate", 280),
@ -1336,6 +1330,36 @@ presets.presets = [
presets.elementHelper("RC_tuning", "dynamic_THR_PID", 20),
presets.elementHelper("RC_tuning", "dynamic_THR_breakpoint", 1600)
],
settings: [
{
key: "platform_type",
value: "AIRPLANE"
},
{
key: "fw_p_pitch",
value: 6
},
{
key: "fw_i_pitch",
value: 9
},
{
key: "fw_ff_pitch",
value: 52
},
{
key: "fw_p_roll",
value: 6
},
{
key: "fw_i_roll",
value: 6
},
{
key: "fw_ff_roll",
value: 49
}
],
type: 'flyingwing'
},
{
@ -1346,12 +1370,8 @@ presets.presets = [
"Adjusted PIDs",
"Adjusted rates"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 8),
presets.elementHelper("MIXER_CONFIG", "platformType", 1),
presets.elementHelper("PIDs", 0, [7, 7, 0, 25]), //ROLL PIDs
presets.elementHelper("PIDs", 1, [5, 9, 0, 56]), //PITCH PIDs
presets.elementHelper("INAV_PID_CONFIG", "gyroscopeLpf", 0),
presets.elementHelper("FILTER_CONFIG", "gyroSoftLpfHz", 35),
presets.elementHelper("RC_tuning", "roll_rate", 260),
@ -1359,6 +1379,36 @@ presets.presets = [
presets.elementHelper("RC_tuning", "dynamic_THR_PID", 30),
presets.elementHelper("RC_tuning", "dynamic_THR_breakpoint", 1550)
],
settings: [
{
key: "platform_type",
value: "AIRPLANE"
},
{
key: "fw_p_pitch",
value: 5
},
{
key: "fw_i_pitch",
value: 14
},
{
key: "fw_ff_pitch",
value: 56
},
{
key: "fw_p_roll",
value: 7
},
{
key: "fw_i_roll",
value: 12
},
{
key: "fw_ff_roll",
value: 25
}
],
type: 'flyingwing'
},
{
@ -1369,12 +1419,8 @@ presets.presets = [
"Adjusted PIDs",
"Adjusted rates"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 8),
presets.elementHelper("MIXER_CONFIG", "platformType", 1),
presets.elementHelper("PIDs", 0, [9, 12, 0, 15]), //ROLL PIDs
presets.elementHelper("PIDs", 1, [9, 15, 0, 14]), //PITCH PIDs
presets.elementHelper("INAV_PID_CONFIG", "gyroscopeLpf", 0),
presets.elementHelper("FILTER_CONFIG", "gyroSoftLpfHz", 35),
presets.elementHelper("RC_tuning", "roll_rate", 360),
@ -1382,6 +1428,36 @@ presets.presets = [
presets.elementHelper("RC_tuning", "dynamic_THR_PID", 30),
presets.elementHelper("RC_tuning", "dynamic_THR_breakpoint", 1500)
],
settings: [
{
key: "platform_type",
value: "AIRPLANE"
},
{
key: "fw_p_pitch",
value: 9
},
{
key: "fw_i_pitch",
value: 15
},
{
key: "fw_ff_pitch",
value: 14
},
{
key: "fw_p_roll",
value: 9
},
{
key: "fw_i_roll",
value: 12
},
{
key: "fw_ff_roll",
value: 15
}
],
type: 'flyingwing'
},
{
@ -1392,17 +1468,43 @@ presets.presets = [
"Adjusted PIDs",
"Adjusted rates"
],
applyDefaults: ["PIDs", "INAV_PID_CONFIG", "ADVANCED_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG", "FC_CONFIG", "MIXER_CONFIG"],
applyDefaults: ["INAV_PID_CONFIG", "RC_tuning", "PID_ADVANCED", "FILTER_CONFIG"],
settingsMSP: [
presets.elementHelper("BF_CONFIG", "mixerConfiguration", 8),
presets.elementHelper("MIXER_CONFIG", "platformType", 1),
presets.elementHelper("PIDs", 0, [8, 16, 0, 64]), //ROLL PIDs
presets.elementHelper("PIDs", 1, [5, 18, 0, 60]), //PITCH PIDs
presets.elementHelper("INAV_PID_CONFIG", "gyroscopeLpf", 0),
presets.elementHelper("FILTER_CONFIG", "gyroSoftLpfHz", 35),
presets.elementHelper("RC_tuning", "roll_rate", 280),
presets.elementHelper("RC_tuning", "pitch_rate", 120)
],
settings: [
{
key: "platform_type",
value: "AIRPLANE"
},
{
key: "fw_p_pitch",
value: 5
},
{
key: "fw_i_pitch",
value: 18
},
{
key: "fw_ff_pitch",
value: 60
},
{
key: "fw_p_roll",
value: 8
},
{
key: "fw_i_roll",
value: 16
},
{
key: "fw_ff_roll",
value: 64
}
],
type: 'flyingwing'
}
];

@ -17,24 +17,13 @@ presets.model = (function () {
if (toApply.hasOwnProperty(settingToApply)) {
var settingName = toApply[settingToApply],
values;
if (settingName == 'PIDs') {
if (mixerType == 'multirotor') {
values = defaults[settingName]['mr'];
} else {
values = defaults[settingName]['fw'];
}
} else {
values = defaults[settingName];
}
for (var key in values) {
if (values.hasOwnProperty(key)) {
window[settingName][key] = values[key];
}
}
}
}
if (mixerType == 'airplane' || mixerType == 'flyingwing') {
@ -106,27 +95,29 @@ TABS.profiles.initialize = function (callback, scrollPosition) {
}
function applySettings() {
Promise.mapSeries(currentPreset.settings, function (input, ii) {
return mspHelper.getSetting(input.key);
}).then(function () {
if (currentPreset.settings && currentPreset.settings.length > 0) {
Promise.mapSeries(currentPreset.settings, function (input, ii) {
console.log('applying', input.key, input.value);
return mspHelper.setSetting(input.key, input.value);
return mspHelper.getSetting(input.key);
}).then(function () {
mspHelper.saveToEeprom(function () {
//noinspection JSUnresolvedVariable
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
//noinspection JSUnresolvedVariable
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
GUI.handleReconnect();
Promise.mapSeries(currentPreset.settings, function (input, ii) {
console.log('applying', input.key, input.value);
return mspHelper.setSetting(input.key, input.value);
}).then(function () {
mspHelper.saveToEeprom(function () {
//noinspection JSUnresolvedVariable
GUI.log(chrome.i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(function() {
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, function () {
//noinspection JSUnresolvedVariable
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
GUI.handleReconnect();
});
});
});
});
})
});
})
});
}
}
function applyAndSave() {

Loading…
Cancel
Save