1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-23 16:25:19 +03:00

Merge pull request #365 from shellixyz/air_speed_sensor_graph

Add air speed graph in sensors tab
This commit is contained in:
Konstantin Sharlaimov 2018-03-07 17:09:36 +10:00 committed by GitHub
commit 578d5f3e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 9 deletions

View file

@ -177,6 +177,7 @@ var FC = {
altitude: 0, altitude: 0,
barometer: 0, barometer: 0,
sonar: 0, sonar: 0,
air_speed: 0,
kinematics: [0.0, 0.0, 0.0], kinematics: [0.0, 0.0, 0.0],
debug: [0, 0, 0, 0] debug: [0, 0, 0, 0]
}; };

View file

@ -164,4 +164,5 @@ var MSPCodes = {
MSPV2_INAV_SET_BATTERY_CONFIG: 0x2006, MSPV2_INAV_SET_BATTERY_CONFIG: 0x2006,
MSPV2_INAV_RATE_PROFILE: 0x2007, MSPV2_INAV_RATE_PROFILE: 0x2007,
MSPV2_INAV_SET_RATE_PROFILE: 0x2008, MSPV2_INAV_SET_RATE_PROFILE: 0x2008,
MSPV2_INAV_AIR_SPEED: 0x2009,
}; };

View file

