Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/pg_struct_sizes.reference.db
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gimbalSerialConfig_t 1 0
gpsConfig_t 11 5
gyroConfig_t 64 12
headTrackerConfig_t 16 1
imuConfig_t 16 2
imuConfig_t 18 2
ledPinConfig_t 1 0
logConfig_t 8 0
modeActivationOperatorConfig_t 1 0
Expand Down
1 change: 1 addition & 0 deletions docs/Blackbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ The CLI command `blackbox` allows setting which Blackbox fields are recorded to
* `PEAKS_P` - Pitch axis noise peak
* `PEAKS_Y` - Yaw axis noise peak
* `SERVOS` - Servo outputs (for planes, tris, etc.)
* `MAG_LEARN` - In-flight compass offset learning (`mag_learn`), in the slow frame; logged only while the setting is ON

On a board with two IMUs, `gyro_secondary_enabled` adds `gyroRaw2[0..2]`, the second
sensor's rates in deg/s, in the same body frame as `gyroRaw` and with that sensor's
Expand Down
10 changes: 10 additions & 0 deletions docs/Sensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ Best calibrated by checking barometer altitude in the Configurator Sensor tab, p
### Nav Acceleromter Z Axis Calibration
The Nav accelerometer Z axis is calibrated in a similar way to the Barometer except it isn't so easy to check while calibrating given the lack of direct feedback. The acc Z value in the Configurator Sensors tab isn't the corrected value so can't be used. Instead set `debug_mode` to `ALTITUDE` and check the behaviour of `Debug 3` in the Configurator Sensors Tab for Debug output. It will drift during calibration then show a sudden change when calibration is finished. After saving and rebooting check `Debug 3` in the Configurator Sensors tab, it should show much less drift from zero if the calibration was successful. Successful calibration can also be checked by making sure `acc_temp_correction` shows a value other than 0 or 51.

## Compass offset learning in flight
With `mag_learn` ON, the compass offsets (`magzero_x/y/z`) are refitted from what the compass reads during each flight and saved after disarm. It refines a calibration that already exists: it needs a calibrated compass, leaves `maggain_x/y/z` as they are, and is not available on targets with 512 KB of flash or less.

While armed and flying, the flight controller keeps one reading for each direction the field has taken in the aircraft's frame (12 headings by 6 elevation bands). After disarm it fits a sphere to those readings, as the ground calibration does, and saves the new offsets only if all of these hold:

* the flight turned through at least 270 degrees of heading (9 of 12 heading sectors) and filled at least 12 sectors;
* the readings lie on a sphere: their distance from the fitted centre varies by no more than 5%. A field that changes with throttle (current in a battery lead next to the compass) or a nearby iron object fails this check;
* the sphere's radius is within 30% of what `maggain` implies, so the stored scale still holds;
* no offset moves by more than 30% of the radius in one flight.

A circle flown at one bank angle shows the field on a single tilted plane, and the offset across that plane stays unobserved: the fit keeps that part, and the vertical in level flight, near the stored value. Turns both ways, at a fair bank, measure it; otherwise it closes over a few flights. The steeper the local inclination of the field, the smaller the part of the error one flight removes. The learned offsets include the average field of the motor current during flight, which is what the heading needs in cruise.

Samples are taken only while the flight controller considers the aircraft flying, so an airplane needs a GPS; rovers and boats never collect, as INAV's flight detection does not run for them. The save waits out the 5 s in which INAV accepts an emergency rearm after a disarm, so that a rearm finds the same calibration and no write to the flash, and then for the aircraft to be still (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.

