-This tool takes a .bin log and performs a "MAGFit inflight calibration". Calibration parameters are found that fit the measured magnetic field from the log to the expected field from the World Magnetic Model.
-For best results use a flight log that covers as many orientations as possible. Flying figure of eight patterns works well. If you need a motor calibration using either throttle or a current reading then you should also cover as wide a range of throttles and current draws as possible. You do not have to be in any particular flight mode.
-
+
\ No newline at end of file
diff --git a/MAGFit/magfit.js b/MAGFit/magfit.js
index c7847ae7..08628276 100644
--- a/MAGFit/magfit.js
+++ b/MAGFit/magfit.js
@@ -1,7 +1,7 @@
// MAGFit tool for compass calibration
-var DataflashParser
-const import_done = import('../modules/JsDataflashParser/parser.js').then((mod) => { DataflashParser = mod.default });
+// DataflashParser is now available globally from parser.js
+const import_done = Promise.resolve() // No longer need async import
const axis = ['x', 'y', 'z']
const fit_types = { offsets: "Offsets", scale: "Offsets and scale", iron: "Offsets and iron" }
@@ -1685,12 +1685,12 @@ async function load(log_file) {
// This is needed when called from "open in"
await import_done
- let log = new DataflashParser()
+ let log = new window.DataflashParser()
log.processData(log_file, [])
open_in_update(log)
- if (!("MAG" in log.messageTypes) || !("instances" in log.messageTypes.MAG)) {
+ if (!("MAG" in log.messageTypes)) {
alert("No compass data in log")
return
}
@@ -1780,7 +1780,13 @@ async function load(log_file) {
let info = document.getElementById(name)
info.replaceChildren()
- if (!(i in log.messageTypes.MAG.instances)) {
+ // Check if this instance exists in either modern or legacy format
+ const hasInstance = log.messageTypes.MAG.instances && (i in log.messageTypes.MAG.instances)
+ const hasLegacyMag = (i === 0 && "MAG" in log.messageTypes) ||
+ (i === 1 && "MAG2" in log.messageTypes) ||
+ (i === 2 && "MAG3" in log.messageTypes)
+
+ if (!hasInstance && !hasLegacyMag) {
info.appendChild(document.createTextNode("Not found"))
document.getElementById("MAG_" + (i + 1) + "_PARAM_INFO").replaceChildren(document.createTextNode("Not found"))
continue
@@ -1855,9 +1861,14 @@ async function load(log_file) {
// Remove calibration to get raw values
// Subtract compass-motor compensation
- let x = array_sub(MAG_Data[i].orig.x, Array.from(MAG_msg.MOX))
- let y = array_sub(MAG_Data[i].orig.y, Array.from(MAG_msg.MOY))
- let z = array_sub(MAG_Data[i].orig.z, Array.from(MAG_msg.MOZ))
+ // Handle both old format (MOfsX/MOfsY/MOfsZ) and new format (MOX/MOY/MOZ)
+ const mox = MAG_msg.MOX || MAG_msg.MOfsX || new Array(MAG_Data[i].orig.x.length).fill(0)
+ const moy = MAG_msg.MOY || MAG_msg.MOfsY || new Array(MAG_Data[i].orig.y.length).fill(0)
+ const moz = MAG_msg.MOZ || MAG_msg.MOfsZ || new Array(MAG_Data[i].orig.z.length).fill(0)
+
+ let x = array_sub(MAG_Data[i].orig.x, Array.from(mox))
+ let y = array_sub(MAG_Data[i].orig.y, Array.from(moy))
+ let z = array_sub(MAG_Data[i].orig.z, Array.from(moz))
// Remove iron correction
if (!array_all_equal(MAG_Data[i].params.diagonals, 0.0)) {
diff --git a/modules/JsDataflashParser b/modules/JsDataflashParser
index 220e354b..d9787d64 160000
--- a/modules/JsDataflashParser
+++ b/modules/JsDataflashParser
@@ -1 +1 @@
-Subproject commit 220e354ba3cd479e4378ee4bc9989364b9098227
+Subproject commit d9787d646f62b1b186ab31df020e393d194de4a4