Merge pull request #71 from NightHawk32/NewPIDFunctions

added MSP support for sensor orientation, some fixes for 3D backup and restore
10.3.x-maintenance
Albert Kravcov 2015-12-15 15:11:20 +01:00
commit fa02c4ca18
5 changed files with 92 additions and 8 deletions

View File

@ -106,6 +106,7 @@ function configuration_backup(callback) {
uniqueData.push(MSP_codes.MSP_3D);
}
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
uniqueData.push(MSP_codes.MSP_SENSOR_ALIGNMENT);
uniqueData.push(MSP_codes.MSP_RX_CONFIG);
uniqueData.push(MSP_codes.MSP_FAILSAFE_CONFIG);
uniqueData.push(MSP_codes.MSP_RXFAIL_CONFIG);
@ -138,6 +139,7 @@ function configuration_backup(callback) {
configuration._3D = jQuery.extend(true, {}, _3D);
}
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
configuration.SENSOR_ALIGNMENT = jQuery.extend(true, {}, SENSOR_ALIGNMENT);
configuration.RX_CONFIG = jQuery.extend(true, {}, RX_CONFIG);
configuration.FAILSAFE_CONFIG = jQuery.extend(true, {}, FAILSAFE_CONFIG);
configuration.RXFAIL_CONFIG = jQuery.extend(true, [], RXFAIL_CONFIG);
@ -523,10 +525,10 @@ function configuration_restore(callback) {
appliedMigrationsCount++;
}
if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.15.0')) {
// api 1.15 exposes RCcontrols and sensor alignment
// api 1.14 exposes deadband and yaw_deadband
for (var profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) {
if (configuration.profile[profileIndex].RCcontrols == undefined) {
@ -538,6 +540,13 @@ function configuration_restore(callback) {
};
}
}
if (configuration.SENSOR_ALIGNMENT == undefined) {
configuration.SENSOR_ALIGNMENT = {
align_gyro: 0,
align_acc: 0,
align_mag: 0
};
}
appliedMigrationsCount++;
}
@ -702,6 +711,7 @@ function configuration_restore(callback) {
uniqueData.push(MSP_codes.MSP_SET_3D);
}
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
uniqueData.push(MSP_codes.MSP_SET_SENSOR_ALIGNMENT);
uniqueData.push(MSP_codes.MSP_SET_RX_CONFIG);
uniqueData.push(MSP_codes.MSP_SET_FAILSAFE_CONFIG);
uniqueData.push(MSP_codes.MSP_SET_RXFAIL_CONFIG);
@ -717,6 +727,7 @@ function configuration_restore(callback) {
ARMING_CONFIG = configuration.ARMING_CONFIG;
FC_CONFIG = configuration.FC_CONFIG;
_3D = configuration._3D;
SENSOR_ALIGNMENT = configuration.SENSOR_ALIGNMENT;
RX_CONFIG = configuration.RX_CONFIG;
FAILSAFE_CONFIG = configuration.FAILSAFE_CONFIG;
RXFAIL_CONFIG = configuration.RXFAIL_CONFIG;

View File

@ -186,6 +186,12 @@ var RC_controls = {
alt_hold_fast_change: 0
};
var SENSOR_ALIGNMENT = {
align_gyro: 0,
align_acc: 0,
align_mag: 0
};
var RX_CONFIG = {
serialrx_provider: 0,
maxcheck: 0,

View File

@ -60,6 +60,7 @@ var MSP_codes = {
MSP_SERVO_CONFIGURATIONS: 120,
MSP_3D: 124,
MSP_RC_CONTROLS: 125,
MSP_SENSOR_ALIGNMENT: 126,
MSP_SET_RAW_RC: 200,
MSP_SET_RAW_GPS: 201,
@ -78,6 +79,7 @@ var MSP_codes = {
MSP_SET_3D: 217,
MSP_SET_RC_CONTROLS: 218,
MSP_SET_RESET_CURR_PID: 219,
MSP_SET_SENSOR_ALIGNMENT: 220,
// MSP_BIND: 240,
@ -530,6 +532,12 @@ var MSP = {
RC_controls.alt_hold_deadband = data.getUint8(offset++, 1);
RC_controls.alt_hold_fast_change = data.getUint8(offset++, 1);
break;
case MSP_codes.MSP_SENSOR_ALIGNMENT:
var offset = 0;
SENSOR_ALIGNMENT.align_gyro = data.getUint8(offset++, 1);
SENSOR_ALIGNMENT.align_acc = data.getUint8(offset++, 1);
SENSOR_ALIGNMENT.align_mag = data.getUint8(offset++, 1);
break;
case MSP_codes.MSP_SET_RAW_RC:
break;
case MSP_codes.MSP_SET_RAW_GPS:
@ -920,6 +928,12 @@ var MSP = {
case MSP_codes.MSP_SET_RESET_CURR_PID:
console.log('Current PID profile reset');
break;
case MSP_codes.MSP_SET_3D:
console.log('3D settings saved');
break;
case MSP_codes.MSP_SET_SENSOR_ALIGNMENT:
console.log('Sensor alignment saved');
break;
case MSP_codes.MSP_SET_RX_CONFIG:
console.log('Rx config saved');
break;
@ -1275,6 +1289,12 @@ MSP.crunch = function (code) {
buffer.push(RC_controls.alt_hold_fast_change);
break;
case MSP_codes.MSP_SET_SENSOR_ALIGNMENT:
buffer.push(SENSOR_ALIGNMENT.align_gyro);
buffer.push(SENSOR_ALIGNMENT.align_acc);
buffer.push(SENSOR_ALIGNMENT.align_mag);
break
default:
return false;
}

View File

@ -132,19 +132,19 @@
<div class="sensoralignment" style="width:40%; float:left;">
<div class="number">
<select class="gyroalign">
<option>Gyro Alignment</option>
<option value="0">Gyro Alignment</option>
<!-- list generated here -->
</select>
</div>
<div class="number">
<select class="accalign">
<option>Acc Alignment</option>
<option value="0">Acc Alignment</option>
<!-- list generated here -->
</select>
</div>
<div class="number">
<select class="magalign">
<option>Mag Alignment</option>
<option value="0">Mag Alignment</option>
<!-- list generated here -->
</select>
</div>

View File

@ -54,13 +54,22 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
function load_3d() {
var next_callback = load_html;
if (semver.lt(CONFIG.apiVersion, "1.14.0")) {
var next_callback = load_sensor_alignment;
if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
MSP.send_message(MSP_codes.MSP_3D, false, false, next_callback);
} else {
next_callback();
}
}
function load_sensor_alignment() {
var next_callback = load_html;
if (semver.gte(CONFIG.apiVersion, "1.15.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_ALIGNMENT, false, false, next_callback);
} else {
next_callback();
}
}
function load_html() {
$('#content').load("./tabs/configuration.html", process_html);
@ -193,6 +202,35 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
});
}
var alignments = [
'CW0',
'CW90',
'CW180',
'CW270',
'CW0FLIP',
'CW90FLIP',
'CW180FLIP',
'CW270FLIP'
];
if (semver.lt(CONFIG.apiVersion, "1.15.0")) {
$('.tab-configuration .sensoralignment').hide();
} else {
var orientation_gyro_e = $('select.gyroalign');
var orientation_acc_e = $('select.accalign');
var orientation_mag_e = $('select.magalign');
for (var i = 0; i < alignments.length; i++) {
orientation_gyro_e.append('<option value="' + (i+1) + '">' + alignments[i] + '</option>');
orientation_acc_e.append('<option value="' + (i+1) + '">' + alignments[i] + '</option>');
orientation_mag_e.append('<option value="' + (i+1) + '">' + alignments[i] + '</option>');
}
orientation_gyro_e.val(SENSOR_ALIGNMENT.align_gyro);
orientation_acc_e.val(SENSOR_ALIGNMENT.align_acc);
orientation_mag_e.val(SENSOR_ALIGNMENT.align_mag);
}
// generate GPS
var gpsProtocols = [
'NMEA',
@ -216,6 +254,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
'Indian GAGAN'
];
var gps_protocol_e = $('select.gps_protocol');
for (var i = 0; i < gpsProtocols.length; i++) {
gps_protocol_e.append('<option value="' + i + '">' + gpsProtocols[i] + '</option>');
@ -424,6 +463,10 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
_3D.neutral3d = parseInt($('input[name="3dneutral"]').val());
_3D.deadband3d_throttle = ($('input[name="3ddeadbandthrottle"]').val());
SENSOR_ALIGNMENT.align_gyro = parseInt(orientation_gyro_e.val());
SENSOR_ALIGNMENT.align_acc = parseInt(orientation_acc_e.val());
SENSOR_ALIGNMENT.align_mag = parseInt(orientation_mag_e.val());
function save_serial_config() {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_misc);
@ -437,7 +480,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
function save_3d() {
MSP.send_message(MSP_codes.MSP_SET_3D, MSP.crunch(MSP_codes.MSP_SET_3D), false, save_acc_trim);
MSP.send_message(MSP_codes.MSP_SET_3D, MSP.crunch(MSP_codes.MSP_SET_3D), false, save_sensor_alignment);
}
function save_sensor_alignment() {
MSP.send_message(MSP_codes.MSP_SET_SENSOR_ALIGNMENT, MSP.crunch(MSP_codes.MSP_SET_SENSOR_ALIGNMENT), false, save_acc_trim);
}
function save_acc_trim() {