Skip to content

Commit

Permalink
Move declination to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Jan 6, 2025
1 parent bf82329 commit 96dfc06
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 45 deletions.
17 changes: 10 additions & 7 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,15 @@
"configurationMagAlignmentHelp": {
"message": "The magnetometer alignment is the orientation of the magnetometer sensor on the flight controller board. The default is usually correct, but if you have a custom build or a flight controller with a different magnetometer orientation, you may need to adjust this setting."
},
"configurationMagDeclination": {
"message": "Magnetometer Declination"
},
"configurationMagDeclinationInput": {
"message": "Declination Degrees"
},
"configurationMagDeclinationHelp": {
"message": "The magnetic declination is the angle between magnetic north and true north. It is different for every location on earth. You can find the declination for your location on the internet"
},
"configurationBoardAlignment": {
"message": "Board Alignment"
},
Expand Down Expand Up @@ -1424,7 +1433,7 @@
"message": "$t(configurationBoardAlignmentYaw.message)"
},
"configurationMagAlignment": {
"message": "Mag Alignment"
"message": "Magnetometer Alignment"
},
"configurationBoardAlignmentHelp": {
"message": "Arbitrary board rotation in degrees, to allow mounting it sideways / upside down / rotated etc. When running external sensors, use the sensor alignments (Gyro, Acc, Mag) to define sensor position independent from board orientation. "
Expand Down Expand Up @@ -1468,9 +1477,6 @@
"configurationSensorAlignmentAcc": {
"message": "ACCEL Alignment"
},
"configurationSensorAlignmentMag": {
"message": "Alignment"
},
"configurationSensorAlignmentDefaultOption": {
"message": "Default"
},
Expand All @@ -1489,9 +1495,6 @@
"configurationArmingHelp": {
"message": "Some Arming options may require accelerometer be enabled"
},
"configurationMagDeclination": {
"message": "Magnetometer Declination [deg]"
},
"configurationReverseMotorSwitch": {
"message": "Motor direction is reversed"
},
Expand Down
14 changes: 6 additions & 8 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,13 @@ MspHelper.prototype.process_data = function (dataHandler) {
FC.SENSOR_ALIGNMENT.gyro_1_align = data.readU8();
FC.SENSOR_ALIGNMENT.gyro_2_align = data.readU8();
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
FC.SENSOR_ALIGNMENT.gyro_align_roll = data.readU16() / 10;
FC.SENSOR_ALIGNMENT.gyro_align_pitch = data.readU16() / 10;
FC.SENSOR_ALIGNMENT.gyro_align_yaw = data.readU16() / 10;
FC.SENSOR_ALIGNMENT.gyro_align_roll = data.read16() / 10;
FC.SENSOR_ALIGNMENT.gyro_align_pitch = data.read16() / 10;
FC.SENSOR_ALIGNMENT.gyro_align_yaw = data.read16() / 10;

FC.SENSOR_ALIGNMENT.mag_align_roll = data.readU16() / 10;
FC.SENSOR_ALIGNMENT.mag_align_pitch = data.readU16() / 10;
FC.SENSOR_ALIGNMENT.mag_align_yaw = data.readU16() / 10;
FC.SENSOR_ALIGNMENT.mag_align_roll = data.read16() / 10;
FC.SENSOR_ALIGNMENT.mag_align_pitch = data.read16() / 10;
FC.SENSOR_ALIGNMENT.mag_align_yaw = data.read16() / 10;
}
break;
case MSPCodes.MSP_DISPLAYPORT:
Expand Down Expand Up @@ -2057,8 +2057,6 @@ MspHelper.prototype.crunch = function (code, modifierCode = undefined) {
.push8(FC.SENSOR_ALIGNMENT.gyro_1_align)
.push8(FC.SENSOR_ALIGNMENT.gyro_2_align);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
// // Use gyro_2_align[RPY] when GYRO_CONFIG_USE_GYRO_2 = 1
// if (FC.SENSOR_ALIGNMENT.gyro_to_use === 1) {
buffer.push16(FC.SENSOR_ALIGNMENT.gyro_align_roll * 10);
buffer.push16(FC.SENSOR_ALIGNMENT.gyro_align_pitch * 10);
buffer.push16(FC.SENSOR_ALIGNMENT.gyro_align_yaw * 10);
Expand Down
29 changes: 29 additions & 0 deletions src/js/tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MSPCodes from "../msp/MSPCodes";
import { API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from "../data_storage";
import { updateTabList } from "../utils/updateTabList";
import $ from "jquery";
import { have_sensor } from "../sensor_helpers";

const configuration = {
analyticsChanges: {},
Expand Down Expand Up @@ -53,6 +54,11 @@ configuration.initialize = function (callback) {
: Promise.resolve(true),
)
.then(() => MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG))
.then(() =>
semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)
? MSP.promise(MSPCodes.MSP_COMPASS_CONFIG)
: Promise.resolve(true),
)
.then(() => load_html());
}

Expand Down Expand Up @@ -128,6 +134,15 @@ configuration.initialize = function (callback) {
const orientation_gyro_1_align_e = $("select.gyro_1_align");
const orientation_gyro_2_align_e = $("select.gyro_2_align");

const hasMag =
have_sensor(FC.CONFIG.activeSensors, "mag") && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46);

if (hasMag) {
$('input[name="mag_declination"]').val(FC.COMPASS_CONFIG.mag_declination.toFixed(1));
} else {
$("div.mag_declination").parent().parent().hide();
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
$(".tab-configuration .gyro_align_custom").show();
$(".tab-configuration .mag_align_custom").show();
Expand Down Expand Up @@ -433,6 +448,12 @@ configuration.initialize = function (callback) {
FC.ARMING_CONFIG.auto_disarm_delay = parseInt($('input[id="configurationAutoDisarmDelay"]').val());
}
}

// declination added first in #3676
if (hasMag) {
FC.COMPASS_CONFIG.mag_declination = $('input[name="mag_declination"]').val();
}

FC.ARMING_CONFIG.small_angle = parseInt($('input[id="configurationSmallAngle"]').val());

FC.SENSOR_ALIGNMENT.gyro_to_use = parseInt(orientation_gyro_to_use_e.val());
Expand Down Expand Up @@ -524,6 +545,14 @@ configuration.initialize = function (callback) {
: Promise.resolve(true),
)
.then(() => MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG)))
.then(() =>
semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)
? MSP.promise(
MSPCodes.MSP_SET_COMPASS_CONFIG,
mspHelper.crunch(MSPCodes.MSP_SET_COMPASS_CONFIG),
)
: Promise.resolve(true),
)
.then(() => mspHelper.writeConfiguration(true));
}

