1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-13 19:40:22 +03:00

bugfixes & tiny optimizations

This commit is contained in:
cTn 2013-12-15 02:28:12 +01:00
parent fd62b8568c
commit 01a5c753aa
6 changed files with 585 additions and 582 deletions

View file

@ -1,6 +1,6 @@
<span>xx.xx.xxxx - 0.20</span> <span>xx.xx.xxxx - 0.20</span>
<p> <p>
- Minor improvements<br /> - Minor iprovements &amp; bugfixes<br />
</p> </p>
<span>12.09.2013 - 0.19</span> <span>12.09.2013 - 0.19</span>
<p> <p>

View file

@ -224,7 +224,6 @@ function process_data(command, message_buffer, message_length_expected) {
CONFIG.profile = data.getUint8(10); CONFIG.profile = data.getUint8(10);
$('span.cycle-time').html(CONFIG.cycleTime); $('span.cycle-time').html(CONFIG.cycleTime);
sensor_status(CONFIG.activeSensors);
break; break;
case MSP_codes.MSP_RAW_IMU: case MSP_codes.MSP_RAW_IMU:
SENSOR_DATA.accelerometer[0] = data.getInt16(0, 1) / 1000; // properly scaled SENSOR_DATA.accelerometer[0] = data.getInt16(0, 1) / 1000; // properly scaled

View file

@ -190,17 +190,14 @@ function onOpen(openInfo) {
} }
}, 10000); }, 10000);
// baseflight specific
send_message(MSP_codes.MSP_UID, MSP_codes.MSP_UID);
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM);
// request configuration data // request configuration data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); send_message(MSP_codes.MSP_UID, MSP_codes.MSP_UID);
send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); // in theory this could be removed (MSP_STATUS is pulled in initial tab)
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING);
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() { send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() {
GUI.timeout_remove('connecting'); // kill connecting timer GUI.timeout_remove('connecting'); // kill connecting timer
// Update UI elements that doesn't need consistent refreshing
sensor_status(CONFIG.activeSensors);
$('.software-version').html(CONFIG.version); $('.software-version').html(CONFIG.version);
configuration_received = true; configuration_received = true;

View file

@ -1,173 +1,175 @@
var yaw_fix = 0.0;
function tab_initialize_initial_setup() { function tab_initialize_initial_setup() {
ga_tracker.sendAppView('Initial Setup'); ga_tracker.sendAppView('Initial Setup');
GUI.active_tab = 'initial_setup'; GUI.active_tab = 'initial_setup';
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() { send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() {
// Fill in the accel trimms from CONFIG object send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, function() {
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]); var yaw_fix = 0.0;
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
// Display multiType
var str = '';
switch (CONFIG.multiType) {
case 1: // TRI
str = 'TRI';
break;
case 2: // QUAD +
str = 'Quad +';
break;
case 3: // QUAD X
str = 'Quad X';
break;
case 4: // BI
str = 'BI';
break;
case 5: // GIMBAL
str = 'Gimbal';
break;
case 6: // Y6
str = 'Y6';
break;
case 7: // HEX 6
str = 'HEX 6';
break;
case 8: // FLYING_WING
str = 'Flying Wing';
break;
case 9: // Y4
str = 'Y4';
break;
case 10: // HEX6 X
str = 'HEX6 X';
break;
case 11: // OCTO X8
case 12:
case 13:
str = 'OCTO X8';
break;
case 14: // AIRPLANE
str = 'Airplane';
break;
case 15: // Heli 120
str = 'Heli 120';
break;
case 16: // Heli 90
str = 'Heli 90';
break;
case 17: // Vtail
str = 'Vtail';
break;
case 18: // HEX6 H
str = 'HEX6 H';
break;
case 19: // PPM to SERVO
str = 'PPM to SERVO';
break;
case 20: // Dualcopter
str = 'Dualcopter';
break;
case 21: //
str = 'Singlecopter';
break;
}
$('span.model').html('Model: ' + str);
// UI Hooks
$('a.calibrateAccel').click(function() {
var self = $(this);
if (!self.hasClass('calibrating')) { // Fill in the accel trimms from CONFIG object
self.addClass('calibrating'); $('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
// During this period MCU won't be able to process any serial commands because its locked in a for/while loop
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow // Display multiType
GUI.interval_pause('initial_setup_data_pull'); var str = '';
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION); switch (CONFIG.multiType) {
case 1: // TRI
GUI.timeout_add('button_reset', function() { str = 'TRI';
GUI.interval_resume('initial_setup_data_pull'); break;
self.removeClass('calibrating'); case 2: // QUAD +
}, 2000); str = 'Quad +';
break;
case 3: // QUAD X
str = 'Quad X';
break;
case 4: // BI
str = 'BI';
break;
case 5: // GIMBAL
str = 'Gimbal';
break;
case 6: // Y6
str = 'Y6';
break;
case 7: // HEX 6
str = 'HEX 6';
break;
case 8: // FLYING_WING
str = 'Flying Wing';
break;
case 9: // Y4
str = 'Y4';
break;
case 10: // HEX6 X
str = 'HEX6 X';
break;
case 11: // OCTO X8
case 12:
case 13:
str = 'OCTO X8';
break;
case 14: // AIRPLANE
str = 'Airplane';
break;
case 15: // Heli 120
str = 'Heli 120';
break;
case 16: // Heli 90
str = 'Heli 90';
break;
case 17: // Vtail
str = 'Vtail';
break;
case 18: // HEX6 H
str = 'HEX6 H';
break;
case 19: // PPM to SERVO
str = 'PPM to SERVO';
break;
case 20: // Dualcopter
str = 'Dualcopter';
break;
case 21: //
str = 'Singlecopter';
break;
} }
});
$('a.calibrateMag').click(function() {
var self = $(this);
if (!self.hasClass('calibrating')) { $('span.model').html('Model: ' + str);
self.addClass('calibrating');
send_message(MSP_codes.MSP_MAG_CALIBRATION, MSP_codes.MSP_MAG_CALIBRATION); // UI Hooks
$('a.calibrateAccel').click(function() {
var self = $(this);
GUI.timeout_add('button_reset', function() { if (!self.hasClass('calibrating')) {
self.removeClass('calibrating'); self.addClass('calibrating');
}, 30000);
} // During this period MCU won't be able to process any serial commands because its locked in a for/while loop
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow
GUI.interval_pause('initial_setup_data_pull');
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION);
GUI.timeout_add('button_reset', function() {
GUI.interval_resume('initial_setup_data_pull');
self.removeClass('calibrating');
}, 2000);
}
});
$('a.calibrateMag').click(function() {
var self = $(this);
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
send_message(MSP_codes.MSP_MAG_CALIBRATION, MSP_codes.MSP_MAG_CALIBRATION);
GUI.timeout_add('button_reset', function() {
self.removeClass('calibrating');
}, 30000);
}
});
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF);
});
$('input[name="pitch"], input[name="roll"]').change(function() {
// if any of the fields changed, unlock update button
$('a.update').addClass('active');
});
$('a.update').click(function() {
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
var buffer_out = new Array();
buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]);
buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]);
buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]);
buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]);
// Send over the new trims
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
// remove the active status
$(this).removeClass('active');
});
// reset yaw button hook
$('div#interactive_block > a.reset').click(function() {
yaw_fix = SENSOR_DATA.kinematicsZ * - 1.0;
console.log("YAW reset to 0");
});
$('#content .backup').click(configuration_backup);
$('#content .restore').click(configuration_restore);
GUI.interval_add('initial_setup_data_pull', function() {
// Update cube
var cube = $('div#cube');
cube.css('-webkit-transform', 'rotateY(' + ((SENSOR_DATA.kinematicsZ * -1.0) - yaw_fix) + 'deg)');
$('#cubePITCH', cube).css('-webkit-transform', 'rotateX(' + SENSOR_DATA.kinematicsY + 'deg)');
$('#cubeROLL', cube).css('-webkit-transform', 'rotateZ(' + SENSOR_DATA.kinematicsX + 'deg)');
// Update Compass
$('div#compass .pointer').css('-webkit-transform', 'rotate(' + (SENSOR_DATA.kinematicsZ) + 'deg)');
$('div#compass .value').html(SENSOR_DATA.kinematicsZ + '&deg;');
// Update voltage indicator
$('span.bat-voltage').html(BATTERY.voltage + ' V');
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE);
send_message(MSP_codes.MSP_COMP_GPS, MSP_codes.MSP_COMP_GPS);
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG);
}, 50, true);
}); });
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF);
});
$('input[name="pitch"], input[name="roll"]').change(function() {
// if any of the fields changed, unlock update button
$('a.update').addClass('active');
});
$('a.update').click(function() {
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
var buffer_out = new Array();
buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]);
buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]);
buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]);
buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]);
// Send over the new trims
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
// remove the active status
$(this).removeClass('active');
});
// reset yaw button hook
$('div#interactive_block > a.reset').click(function() {
yaw_fix = SENSOR_DATA.kinematicsZ * - 1.0;
console.log("YAW reset to 0");
});
$('#content .backup').click(configuration_backup);
$('#content .restore').click(configuration_restore);
GUI.interval_add('initial_setup_data_pull', function() {
// Update cube
var cube = $('div#cube');
cube.css('-webkit-transform', 'rotateY(' + ((SENSOR_DATA.kinematicsZ * -1.0) - yaw_fix) + 'deg)');
$('#cubePITCH', cube).css('-webkit-transform', 'rotateX(' + SENSOR_DATA.kinematicsY + 'deg)');
$('#cubeROLL', cube).css('-webkit-transform', 'rotateZ(' + SENSOR_DATA.kinematicsX + 'deg)');
// Update Compass
$('div#compass .pointer').css('-webkit-transform', 'rotate(' + (SENSOR_DATA.kinematicsZ) + 'deg)');
$('div#compass .value').html(SENSOR_DATA.kinematicsZ + '&deg;');
// Update voltage indicator
$('span.bat-voltage').html(BATTERY.voltage + ' V');
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE);
send_message(MSP_codes.MSP_COMP_GPS, MSP_codes.MSP_COMP_GPS);
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG);
}, 50, true);
}); });
} }

