Skip to content

Commit 06c2044

Browse files
authored
Merge pull request #1338 from fujin/improve-board-and-gyro-alignment
MSP Multiple GYRO/ACC alignment support
2 parents 4b03176 + f002232 commit 06c2044

File tree

6 files changed

+155
-31
lines changed

6 files changed

+155
-31
lines changed

locales/en/messages.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,24 @@
10391039
"configurationSensorAlignmentGyro": {
10401040
"message": "GYRO Alignment"
10411041
},
1042+
"configurationSensorGyroToUse": {
1043+
"message": "GYRO/ACCEL"
1044+
},
1045+
"configurationSensorGyroToUseDefaultOption": {
1046+
"message": "First"
1047+
},
1048+
"configurationSensorGyroToUseSecond": {
1049+
"message": "Second"
1050+
},
1051+
"configurationSensorGyroToUseBoth": {
1052+
"message": "Both"
1053+
},
1054+
"configurationSensorAlignmentGyro1": {
1055+
"message": "First GYRO"
1056+
},
1057+
"configurationSensorAlignmentGyro2": {
1058+
"message": "Second GYRO"
1059+
},
10421060
"configurationSensorAlignmentAcc": {
10431061
"message": "ACCEL Alignment"
10441062
},

src/css/tabs/configuration.css

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@
210210
border-bottom: 1px solid #ddd;
211211
width: 100%;
212212
float: left;
213+
}
214+
215+
.tab-configuration .board_align_inputs,
216+
.tab-configuration .gyro_alignment_inputs {
217+
margin-bottom: 5px;
218+
padding-bottom: 5px;
219+
border-bottom: 1px solid #ddd;
220+
width: 33.3%;
221+
float: left;
222+
white-space: nowrap;
223+
}
224+
225+
.tab-configuration .board_align_inputs input {
226+
width: 3.5em;
227+
}
228+
229+
.tab-configuration .board_align_inputs label,
230+
.tab-configuration .gyro_alignment_inputs label {
231+
display: block;
232+
overflow: hidden;
233+
text-overflow: ellipsis;
213234
}
214235

215236
.tab-configuration .selectProtocol
@@ -365,39 +386,37 @@
365386
}
366387

367388
.tab-configuration .alignicon {
368-
width: 20px;
369-
height: 20px;
389+
width: 15px;
390+
height: 15px;
370391
float: left;
371-
margin-left: -5px;
392+
margin-left: -1px;
372393
margin-right: 3px;
373394
}
374395

375396
.tab-configuration .pitch {
376397
background-image: url(../../images/icons/cf_icon_pitch.svg);
377398
background-repeat: no-repeat;
378-
background-size: 20px;
379399
background-position: center;
380400
}
381401

382402
.tab-configuration .yaw {
383403
background-image: url(../../images/icons/cf_icon_yaw.svg);
384404
background-repeat: no-repeat;
385-
background-size: 20px;
386405
background-position: center;
387406
}
388407

389408
.tab-configuration .roll {
390409
background-image: url(../../images/icons/cf_icon_roll.svg);
391410
background-repeat: no-repeat;
392-
background-size: 20px;
393411
background-position: center;
394412
}
395413

396414
.tab-configuration .board select {
397-
/*float: left;*/
398-
width: 45%;
415+
float: left;
416+
width: fit-content;
417+
max-width: 50%;
399418
height: 20px;
400-
margin: 0 0px 2px 0;
419+
margin-right: 5px;
401420
border: 1px solid silver;
402421
border-radius:3px;
403422
}
@@ -473,19 +492,16 @@
473492
margin-top: 3px;
474493
}
475494

