diff --git a/js/fc.js b/js/fc.js index ac0f10bd..7179b4f8 100644 --- a/js/fc.js +++ b/js/fc.js @@ -177,6 +177,7 @@ var FC = { altitude: 0, barometer: 0, sonar: 0, + air_speed: 0, kinematics: [0.0, 0.0, 0.0], debug: [0, 0, 0, 0] }; diff --git a/js/msp/MSPCodes.js b/js/msp/MSPCodes.js index 3ae4719a..2ba5f237 100644 --- a/js/msp/MSPCodes.js +++ b/js/msp/MSPCodes.js @@ -164,4 +164,5 @@ var MSPCodes = { MSPV2_INAV_SET_BATTERY_CONFIG: 0x2006, MSPV2_INAV_RATE_PROFILE: 0x2007, MSPV2_INAV_SET_RATE_PROFILE: 0x2008, + MSPV2_INAV_AIR_SPEED: 0x2009, }; diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 1bab868a..647e7f15 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -230,6 +230,9 @@ var mspHelper = (function (gui) { case MSPCodes.MSP_SONAR: SENSOR_DATA.sonar = data.getInt32(0, true); break; + case MSPCodes.MSPV2_INAV_AIR_SPEED: + SENSOR_DATA.air_speed = data.getInt32(0, true); + break; case MSPCodes.MSP_ANALOG: ANALOG.voltage = data.getUint8(0) / 10.0; ANALOG.mAhdrawn = data.getUint16(1, true); diff --git a/tabs/sensors.html b/tabs/sensors.html index 420b78b1..44bf0177 100644 --- a/tabs/sensors.html +++ b/tabs/sensors.html @@ -18,7 +18,8 @@ + type="checkbox" name="sonar_on" />Sonar Open Debug Trace @@ -229,6 +230,39 @@
+
+
+
+
Air speed - cm/s
+
+
+
+ +
+
IAS:
+
0
+
+
+ + + + + + + +
+
+
@@ -306,4 +340,4 @@
-
\ No newline at end of file + diff --git a/tabs/sensors.js b/tabs/sensors.js index a5dc342c..e8f0522f 100644 --- a/tabs/sensors.js +++ b/tabs/sensors.js @@ -15,6 +15,7 @@ TABS.sensors.initialize = function (callback) { SENSOR_DATA.gyroscope[i] = 0; SENSOR_DATA.magnetometer[i] = 0; SENSOR_DATA.sonar = 0; + SENSOR_DATA.air_speed = 0; SENSOR_DATA.altitude = 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) { if (enable) { $('.wrapper.debug').show(); @@ -193,6 +202,10 @@ TABS.sensors.initialize = function (callback) { 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 () { var enable = $(this).prop('checked'); var index = $(this).parent().index(); @@ -214,6 +227,9 @@ TABS.sensors.initialize = function (callback) { plot_sonar(enable); break; case 5: + plot_airspeed(enable); + break; + case 6: plot_debug(enable); break; } @@ -248,12 +264,14 @@ TABS.sensors.initialize = function (callback) { samples_mag_i = 0, samples_altitude_i = 0, samples_sonar_i = 0, + samples_airspeed_i = 0, samples_debug_i = 0, gyro_data = initDataArray(3), accel_data = initDataArray(3), mag_data = initDataArray(3), altitude_data = (semver.gte(CONFIG.flightControllerVersion, "1.6.0")) ? initDataArray(2) : initDataArray(1), sonar_data = initDataArray(1), + airspeed_data = initDataArray(1), debug_data = [ initDataArray(1), initDataArray(1), @@ -266,6 +284,7 @@ TABS.sensors.initialize = function (callback) { var magHelpers = initGraphHelpers('#mag', samples_mag_i, [-1, 1]); var altitudeHelpers = initGraphHelpers('#altitude', samples_altitude_i); var sonarHelpers = initGraphHelpers('#sonar', samples_sonar_i); + var airspeedHelpers = initGraphHelpers('#airspeed', samples_airspeed_i); var debugHelpers = [ initGraphHelpers('#debug1', 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="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); // 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 // and timers are re-initialized with the new settings var rates = { - 'gyro': parseInt($('.tab-sensors select[name="gyro_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), - '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) + 'gyro': parseInt($('.tab-sensors select[name="gyro_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), + 'baro': parseInt($('.tab-sensors select[name="baro_refresh_rate"]').val(), 10), + 'sonar': parseInt($('.tab-sensors select[name="sonar_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 = { @@ -402,6 +424,21 @@ TABS.sensors.initialize = function (callback) { } 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() { /* @@ -470,13 +507,21 @@ TABS.sensors.initialize = function (callback) { 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() { for (var i = 0; i < 4; i++) { updateGraphHelperSize(debugHelpers[i]); addSampleToData(debug_data[i], samples_debug_i, [SENSOR_DATA.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++; }