Repository navigation
Conversation
The header declared motor[0..7], while the I and P frames write getMotorCount() values, up to MAX_SUPPORTED_MOTORS (12). With 9 to 12 motors and motor logging on, every frame carried more values than the header described, and no frame of the log decoded. The header now declares motor[8..11] behind four more conditions. The condition cache was a uint64_t already full on dual-gyro targets, so it becomes an array of 32-bit words sized for every condition. The MSP enum reference gets the new values (that enum's section only).
With mag_learn ON, the compass keeps one raw reading per field direction during each flight (12 headings x 6 equal-area elevation bands), refits the offsets with the sphere fit the ground calibration already uses and saves magzero at disarm when the flight turned through at least 270 degrees and the fit agrees with the stored calibration: radius spread within 5%, radius within 30% of what maggain implies, no axis moving more than 30% of the radius. maggain is kept. The fit runs on samples scaled by maggain, so axes of different sensitivity weigh alike, and a ridge toward the stored offset keeps a direction the flight never swept (the vertical in level flight, the normal of a circle flown at one bank) where it was. A calibration started while armed, or mag_learn switched off, drops what the flight had collected. The save waits out the 5 s in which INAV accepts an emergency rearm after a disarm, so a rearm finds the same calibration and no flash write, and then for the aircraft to be still; if it still moves a minute after the disarm, nothing is saved. EMERGENCY_INFLIGHT_REARM_TIME_WINDOW_MS moves to fc_core.h for that. The estimate is refitted about once a second in flight and logged in the blackbox slow frame (magBias, magBiasFlags, magBiasSectors, magBiasSpread; header mag_learn and mag_zero) under its own field group, MAG_LEARN (on by default in a new configuration, logged only while mag_learn is ON), and MSP2_INAV_MAG_LEARN reports it for the Configurator. Built on iNavFlight#12127 for the wider condition cache and on the slow-frame conditions. USE_MAG_LEARN on USE_MAG targets with more than 512 KB of flash. The setting is appended to compassConfig_t with a zero default, so the PG version stays: on ARM (short enums) the struct had no tail padding and grows from 24 to 26 bytes; on SITL the new byte lands in former tail padding, which the reset template writes as zero.
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoLearn compass offsets in flight and correct Blackbox motor headers
AI Description
Diagram
High-Level Assessment
Files changed (24)
|
Code Review by Qodo
1. Pico 2 pilots cannot enable compass learning
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #12142 251 targets built. Find your board's
|
A compass calibrated on the bench drifts once it sits in the airframe: a battery placed differently, a new servo, the
current of the motor. INAV only learns the offsets in the calibration dance, so the error stays until someone notices
the heading wandering and calibrates again. ArduPilot learns them in flight (
COMPASS_LEARN), PX4 estimates them inEKF2. This adds an optional in-flight refit of the offsets, saved after disarm, for airplanes and multirotors on
targets with more than 512 KB of flash.
How it works
mag_learnON (default OFF) and a calibrated compass, the flight controller keeps one raw reading for eachdirection the field takes in the aircraft's frame while it flies: 12 headings by 6 equal-area elevation bands. One
reading per direction, so a long leg weighs no more than a turn.
calibration already uses (
sensorCalibrationSolveForOffset), on the readings scaled bymaggainso that axes ofdifferent sensitivity weigh alike. A ridge toward the stored offset keeps what the flight did not observe (the
vertical in level flight, the normal of a circle flown at one bank angle) where it was.
magzeroand saves, like the servo autotrim, only if all of these hold:nearby, fails it);
maggainimplies;maggainis never changed. A calibration started while armed, ormag_learnswitched off, drops the flight'sreadings.
calibration and no flash write, and then for the aircraft to be still, since it may be carried away right after
landing; if it still moves a minute after the disarm, nothing is saved. Powering off before the save loses the
flight's result.
EMERGENCY_INFLIGHT_REARM_TIME_WINDOW_MSmoves tofc_core.hso both use the same window.isProbablyStillFlying(), no landing detected),so an airplane needs a GPS; rovers and boats never collect, as the flight detection does not run for them.
What the user sees
MAG_LEARN(blackbox MAG_LEARN, logged only whilemag_learnis ON), withmagBias[0..2](the change a save would write, raw counts),magBiasFlags,magBiasSectorsandmagBiasSpreadin the slow frame, refitted about once a second. The header has
mag_learnand themag_zerothe flight startedfrom; with the default
blackbox_arm_controlthe log closes at disarm, before the save, so the next log'smag_zeroshows what was written. The group is on by default in a new configuration; one kept from an earlierversion needs
blackbox MAG_LEARN, and the released Configurator's Blackbox tab clears the bit on save, which theConfigurator PR below fixes.
MSP2_INAV_MAG_LEARN(0x2235) reports the same state, plus whether the last disarm saved. The Configurator side isCalibration and Blackbox tabs: in-flight compass learning (mag_learn) inav-configurator#2832: the switch and a status line in the Calibration tab, the field group
in the Blackbox tab. The Blackbox Explorer side is Fields and header lines of INAV's in-flight compass offset learning (mag_learn) blackbox-log-viewer#126: the fields by name, the
flags decoded, a graph preset and the header lines.
docs/Sensors.mddescribes it;Settings.md,Blackbox.mdand the MSP docs are updated.Commits
already have, every existing one
ALWAYS, so a group can leave its slow fields out of the log and of itsSheader.It builds on #12127 (12 motors in the log header), which widens the blackbox condition cache: it is full on the
USE_DUAL_GYRO targets (63 conditions in a uint64_t). Until #12127 is merged its commit shows here too.
Settings
mag_learnis appended tocompassConfig_twith a zero default, so the PG version stays: on ARM (short enums) thestruct grows from 24 to 26 bytes with no tail padding before; on SITL the new byte lands in what was tail padding,
which a stored record holds as zero (checked on an eeprom saved by a SITL without this change).
Cost
Against #12127 (both commits):
112 to 120 B of the flash is the first commit (the condition byte of every slow field and its test); on F722 the
rest is the CLI name (see below). On the H7 most of the RAM is section alignment: the new variables are about 40 B.
The 432 B of samples are in FASTRAM (CCM on F405, RAM1 on AT32, DTCM on H7); the AT32 startup does not clear it, and
the code reads only the sectors it has written. The fit runs in the compass task, once a second while armed.
Other PRs
1 << 14and the condition afterGYRO_PEAKS_YAWare also taken by my draft gyro: optionally average two IMUs into the control path #11958: whichever goesin second renumbers on the conflict (the CLI names are positional, so the conflict cannot pass unnoticed). The name
MAG_LEARNis in the list on every target, even without the feature, so that a later name never lands on the wrongbit: that is the 8 B on F722, and a
difftaken there has ablackbox MAG_LEARNline that an older firmwarerejects as an invalid name.
MSP2_INAV_MAG_LEARNis 0x2235; no open PR uses it (Add per-motor DShot direction configuration and bounded test pulses #12011, closed, had it).compass.c), Add names for control, battery and mixer profiles #11894, OSD elements for the control, battery and mixer profile names #11896, GPS: report what the receiver actually has, and allow NavIC where it exists #11979 (the versionand the tail of
msp_messages.json), and through the slow-field commit New Feature: Dual switchable receivers #11748 and Support custom Tramp power levels and AUX pit mode #11887 (blackbox.c: they addslow fields, which now need a condition).
Tested
compass_learn_unittest.cc), including axes of differentsensitivity, level turns, maggain 0 and negative; all 633 pass. Removing the gain scaling, or the ridge, makes a
test fail.
at 30 degrees of bank, a straight leg, a left circle) and
magzeroset wrong by (60, -40, 80):magzerofrom(60, -40, 80) to (2, -1, 10), true value 0; the log shows the estimate settling as the turns fill the sectors;
later,
magzerounchanged;blackbox -MAG_LEARN), learning still works and saves, and the six fields areleft out of the log and its
Sheader, as selected;blackbox_decodereads every field.1090 LSB/G, 2 mG, cross-axis 0.2 %FS/G, gains within 5 %; QMC5883L: 2 mG), a 45 uT field at 56 degrees and the
field of the battery leads (a wire's mu0 I / 2 pi d, 30 A at full throttle): offsets off by (4, -3, 5) uT, i.e. 11
degrees of heading, come back to 0.4 to 1.8 degrees in one flight, plane or multirotor, with a twisted pair or an
open pair 10 cm away; an open pair 5 cm away (72 uT at full throttle, more than the Earth's field) is refused.
IST8310 (148 counts, 1 count of noise, turns banked both ways), offsets off by (13, -10, 17) counts.
magzerowentfrom (53, -109, 43) to (41, -99, 30), true value (40, -99, 26), with the spread steady at about 1 %; it was still
there after a reboot; one fit takes 24 us on the H743.
NEUTRONRCF435WING.
Not tested, testing wanted
and 30% limits are reasoned, and an offline simulation with noise and a throttle-dependent field agrees, but the
real margin is what testers will see in
magBiasSpread. A log of a few flights withmag_learnON, on a plane andon a multirotor, would be the test I would like most.