1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-16 04:45:18 +03:00

This supports adds Configurator GUI support for Failsafe Minimum Distance.

I believe everything works and is OK, but I am unclear about MSP/FC/Configurator versioning, so some of what I've done here may not be correct, or may need to be done differently. I would appreciate guidance/explanation.
This commit is contained in:
Stewart Loving-Gibbard 2017-10-06 07:03:18 -07:00
parent afc8722085
commit 81be88311e
6 changed files with 209 additions and 2 deletions

View file

@ -1721,6 +1721,24 @@
"failsafeKillSwitchHelp": { "failsafeKillSwitchHelp": {
"message": "Set this option to make the failsafe switch, configured in the modes tab, act as a direct kill switch, bypassing the selected failsafe procedure. <strong>Note:</strong> Arming is blocked with the failsafe kill switch in the ON position" "message": "Set this option to make the failsafe switch, configured in the modes tab, act as a direct kill switch, bypassing the selected failsafe procedure. <strong>Note:</strong> Arming is blocked with the failsafe kill switch in the ON position"
}, },
"failsafeUseMinimumDistanceItem": {
"message": "Use alternate Minimum Distance Failsafe Procedure when close to Home"
},
"failsafeUseMinimumDistanceHelp": {
"message": "Set this option if you need an alternate failsafe behavior when the craft is close to Home. For example the author of the feature has a plane that failsafes when the wings detach on landing, when the RTH failsafe behavior normally desired in flight is no longer wanted or needed."
},
"failsafeMinDistanceItem": {
"message": "Failsafe Minimum Distance"
},
"failsafeMinDistanceHelp": {
"message": "The craft will use the alternate failsafe behavior when it is between 0 and this minimum distance in meters away from Home. For example if set to 20 meters, if the craft is at 13 meters the Failsafe Minimum Distance Procedure will be followed. At 25 meters, the normal failsafe procedure will be followed. If set to 0, the normal failsafe procedure will be used at all times. "
},
"failsafeMinDistanceProcedureItem": {
"message": "Failsafe Minimum Distance Procedure"
},
"failsafeMinDistanceProcedureHelp": {
"message": "This is the failsafe procedure that will be followed when the craft is closer than the Minimum Distance from Home."
},
"mainHelpArmed": { "mainHelpArmed": {
"message": "Motor Arming" "message": "Motor Arming"
}, },

View file

@ -376,7 +376,14 @@ var FC = {
failsafe_throttle: 0, failsafe_throttle: 0,
failsafe_kill_switch: 0, failsafe_kill_switch: 0,
failsafe_throttle_low_delay: 0, failsafe_throttle_low_delay: 0,
failsafe_procedure: 0 failsafe_procedure: 0,
failsafe_recovery_delay: 0,
failsafe_fw_roll_angle: 0,
failsafe_fw_pitch_angle: 0,
failsafe_fw_yaw_rate: 0,
failsafe_stick_motion_threshold: 0,
failsafe_min_distance: 0,
failsafe_min_distance_procedure: 0
}; };
FW_CONFIG = { FW_CONFIG = {
@ -464,6 +471,14 @@ var FC = {
); );
} }
// Unsure which version these will actually deploy in, guidance welcome. Using 1.7.3
// so it works for the moment. And I'm really not sure how it works anyhow
if (semver.gte(CONFIG.flightControllerVersion, '1.7.3')) {
features.push(
{bit: 30, group: 'rxFailsafeExtended', name: 'FAILSAFE_EXTENDED', haveTip: false, showNameInTip: false}
);
}
return features.reverse(); return features.reverse();
}, },
isFeatureEnabled: function (featureName, features) { isFeatureEnabled: function (featureName, features) {
@ -879,5 +894,13 @@ var FC = {
}, },
getRthAltControlMode: function () { getRthAltControlMode: function () {
return ["Current", "Extra", "Fixed", "Max", "At Least"]; return ["Current", "Extra", "Fixed", "Max", "At Least"];
},
getFailsafeProcedure: function () {
return {
0: "Land",
1: "Drop",
2: "RTH",
3: "Do Nothing",
}
} }
}; };

View file

