Skip to content

Commit 3fdcc93

Browse files
authored
Merge pull request #1799 from RomanLut/submit-fix-mag-tool
fixed: magnetometer align tool does not take board orientation into a…
2 parents 1962218 + 4a6f22c commit 3fdcc93

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

_locales/en/messages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@
20382038
"message": "Magnetometer Alignment"
20392039
},
20402040
"magnetometerHelp": {
2041-
"message": "Adjust the magnetometer position until you get the same on the quad.<br/><strong>Note:</strong> If you have changed your flight controller alignment, make your adjustment relative to the FC position and not to the UAV position "
2041+
"message": "Adjust the magnetometer position until you get the same on the quad.<br/><strong>Note:</strong> Magnetometer alignment is relative to board. Make sure to align board first."
20422042
},
20432043
"magnetometerOrientationPreset": {
20442044
"message": "Orientation presets"

tabs/magnetometer.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
/*global chrome,GUI,TABS,nwdialog,$*/
2+
/*global chrome,GUI,BOARD_ALIGNMENT,TABS,nwdialog,$*/
33

44
TABS.magnetometer = {};
55

@@ -28,6 +28,7 @@ TABS.magnetometer.initialize = function (callback) {
2828

2929
var loadChain = [
3030
mspHelper.loadMixerConfig,
31+
mspHelper.loadBoardAlignment,
3132
mspHelper.loadSensorAlignment,
3233
// Pitch and roll must be inverted
3334
function (callback) {
@@ -219,6 +220,7 @@ TABS.magnetometer.initialize = function (callback) {
219220
elementToShow.change(function () {
220221
const value = parseInt($(this).val());
221222
self.showMagnetometer = (value == 0);
223+
self.render3D();
222224
});
223225

224226
function clamp(input, min, max) {
@@ -390,8 +392,17 @@ TABS.magnetometer.initialize3D = function () {
390392

391393
gps.visible = self.showMagnetometer;
392394
xyz.visible = !self.showMagnetometer;
393-
gps.rotation.set(-THREE.Math.degToRad(self.alignmentConfig.pitch), THREE.Math.degToRad(-180 - self.alignmentConfig.yaw), THREE.Math.degToRad(self.alignmentConfig.roll), 'YXZ');
394-
xyz.rotation.set(-THREE.Math.degToRad(self.alignmentConfig.pitch), THREE.Math.degToRad(-180 - self.alignmentConfig.yaw), THREE.Math.degToRad(self.alignmentConfig.roll), 'YXZ');
395+
396+
var magRotation = new THREE.Euler(-THREE.Math.degToRad(self.alignmentConfig.pitch), THREE.Math.degToRad(-180 - self.alignmentConfig.yaw), THREE.Math.degToRad(self.alignmentConfig.roll), 'YXZ');
397+
var matrix = (new THREE.Matrix4()).makeRotationFromEuler(magRotation);
398+
399+
var boardRotation = new THREE.Euler( THREE.Math.degToRad( -BOARD_ALIGNMENT.pitch / 10.0 ), THREE.Math.degToRad( -BOARD_ALIGNMENT.yaw / 10.0 ), THREE.Math.degToRad( -BOARD_ALIGNMENT.roll / 10.0 ), 'YXZ');
400+
var matrix1 = (new THREE.Matrix4()).makeRotationFromEuler(boardRotation);
401+
402+
matrix.multiply(matrix1);
403+
404+
gps.rotation.setFromRotationMatrix(matrix);
405+
xyz.rotation.setFromRotationMatrix(matrix);
395406

396407
// draw
397408
if (camera != null)

0 commit comments

Comments
 (0)