Skip to content

Commit 8d43a60

Browse files
authored
Merge pull request #454 from mikeller/change_motor_tab_graph_to_gyro
Replaced accelerometer graph on motors tab with gyroscope graph.
2 parents 0a790db + 4a309c7 commit 8d43a60

File tree

4 files changed

+55
-60
lines changed

4 files changed

+55
-60
lines changed

_locales/en/messages.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,12 @@
12491249
"servosEepromSave": {
12501250
"message": "EEPROM <span style=\"color: #ffbb00\">saved</span>"
12511251
},
1252-
1252+
"motorsGyroscope": {
1253+
"message": "Gyroscope - "
1254+
},
1255+
"motorsGyroscopeReset": {
1256+
"message": "[Reset]"
1257+
},
12531258
"gpsHead": {
12541259
"message": "GPS"
12551260
},

tabs/motors.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.tab-motors .modelAndAccel {
1+
.tab-motors .modelAndGyro {
22
float: left;
33
width: 100%;
44
margin-bottom: 0px;
@@ -9,7 +9,7 @@
99
margin: 10px;
1010
}
1111

12-
.tab-motors #accel {
12+
.tab-motors #gyro {
1313
float: left;
1414
width: calc(100% - 292px);
1515
}

tabs/motors.html

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<a id="button-documentation" href="https://github.com/betaflight/betaflight/releases" target="_blank"></a>
66
</div>
77
<div class="gui_box grey" style="margin-bottom: 15px;">
8-
<div class="wrapper modelAndAccel">
8+
<div class="wrapper modelAndGyro">
99
<div class="mixerPreview">
1010
<img src="./resources/motor_order/custom.svg" />
1111
</div>
12-
<svg id="accel">
12+
<svg id="gyro">
1313
<g class="grid x" transform="translate(40, 120)"></g>
1414
<g class="grid y" transform="translate(40, 10)"></g>
1515
<g class="data" transform="translate(41, 10)"></g>
@@ -18,12 +18,13 @@
1818
</svg>
1919
<div class="plot_control">
2020
<div class="title">
21-
Accelerometer - <a class="reset_accel_max" href="#" title="Reset overtime maximum">[Reset]</a>
21+
<span class="title" i18n="motorsGyroscope"/>
22+
<a class="reset_gyro_max" href="#" title="Reset overtime maximum" i18n="motorsGyroscopeReset"/>
2223
</div>
2324
<dl>
2425
<dt i18n="sensorsRefresh"></dt>
2526
<dd class="rate">
26-
<select name="accel_refresh_rate">
27+
<select name="gyro_refresh_rate">
2728
<option value="10">10 ms</option>
2829
<option value="20" selected="selected">20 ms</option>
2930
<option value="30">30 ms</option>
@@ -37,15 +38,15 @@
3738
</dd>
3839
<dt i18n="sensorsScale"></dt>
3940
<dd class="scale">
40-
<select name="accel_scale">
41-
<option value="0.05">0.05</option>
42-
<option value="0.1">0.1</option>
43-
<option value="0.2">0.2</option>
44-
<option value="0.3">0.3</option>
45-
<option value="0.4">0.4</option>
46-
<option value="0.5">0.5</option>
47-
<option value="1">1</option>
48-
<option value="2" selected="selected">2</option>
41+
<select name="gyro_scale">
42+
<option value="50">50</option>
43+
<option value="100">100</option>
44+
<option value="200">200</option>
45+
<option value="300">300</option>
46+
<option value="400">400</option>
47+
<option value="500">500</option>
48+
<option value="1000">1000</option>
49+
<option value="2000" selected="selected">2000</option>
4950
</select>
5051
</dd>
5152
<dt>X:</dt>

tabs/motors.js

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TABS.motors.initialize = function (callback) {
6161

6262
function initSensorData() {
6363
for (var i = 0; i < 3; i++) {
64-
SENSOR_DATA.accelerometer[i] = 0;
64+
SENSOR_DATA.gyroscope[i] = 0;
6565
}
6666
}
6767

@@ -207,12 +207,10 @@ TABS.motors.initialize = function (callback) {
207207
initSensorData();
208208

209209
// Setup variables
210-
var samples_accel_i = 0,
211-
accel_data = initDataArray(3),
212-
accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-2, 2]),
213-
accel_max_read = [0, 0, 0],
214-
accel_offset = [0, 0, 0],
215-
accel_offset_established = false;
210+
var samples_gyro_i = 0,
211+
gyro_data = initDataArray(3),
212+
gyroHelpers = initGraphHelpers('#gyro', samples_gyro_i, [-2, 2]),
213+
gyro_max_read = [0, 0, 0];
216214

217215
var raw_data_text_ements = {
218216
x: [],
@@ -235,10 +233,10 @@ TABS.motors.initialize = function (callback) {
235233
});
236234