476-
.tab-configuration .sensoralignment {
477-
width: 50%;
478-
float: left;
495+
.tab-configuration .gyro_align_content {
496+
width: 100%;
479497
}
480498

481499
.tab-configuration .board_align_content {
482-
width: 50%;
483-
float: left;
500+
width: 100%;
484501
}
485502

486503
.tab-configuration .sensoralignment span {
487-
width: 55%;
488-
float: left;
504+
width: 100%;
489505
}
490506

491507
.tab-configuration .escprotocol {

src/js/fc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ var FC = {
336336
align_gyro: 0,
337337
align_acc: 0,
338338
align_mag: 0,
339+
use_multi_gyro: 0,
340+
gyro_to_use: 0,
341+
gyro_1_align: 0,
342+
gyro_2_align: 0,
339343
};
340344

341345
PID_ADVANCED_CONFIG = {

src/js/msp/MSPHelper.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,13 @@ MspHelper.prototype.process_data = function(dataHandler) {
536536
SENSOR_ALIGNMENT.align_gyro = data.readU8();
537537
SENSOR_ALIGNMENT.align_acc = data.readU8();
538538
SENSOR_ALIGNMENT.align_mag = data.readU8();
539+
540+
if (semver.gte(CONFIG.apiVersion, '1.41.0')) {
541+
SENSOR_ALIGNMENT.use_multi_gyro = data.readU8();
542+
SENSOR_ALIGNMENT.gyro_to_use = data.readU8();
543+
SENSOR_ALIGNMENT.gyro_1_align = data.readU8();
544+
SENSOR_ALIGNMENT.gyro_2_align = data.readU8();
545+
}
539546
break;
540547
case MSPCodes.MSP_DISPLAYPORT:
541548
break;
@@ -1658,6 +1665,11 @@ MspHelper.prototype.crunch = function(code) {
16581665
buffer.push8(SENSOR_ALIGNMENT.align_gyro)
16591666
.push8(SENSOR_ALIGNMENT.align_acc)
16601667
.push8(SENSOR_ALIGNMENT.align_mag);
1668+
if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
1669+
buffer.push8(SENSOR_ALIGNMENT.gyro_to_use)
1670+
.push8(SENSOR_ALIGNMENT.gyro_1_align)
1671+
.push8(SENSOR_ALIGNMENT.gyro_2_align);
1672+
}
16611673
break;
16621674
case MSPCodes.MSP_SET_ADVANCED_CONFIG:
16631675
buffer.push8(PID_ADVANCED_CONFIG.gyro_sync_denom)

src/js/tabs/configuration.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,26 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
311311
// translate to user-selected language
312312
i18n.localizePage();
313313

314+
var gyro_align_content_e = $('.tab-configuration .gyro_align_content');
315+
var legacy_gyro_alignment_e = $('.tab-configuration .legacy_gyro_alignment');
316+
var legacy_accel_alignment_e = $('.tab-configuration .legacy_accel_alignment');
317+
318+
// Hide the new multi gyro element by default
319+
gyro_align_content_e.hide();
320+
321+
// If we are sent USE_MULTI_GYRO flag from the target, show the new element, while hiding the old ones.
322+
if (SENSOR_ALIGNMENT.use_multi_gyro == 1) {
323+
gyro_align_content_e.show();
324+
legacy_gyro_alignment_e.hide();
325+
legacy_accel_alignment_e.hide();
326+
}
327+
328+
// As the gyro_to_use does not have a 'DEFAULT' 0th element enum like alingments, the 0th element 'First' is excluded from here.
329+
var gyros = [
330+
i18n.getMessage('configurationSensorGyroToUseSecond'),
331+
i18n.getMessage('configurationSensorGyroToUseBoth')
332+
];
333+
314334
var alignments = [
315335
'CW 0°',
316336
'CW 90°',
@@ -326,17 +346,32 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
326346
var orientation_acc_e = $('select.accalign');
327347
var orientation_mag_e = $('select.magalign');
328348

349+
var orientation_gyro_to_use_e = $('select.gyro_to_use');
350+
var orientation_gyro_1_align_e = $('select.gyro_1_align');
351+
var orientation_gyro_2_align_e = $('select.gyro_2_align');
352+
329353
if (semver.lt(CONFIG.apiVersion, "1.15.0")) {
330354
$('.tab-configuration .sensoralignment').hide();
331355
} else {
356+
for (var i = 0; i< gyros.length; i++) {
357+
orientation_gyro_to_use_e.append('<option value="' + (i+1) + '">'+ gyros[i] + '</option>');
358+
}
332359
for (var i = 0; i < alignments.length; i++) {
333360
orientation_gyro_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
334361
orientation_acc_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
335362
orientation_mag_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
363+
364+
orientation_gyro_1_align_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
365+
orientation_gyro_2_align_e.append('<option value="' + (i+1) + '">'+ alignments[i] + '</option>');
336366
}
337367
orientation_gyro_e.val(SENSOR_ALIGNMENT.align_gyro);
338368
orientation_acc_e.val(SENSOR_ALIGNMENT.align_acc);
339369
orientation_mag_e.val(SENSOR_ALIGNMENT.align_mag);
370+
371+
orientation_gyro_to_use_e.val(SENSOR_ALIGNMENT.gyro_to_use);
372+
373+
orientation_gyro_1_align_e.val(SENSOR_ALIGNMENT.gyro_1_align);
374+
orientation_gyro_2_align_e.val(SENSOR_ALIGNMENT.gyro_2_align);
340375
}
341376

342377
// ESC protocols
@@ -1023,6 +1058,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
10231058
SENSOR_ALIGNMENT.align_gyro = parseInt(orientation_gyro_e.val());
10241059
SENSOR_ALIGNMENT.align_acc = parseInt(orientation_acc_e.val());
10251060
SENSOR_ALIGNMENT.align_mag = parseInt(orientation_mag_e.val());
1061+
if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
1062+
SENSOR_ALIGNMENT.gyro_to_use = parseInt(orientation_gyro_to_use_e.val());
1063+
SENSOR_ALIGNMENT.gyro_1_align = parseInt(orientation_gyro_1_align_e.val());
1064+
SENSOR_ALIGNMENT.gyro_2_align = parseInt(orientation_gyro_2_align_e.val());
1065+
}
10261066

10271067
PID_ADVANCED_CONFIG.fast_pwm_protocol = parseInt(esc_protocol_e.val()-1);
10281068
PID_ADVANCED_CONFIG.use_unsyncedPwm = $('input[id="unsyncedPWMSwitch"]').is(':checked') ? 1 : 0;

src/tabs/configuration.html

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,61 @@
247247
</div>
248248
<div class="spacer_box">
249249
<div class="board_align_content">
250-
<div class="number">
251-
<label> <input type="number" name="board_align_roll" step="1" min="-180" max="360" /> <span
252-
i18n="configurationBoardAlignmentRoll"></span>
253-
</label>
250+
<div class="board_align_inputs">
254251
<div class="alignicon roll"></div>
252+
<label>
253+
<input type="number" name="board_align_roll" step="1" min="-180" max="360" />
254+
<span i18n="configurationBoardAlignmentRoll"></span>
255+
</label>
256+
</div>
257+
258+
<div class="board_align_inputs">
259+
<div class="alignicon pitch"></div>
260+
<label>
261+
<input type="number" name="board_align_pitch" step="1" min="-180" max="360" />
262+
<span i18n="configurationBoardAlignmentPitch"></span>
263+
</label>
264+
</div>
265+
266+
<div class="board_align_inputs">
267+
<div class="alignicon yaw"></div>
268+
<label>
269+
<input type="number" name="board_align_yaw" step="1" min="-180" max="360" />
270+
<span i18n="configurationBoardAlignmentYaw"></span>
271+
</label>
272+
</div>
273+
</div>
274+
<div class="gyro_align_content">
275+
<div class="gyro_alignment_inputs">
276+
<label>
277+
<select class="gyro_to_use">
278+
<option i18n="configurationSensorGyroToUseDefaultOption" value="0"></option>
279+
<!-- list generated here -->
280+
</select>
281+
<span i18n="configurationSensorGyroToUse"></span>
282+
</label>
255283
</div>
256-
<div class="number">
257-
<label> <input type="number" name="board_align_pitch" step="1" min="-180" max="360" />
258-
<span i18n="configurationBoardAlignmentPitch"></span>
284+
<div class="gyro_alignment_inputs">
285+
<label>
286+
<select class="gyro_1_align">
287+
<option i18n="configurationSensorAlignmentDefaultOption" value="0"></option>
288+
<!-- list generated here -->
289+
</select>
290+
<span i18n="configurationSensorAlignmentGyro1"></span>
259291
</label>
260-
<div class="alignicon pitch"></div>
261292
</div>
262-
<div class="number">
263-
<label> <input type="number" name="board_align_yaw" step="1" min="-180" max="360" /> <span
264-
i18n="configurationBoardAlignmentYaw"></span>
293+
<div class="gyro_alignment_inputs">
294+
<label>
295+
<select class="gyro_2_align">
296+
<option i18n="configurationSensorAlignmentDefaultOption" value="0"></option>
297+
<!-- list generated here -->
298+
</select>
299+
<span i18n="configurationSensorAlignmentGyro2"></span>
265300
</label>
266-
<div class="alignicon yaw"></div>
267301
</div>
268302
</div>
269-
<div class="sensoralignment">
270-
<div class="select">
303+
<div class="sensor_align_content">
304+
<div class="legacy_gyro_alignment select">
271305
<label>
272306
<span i18n="configurationSensorAlignmentGyro"></span>
273307
<select class="gyroalign">
@@ -276,7 +310,7 @@
276310
</select>
277311
</label>
278312
</div>
279-
<div class="select">
313+
<div class="legacy_accel_alignment select">
280314
<label>
281315
<span i18n="configurationSensorAlignmentAcc"></span>
282316
<select class="accalign">

0 commit comments

Comments
 (0)