Sonar altitude added to sensors

10.3.x-maintenance
Krzysztof Rosinski 2015-01-28 22:24:44 +01:00
parent 862e96f2aa
commit f933dbf330
3 changed files with 71 additions and 1 deletions

View File

@ -42,6 +42,7 @@ var MSP_codes = {
MSP_WP: 118, MSP_WP: 118,
MSP_BOXIDS: 119, MSP_BOXIDS: 119,
MSP_SERVO_CONF: 120, MSP_SERVO_CONF: 120,
MSP_SONAR: 123,
MSP_SET_RAW_RC: 200, MSP_SET_RAW_RC: 200,
MSP_SET_RAW_GPS: 201, MSP_SET_RAW_GPS: 201,
@ -260,6 +261,9 @@ var MSP = {
case MSP_codes.MSP_ALTITUDE: case MSP_codes.MSP_ALTITUDE:
SENSOR_DATA.altitude = parseFloat((data.getInt32(0, 1) / 100.0).toFixed(2)); // correct scale factor SENSOR_DATA.altitude = parseFloat((data.getInt32(0, 1) / 100.0).toFixed(2)); // correct scale factor
break; break;
case MSP_codes.MSP_SONAR:
SENSOR_DATA.sonar = data.getInt32(0, 1);
break;
case MSP_codes.MSP_ANALOG: case MSP_codes.MSP_ANALOG:
ANALOG.voltage = data.getUint8(0) / 10.0; ANALOG.voltage = data.getUint8(0) / 10.0;
ANALOG.mAhdrawn = data.getUint16(1, 1); ANALOG.mAhdrawn = data.getUint16(1, 1);

View File

@ -10,6 +10,7 @@
<label><input type="checkbox" name="accel_on" />Accelerometer</label> <label><input type="checkbox" name="accel_on" />Accelerometer</label>
<label><input type="checkbox" name="mag_on" />Magnetometer</label> <label><input type="checkbox" name="mag_on" />Magnetometer</label>
<label><input type="checkbox" name="baro_on" />Barometer</label> <label><input type="checkbox" name="baro_on" />Barometer</label>
<label><input type="checkbox" name="sonar_on" />Sonar</label>
<label><input type="checkbox" name="debug_on" />Debug</label> <label><input type="checkbox" name="debug_on" />Debug</label>
</div> </div>
</div> </div>
@ -163,6 +164,36 @@
</svg> </svg>
<div class="clear-both"></div> <div class="clear-both"></div>
</div> </div>
<div class="wrapper sonar">
<div class="plot_control">
<div class="title">Sonar - cm</div>
<dl>
<dt i18n="sensorsRefresh"></dt>
<dd class="rate">
<select name="sonar_refresh_rate">
<option value="10">10 ms</option>
<option value="20">20 ms</option>
<option value="30">30 ms</option>
<option value="40">40 ms</option>
<option value="50">50 ms</option>
<option value="100" selected="selected">100 ms</option>
<option value="250">250 ms</option>
<option value="500">500 ms</option>
<option value="1000">1000 ms</option>
</select>
</dd>
<dt>X:</dt><dd class="x">0</dd>
</dl>
</div>
<svg id="sonar">
<g class="grid x" transform="translate(40, 120)"></g>
<g class="grid y" transform="translate(40, 10)"></g>
<g class="data" transform="translate(41, 10)"></g>
<g class="axis x" transform="translate(40, 120)"></g>
<g class="axis y" transform="translate(40, 10)"></g>
</svg>
<div class="clear-both"></div>
</div>
<div class="wrapper debug"> <div class="wrapper debug">
<div class="plot_control"> <div class="plot_control">
<div class="title">Debug 1</div> <div class="title">Debug 1</div>

View File

@ -14,6 +14,7 @@ TABS.sensors.initialize = function (callback) {
SENSOR_DATA.accelerometer[i] = 0; SENSOR_DATA.accelerometer[i] = 0;
SENSOR_DATA.gyroscope[i] = 0; SENSOR_DATA.gyroscope[i] = 0;
SENSOR_DATA.magnetometer[i] = 0; SENSOR_DATA.magnetometer[i] = 0;
SENSOR_DATA.sonar[i] = 0;
SENSOR_DATA.debug[i] = 0; SENSOR_DATA.debug[i] = 0;
} }
} }
@ -162,6 +163,14 @@ TABS.sensors.initialize = function (callback) {
} }
} }
function plot_sonar(enable) {
if (enable) {
$('.wrapper.sonar').show();
} else {
$('.wrapper.sonar').hide();
}
}
function plot_debug(enable) { function plot_debug(enable) {
if (enable) { if (enable) {
$('.wrapper.debug').show(); $('.wrapper.debug').show();
@ -182,6 +191,9 @@ TABS.sensors.initialize = function (callback) {
if (!bit_check(CONFIG.activeSensors, 2)) { // mag if (!bit_check(CONFIG.activeSensors, 2)) { // mag
checkboxes.eq(2).prop('disabled', true); checkboxes.eq(2).prop('disabled', true);
} }
if (!bit_check(CONFIG.activeSensors, 4)) { // sonar
checkboxes.eq(4).prop('disabled', true);
}
$('.tab-sensors .info .checkboxes input').change(function () { $('.tab-sensors .info .checkboxes input').change(function () {
var enable = $(this).prop('checked'); var enable = $(this).prop('checked');
@ -201,6 +213,9 @@ TABS.sensors.initialize = function (callback) {
plot_baro(enable); plot_baro(enable);
break; break;
case 4: case 4:
plot_sonar(enable);
break;
case 5:
plot_debug(enable); plot_debug(enable);
break; break;
} }
@ -234,11 +249,13 @@ TABS.sensors.initialize = function (callback) {
samples_accel_i = 0, samples_accel_i = 0,
samples_mag_i = 0, samples_mag_i = 0,
samples_baro_i = 0, samples_baro_i = 0,
samples_sonar_i = 0,
samples_debug_i = 0, samples_debug_i = 0,
gyro_data = initDataArray(3), gyro_data = initDataArray(3),
accel_data = initDataArray(3), accel_data = initDataArray(3),
mag_data = initDataArray(3), mag_data = initDataArray(3),
baro_data = initDataArray(1), baro_data = initDataArray(1),
sonar_data = initDataArray(1),
debug_data = [ debug_data = [
initDataArray(1), initDataArray(1),
initDataArray(1), initDataArray(1),
@ -250,6 +267,7 @@ TABS.sensors.initialize = function (callback) {
var accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-2, 2]); var accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-2, 2]);
var magHelpers = initGraphHelpers('#mag', samples_mag_i, [-1, 1]); var magHelpers = initGraphHelpers('#mag', samples_mag_i, [-1, 1]);
var baroHelpers = initGraphHelpers('#baro', samples_baro_i); var baroHelpers = initGraphHelpers('#baro', samples_baro_i);
var sonarHelpers = initGraphHelpers('#sonar', samples_sonar_i);
var debugHelpers = [ var debugHelpers = [
initGraphHelpers('#debug1', samples_debug_i), initGraphHelpers('#debug1', samples_debug_i),
initGraphHelpers('#debug2', samples_debug_i), initGraphHelpers('#debug2', samples_debug_i),
@ -286,6 +304,8 @@ TABS.sensors.initialize = function (callback) {
$('.tab-sensors select[name="mag_scale"]').val(result.sensor_settings.scales.mag); $('.tab-sensors select[name="mag_scale"]').val(result.sensor_settings.scales.mag);
$('.tab-sensors select[name="baro_refresh_rate"]').val(result.sensor_settings.rates.baro); $('.tab-sensors select[name="baro_refresh_rate"]').val(result.sensor_settings.rates.baro);
$('.tab-sensors select[name="sonar_refresh_rate"]').val(result.sensor_settings.rates.sonar);
$('.tab-sensors select[name="debug_refresh_rate"]').val(result.sensor_settings.rates.debug); $('.tab-sensors select[name="debug_refresh_rate"]').val(result.sensor_settings.rates.debug);
// start polling data by triggering refresh rate change event // start polling data by triggering refresh rate change event
@ -304,6 +324,7 @@ TABS.sensors.initialize = function (callback) {
'accel': parseInt($('.tab-sensors select[name="accel_refresh_rate"]').val(), 10), 'accel': parseInt($('.tab-sensors select[name="accel_refresh_rate"]').val(), 10),
'mag': parseInt($('.tab-sensors select[name="mag_refresh_rate"]').val(), 10), 'mag': parseInt($('.tab-sensors select[name="mag_refresh_rate"]').val(), 10),
'baro': parseInt($('.tab-sensors select[name="baro_refresh_rate"]').val(), 10), 'baro': parseInt($('.tab-sensors select[name="baro_refresh_rate"]').val(), 10),
'sonar': parseInt($('.tab-sensors select[name="sonar_refresh_rate"]').val(), 10),
'debug': parseInt($('.tab-sensors select[name="debug_refresh_rate"]').val(), 10) 'debug': parseInt($('.tab-sensors select[name="debug_refresh_rate"]').val(), 10)
}; };
@ -350,6 +371,12 @@ TABS.sensors.initialize = function (callback) {
} }
if (checkboxes[4]) { if (checkboxes[4]) {
GUI.interval_add('sonar_pull', function sonar_data_pull() {
MSP.send_message(MSP_codes.MSP_SONAR, false, false, update_sonar_graphs);
}, rates.sonar, true);
}
if (checkboxes[5]) {
GUI.interval_add('debug_pull', function debug_data_pull() { GUI.interval_add('debug_pull', function debug_data_pull() {
MSP.send_message(MSP_codes.MSP_DEBUG, false, false, update_debug_graphs); MSP.send_message(MSP_codes.MSP_DEBUG, false, false, update_debug_graphs);
}, rates.debug, true); }, rates.debug, true);
@ -395,13 +422,21 @@ TABS.sensors.initialize = function (callback) {
raw_data_text_ements.x[3].text(SENSOR_DATA.altitude.toFixed(2)); raw_data_text_ements.x[3].text(SENSOR_DATA.altitude.toFixed(2));
} }
function update_sonar_graphs() {
updateGraphHelperSize(sonarHelpers);
samples_sonar_i = addSampleToData(sonar_data, samples_sonar_i, [SENSOR_DATA.sonar]);
drawGraph(sonarHelpers, sonar_data, samples_sonar_i);
raw_data_text_ements.x[4].text(SENSOR_DATA.sonar.toFixed(2));
}
function update_debug_graphs() { function update_debug_graphs() {
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
updateGraphHelperSize(debugHelpers[i]); updateGraphHelperSize(debugHelpers[i]);
addSampleToData(debug_data[i], samples_debug_i, [SENSOR_DATA.debug[i]]); addSampleToData(debug_data[i], samples_debug_i, [SENSOR_DATA.debug[i]]);
drawGraph(debugHelpers[i], debug_data[i], samples_debug_i); drawGraph(debugHelpers[i], debug_data[i], samples_debug_i);
raw_data_text_ements.x[4 + i].text(SENSOR_DATA.debug[i]); raw_data_text_ements.x[5 + i].text(SENSOR_DATA.debug[i]);
} }
samples_debug_i++; samples_debug_i++;
} }