@ -230,6 +230,9 @@ var mspHelper = (function (gui) {
case MSPCodes.MSP_SONAR: case MSPCodes.MSP_SONAR:
SENSOR_DATA.sonar = data.getInt32(0, true); SENSOR_DATA.sonar = data.getInt32(0, true);
break; break;
case MSPCodes.MSPV2_INAV_AIR_SPEED:
SENSOR_DATA.air_speed = data.getInt32(0, true);
break;
case MSPCodes.MSP_ANALOG: case MSPCodes.MSP_ANALOG:
ANALOG.voltage = data.getUint8(0) / 10.0; ANALOG.voltage = data.getUint8(0) / 10.0;
ANALOG.mAhdrawn = data.getUint16(1, true); ANALOG.mAhdrawn = data.getUint16(1, true);

View file

@ -18,7 +18,8 @@
<label><input type="checkbox" name="gyro_on" class="first" />Gyroscope</label> <label><input <label><input type="checkbox" name="gyro_on" class="first" />Gyroscope</label> <label><input
type="checkbox" name="accel_on" />Accelerometer</label> <label><input type="checkbox" type="checkbox" name="accel_on" />Accelerometer</label> <label><input type="checkbox"
name="mag_on" />Magnetometer</label> <label><input type="checkbox" name="baro_on" />Barometer</label> <label><input name="mag_on" />Magnetometer</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> type="checkbox" name="sonar_on" />Sonar</label> <label><input type="checkbox" name="airspeed_on" />Air speed</label> <label><input
type="checkbox" name="debug_on" />Debug</label>
<a class="debug-trace" href="javascript:void(0);">Open Debug Trace</a> <a class="debug-trace" href="javascript:void(0);">Open Debug Trace</a>
</div> </div>
@ -229,6 +230,39 @@
<div class="clear-both"></div> <div class="clear-both"></div>
</div> </div>
</div> </div>
<div class="wrapper airspeed">
<div class="gui_box grey">
<div class="plot_control">
<div class="title">Air speed - cm/s</div>
<dl>
<dt i18n="sensorsRefresh"></dt>
<dd class="rate">
<select name="airspeed_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" selected="selected">50 ms</option>
<option value="100">100 ms</option>
<option value="250">250 ms</option>
<option value="500">500 ms</option>
<option value="1000">1000 ms</option>
</select>
</dd>
<dt>IAS:</dt>
<dd class="x">0</dd>
</dl>
</div>
<svg id="airspeed">
<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>
<div class="wrapper debug"> <div class="wrapper debug">
<div class="gui_box grey"> <div class="gui_box grey">
<div class="plot_control"> <div class="plot_control">
@ -306,4 +340,4 @@
</svg> </svg>
</div> </div>
</div> </div>
</div> </div>

View file

@ -15,6 +15,7 @@ TABS.sensors.initialize = function (callback) {
SENSOR_DATA.gyroscope[i] = 0; SENSOR_DATA.gyroscope[i] = 0;
SENSOR_DATA.magnetometer[i] = 0; SENSOR_DATA.magnetometer[i] = 0;
SENSOR_DATA.sonar = 0; SENSOR_DATA.sonar = 0;
SENSOR_DATA.air_speed = 0;
SENSOR_DATA.altitude = 0; SENSOR_DATA.altitude = 0;
SENSOR_DATA.debug[i] = 0; SENSOR_DATA.debug[i] = 0;
} }
@ -172,6 +173,14 @@ TABS.sensors.initialize = function (callback) {
} }
} }
function plot_airspeed(enable) {
if (enable) {
$('.wrapper.airspeed').show();
} else {
$('.wrapper.airspeed').hide();
}
}
function plot_debug(enable) { function plot_debug(enable) {
if (enable) { if (enable) {
$('.wrapper.debug').show(); $('.wrapper.debug').show();
@ -193,6 +202,10 @@ TABS.sensors.initialize = function (callback) {
checkboxes.eq(4).prop('disabled', true); checkboxes.eq(4).prop('disabled', true);
} }
if (semver.lt(CONFIG.flightControllerVersion, "1.9.1") || (!bit_check(CONFIG.activeSensors, 6))) { // airspeed
checkboxes.eq(5).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');
var index = $(this).parent().index(); var index = $(this).parent().index();
@ -214,6 +227,9 @@ TABS.sensors.initialize = function (callback) {
plot_sonar(enable); plot_sonar(enable);
break; break;
case 5: case 5:
plot_airspeed(enable);
break;
case 6:
plot_debug(enable); plot_debug(enable);
break; break;
} }
@ -248,12 +264,14 @@ TABS.sensors.initialize = function (callback) {
samples_mag_i = 0, samples_mag_i = 0,
samples_altitude_i = 0, samples_altitude_i = 0,
samples_sonar_i = 0, samples_sonar_i = 0,
samples_airspeed_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),
altitude_data = (semver.gte(CONFIG.flightControllerVersion, "1.6.0")) ? initDataArray(2) : initDataArray(1), altitude_data = (semver.gte(CONFIG.flightControllerVersion, "1.6.0")) ? initDataArray(2) : initDataArray(1),
sonar_data = initDataArray(1), sonar_data = initDataArray(1),
airspeed_data = initDataArray(1),
debug_data = [ debug_data = [
initDataArray(1), initDataArray(1),
initDataArray(1), initDataArray(1),
@ -266,6 +284,7 @@ TABS.sensors.initialize = function (callback) {
var magHelpers = initGraphHelpers('#mag', samples_mag_i, [-1, 1]); var magHelpers = initGraphHelpers('#mag', samples_mag_i, [-1, 1]);
var altitudeHelpers = initGraphHelpers('#altitude', samples_altitude_i); var altitudeHelpers = initGraphHelpers('#altitude', samples_altitude_i);
var sonarHelpers = initGraphHelpers('#sonar', samples_sonar_i); var sonarHelpers = initGraphHelpers('#sonar', samples_sonar_i);
var airspeedHelpers = initGraphHelpers('#airspeed', samples_airspeed_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),
@ -304,6 +323,8 @@ TABS.sensors.initialize = function (callback) {
$('.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="sonar_refresh_rate"]').val(result.sensor_settings.rates.sonar);
$('.tab-sensors select[name="airspeed_refresh_rate"]').val(result.sensor_settings.rates.airspeed);
$('.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
@ -318,12 +339,13 @@ TABS.sensors.initialize = function (callback) {
// if any of the select fields change value, all of the select values are grabbed // if any of the select fields change value, all of the select values are grabbed
// and timers are re-initialized with the new settings // and timers are re-initialized with the new settings
var rates = { var rates = {
'gyro': parseInt($('.tab-sensors select[name="gyro_refresh_rate"]').val(), 10), 'gyro': parseInt($('.tab-sensors select[name="gyro_refresh_rate"]').val(), 10),
'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), 'sonar': parseInt($('.tab-sensors select[name="sonar_refresh_rate"]').val(), 10),
'debug': parseInt($('.tab-sensors select[name="debug_refresh_rate"]').val(), 10) 'airspeed': parseInt($('.tab-sensors select[name="airspeed_refresh_rate"]').val(), 10),
'debug': parseInt($('.tab-sensors select[name="debug_refresh_rate"]').val(), 10)
}; };
var scales = { var scales = {
@ -402,6 +424,21 @@ TABS.sensors.initialize = function (callback) {
} }
if (checkboxes[5]) { if (checkboxes[5]) {
helper.interval.add('airspeed_pull', function airspeed_data_pull() {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
update_airspeed_graphs();
return;
}
MSP.send_message(MSPCodes.MSPV2_INAV_AIR_SPEED, false, false, update_airspeed_graphs);
}, rates.airspeed, true);
}
if (checkboxes[6]) {
helper.interval.add('debug_pull', function debug_data_pull() { helper.interval.add('debug_pull', function debug_data_pull() {
/* /*
@ -470,13 +507,21 @@ TABS.sensors.initialize = function (callback) {
raw_data_text_ements.x[4].text(SENSOR_DATA.sonar.toFixed(2)); raw_data_text_ements.x[4].text(SENSOR_DATA.sonar.toFixed(2));
} }
function update_airspeed_graphs() {
updateGraphHelperSize(airspeedHelpers);
samples_airspeed_i = addSampleToData(airspeed_data, samples_airspeed_i, [SENSOR_DATA.air_speed]);
drawGraph(airspeedHelpers, airspeed_data, samples_airspeed_i);
raw_data_text_ements.x[5].text(SENSOR_DATA.air_speed);
}
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[5 + i].text(SENSOR_DATA.debug[i]); raw_data_text_ements.x[6 + i].text(SENSOR_DATA.debug[i]);
} }
samples_debug_i++; samples_debug_i++;
} }