@ -617,6 +617,20 @@ var mspHelper = (function (gui) {
offset += 2; offset += 2;
FAILSAFE_CONFIG.failsafe_procedure = data.getUint8(offset); FAILSAFE_CONFIG.failsafe_procedure = data.getUint8(offset);
offset++; offset++;
FAILSAFE_CONFIG.failsafe_recovery_delay = data.getUint8(offset);
offset++;
FAILSAFE_CONFIG.failsafe_fw_roll_angle = data.getUint16(offset, true);
offset += 2;
FAILSAFE_CONFIG.failsafe_fw_pitch_angle = data.getUint16(offset, true);
offset += 2;
FAILSAFE_CONFIG.failsafe_fw_yaw_rate = data.getUint16(offset, true);
offset += 2;
FAILSAFE_CONFIG.failsafe_stick_motion_threshold = data.getUint16(offset, true);
offset += 2;
FAILSAFE_CONFIG.failsafe_min_distance = data.getUint16(offset, true);
offset += 2;
FAILSAFE_CONFIG.failsafe_min_distance_procedure = data.getUint8(offset);
offset++;
break; break;
case MSPCodes.MSP_RXFAIL_CONFIG: case MSPCodes.MSP_RXFAIL_CONFIG:
@ -1194,6 +1208,33 @@ var mspHelper = (function (gui) {
buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_throttle_low_delay)); buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_throttle_low_delay));
buffer.push(highByte(FAILSAFE_CONFIG.failsafe_throttle_low_delay)); buffer.push(highByte(FAILSAFE_CONFIG.failsafe_throttle_low_delay));
buffer.push(FAILSAFE_CONFIG.failsafe_procedure); buffer.push(FAILSAFE_CONFIG.failsafe_procedure);
buffer.push(FAILSAFE_CONFIG.failsafe_recovery_delay);
// API version check needed here?
//if (semver.gte(CONFIG.apiVersion, "1.21.0")) {
// Or
// if (semver.gte(CONFIG.flightControllerVersion, "1.7.3")) {
//
// Guidance wanted...
buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_fw_roll_angle));
buffer.push(highByte(FAILSAFE_CONFIG.failsafe_fw_roll_angle));
buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_fw_pitch_angle));
buffer.push(highByte(FAILSAFE_CONFIG.failsafe_fw_pitch_angle));
buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_fw_yaw_rate));
buffer.push(highByte(FAILSAFE_CONFIG.failsafe_fw_yaw_rate));
buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_stick_motion_threshold));
buffer.push(highByte(FAILSAFE_CONFIG.failsafe_stick_motion_threshold));
buffer.push(lowByte(FAILSAFE_CONFIG.failsafe_min_distance));
buffer.push(highByte(FAILSAFE_CONFIG.failsafe_min_distance));
buffer.push(FAILSAFE_CONFIG.failsafe_min_distance_procedure);
//}
break; break;
case MSPCodes.MSP_SET_TRANSPONDER_CONFIG: case MSPCodes.MSP_SET_TRANSPONDER_CONFIG:

View file

@ -253,6 +253,12 @@
height: 90px; height: 90px;
} }
.tab-failsafe .minimumDistance {
width: 100px !important;
padding-left: 3px;
margin-right: 11px;
}
@media only screen and (max-width: 1055px) , only screen and (max-device-width: 1055px) { @media only screen and (max-width: 1055px) , only screen and (max-device-width: 1055px) {
} }

View file

@ -109,9 +109,87 @@
<label for="nothing" data-i18n="failsafeProcedureItemSelect4"></label> <label for="nothing" data-i18n="failsafeProcedureItemSelect4"></label>
</div> </div>
</div> </div>
<!-- Unsure about this requires-v1_7.. should it be another version? 1.8? -->
<div class="requires-v1_7">
<div class="checkbox stage2">
<div class="numberspacer" >
<input type="checkbox" name="failsafe_use_minimum_distance" class="toggle" id="failsafe_use_minimum_distance" />
</div>
<label for="failsafe_use_minimum_distance"><span data-i18n="failsafeUseMinimumDistanceItem"></span>
</label>
<div class="helpicon cf_tip" data-i18n_title="failsafeUseMinimumDistanceHelp"></div>
</div>
<div class="number" id="failsafe_min_distance_elements">
<label> <input class="minimumDistance" type="number" name="failsafe_min_distance" id="failsafe_min_distance" min="0" max="6000" /> <span
data-i18n="failsafeMinDistanceItem"></span>
</label>
<div class="helpicon cf_tip" data-i18n_title="failsafeMinDistanceHelp"></div>
</div>
<div class="select" id="failsafe_min_distance_procedure_elements">
<select class="minimumDistance" id="failsafe_min_distance_procedure"></select>
<label for="failsafe_min_distance_procedure"> <span data-i18n="failsafeMinDistanceProcedureItem"></span></label>
<div class="helpicon cf_tip" data-i18n_title="failsafeMinDistanceProcedureHelp"></div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="content_toolbar"> <div class="content_toolbar">
<div class="btn save_btn"> <div class="btn save_btn">

View file