View file

@ -2,233 +2,237 @@ function tab_initialize_pid_tuning() {
ga_tracker.sendAppView('PID Tuning'); ga_tracker.sendAppView('PID Tuning');
GUI.active_tab = 'pid_tuning'; GUI.active_tab = 'pid_tuning';
// Fill in the data from PIDs array send_message(MSP_codes.MSP_PID, MSP_codes.MSP_PID, false, function() {
var needle = 0; send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, function() {
// Fill in the data from PIDs array
var needle = 0;
var i = 0; var i = 0;
$('.pid_tuning .ROLL input').each(function() { $('.pid_tuning .ROLL input').each(function() {
switch (i) { switch (i) {
case 0: case 0:
$(this).val(PIDs[needle][i++].toFixed(1)); $(this).val(PIDs[needle][i++].toFixed(1));
break; break;
case 1: case 1:
$(this).val(PIDs[needle][i++].toFixed(3)); $(this).val(PIDs[needle][i++].toFixed(3));
break; break;
case 2: case 2:
$(this).val(PIDs[needle][i++].toFixed(0)); $(this).val(PIDs[needle][i++].toFixed(0));
break; break;
} }
}); });
needle++; needle++;
i = 0;
$('.pid_tuning .PITCH input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .YAW input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .ALT input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .Pos input').each(function() {
$(this).val(PIDs[needle][i++].toFixed(2));
});
needle++;
i = 0;
$('.pid_tuning .PosR input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(2));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .NavR input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(2));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .LEVEL input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(2));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .MAG input').each(function() {
$(this).val(PIDs[needle][i++].toFixed(1));
});
needle++;
// Fill in data from RC_tuning object
$('.rate-tpa input[name="roll-pitch"]').val(RC_tuning.roll_pitch_rate.toFixed(2));
$('.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));
// UI Hooks
$('.pid_tuning input, .rate-tpa input').change(function() {
// if any of the fields changed, unlock update button
$('a.update').addClass('active');
});
$('a.update').click(function() {
if ($(this).hasClass('active')) {
// Catch all the changes and stuff the inside PIDs array
var needle_main = 0;
var needle_secondary = 0;
$('.pid_tuning input').each(function() { i = 0;
PIDs[needle_main][needle_secondary] = parseFloat($(this).val()); $('.pid_tuning .PITCH input').each(function() {
needle_secondary++; switch (i) {
case 0:
// exceptions (required for the "shorter" PID arrays, 2 fields, 1 field, etc) $(this).val(PIDs[needle][i++].toFixed(1));
if (needle_main == 4) { break;
if (needle_secondary >= 2) { case 1:
needle_main++; $(this).val(PIDs[needle][i++].toFixed(3));
needle_secondary = 0; break;
} case 2:
} else if (needle_main == 8) { $(this).val(PIDs[needle][i++].toFixed(0));
if (needle_secondary >= 1) { break;
needle_main++; }
needle_secondary = 0; });
} needle++;
} else {
if (needle_secondary >= 3) { i = 0;
needle_main++; $('.pid_tuning .YAW input').each(function() {
needle_secondary = 0; switch (i) {
} case 0:
} $(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .ALT input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .Pos input').each(function() {
$(this).val(PIDs[needle][i++].toFixed(2));
});
needle++;
i = 0;
$('.pid_tuning .PosR input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(2));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .NavR input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(2));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(3));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .LEVEL input').each(function() {
switch (i) {
case 0:
$(this).val(PIDs[needle][i++].toFixed(1));
break;
case 1:
$(this).val(PIDs[needle][i++].toFixed(2));
break;
case 2:
$(this).val(PIDs[needle][i++].toFixed(0));
break;
}
});
needle++;
i = 0;
$('.pid_tuning .MAG input').each(function() {
$(this).val(PIDs[needle][i++].toFixed(1));
});
needle++;
// Fill in data from RC_tuning object
$('.rate-tpa input[name="roll-pitch"]').val(RC_tuning.roll_pitch_rate.toFixed(2));
$('.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));
// UI Hooks
$('.pid_tuning input, .rate-tpa input').change(function() {
// if any of the fields changed, unlock update button
$('a.update').addClass('active');
}); });
var PID_buffer_out = new Array(); $('a.update').click(function() {
var PID_buffer_needle = 0; if ($(this).hasClass('active')) {
for (var i = 0; i < PIDs.length; i++) { // Catch all the changes and stuff the inside PIDs array
switch (i) { var needle_main = 0;
case 0: var needle_secondary = 0;
case 1:
case 2: $('.pid_tuning input').each(function() {
case 3: PIDs[needle_main][needle_secondary] = parseFloat($(this).val());
case 7: needle_secondary++;
case 8:
case 9: // exceptions (required for the "shorter" PID arrays, 2 fields, 1 field, etc)
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10); if (needle_main == 4) {
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 1000); if (needle_secondary >= 2) {
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]); needle_main++;
break; needle_secondary = 0;
case 4: }
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 100); } else if (needle_main == 8) {
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100); if (needle_secondary >= 1) {
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]); needle_main++;
break; needle_secondary = 0;
case 5: }
case 6: } else {
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10); if (needle_secondary >= 3) {
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100); needle_main++;
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2] * 1000); needle_secondary = 0;
break; }
}
});
var PID_buffer_out = new Array();
var PID_buffer_needle = 0;
for (var i = 0; i < PIDs.length; i++) {
switch (i) {
case 0:
case 1:
case 2:
case 3:
case 7:
case 8:
case 9:
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10);
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 1000);
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]);
break;
case 4:
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 100);
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100);
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2]);
break;
case 5:
case 6:
PID_buffer_out[PID_buffer_needle] = parseInt(PIDs[i][0] * 10);
PID_buffer_out[PID_buffer_needle + 1] = parseInt(PIDs[i][1] * 100);
PID_buffer_out[PID_buffer_needle + 2] = parseInt(PIDs[i][2] * 1000);
break;
}
PID_buffer_needle += 3;
}
// Send over the PID changes
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out);
// catch RC_tuning changes
RC_tuning.roll_pitch_rate = parseFloat($('.rate-tpa input[name="roll-pitch"]').val());
RC_tuning.yaw_rate = parseFloat($('.rate-tpa input[name="yaw"]').val());
RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val());
var RC_tuning_buffer_out = new Array();
RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100);
RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100);
RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100);
RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100);
RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100);
RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100);
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
// Send over the RC_tuning changes
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
// remove the active status
$(this).removeClass('active');
} }
PID_buffer_needle += 3; });
}
// Send over the PID changes
send_message(MSP_codes.MSP_SET_PID, PID_buffer_out);
// catch RC_tuning changes
RC_tuning.roll_pitch_rate = parseFloat($('.rate-tpa input[name="roll-pitch"]').val());
RC_tuning.yaw_rate = parseFloat($('.rate-tpa input[name="yaw"]').val());
RC_tuning.dynamic_THR_PID = parseFloat($('.rate-tpa input[name="tpa"]').val());
var RC_tuning_buffer_out = new Array();
RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100);
RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100);
RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100);
RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100);
RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100);
RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100);
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
// Send over the RC_tuning changes
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
// remove the active status
$(this).removeClass('active');
}
});
// enable data pulling // enable data pulling
GUI.interval_add('pid_data_poll', function() { GUI.interval_add('pid_data_poll', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
}, 50); }, 50);
});
});
} }