237235
// set refresh speeds according to configuration saved in storage
238-
chrome.storage.local.get('motors_tab_accel_settings', function (result) {
239-
if (result.motors_tab_accel_settings) {
240-
$('.tab-motors select[name="accel_refresh_rate"]').val(result.motors_tab_accel_settings.rate);
241-
$('.tab-motors select[name="accel_scale"]').val(result.motors_tab_accel_settings.scale);
236+
chrome.storage.local.get('motors_tab_gyro_settings', function (result) {
237+
if (result.motors_tab_gyro_settings) {
238+
$('.tab-motors select[name="gyro_refresh_rate"]').val(result.motors_tab_gyro_settings.rate);
239+
$('.tab-motors select[name="gyro_scale"]').val(result.motors_tab_gyro_settings.scale);
242240

243241
// start polling data by triggering refresh rate change event
244242
$('.tab-motors .rate select:first').change();
@@ -249,63 +247,54 @@ TABS.motors.initialize = function (callback) {
249247
});
250248

251249
$('.tab-motors .rate select, .tab-motors .scale select').change(function () {
252-
var rate = parseInt($('.tab-motors select[name="accel_refresh_rate"]').val(), 10);
253-
var scale = parseFloat($('.tab-motors select[name="accel_scale"]').val());
250+
var rate = parseInt($('.tab-motors select[name="gyro_refresh_rate"]').val(), 10);
251+
var scale = parseFloat($('.tab-motors select[name="gyro_scale"]').val());
254252

255253
// store current/latest refresh rates in the storage
256-
chrome.storage.local.set({'motors_tab_accel_settings': {'rate': rate, 'scale': scale}});
254+
chrome.storage.local.set({'motors_tab_gyro_settings': {'rate': rate, 'scale': scale}});
257255

258-
accelHelpers = initGraphHelpers('#accel', samples_accel_i, [-scale, scale]);
256+
gyroHelpers = initGraphHelpers('#gyro', samples_gyro_i, [-scale, scale]);
259257

260258
// timer initialization
261259
GUI.interval_kill_all(['motor_and_status_pull']);
262260

263261
GUI.interval_add('IMU_pull', function imu_data_pull() {
264-
MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_accel_graph);
262+
MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_gyro_graph);
265263
}, rate, true);
266264

267-
function update_accel_graph() {
268-
if (!accel_offset_established) {
269-
for (var i = 0; i < 3; i++) {
270-
accel_offset[i] = SENSOR_DATA.accelerometer[i] * -1;
271-
}
272-
273-
accel_offset_established = true;
274-
}
275-
276-
var accel_with_offset = [
277-
accel_offset[0] + SENSOR_DATA.accelerometer[0],
278-
accel_offset[1] + SENSOR_DATA.accelerometer[1],
279-
accel_offset[2] + SENSOR_DATA.accelerometer[2]
265+
function update_gyro_graph() {
266+
var gyro = [
267+
SENSOR_DATA.gyroscope[0],
268+
SENSOR_DATA.gyroscope[1],
269+
SENSOR_DATA.gyroscope[2]
280270
];
281271

282-
updateGraphHelperSize(accelHelpers);
283-
samples_accel_i = addSampleToData(accel_data, samples_accel_i, accel_with_offset);
284-
drawGraph(accelHelpers, accel_data, samples_accel_i);
272+
updateGraphHelperSize(gyroHelpers);
273+
samples_gyro_i = addSampleToData(gyro_data, samples_gyro_i, gyro);
274+
drawGraph(gyroHelpers, gyro_data, samples_gyro_i);
285275

286-
// Compute RMS of acceleration in displayed period of time
276+
// Compute RMS of gyroscope readings in displayed period of time
287277
// This is particularly useful for motor balancing as it
288278
// eliminates the need for external tools
289279
var sum = 0.0;
290-
for (var j = 0; j < accel_data.length; j++)
291-
for (var k = 0; k < accel_data[j].length; k++)
292-
sum += accel_data[j][k][1]*accel_data[j][k][1];
293-
var rms = Math.sqrt(sum/(accel_data[0].length+accel_data[1].length+accel_data[2].length));
294-
295-
raw_data_text_ements.x[0].text(accel_with_offset[0].toFixed(2) + ' (' + accel_max_read[0].toFixed(2) + ')');
296-
raw_data_text_ements.y[0].text(accel_with_offset[1].toFixed(2) + ' (' + accel_max_read[1].toFixed(2) + ')');
297-
raw_data_text_ements.z[0].text(accel_with_offset[2].toFixed(2) + ' (' + accel_max_read[2].toFixed(2) + ')');
280+
for (var j = 0; j < gyro_data.length; j++)
281+
for (var k = 0; k < gyro_data[j].length; k++)
282+
sum += gyro_data[j][k][1]*gyro_data[j][k][1];
283+
var rms = Math.sqrt(sum/(gyro_data[0].length+gyro_data[1].length+gyro_data[2].length));
284+
285+
raw_data_text_ements.x[0].text(gyro[0].toFixed(2) + ' (' + gyro_max_read[0].toFixed(2) + ')');
286+
raw_data_text_ements.y[0].text(gyro[1].toFixed(2) + ' (' + gyro_max_read[1].toFixed(2) + ')');
287+
raw_data_text_ements.z[0].text(gyro[2].toFixed(2) + ' (' + gyro_max_read[2].toFixed(2) + ')');
298288
raw_data_text_ements.rms[0].text(rms.toFixed(4));
299289

300290
for (var i = 0; i < 3; i++) {
301-
if (Math.abs(accel_with_offset[i]) > Math.abs(accel_max_read[i])) accel_max_read[i] = accel_with_offset[i];
291+
if (Math.abs(gyro[i]) > Math.abs(gyro_max_read[i])) gyro_max_read[i] = gyro[i];
302292
}
303293
}
304294
});
305295

306296
$('a.reset_accel_max').click(function () {
307-
accel_max_read = [0, 0, 0];
308-
accel_offset_established = false;
297+
gyro_max_read = [0, 0, 0];
309298
});
310299

311300
var number_of_valid_outputs = (MOTOR_DATA.indexOf(0) > -1) ? MOTOR_DATA.indexOf(0) : 8;

0 commit comments

Comments
 (0)