@ -75,6 +75,12 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
// translate to user-selected language // translate to user-selected language
localize(); localize();
var $failsafeUseMinimumDistanceCheckbox = $('#failsafe_use_minimum_distance');
var $failsafeMinDistanceElements = $('#failsafe_min_distance_elements')
var $failsafeMinDistance = $('#failsafe_min_distance')
var $failsafeMinDistanceProcedureElements = $('#failsafe_min_distance_procedure_elements')
var $failsafeMinDistanceProcedure = $('#failsafe_min_distance_procedure');
// generate labels for assigned aux modes // generate labels for assigned aux modes
var auxAssignment = [], var auxAssignment = [],
i, i,
@ -209,7 +215,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
isFailsafeEnabled = bit_check(BF_CONFIG.features, 8); isFailsafeEnabled = bit_check(BF_CONFIG.features, 8);
} }
// fill stage 2 fields // Change Failsafe Procedure Minimum Distance appropriately when checkbox manipulated
failsafeFeature = $('input[name="failsafe_feature_new"]'); failsafeFeature = $('input[name="failsafe_feature_new"]');
failsafeFeature.change(function () { failsafeFeature.change(function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
@ -226,6 +232,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
$('input[name="failsafe_off_delay"]').val(FAILSAFE_CONFIG.failsafe_off_delay); $('input[name="failsafe_off_delay"]').val(FAILSAFE_CONFIG.failsafe_off_delay);
$('input[name="failsafe_throttle_low_delay"]').val(FAILSAFE_CONFIG.failsafe_throttle_low_delay); $('input[name="failsafe_throttle_low_delay"]').val(FAILSAFE_CONFIG.failsafe_throttle_low_delay);
$('input[name="failsafe_delay"]').val(FAILSAFE_CONFIG.failsafe_delay); $('input[name="failsafe_delay"]').val(FAILSAFE_CONFIG.failsafe_delay);
$('input[name="failsafe_min_distance"]').val(FAILSAFE_CONFIG.failsafe_min_distance);
// set stage 2 failsafe procedure // set stage 2 failsafe procedure
$('input[type="radio"].procedure').change(function () { $('input[type="radio"].procedure').change(function () {
@ -276,6 +283,39 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
// set stage 2 kill switch option // set stage 2 kill switch option
$('input[name="failsafe_kill_switch"]').prop('checked', FAILSAFE_CONFIG.failsafe_kill_switch); $('input[name="failsafe_kill_switch"]').prop('checked', FAILSAFE_CONFIG.failsafe_kill_switch);
// Adjust Minimum Distance values when checkbox is checked/unchecked
$failsafeUseMinimumDistanceCheckbox.change(function() {
if ($(this).is(':checked')) {
// 20 meters seems like a reasonable default for a minimum distance
$failsafeMinDistance.val(20);
$failsafeMinDistanceElements.show();
$failsafeMinDistanceProcedureElements.show();
} else {
// If they uncheck it, clear the distance to 0, which disables this feature
$failsafeMinDistance.val(0);
$failsafeMinDistanceElements.hide();
$failsafeMinDistanceProcedureElements.hide();
}
})
// Set initial state of controls according to data
if (FAILSAFE_CONFIG.failsafe_min_distance > 0) {
$failsafeUseMinimumDistanceCheckbox.prop('checked', true);
$failsafeMinDistanceElements.show();
$failsafeMinDistanceProcedureElements.show();
} else {
$failsafeUseMinimumDistanceCheckbox.prop('checked', false);
$failsafeMinDistanceElements.hide();
$failsafeMinDistanceProcedureElements.hide();
}
// Alternate, minimum distance failsafe procedure
GUI.fillSelect($failsafeMinDistanceProcedure, FC.getFailsafeProcedure(), FAILSAFE_CONFIG.failsafe_min_distance_procedure);
$failsafeMinDistanceProcedure.val(FAILSAFE_CONFIG.failsafe_min_distance_procedure);
$failsafeMinDistanceProcedure.change(function () {
FAILSAFE_CONFIG.failsafe_min_distance_procedure = $failsafeMinDistanceProcedure.val();
});
$('a.save').click(function () { $('a.save').click(function () {
// gather data that doesn't have automatic change event bound // gather data that doesn't have automatic change event bound
RX_CONFIG.rx_min_usec = parseInt($('input[name="rx_min_usec"]').val()); RX_CONFIG.rx_min_usec = parseInt($('input[name="rx_min_usec"]').val());
@ -293,6 +333,7 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
FAILSAFE_CONFIG.failsafe_off_delay = parseInt($('input[name="failsafe_off_delay"]').val()); FAILSAFE_CONFIG.failsafe_off_delay = parseInt($('input[name="failsafe_off_delay"]').val());
FAILSAFE_CONFIG.failsafe_throttle_low_delay = parseInt($('input[name="failsafe_throttle_low_delay"]').val()); FAILSAFE_CONFIG.failsafe_throttle_low_delay = parseInt($('input[name="failsafe_throttle_low_delay"]').val());
FAILSAFE_CONFIG.failsafe_delay = parseInt($('input[name="failsafe_delay"]').val()); FAILSAFE_CONFIG.failsafe_delay = parseInt($('input[name="failsafe_delay"]').val());
FAILSAFE_CONFIG.failsafe_min_distance = parseInt($('input[name="failsafe_min_distance"]').val());
if ($('input[id="land"]').is(':checked')) { if ($('input[id="land"]').is(':checked')) {
FAILSAFE_CONFIG.failsafe_procedure = 0; FAILSAFE_CONFIG.failsafe_procedure = 0;