From a8c76cf27887d48119587f9decd5716d2fc73cda Mon Sep 17 00:00:00 2001 From: cTn Date: Thu, 11 Apr 2013 16:19:24 +0200 Subject: [PATCH] RAW sensor data plot tab --- css/style.css | 19 ++++- js/main.js | 2 + js/serial_backend.js | 12 +-- tabs/receiver.js | 2 + tabs/sensors.html | 5 +- tabs/sensors.js | 181 ++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 211 insertions(+), 10 deletions(-) diff --git a/css/style.css b/css/style.css index 73ab23fe40..534b796ac8 100644 --- a/css/style.css +++ b/css/style.css @@ -627,13 +627,28 @@ a:hover { border: 1px dotted silver; } +.tab-sensors { +} + .tab-sensors #gyro { + height: 120px; + } + .tab-sensors #accel { + height: 120px; + } + .tab-sensors #mag { + height: 120px; + } + .tab-sensors #baro { + height: 120px; + } /* Flotr related styles */ -.flotr-legend { +.flotr-legend { padding: 2px; - left: 31px; + margin-left: 31px; top: 20px; border: 0; background-color: white; + opacity: 0.5; } \ No newline at end of file diff --git a/js/main.js b/js/main.js index 1754b56994..d854c18c5b 100644 --- a/js/main.js +++ b/js/main.js @@ -45,4 +45,6 @@ function disable_timers() { // kill all the refferences timers = []; + + return true; } \ No newline at end of file diff --git a/js/serial_backend.js b/js/serial_backend.js index e99f2d1b53..3d5fbab5ee 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -405,15 +405,15 @@ function process_message(code, data) { sensor_status(CONFIG.activeSensors); break; case MSP_codes.MSP_RAW_IMU: - SENSOR_DATA.accelerometer[0] = view.getInt16(0, 1); - SENSOR_DATA.accelerometer[1] = view.getInt16(2, 1); - SENSOR_DATA.accelerometer[2] = view.getInt16(4, 1); + SENSOR_DATA.accelerometer[0] = view.getInt16(0, 1) / 1000; // properly scaled + SENSOR_DATA.accelerometer[1] = view.getInt16(2, 1) / 1000; + SENSOR_DATA.accelerometer[2] = view.getInt16(4, 1) / 1000; - SENSOR_DATA.gyroscope[0] = view.getInt16(6, 1) / 8; + SENSOR_DATA.gyroscope[0] = view.getInt16(6, 1) / 8; // no clue about scaling factor SENSOR_DATA.gyroscope[1] = view.getInt16(8, 1) / 8; SENSOR_DATA.gyroscope[2] = view.getInt16(10, 1) / 8; - SENSOR_DATA.magnetometer[0] = view.getInt16(12, 1) / 3; + SENSOR_DATA.magnetometer[0] = view.getInt16(12, 1) / 3; // no clue about scaling factor SENSOR_DATA.magnetometer[1] = view.getInt16(14, 1) / 3; SENSOR_DATA.magnetometer[2] = view.getInt16(16, 1) / 3; break; @@ -463,7 +463,7 @@ function process_message(code, data) { SENSOR_DATA.kinematicsZ = view.getInt16(4, 1); break; case MSP_codes.MSP_ALTITUDE: - SENSOR_DATA.altitude = view.getUint32(0, 1); + SENSOR_DATA.altitude = view.getUint32(0, 1) / 100.0; // correct scale factor break; case MSP_codes.MSP_BAT: console.log(data); diff --git a/tabs/receiver.js b/tabs/receiver.js index da07aa3d58..83d857ab93 100644 --- a/tabs/receiver.js +++ b/tabs/receiver.js @@ -29,6 +29,7 @@ function tab_initialize_receiver() { e_RX_plot = document.getElementById("RX_plot"); RX_plot_options = { + title: "Channel width (us)", shadowSize: 0, yaxis : { max: 2200, @@ -41,6 +42,7 @@ function tab_initialize_receiver() { backgroundColor: "#FFFFFF" }, legend : { + position: "we", backgroundOpacity: 0 } }; diff --git a/tabs/sensors.html b/tabs/sensors.html index 90e3cbf15c..5e6953ba91 100644 --- a/tabs/sensors.html +++ b/tabs/sensors.html @@ -1,3 +1,6 @@
- Hello Sensors. +
+
+
+
\ No newline at end of file diff --git a/tabs/sensors.js b/tabs/sensors.js index 55aa35f786..3ed83294ff 100644 --- a/tabs/sensors.js +++ b/tabs/sensors.js @@ -1,8 +1,187 @@ function tab_initialize_sensors() { + // Setup variables + samples_i = 300; + + gyro_data = new Array(3); + accel_data = new Array(3); + mag_data = new Array(3); + baro_data = new Array(1); + + gyro_data[0] = new Array(); + gyro_data[1] = new Array(); + gyro_data[2] = new Array(); + + accel_data[0] = new Array(); + accel_data[1] = new Array(); + accel_data[2] = new Array(); + + mag_data[0] = new Array(); + mag_data[1] = new Array(); + mag_data[2] = new Array(); + + baro_data[0] = new Array(); + + for (var i = 0; i <= 300; i++) { + gyro_data[0].push([i, 0]); + gyro_data[1].push([i, 0]); + gyro_data[2].push([i, 0]); + + accel_data[0].push([i, 0]); + accel_data[1].push([i, 0]); + accel_data[2].push([i, 0]); + + mag_data[0].push([i, 0]); + mag_data[1].push([i, 0]); + mag_data[2].push([i, 0]); + + baro_data[0].push([i, 0]); + } + + // plot specific stuff + e_graph_gyro = document.getElementById("gyro"); + e_graph_accel = document.getElementById("accel"); + e_graph_mag = document.getElementById("mag"); + e_graph_baro = document.getElementById("baro"); + + gyro_options = { + title: "Gyroscope (deg/s)", + shadowSize: 0, + yaxis : { + tickDecimals: 0, + max: 150, + min: -150 + }, + xaxis : { + //noTicks = 0 + }, + grid : { + backgroundColor: "#FFFFFF" + }, + legend : { + position: "we", + backgroundOpacity: 0 + } + } + + accel_options = { + title: "Accelerometer (g)", + shadowSize: 0, + yaxis : { + tickDecimals: 1, + max : 1.5, + min : -1.5 + }, + xaxis : { + //noTicks = 0 + }, + grid : { + backgroundColor : "#FFFFFF" + }, + legend : { + position: "we", + backgroundOpacity: 0 + } + } + + mag_options = { + title: "Magnetometer (Ga)", + shadowSize: 0, + yaxis : { + tickDecimals: 0, + max : 120, + min : -120 + }, + xaxis : { + //noTicks = 0 + }, + grid : { + backgroundColor : "#FFFFFF" + }, + legend : { + position: "we", + backgroundOpacity: 0 + } + } + + baro_options = { + title: "Barometer (m)", + shadowSize: 0, + yaxis : { + tickDecimals: 1, + /* + max : 1.5, + min : -1.5 + */ + }, + xaxis : { + //noTicks = 0 + }, + grid : { + backgroundColor : "#FFFFFF" + }, + legend : { + position: "we", + backgroundOpacity: 0 + } + } + + // start polling data + timers.push(setInterval(sensor_array_pull, 50)); } function sensor_array_pull() { - // Update UI + // push data to the main array + gyro_data[0].push([samples_i, SENSOR_DATA.gyroscope[0]]); + gyro_data[1].push([samples_i, SENSOR_DATA.gyroscope[1]]); + gyro_data[2].push([samples_i, SENSOR_DATA.gyroscope[2]]); + + accel_data[0].push([samples_i, SENSOR_DATA.accelerometer[0]]); + accel_data[1].push([samples_i, SENSOR_DATA.accelerometer[1]]); + accel_data[2].push([samples_i, SENSOR_DATA.accelerometer[2]]); + + mag_data[0].push([samples_i, SENSOR_DATA.magnetometer[0]]); + mag_data[1].push([samples_i, SENSOR_DATA.magnetometer[1]]); + mag_data[2].push([samples_i, SENSOR_DATA.magnetometer[2]]); + + baro_data[0].push([samples_i, SENSOR_DATA.altitude]); + + // Remove old data from array + while (gyro_data[0].length > 300) { + gyro_data[0].shift(); + gyro_data[1].shift(); + gyro_data[2].shift(); + + accel_data[0].shift(); + accel_data[1].shift(); + accel_data[2].shift(); + + mag_data[0].shift(); + mag_data[1].shift(); + mag_data[2].shift(); + + baro_data[0].shift(); + } + + // Update graphs + Flotr.draw(e_graph_gyro, [ + {data: gyro_data[0], label: "X - rate [" + SENSOR_DATA.gyroscope[0].toFixed(2) + "]"}, + {data: gyro_data[1], label: "Y - rate [" + SENSOR_DATA.gyroscope[1].toFixed(2) + "]"}, + {data: gyro_data[2], label: "Z - rate [" + SENSOR_DATA.gyroscope[2].toFixed(2) + "]"} ], gyro_options); + + Flotr.draw(e_graph_accel, [ + {data: accel_data[1], label: "X - acceleration [" + SENSOR_DATA.accelerometer[0].toFixed(2) + "]"}, + {data: accel_data[0], label: "Y - acceleration [" + SENSOR_DATA.accelerometer[1].toFixed(2) + "]"}, + {data: accel_data[2], label: "Z - acceleration [" + SENSOR_DATA.accelerometer[2].toFixed(2) + "]"} ], accel_options); + + Flotr.draw(e_graph_mag, [ + {data: mag_data[1], label: "X - Ga [" + SENSOR_DATA.magnetometer[0].toFixed(2) + "]"}, + {data: mag_data[0], label: "Y - Ga [" + SENSOR_DATA.magnetometer[1].toFixed(2) + "]"}, + {data: mag_data[2], label: "Z - Ga [" + SENSOR_DATA.magnetometer[2].toFixed(2) + "]"} ], mag_options); + + Flotr.draw(e_graph_baro, [ + {data: baro_data[0], label: "X - meters [" + SENSOR_DATA.altitude.toFixed(2) + "]"} ], baro_options); + + samples_i++; // Request new data send_message(MSP_codes.MSP_RAW_IMU, MSP_codes.MSP_RAW_IMU);