2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-16 11:12:02 +00:00
|
|
|
TABS.motors = {
|
|
|
|
allowTestMode: false,
|
|
|
|
feature3DEnabled: false,
|
|
|
|
feature3DSupported: false
|
|
|
|
};
|
2014-10-30 11:43:35 +00:00
|
|
|
TABS.motors.initialize = function (callback) {
|
2014-10-01 10:58:09 +00:00
|
|
|
var self = this;
|
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
self.armed = false;
|
2015-12-16 13:46:07 +00:00
|
|
|
self.feature3DSupported = false;
|
|
|
|
self.allowTestMode = true;
|
2015-05-25 22:00:54 +00:00
|
|
|
|
2014-10-30 11:43:35 +00:00
|
|
|
if (GUI.active_tab != 'motors') {
|
|
|
|
GUI.active_tab = 'motors';
|
2014-10-30 11:33:39 +00:00
|
|
|
googleAnalytics.sendAppView('Motors');
|
2014-10-01 11:16:22 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
function get_arm_status() {
|
2015-11-12 21:00:07 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS, false, false, load_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_config() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_BF_CONFIG, false, false, load_3d);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_3d() {
|
2015-12-16 11:12:02 +00:00
|
|
|
var next_callback = get_motor_data;
|
|
|
|
if (semver.gte(CONFIG.apiVersion, "1.14.0")) {
|
|
|
|
self.feature3DSupported = true;
|
|
|
|
MSP.send_message(MSP_codes.MSP_3D, false, false, next_callback);
|
|
|
|
} else {
|
|
|
|
next_callback();
|
|
|
|
}
|
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 14:02:57 +00:00
|
|
|
function get_motor_data() {
|
2015-05-25 22:00:54 +00:00
|
|
|
update_arm_status();
|
2014-09-30 14:02:57 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MOTOR, false, false, load_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
2014-10-30 11:43:35 +00:00
|
|
|
$('#content').load("./tabs/motors.html", process_html);
|
2014-09-30 14:02:57 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MISC, false, false, get_arm_status);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2015-12-16 11:12:02 +00:00
|
|
|
function update_arm_status() {
|
|
|
|
self.armed = bit_check(CONFIG.mode, 0);
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:01:21 +00:00
|
|
|
function initSensorData() {
|
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
|
SENSOR_DATA.accelerometer[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initDataArray(length) {
|
|
|
|
var data = new Array(length);
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
data[i] = new Array();
|
|
|
|
data[i].min = -1;
|
|
|
|
data[i].max = 1;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSampleToData(data, sampleNumber, sensorData) {
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
var dataPoint = sensorData[i];
|
|
|
|
data[i].push([sampleNumber, dataPoint]);
|
|
|
|
if (dataPoint < data[i].min) {
|
|
|
|
data[i].min = dataPoint;
|
|
|
|
}
|
|
|
|
if (dataPoint > data[i].max) {
|
|
|
|
data[i].max = dataPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (data[0].length > 300) {
|
|
|
|
for (i = 0; i < data.length; i++) {
|
|
|
|
data[i].shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sampleNumber + 1;
|
|
|
|
}
|
|
|
|
|
2014-07-10 21:28:58 +00:00
|
|
|
var margin = {top: 20, right: 30, bottom: 10, left: 20};
|
2014-06-25 11:01:21 +00:00
|
|
|
function updateGraphHelperSize(helpers) {
|
|
|
|
helpers.width = helpers.targetElement.width() - margin.left - margin.right;
|
|
|
|
helpers.height = helpers.targetElement.height() - margin.top - margin.bottom;
|
|
|
|
|
|
|
|
helpers.widthScale.range([0, helpers.width]);
|
|
|
|
helpers.heightScale.range([helpers.height, 0]);
|
|
|
|
|
|
|
|
helpers.xGrid.tickSize(-helpers.height, 0, 0);
|
|
|
|
helpers.yGrid.tickSize(-helpers.width, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function initGraphHelpers(selector, sampleNumber, heightDomain) {
|
|
|
|
var helpers = {selector: selector, targetElement: $(selector), dynamicHeightDomain: !heightDomain};
|
|
|
|
|
|
|
|
helpers.widthScale = d3.scale.linear()
|
|
|
|
.clamp(true)
|
|
|
|
.domain([(sampleNumber - 299), sampleNumber]);
|
|
|
|
|
|
|
|
helpers.heightScale = d3.scale.linear()
|
|
|
|
.clamp(true)
|
|
|
|
.domain(heightDomain || [1, -1]);
|
|
|
|
|
|
|
|
helpers.xGrid = d3.svg.axis();
|
|
|
|
helpers.yGrid = d3.svg.axis();
|
|
|
|
|
|
|
|
updateGraphHelperSize(helpers);
|
|
|
|
|
|
|
|
helpers.xGrid
|
|
|
|
.scale(helpers.widthScale)
|
|
|
|
.orient("bottom")
|
|
|
|
.ticks(5)
|
|
|
|
.tickFormat("");
|
|
|
|
|
|
|
|
helpers.yGrid
|
|
|
|
.scale(helpers.heightScale)
|
|
|
|
.orient("left")
|
|
|
|
.ticks(5)
|
|
|
|
.tickFormat("");
|
|
|
|
|
|
|
|
helpers.xAxis = d3.svg.axis()
|
|
|
|
.scale(helpers.widthScale)
|
|
|
|
.ticks(5)
|
|
|
|
.orient("bottom")
|
2014-08-12 14:20:26 +00:00
|
|
|
.tickFormat(function (d) {return d;});
|
2014-06-25 11:01:21 +00:00
|
|
|
|
|
|
|
helpers.yAxis = d3.svg.axis()
|
|
|
|
.scale(helpers.heightScale)
|
|
|
|
.ticks(5)
|
|
|
|
.orient("left")
|
2014-08-12 14:20:26 +00:00
|
|
|
.tickFormat(function (d) {return d;});
|
2014-06-25 11:01:21 +00:00
|
|
|
|
|
|
|
helpers.line = d3.svg.line()
|
2014-08-12 14:20:26 +00:00
|
|
|
.x(function (d) { return helpers.widthScale(d[0]); })
|
|
|
|
.y(function (d) { return helpers.heightScale(d[1]); });
|
2014-06-25 11:01:21 +00:00
|
|
|
|
|
|
|
return helpers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawGraph(graphHelpers, data, sampleNumber) {
|
2014-08-09 18:01:17 +00:00
|
|
|
var svg = d3.select(graphHelpers.selector);
|
2014-06-25 11:01:21 +00:00
|
|
|
|
|
|
|
if (graphHelpers.dynamicHeightDomain) {
|
|
|
|
var limits = [];
|
2014-08-12 14:20:26 +00:00
|
|
|
$.each(data, function (idx, datum) {
|
2014-06-25 11:01:21 +00:00
|
|
|
limits.push(datum.min);
|
|
|
|
limits.push(datum.max);
|
|
|
|
});
|
|
|
|
graphHelpers.heightScale.domain(d3.extent(limits));
|
|
|
|
}
|
|
|
|
graphHelpers.widthScale.domain([(sampleNumber - 299), sampleNumber]);
|
|
|
|
|
|
|
|
svg.select(".x.grid").call(graphHelpers.xGrid);
|
|
|
|
svg.select(".y.grid").call(graphHelpers.yGrid);
|
|
|
|
svg.select(".x.axis").call(graphHelpers.xAxis);
|
|
|
|
svg.select(".y.axis").call(graphHelpers.yAxis);
|
|
|
|
|
|
|
|
var group = svg.select("g.data");
|
2014-08-12 14:20:26 +00:00
|
|
|
var lines = group.selectAll("path").data(data, function (d, i) {return i;});
|
2014-06-25 11:01:21 +00:00
|
|
|
var newLines = lines.enter().append("path").attr("class", "line");
|
|
|
|
lines.attr('d', graphHelpers.line);
|
|
|
|
}
|
|
|
|
|
2014-12-20 00:29:49 +00:00
|
|
|
function update_model(val) {
|
|
|
|
$('.mixerPreview img').attr('src', './resources/motor_order/' + mixerList[val - 1].image + '.svg');
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function process_html() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2015-12-16 11:12:02 +00:00
|
|
|
self.feature3DEnabled = bit_check(BF_CONFIG.features, 12);
|
2015-12-16 13:46:07 +00:00
|
|
|
|
2015-12-16 11:12:02 +00:00
|
|
|
if (self.feature3DEnabled && !self.feature3DSupported) {
|
|
|
|
self.allowTestMode = false;
|
|
|
|
}
|
|
|
|
|
2016-01-09 22:48:41 +00:00
|
|
|
$('#motorsEnableTestMode').prop('checked', false);
|
|
|
|
$('#motorsEnableTestMode').prop('disabled', true);
|
2015-12-16 11:12:02 +00:00
|
|
|
|
2014-09-04 01:59:31 +00:00
|
|
|
update_model(CONFIG.multiType);
|
|
|
|
|
2014-06-25 11:01:21 +00:00
|
|
|
// Always start with default/empty sensor data array, clean slate all
|
|
|
|
initSensorData();
|
|
|
|
|
|
|
|
// Setup variables
|
2014-09-30 14:41:17 +00:00
|
|
|
var samples_accel_i = 0,
|
|
|
|
accel_data = initDataArray(3),
|
|
|
|
accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-2, 2]),
|
|
|
|
accel_max_read = [0, 0, 0],
|
|
|
|
accel_offset = [0, 0, 0],
|
|
|
|
accel_offset_established = false;
|
2014-06-25 11:01:21 +00:00
|
|
|
|
|
|
|
var raw_data_text_ements = {
|
|
|
|
x: [],
|
|
|
|
y: [],
|
2016-01-17 21:54:10 +00:00
|
|
|
z: [],
|
|
|
|
rms: []
|
2014-06-25 11:01:21 +00:00
|
|
|
};
|
2014-09-30 14:02:57 +00:00
|
|
|
|
2016-01-17 21:54:10 +00:00
|
|
|
$('.plot_control .x, .plot_control .y, .plot_control .z, .plot_control .rms').each(function () {
|
2014-06-25 11:01:21 +00:00
|
|
|
var el = $(this);
|
|
|
|
if (el.hasClass('x')) {
|
|
|
|
raw_data_text_ements.x.push(el);
|
|
|
|
} else if (el.hasClass('y')) {
|
|
|
|
raw_data_text_ements.y.push(el);
|
2016-01-17 21:54:10 +00:00
|
|
|
} else if (el.hasClass('z')) {
|
2014-06-25 11:01:21 +00:00
|
|
|
raw_data_text_ements.z.push(el);
|
2016-01-17 21:54:10 +00:00
|
|
|
} else if (el.hasClass('rms')) {
|
|
|
|
raw_data_text_ements.rms.push(el);
|
2014-06-25 11:01:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-25 11:06:55 +00:00
|
|
|
// set refresh speeds according to configuration saved in storage
|
2014-08-12 14:20:26 +00:00
|
|
|
chrome.storage.local.get('motors_tab_accel_settings', function (result) {
|
2014-06-25 11:06:55 +00:00
|
|
|
if (result.motors_tab_accel_settings) {
|
2014-10-30 11:47:52 +00:00
|
|
|
$('.tab-motors select[name="accel_refresh_rate"]').val(result.motors_tab_accel_settings.rate);
|
|
|
|
$('.tab-motors select[name="accel_scale"]').val(result.motors_tab_accel_settings.scale);
|
2014-06-25 11:06:55 +00:00
|
|
|
|
|
|
|
// start polling data by triggering refresh rate change event
|
2014-10-30 11:47:52 +00:00
|
|
|
$('.tab-motors .rate select:first').change();
|
2014-06-25 11:06:55 +00:00
|
|
|
} else {
|
|
|
|
// start polling immediatly (as there is no configuration saved in the storage)
|
2014-10-30 11:47:52 +00:00
|
|
|
$('.tab-motors .rate select:first').change();
|
2014-06-25 11:06:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-10-30 11:47:52 +00:00
|
|
|
$('.tab-motors .rate select, .tab-motors .scale select').change(function () {
|
|
|
|
var rate = parseInt($('.tab-motors select[name="accel_refresh_rate"]').val(), 10);
|
|
|
|
var scale = parseFloat($('.tab-motors select[name="accel_scale"]').val());
|
2014-06-25 11:01:21 +00:00
|
|
|
|
2014-06-25 11:06:55 +00:00
|
|
|
// store current/latest refresh rates in the storage
|
|
|
|
chrome.storage.local.set({'motors_tab_accel_settings': {'rate': rate, 'scale': scale}});
|
|
|
|
|
2014-06-25 11:01:21 +00:00
|
|
|
accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-scale, scale]);
|
|
|
|
|
|
|
|
// timer initialization
|
2015-05-25 22:00:54 +00:00
|
|
|
GUI.interval_kill_all(['motor_and_status_pull']);
|
2014-06-25 11:01:21 +00:00
|
|
|
|
|
|
|
GUI.interval_add('IMU_pull', function imu_data_pull() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_RAW_IMU, false, false, update_accel_graph);
|
|
|
|
}, rate, true);
|
|
|
|
|
|
|
|
function update_accel_graph() {
|
2014-06-28 11:47:52 +00:00
|
|
|
if (!accel_offset_established) {
|
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
|
accel_offset[i] = SENSOR_DATA.accelerometer[i] * -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
accel_offset_established = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var accel_with_offset = [
|
|
|
|
accel_offset[0] + SENSOR_DATA.accelerometer[0],
|
|
|
|
accel_offset[1] + SENSOR_DATA.accelerometer[1],
|
2014-11-15 00:18:04 +00:00
|
|
|
accel_offset[2] + SENSOR_DATA.accelerometer[2]
|
2014-06-28 11:47:52 +00:00
|
|
|
];
|
2014-06-25 11:01:21 +00:00
|
|
|
|
2014-06-28 11:47:52 +00:00
|
|
|
updateGraphHelperSize(accelHelpers);
|
|
|
|
samples_accel_i = addSampleToData(accel_data, samples_accel_i, accel_with_offset);
|
2014-06-25 11:01:21 +00:00
|
|
|
drawGraph(accelHelpers, accel_data, samples_accel_i);
|
2014-06-28 11:47:52 +00:00
|
|
|
|
2016-01-17 21:54:10 +00:00
|
|
|
// Compute RMS of acceleration in displayed period of time
|
|
|
|
// This is particularly useful for motor balancing as it
|
|
|
|
// eliminates the need for external tools
|
|
|
|
var sum = 0.0;
|
2016-01-18 07:45:19 +00:00
|
|
|
for (var j = 0; j < accel_data.length; j++)
|
2016-01-18 07:52:42 +00:00
|
|
|
for (var k = 0; k < accel_data[j].length; k++)
|
2016-01-18 07:45:19 +00:00
|
|
|
sum += accel_data[j][k][1]*accel_data[j][k][1];
|
2016-01-17 21:54:10 +00:00
|
|
|
var rms = Math.sqrt(sum/(accel_data[0].length+accel_data[1].length+accel_data[2].length));
|
|
|
|
|
2014-06-28 11:47:52 +00:00
|
|
|
raw_data_text_ements.x[0].text(accel_with_offset[0].toFixed(2) + ' (' + accel_max_read[0].toFixed(2) + ')');
|
|
|
|
raw_data_text_ements.y[0].text(accel_with_offset[1].toFixed(2) + ' (' + accel_max_read[1].toFixed(2) + ')');
|
|
|
|
raw_data_text_ements.z[0].text(accel_with_offset[2].toFixed(2) + ' (' + accel_max_read[2].toFixed(2) + ')');
|
2016-01-17 21:54:10 +00:00
|
|
|
raw_data_text_ements.rms[0].text(rms.toFixed(4));
|
2014-06-28 11:47:52 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
|
if (Math.abs(accel_with_offset[i]) > Math.abs(accel_max_read[i])) accel_max_read[i] = accel_with_offset[i];
|
|
|
|
}
|
2014-06-25 11:01:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('a.reset_accel_max').click(function () {
|
2014-06-25 11:25:46 +00:00
|
|
|
accel_max_read = [0, 0, 0];
|
2014-06-28 11:47:52 +00:00
|
|
|
accel_offset_established = false;
|
2014-06-25 11:25:46 +00:00
|
|
|
});
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
var number_of_valid_outputs = (MOTOR_DATA.indexOf(0) > -1) ? MOTOR_DATA.indexOf(0) : 8;
|
|
|
|
|
2014-09-30 14:41:17 +00:00
|
|
|
var motors_wrapper = $('.motors .bar-wrapper'),
|
|
|
|
servos_wrapper = $('.servos .bar-wrapper');
|
|
|
|
|
2014-09-30 14:02:57 +00:00
|
|
|
for (var i = 0; i < 8; i++) {
|
|
|
|
motors_wrapper.append('\
|
|
|
|
<div class="m-block motor-' + i + '">\
|
2014-09-30 14:33:47 +00:00
|
|
|
<div class="meter-bar">\
|
|
|
|
<div class="label"></div>\
|
|
|
|
<div class="indicator">\
|
|
|
|
<div class="label">\
|
|
|
|
<div class="label"></div>\
|
|
|
|
</div>\
|
2014-09-30 14:02:57 +00:00
|
|
|
</div>\
|
|
|
|
</div>\
|
|
|
|
</div>\
|
|
|
|
');
|
|
|
|
|
|
|
|
servos_wrapper.append('\
|
2015-10-14 20:20:42 +00:00
|
|
|
<div class="m-block servo-' + (7 - i) + '">\
|
2014-09-30 14:33:47 +00:00
|
|
|
<div class="meter-bar">\
|
|
|
|
<div class="label"></div>\
|
|
|
|
<div class="indicator">\
|
|
|
|
<div class="label">\
|
|
|
|
<div class="label"></div>\
|
|
|
|
</div>\
|
2014-09-30 14:02:57 +00:00
|
|
|
</div>\
|
|
|
|
</div>\
|
|
|
|
</div>\
|
|
|
|
');
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
$('div.sliders input').prop('min', MISC.mincommand);
|
|
|
|
$('div.sliders input').prop('max', MISC.maxthrottle);
|
2014-08-18 17:28:26 +00:00
|
|
|
$('div.values li:not(:last)').text(MISC.mincommand);
|
2015-12-16 11:12:02 +00:00
|
|
|
|
|
|
|
if(self.feature3DEnabled && self.feature3DSupported) {
|
2016-01-10 02:25:03 +00:00
|
|
|
//Arbitrary sanity checks
|
|
|
|
//Note: values may need to be revisited
|
|
|
|
if(_3D.neutral3d > 1575 || _3D.neutral3d < 1425)
|
|
|
|
_3D.neutral3d = 1500;
|
|
|
|
|
2015-11-12 22:33:17 +00:00
|
|
|
$('div.sliders input').val(_3D.neutral3d);
|
2015-12-16 11:12:02 +00:00
|
|
|
} else {
|
|
|
|
$('div.sliders input').val(MISC.mincommand);
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
if(self.allowTestMode){
|
|
|
|
// UI hooks
|
|
|
|
var buffering_set_motor = [],
|
|
|
|
buffer_delay = false;
|
|
|
|
$('div.sliders input:not(.master)').on('input', function () {
|
2015-05-25 22:00:54 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
var index = $(this).index(),
|
|
|
|
buffer = [],
|
|
|
|
i;
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
$('div.values li').eq(index).text($(this).val());
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
var val = parseInt($('div.sliders input').eq(i).val());
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
buffer.push(lowByte(val));
|
|
|
|
buffer.push(highByte(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
buffering_set_motor.push(buffer);
|
2014-08-18 17:28:26 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
if (!buffer_delay) {
|
|
|
|
buffer_delay = setTimeout(function () {
|
|
|
|
buffer = buffering_set_motor.pop();
|
2016-01-09 22:48:41 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SET_MOTOR, buffer);
|
2014-08-18 17:28:26 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
buffering_set_motor = [];
|
|
|
|
buffer_delay = false;
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-08-12 14:20:26 +00:00
|
|
|
$('div.sliders input.master').on('input', function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var val = $(this).val();
|
|
|
|
|
|
|
|
$('div.sliders input:not(:disabled, :last)').val(val);
|
2014-08-18 17:28:26 +00:00
|
|
|
$('div.values li:not(:last)').slice(0, number_of_valid_outputs).text(val);
|
2014-04-10 15:36:26 +00:00
|
|
|
$('div.sliders input:not(:last):first').trigger('input');
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
$('#motorsEnableTestMode').change(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
$('div.sliders input').slice(0, number_of_valid_outputs).prop('disabled', false);
|
|
|
|
|
|
|
|
// unlock master slider
|
|
|
|
$('div.sliders input:last').prop('disabled', false);
|
|
|
|
} else {
|
|
|
|
// disable sliders / min max
|
|
|
|
$('div.sliders input').prop('disabled', true);
|
|
|
|
|
|
|
|
// change all values to default
|
2015-12-16 11:12:02 +00:00
|
|
|
if (self.feature3DEnabled && self.feature3DSupported) {
|
2015-11-12 21:00:07 +00:00
|
|
|
$('div.sliders input').val(_3D.neutral3d);
|
2015-12-16 11:12:02 +00:00
|
|
|
} else {
|
|
|
|
$('div.sliders input').val(MISC.mincommand);
|
2015-11-12 21:00:07 +00:00
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2016-01-12 22:18:34 +00:00
|
|
|
$('div.sliders input').trigger('input');
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-02-14 21:17:51 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-06-23 17:50:39 +00:00
|
|
|
// check if motors are already spinning
|
|
|
|
var motors_running = false;
|
|
|
|
|
2015-11-12 22:33:17 +00:00
|
|
|
for (var i = 0; i < number_of_valid_outputs; i++) {
|
2016-01-12 22:18:34 +00:00
|
|
|
if( !self.feature3DEnabled ){
|
2015-11-12 21:22:04 +00:00
|
|
|
if (MOTOR_DATA[i] > MISC.mincommand) {
|
|
|
|
motors_running = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if( (MOTOR_DATA[i] < _3D.deadband3d_low) || (MOTOR_DATA[i] > _3D.deadband3d_high) ){
|
|
|
|
motors_running = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-11-12 22:33:17 +00:00
|
|
|
}
|
2014-06-23 17:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (motors_running) {
|
2016-01-12 22:18:34 +00:00
|
|
|
if (!self.armed && self.allowTestMode) {
|
2015-05-25 22:00:54 +00:00
|
|
|
$('#motorsEnableTestMode').prop('checked', true);
|
|
|
|
}
|
|
|
|
// motors are running adjust sliders to current values
|
2014-06-23 17:50:39 +00:00
|
|
|
|
|
|
|
var sliders = $('div.sliders input:not(.master)');
|
|
|
|
|
2014-06-27 16:49:41 +00:00
|
|
|
var master_value = MOTOR_DATA[0];
|
2014-06-23 17:50:39 +00:00
|
|
|
for (var i = 0; i < MOTOR_DATA.length; i++) {
|
|
|
|
if (MOTOR_DATA[i] > 0) {
|
|
|
|
sliders.eq(i).val(MOTOR_DATA[i]);
|
2014-06-27 16:49:41 +00:00
|
|
|
|
|
|
|
if (master_value != MOTOR_DATA[i]) {
|
|
|
|
master_value = false;
|
|
|
|
}
|
2014-06-23 17:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only fire events when all values are set
|
|
|
|
sliders.trigger('input');
|
2014-06-27 16:49:41 +00:00
|
|
|
|
|
|
|
// slide master slider if condition is valid
|
|
|
|
if (master_value) {
|
|
|
|
$('div.sliders input.master').val(master_value);
|
|
|
|
$('div.sliders input.master').trigger('input');
|
|
|
|
}
|
2014-06-23 17:50:39 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
$('#motorsEnableTestMode').change();
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// data pulling functions used inside interval timer
|
2015-05-25 22:00:54 +00:00
|
|
|
|
|
|
|
function get_status() {
|
|
|
|
// status needed for arming flag
|
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_motor_data);
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function get_motor_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MOTOR, false, false, get_servo_data);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_servo_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_SERVO, false, false, update_ui);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 17:50:39 +00:00
|
|
|
var full_block_scale = MISC.maxthrottle - MISC.mincommand;
|
2016-01-09 22:48:41 +00:00
|
|
|
|
|
|
|
function update_ui() {
|
|
|
|
var previousArmState = self.armed;
|
2014-03-22 23:28:41 +00:00
|
|
|
var block_height = $('div.m-block:first').height();
|
|
|
|
|
|
|
|
for (var i = 0; i < MOTOR_DATA.length; i++) {
|
2014-09-30 14:02:57 +00:00
|
|
|
var data = MOTOR_DATA[i] - MISC.mincommand,
|
2014-10-05 17:46:27 +00:00
|
|
|
margin_top = block_height - (data * (block_height / full_block_scale)).clamp(0, block_height),
|
|
|
|
height = (data * (block_height / full_block_scale)).clamp(0, block_height),
|
2015-11-09 20:40:26 +00:00
|
|
|
color = parseInt(data * 0.009);
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-09-30 14:41:17 +00:00
|
|
|
$('.motor-' + i + ' .label', motors_wrapper).text(MOTOR_DATA[i]);
|
2015-11-09 20:57:37 +00:00
|
|
|
$('.motor-' + i + ' .indicator', motors_wrapper).css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgba(89,170,41,1.'+ color +')'});
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 17:50:39 +00:00
|
|
|
// servo indicators are still using old (not flexible block scale), it will be changed in the future accordingly
|
2014-03-22 23:28:41 +00:00
|
|
|
for (var i = 0; i < SERVO_DATA.length; i++) {
|
2014-09-30 14:02:57 +00:00
|
|
|
var data = SERVO_DATA[i] - 1000,
|
2014-10-05 17:46:27 +00:00
|
|
|
margin_top = block_height - (data * (block_height / 1000)).clamp(0, block_height),
|
|
|
|
height = (data * (block_height / 1000)).clamp(0, block_height),
|
2015-11-09 20:40:26 +00:00
|
|
|
color = parseInt(data * 0.009);
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-09-30 14:41:17 +00:00
|
|
|
$('.servo-' + i + ' .label', servos_wrapper).text(SERVO_DATA[i]);
|
2015-11-09 20:57:37 +00:00
|
|
|
$('.servo-' + i + ' .indicator', servos_wrapper).css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgba(89,170,41,1'+ color +')'});
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2016-01-09 22:48:41 +00:00
|
|
|
//keep the following here so at least we get a visual cue of our motor setup
|
|
|
|
update_arm_status();
|
|
|
|
if (!self.allowTestMode) return;
|
|
|
|
|
|
|
|
if (self.armed) {
|
|
|
|
$('#motorsEnableTestMode').prop('disabled', true);
|
|
|
|
$('#motorsEnableTestMode').prop('checked', false);
|
|
|
|
} else {
|
|
|
|
if (self.allowTestMode) {
|
|
|
|
$('#motorsEnableTestMode').prop('disabled', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previousArmState != self.armed) {
|
|
|
|
console.log('arm state change detected');
|
|
|
|
$('#motorsEnableTestMode').change();
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 22:00:54 +00:00
|
|
|
// enable Status and Motor data pulling
|
|
|
|
GUI.interval_add('motor_and_status_pull', get_status, 50, true);
|
2014-07-10 16:29:09 +00:00
|
|
|
|
2015-11-11 21:01:22 +00:00
|
|
|
GUI.content_ready(callback);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:29:09 +00:00
|
|
|
};
|
|
|
|
|
2014-10-30 11:43:35 +00:00
|
|
|
TABS.motors.cleanup = function (callback) {
|
2014-07-10 16:29:09 +00:00
|
|
|
if (callback) callback();
|
2016-01-10 02:25:03 +00:00
|
|
|
};
|