Expand Down
25 changes: 1 addition & 24 deletions src/js/tabs/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ gps.initialize = async function (callback) {
// mag support added in 1.46
const hasMag = have_sensor(FC.CONFIG.activeSensors, "mag") && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46);

if (hasMag) {
await MSP.promise(MSPCodes.MSP_COMPASS_CONFIG);
}

await MSP.promise(MSPCodes.MSP_GPS_CONFIG);

load_html();
Expand Down Expand Up @@ -64,15 +60,7 @@ gps.initialize = async function (callback) {
}

function get_attitude_data() {
MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, load_compass_config);
}

function load_compass_config() {
if (hasMag) {
MSP.send_message(MSPCodes.MSP_COMPASS_CONFIG, false, false, get_imu_data);
} else {
get_imu_data();
}
MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, get_imu_data);
}

function get_imu_data() {
Expand Down Expand Up @@ -198,13 +186,6 @@ gps.initialize = async function (callback) {
gpsBaudrateElement.prop("disabled", true);
gpsBaudrateElement.parent().hide();

// fill magnetometer
if (hasMag) {
$('input[name="mag_declination"]').val(FC.COMPASS_CONFIG.mag_declination.toFixed(1));
} else {
$("div.mag_declination").hide();
}

if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
$(".GPS_info td.positionalDop").parent().hide();
}
Expand Down Expand Up @@ -427,12 +408,8 @@ gps.initialize = async function (callback) {
// fill some data
FC.GPS_CONFIG.auto_baud = $('input[name="gps_auto_baud"]').is(":checked") ? 1 : 0;
FC.GPS_CONFIG.auto_config = $('input[name="gps_auto_config"]').is(":checked") ? 1 : 0;
FC.COMPASS_CONFIG.mag_declination = $('input[name="mag_declination"]').val();

await MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG));
if (hasMag) {
await MSP.promise(MSPCodes.MSP_SET_COMPASS_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_COMPASS_CONFIG));
}
await MSP.promise(MSPCodes.MSP_SET_GPS_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_GPS_CONFIG));

mspHelper.writeConfiguration(true);
Expand Down
17 changes: 16 additions & 1 deletion src/tabs/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
<div class="spacer_box">
<div class="select">
<label>
<span i18n="configurationSensorAlignmentMag"></span>
<select class="magalign">
<option value="0" i18n="configurationSensorAlignmentDefaultOption"></option>
<!-- list generated here -->
Expand Down Expand Up @@ -323,6 +322,22 @@
</div>
<!-- END MAGNETOMETER ALIGNMENT -->

<!-- MAGNETIC DECLINATION -->
<div class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="configurationMagDeclination"></div>
<div class="helpicon cf_tip" i18n_title="configurationMagDeclinationHelp"></div>
</div>
<div class="spacer_box">
<div class="number mag_declination">
<label> <input type="number" name="mag_declination" step="0.1" min="-30.0" max="30.0" />
<span i18n="configurationMagDeclinationInput"></span>
</label>
</div>
</div>
</div>
<!-- END MAGNETIC DECLINATION -->

<!-- ACCELEROMETER TRIM -->
<div class="gui_box grey accelNeeded">
<div class="gui_box_titlebar">
Expand Down
5 changes: 0 additions & 5 deletions src/tabs/gps.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
</select>
<span i18n="configurationGPSubxSbas"></span>
</div>
<div class="number mag_declination">
<label> <input type="number" name="mag_declination" step="0.1" min="0" max="359.9" />
<span i18n="configurationMagDeclination"></span>
</label>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 96dfc06

Please sign in to comment.