With the `MAG_LEARN` field group selected (`blackbox MAG_LEARN`; on by default in a new configuration, while one kept from an earlier version needs it set, or the box in the Configurator's Blackbox tab), the blackbox logs the estimate, refitted about once a second, in the slow frame: `magBias[0..2]` (the change a save would write, in raw counts), `magBiasFlags` (bit 0 collecting, 1 paused, 4 save due, 5 too few sectors, 6 too few headings, 7 not a sphere, 8 off the stored scale, 9 step too big, 11 disarmed while flying), `magBiasSectors` and `magBiasSpread` (0.1% of the radius). The header records `mag_learn` and the `mag_zero` the flight started from. With the default `blackbox_arm_control` the log closes at disarm, before the save, and the next log's `mag_zero` shows what was written. `MSP2_INAV_MAG_LEARN` reports the same state, with bit 10 when the last disarm saved.

20 changes: 20 additions & 0 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ Wind compensation in heading estimation from gps groundcourse(fixed wing only)

---

### ahrs_gsf_yaw

Airplanes only. Uses the heading the GSF estimator learns in flight from GPS velocity and the IMU, without the compass, once it has settled: it replaces the GPS course as the AHRS's GPS heading (sharing with the compass as set by ahrs_gps_yaw_weight), the compass is left out while it disagrees with it, and a heading far from it with no compass to hold it is reset to it, at most twice a flight. Off, the estimator still runs and the blackbox logs it (GSF). Not on targets with 512 KB of flash or less.

| Default | Min | Max |
| --- | --- | --- |
| OFF | OFF | ON |

---

### ahrs_inertia_comp_method

Inertia force compensation method when gps is avaliable, VELNED use the accleration from gps, TURNRATE calculates accleration by turnrate multiplied by speed, ADAPTIVE choose best result from two in each ahrs loop
Expand Down Expand Up @@ -2886,6 +2896,16 @@ Selection of mag hardware. See Wiki Sensor auto detect and hardware failure dete

---

### mag_learn

Refits the compass offsets (magzero; maggain is kept) from the readings of each flight and saves them after disarm, when the flight turned through at least 270 degrees and the fit agrees with the stored calibration. Needs a calibrated compass; airplanes and multirotors only. The blackbox logs the estimate as magBias. Not on targets with 512 KB of flash or less.

| Default | Min | Max |
| --- | --- | --- |
| OFF | OFF | ON |

---

### mag_to_use

Allow to chose between built-in and external compass sensor if they are connected to separate buses. Currently only for REVO target
Expand Down
17 changes: 17 additions & 0 deletions docs/development/msp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ When the MSP JSON specification changes, bump `msp_messages.json` version:
[8754 - MSP2_INAV_MAG_UNALIGNED](#msp2_inav_mag_unaligned)
[8755 - MSP2_INAV_ESC_SRXL2_STATUS](#msp2_inav_esc_srxl2_status)
[8756 - MSP2_INAV_ESC_SRXL2_CALIBRATE](#msp2_inav_esc_srxl2_calibrate)
[8757 - MSP2_INAV_MAG_LEARN](#msp2_inav_mag_learn)
[12288 - MSP2_BETAFLIGHT_BIND](#msp2_betaflight_bind)
[12289 - MSP2_RX_BIND](#msp2_rx_bind)

Expand Down Expand Up @@ -5045,6 +5046,22 @@ When the MSP JSON specification changes, bump `msp_messages.json` version:

**Notes:** Requires USE_MOTOR_SRXL2 and at least one request byte. Accepted commands: 0 abort, 1 automatic start, 4 manual high, 5 manual low. Driver safety checks can reject start requests; read MSP2_INAV_ESC_SRXL2_STATUS for the reason. Other command values return an MSP error. Remove propellers before calibration.

## <a id="msp2_inav_mag_learn"></a>`MSP2_INAV_MAG_LEARN (8757 / 0x2235)`
**Description:** Reads the state of the in-flight compass offset learning for the current flight, or for the last one once disarmed.

**Request Payload:** **None**

**Reply Payload:**
|Field|C Type|Size (Bytes)|Units|Description|
|---|---|---|---|---|
| `flags` | `uint16_t` | 2 | Bitmask | Bitmask (magLearnFlags_e): 0 collecting, 1 paused (armed, not flying), 4 save due at disarm, 5 too few sectors, 6 too few headings, 7 not a sphere, 8 off the stored scale, 9 step too big, 10 saved at the last disarm, 11 still moving a minute after the disarm (nothing saved). |
| `sectors` | `uint8_t` | 1 | - | Direction sectors filled, of 72 (12 headings x 6 elevation bands). |
| `headings` | `uint8_t` | 1 | - | Heading sectors filled, of 12. |
| `spread` | `uint16_t` | 2 | 0.1 % | Spread of the field magnitude around the fitted radius. |
| `delta` | `int16_t[3]` | 6 | Raw ADC | Fitted offset minus the stored magZero, X, Y, Z. After a save it is the change written. |

**Notes:** Requires USE_MAG_LEARN (USE_MAG on targets with more than 512 KB of flash); without it the command is not supported. All zero until the first armed flight with mag_learn ON. The save is decided once the 5 s emergency rearm window is over and the aircraft is still, at most a minute after the disarm. Kept in RAM only: lost at power off.

## <a id="msp2_betaflight_bind"></a>`MSP2_BETAFLIGHT_BIND (12288 / 0x3000)`
**Description:** Initiates the receiver binding procedure for supported serial protocols (CRSF, SRXL2).

Expand Down
144 changes: 90 additions & 54 deletions docs/development/msp/inav_enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@
"BLACKBOX_FEATURE_GYRO_PEAKS_ROLL": "1 << 10",
"BLACKBOX_FEATURE_GYRO_PEAKS_PITCH": "1 << 11",
"BLACKBOX_FEATURE_GYRO_PEAKS_YAW": "1 << 12",
"BLACKBOX_FEATURE_SERVOS": "1 << 13"
"BLACKBOX_FEATURE_SERVOS": "1 << 13",
"BLACKBOX_FEATURE_MAG_LEARN": "1 << 14",
"BLACKBOX_FEATURE_GSF": "1 << 15"
},
"BlackboxState": {
"_source": "inav/src/main/blackbox/blackbox.h",
Expand Down Expand Up @@ -1298,59 +1300,69 @@
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_6": "7",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_7": "8",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_8": "9",
"FLIGHT_LOG_FIELD_CONDITION_SERVOS": "10",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_1": "11",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_2": "12",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_3": "13",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_4": "14",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_5": "15",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_6": "16",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_7": "17",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_8": "18",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_9": "19",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_10": "20",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_11": "21",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_12": "22",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_13": "23",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_14": "24",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_15": "25",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_16": "26",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_17": "27",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_18": "28",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_19": "29",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_20": "30",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_21": "31",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_22": "32",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_23": "33",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_24": "34",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_25": "35",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_26": "36",
"FLIGHT_LOG_FIELD_CONDITION_MAG": "37",
"FLIGHT_LOG_FIELD_CONDITION_BARO": "38",
"FLIGHT_LOG_FIELD_CONDITION_PITOT": "39",
"FLIGHT_LOG_FIELD_CONDITION_VBAT": "40",
"FLIGHT_LOG_FIELD_CONDITION_AMPERAGE": "41",
"FLIGHT_LOG_FIELD_CONDITION_SURFACE": "42",
"FLIGHT_LOG_FIELD_CONDITION_FIXED_WING_NAV": "43",
"FLIGHT_LOG_FIELD_CONDITION_MC_NAV": "44",
"FLIGHT_LOG_FIELD_CONDITION_RSSI": "45",
"FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_0": "46",
"FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_1": "47",
"FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_2": "48",
"FLIGHT_LOG_FIELD_CONDITION_NOT_LOGGING_EVERY_FRAME": "49",
"FLIGHT_LOG_FIELD_CONDITION_DEBUG": "50",
"FLIGHT_LOG_FIELD_CONDITION_NAV_ACC": "51",
"FLIGHT_LOG_FIELD_CONDITION_NAV_POS": "52",
"FLIGHT_LOG_FIELD_CONDITION_NAV_PID": "53",
"FLIGHT_LOG_FIELD_CONDITION_ACC": "54",
"FLIGHT_LOG_FIELD_CONDITION_ATTITUDE": "55",
"FLIGHT_LOG_FIELD_CONDITION_RC_DATA": "56",
"FLIGHT_LOG_FIELD_CONDITION_RC_COMMAND": "57",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_RAW": "58",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_PEAKS_ROLL": "59",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_PEAKS_PITCH": "60",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_PEAKS_YAW": "61",
"FLIGHT_LOG_FIELD_CONDITION_NEVER": "62",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_9": "10",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_10": "11",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_11": "12",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_MOTORS_12": "13",
"FLIGHT_LOG_FIELD_CONDITION_SERVOS": "14",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_1": "15",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_2": "16",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_3": "17",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_4": "18",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_5": "19",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_6": "20",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_7": "21",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_8": "22",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_9": "23",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_10": "24",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_11": "25",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_12": "26",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_13": "27",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_14": "28",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_15": "29",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_16": "30",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_17": "31",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_18": "32",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_19": "33",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_20": "34",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_21": "35",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_22": "36",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_23": "37",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_24": "38",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_25": "39",
"FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_26": "40",
"FLIGHT_LOG_FIELD_CONDITION_MAG": "41",
"FLIGHT_LOG_FIELD_CONDITION_BARO": "42",
"FLIGHT_LOG_FIELD_CONDITION_PITOT": "43",
"FLIGHT_LOG_FIELD_CONDITION_VBAT": "44",
"FLIGHT_LOG_FIELD_CONDITION_AMPERAGE": "45",
"FLIGHT_LOG_FIELD_CONDITION_SURFACE": "46",
"FLIGHT_LOG_FIELD_CONDITION_FIXED_WING_NAV": "47",
"FLIGHT_LOG_FIELD_CONDITION_MC_NAV": "48",
"FLIGHT_LOG_FIELD_CONDITION_RSSI": "49",
"FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_0": "50",
"FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_1": "51",
"FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_2": "52",
"FLIGHT_LOG_FIELD_CONDITION_NOT_LOGGING_EVERY_FRAME": "53",
"FLIGHT_LOG_FIELD_CONDITION_DEBUG": "54",
"FLIGHT_LOG_FIELD_CONDITION_NAV_ACC": "55",
"FLIGHT_LOG_FIELD_CONDITION_NAV_POS": "56",
"FLIGHT_LOG_FIELD_CONDITION_NAV_PID": "57",
"FLIGHT_LOG_FIELD_CONDITION_ACC": "58",
"FLIGHT_LOG_FIELD_CONDITION_ATTITUDE": "59",
"FLIGHT_LOG_FIELD_CONDITION_RC_DATA": "60",
"FLIGHT_LOG_FIELD_CONDITION_RC_COMMAND": "61",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_RAW": "62",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_SECONDARY": [
"(63)",
"USE_DUAL_GYRO"
],
"FLIGHT_LOG_FIELD_CONDITION_GYRO_PEAKS_ROLL": "64",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_PEAKS_PITCH": "65",
"FLIGHT_LOG_FIELD_CONDITION_GYRO_PEAKS_YAW": "66",
"FLIGHT_LOG_FIELD_CONDITION_MAG_LEARN": "67",
"FLIGHT_LOG_FIELD_CONDITION_GSF": "68",
"FLIGHT_LOG_FIELD_CONDITION_NEVER": "69",
"FLIGHT_LOG_FIELD_CONDITION_FIRST": "FLIGHT_LOG_FIELD_CONDITION_ALWAYS",
"FLIGHT_LOG_FIELD_CONDITION_LAST": "FLIGHT_LOG_FIELD_CONDITION_NEVER"
},
Expand Down Expand Up @@ -1721,6 +1733,17 @@
"GYRO_HARDWARE_LPF_EXPERIMENTAL": "3",
"GYRO_HARDWARE_LPF_COUNT": "4"
},
"gsfYawFlags_e": {
"_source": "inav/src/main/flight/gsf_yaw.h",
"GSF_YAW_FUSING": "1 << 0",
"GSF_YAW_USABLE": "1 << 1",
"GSF_YAW_INCONSISTENT": "1 << 2",
"GSF_YAW_DELAY_MEASURED": "1 << 3",
"GSF_YAW_MAG_COMPARED": "1 << 4",
"GSF_YAW_MAG_DISAGREES": "1 << 5",
"GSF_YAW_IN_AHRS": "1 << 6",
"GSF_YAW_RESET": "1 << 7"
},
"gyroSensor_e": {
"_source": "inav/src/main/sensors/gyro.h",
"GYRO_NONE": "0",
Expand Down Expand Up @@ -2543,6 +2566,19 @@
"LTM_RATE_MEDIUM": "1",
"LTM_RATE_SLOW": "2"
},
"magLearnFlags_e": {
"_source": "inav/src/main/sensors/compass_learn.h",
"MAG_LEARN_COLLECTING": "1 << 0",
"MAG_LEARN_PAUSED": "1 << 1",
"MAG_LEARN_SAVE_DUE": "1 << 4",
"MAG_LEARN_FEW_SECTORS": "1 << 5",
"MAG_LEARN_FEW_HEADINGS": "1 << 6",
"MAG_LEARN_NOT_SPHERE": "1 << 7",
"MAG_LEARN_OFF_SCALE": "1 << 8",
"MAG_LEARN_STEP_TOO_BIG": "1 << 9",
"MAG_LEARN_SAVED": "1 << 10",
"MAG_LEARN_DISARMED_FLYING": "1 << 11"
},
"magSensor_e": {
"_source": "inav/src/main/sensors/compass.h",
"MAG_NONE": "0",
Expand Down
Loading
Loading