View file

@ -1,203 +1,204 @@
var samples_i;
function tab_initialize_receiver() { function tab_initialize_receiver() {
ga_tracker.sendAppView('Receiver Page'); ga_tracker.sendAppView('Receiver Page');
GUI.active_tab = 'receiver'; GUI.active_tab = 'receiver';
// fill in data from RC_tuning send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING, false, function() {
$('.tunings .throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2)); // fill in data from RC_tuning
$('.tunings .throttle input[name="expo"]').val(RC_tuning.throttle_EXPO.toFixed(2)); $('.tunings .throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2));
$('.tunings .throttle input[name="expo"]').val(RC_tuning.throttle_EXPO.toFixed(2));
$('.tunings .rate input[name="rate"]').val(RC_tuning.RC_RATE.toFixed(2)); $('.tunings .rate input[name="rate"]').val(RC_tuning.RC_RATE.toFixed(2));
$('.tunings .rate input[name="expo"]').val(RC_tuning.RC_EXPO.toFixed(2)); $('.tunings .rate input[name="expo"]').val(RC_tuning.RC_EXPO.toFixed(2));
// Setup plot variables and plot it self // Setup plot variables and plot it self
samples_i = 300; var samples_i = 300;
RX_plot_data = new Array(8); RX_plot_data = new Array(8);
for (var i = 0; i < 8; i++) { for (var i = 0; i < 8; i++) {
RX_plot_data[i] = new Array(); RX_plot_data[i] = new Array();
} }
for (var i = 0; i <= 300; i++) { for (var i = 0; i <= 300; i++) {
RX_plot_data[0].push([i, 0]); RX_plot_data[0].push([i, 0]);
RX_plot_data[1].push([i, 0]); RX_plot_data[1].push([i, 0]);
RX_plot_data[2].push([i, 0]); RX_plot_data[2].push([i, 0]);
RX_plot_data[3].push([i, 0]); RX_plot_data[3].push([i, 0]);
RX_plot_data[4].push([i, 0]); RX_plot_data[4].push([i, 0]);
RX_plot_data[5].push([i, 0]); RX_plot_data[5].push([i, 0]);
RX_plot_data[6].push([i, 0]); RX_plot_data[6].push([i, 0]);
RX_plot_data[7].push([i, 0]); RX_plot_data[7].push([i, 0]);
}
e_RX_plot = document.getElementById("RX_plot");
RX_plot_options = {
title: "Channel width (us)",
shadowSize: 0,
yaxis : {
max: 2200,
min: 800,
noTicks: 10
},
xaxis : {
//noTicks = 0
},
grid : {
backgroundColor: "#FFFFFF"
},
legend : {
position: "we",
backgroundOpacity: 0
}
};
// UI Hooks
$('.tunings input').change(function() {
// if any of the fields changed, unlock update button
$('a.update').addClass('active');
});
// curves
$('.tunings .throttle input').change(function() {
var mid = parseFloat($('.tunings .throttle input[name="mid"]').val());
var expo = parseFloat($('.tunings .throttle input[name="expo"]').val());
var throttle_curve = $('.throttle_curve canvas').get(0);
var context = throttle_curve.getContext("2d");
context.clearRect(0, 0, 220, 58);
// math magic by englishman
var midx = 220 * mid;
var midxl = midx * .5;
var midxr = (((220 - midx) * .5) + midx);
var midy = 58 - (midx * (58 / 220));
var midyl = 58 - ((58 - midy) * .5 *(expo + 1));
var midyr = (midy / 2) * (expo + 1);
context.beginPath();
context.moveTo(0, 58);
context.quadraticCurveTo(midxl, midyl, midx, midy);
context.moveTo(midx, midy);
context.quadraticCurveTo(midxr, midyr, 220, 0);
context.lineWidth = 2;
context.stroke();
});
$('.tunings .throttle input').trigger('change'); // initial software trigger
$('.tunings .rate input').change(function() {
var rate = parseFloat($('.tunings .rate input[name="rate"]').val());
var expo = parseFloat($('.tunings .rate input[name="expo"]').val());
var pitch_roll_curve = $('.pitch_roll_curve canvas').get(0);
var context = pitch_roll_curve.getContext("2d");
context.clearRect(0, 0, 220, 58);
// math magic by englishman
var ratey = 58 * rate;
context.beginPath();
context.moveTo(0, 58);
context.quadraticCurveTo(110, 58 - ((ratey / 2) * (1 - expo)), 220, 58 - ratey);
context.lineWidth = 2;
context.stroke();
});
$('.tunings .rate input').trigger('change'); // initial software trigger
$('a.update').click(function() {
if ($(this).hasClass('active')) {
// catch RC_tuning changes
RC_tuning.throttle_MID = parseFloat($('.tunings .throttle input[name="mid"]').val());
RC_tuning.throttle_EXPO = parseFloat($('.tunings .throttle input[name="expo"]').val());
RC_tuning.RC_RATE = parseFloat($('.tunings .rate input[name="rate"]').val());
RC_tuning.RC_EXPO = parseFloat($('.tunings .rate input[name="expo"]').val());
var RC_tuning_buffer_out = new Array();
RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100);
RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100);
RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100);
RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100);
RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100);
RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100);
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
// Send over the RC_tuning changes
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
// remove the active status
$(this).removeClass('active');
} }
});
// enable RC data pulling
GUI.interval_add('receiver_poll', function() {
// Update UI with latest data
$('.tab-receiver meter:eq(0)').val(RC.throttle);
$('.tab-receiver .value:eq(0)').html(RC.throttle);
$('.tab-receiver meter:eq(1)').val(RC.pitch); e_RX_plot = document.getElementById("RX_plot");
$('.tab-receiver .value:eq(1)').html(RC.pitch);
$('.tab-receiver meter:eq(2)').val(RC.roll); RX_plot_options = {
$('.tab-receiver .value:eq(2)').html(RC.roll); title: "Channel width (us)",
shadowSize: 0,
$('.tab-receiver meter:eq(3)').val(RC.yaw); yaxis : {
$('.tab-receiver .value:eq(3)').html(RC.yaw); max: 2200,
min: 800,
noTicks: 10
$('.tab-receiver meter:eq(4)').val(RC.AUX1); },
$('.tab-receiver .value:eq(4)').html(RC.AUX1); xaxis : {
//noTicks = 0
$('.tab-receiver meter:eq(5)').val(RC.AUX2); },
$('.tab-receiver .value:eq(5)').html(RC.AUX2); grid : {
backgroundColor: "#FFFFFF"
$('.tab-receiver meter:eq(6)').val(RC.AUX3); },
$('.tab-receiver .value:eq(6)').html(RC.AUX3); legend : {
position: "we",
$('.tab-receiver meter:eq(7)').val(RC.AUX4); backgroundOpacity: 0
$('.tab-receiver .value:eq(7)').html(RC.AUX4); }
// push latest data to the main array
RX_plot_data[0].push([samples_i, RC.throttle]);
RX_plot_data[1].push([samples_i, RC.pitch]);
RX_plot_data[2].push([samples_i, RC.roll]);
RX_plot_data[3].push([samples_i, RC.yaw]);
RX_plot_data[4].push([samples_i, RC.AUX1]);
RX_plot_data[5].push([samples_i, RC.AUX2]);
RX_plot_data[6].push([samples_i, RC.AUX3]);
RX_plot_data[7].push([samples_i, RC.AUX4]);
// Remove old data from array
while (RX_plot_data[0].length > 300) {
RX_plot_data[0].shift();
RX_plot_data[1].shift();
RX_plot_data[2].shift();
RX_plot_data[3].shift();
RX_plot_data[4].shift();
RX_plot_data[5].shift();
RX_plot_data[6].shift();
RX_plot_data[7].shift();
}; };
// redraw plot // UI Hooks
Flotr.draw(e_RX_plot, [ $('.tunings input').change(function() {
{data: RX_plot_data[0], label: "THROTTLE"}, // if any of the fields changed, unlock update button
{data: RX_plot_data[1], label: "PITCH"}, $('a.update').addClass('active');
{data: RX_plot_data[2], label: "ROLL"}, });
{data: RX_plot_data[3], label: "YAW"},
{data: RX_plot_data[4], label: "AUX1"},
{data: RX_plot_data[5], label: "AUX2"},
{data: RX_plot_data[6], label: "AUX3"},
{data: RX_plot_data[7], label: "AUX4"} ], RX_plot_options);
samples_i++;
// Request new data // curves
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); $('.tunings .throttle input').change(function() {
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC); var mid = parseFloat($('.tunings .throttle input[name="mid"]').val());
}, 50); var expo = parseFloat($('.tunings .throttle input[name="expo"]').val());
var throttle_curve = $('.throttle_curve canvas').get(0);
var context = throttle_curve.getContext("2d");
context.clearRect(0, 0, 220, 58);
// math magic by englishman
var midx = 220 * mid;
var midxl = midx * .5;
var midxr = (((220 - midx) * .5) + midx);
var midy = 58 - (midx * (58 / 220));
var midyl = 58 - ((58 - midy) * .5 *(expo + 1));
var midyr = (midy / 2) * (expo + 1);
context.beginPath();
context.moveTo(0, 58);
context.quadraticCurveTo(midxl, midyl, midx, midy);
context.moveTo(midx, midy);
context.quadraticCurveTo(midxr, midyr, 220, 0);
context.lineWidth = 2;
context.stroke();
});
$('.tunings .throttle input').trigger('change'); // initial software trigger
$('.tunings .rate input').change(function() {
var rate = parseFloat($('.tunings .rate input[name="rate"]').val());
var expo = parseFloat($('.tunings .rate input[name="expo"]').val());
var pitch_roll_curve = $('.pitch_roll_curve canvas').get(0);
var context = pitch_roll_curve.getContext("2d");
context.clearRect(0, 0, 220, 58);
// math magic by englishman
var ratey = 58 * rate;
context.beginPath();
context.moveTo(0, 58);
context.quadraticCurveTo(110, 58 - ((ratey / 2) * (1 - expo)), 220, 58 - ratey);
context.lineWidth = 2;
context.stroke();
});
$('.tunings .rate input').trigger('change'); // initial software trigger
$('a.update').click(function() {
if ($(this).hasClass('active')) {
// catch RC_tuning changes
RC_tuning.throttle_MID = parseFloat($('.tunings .throttle input[name="mid"]').val());
RC_tuning.throttle_EXPO = parseFloat($('.tunings .throttle input[name="expo"]').val());
RC_tuning.RC_RATE = parseFloat($('.tunings .rate input[name="rate"]').val());
RC_tuning.RC_EXPO = parseFloat($('.tunings .rate input[name="expo"]').val());
var RC_tuning_buffer_out = new Array();
RC_tuning_buffer_out[0] = parseInt(RC_tuning.RC_RATE * 100);
RC_tuning_buffer_out[1] = parseInt(RC_tuning.RC_EXPO * 100);
RC_tuning_buffer_out[2] = parseInt(RC_tuning.roll_pitch_rate * 100);
RC_tuning_buffer_out[3] = parseInt(RC_tuning.yaw_rate * 100);
RC_tuning_buffer_out[4] = parseInt(RC_tuning.dynamic_THR_PID * 100);
RC_tuning_buffer_out[5] = parseInt(RC_tuning.throttle_MID * 100);
RC_tuning_buffer_out[6] = parseInt(RC_tuning.throttle_EXPO * 100);
// Send over the RC_tuning changes
send_message(MSP_codes.MSP_SET_RC_TUNING, RC_tuning_buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
// remove the active status
$(this).removeClass('active');
}
});
// enable RC data pulling
GUI.interval_add('receiver_poll', function() {
// Update UI with latest data
$('.tab-receiver meter:eq(0)').val(RC.throttle);
$('.tab-receiver .value:eq(0)').html(RC.throttle);
$('.tab-receiver meter:eq(1)').val(RC.pitch);
$('.tab-receiver .value:eq(1)').html(RC.pitch);
$('.tab-receiver meter:eq(2)').val(RC.roll);
$('.tab-receiver .value:eq(2)').html(RC.roll);
$('.tab-receiver meter:eq(3)').val(RC.yaw);
$('.tab-receiver .value:eq(3)').html(RC.yaw);
$('.tab-receiver meter:eq(4)').val(RC.AUX1);
$('.tab-receiver .value:eq(4)').html(RC.AUX1);
$('.tab-receiver meter:eq(5)').val(RC.AUX2);
$('.tab-receiver .value:eq(5)').html(RC.AUX2);
$('.tab-receiver meter:eq(6)').val(RC.AUX3);
$('.tab-receiver .value:eq(6)').html(RC.AUX3);
$('.tab-receiver meter:eq(7)').val(RC.AUX4);
$('.tab-receiver .value:eq(7)').html(RC.AUX4);
// push latest data to the main array
RX_plot_data[0].push([samples_i, RC.throttle]);
RX_plot_data[1].push([samples_i, RC.pitch]);
RX_plot_data[2].push([samples_i, RC.roll]);
RX_plot_data[3].push([samples_i, RC.yaw]);
RX_plot_data[4].push([samples_i, RC.AUX1]);
RX_plot_data[5].push([samples_i, RC.AUX2]);
RX_plot_data[6].push([samples_i, RC.AUX3]);
RX_plot_data[7].push([samples_i, RC.AUX4]);
// Remove old data from array
while (RX_plot_data[0].length > 300) {
RX_plot_data[0].shift();
RX_plot_data[1].shift();
RX_plot_data[2].shift();
RX_plot_data[3].shift();
RX_plot_data[4].shift();
RX_plot_data[5].shift();
RX_plot_data[6].shift();
RX_plot_data[7].shift();
};
// redraw plot
Flotr.draw(e_RX_plot, [
{data: RX_plot_data[0], label: "THROTTLE"},
{data: RX_plot_data[1], label: "PITCH"},
{data: RX_plot_data[2], label: "ROLL"},
{data: RX_plot_data[3], label: "YAW"},
{data: RX_plot_data[4], label: "AUX1"},
{data: RX_plot_data[5], label: "AUX2"},
{data: RX_plot_data[6], label: "AUX3"},
{data: RX_plot_data[7], label: "AUX4"} ], RX_plot_options);
samples_i++;
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC);
}, 50);
});
} }