feat(tools): add a script to convert v1.17 parameter files for v1.18 (#29363)

* feat(tools): add a script to convert v1.17 parameter files for v1.18

param_translation.cpp converts renamed parameters only when PX4 upgrades
the parameters stored on the vehicle. QGroundControl loads a .params
file parameter by parameter, so values saved under old names are
ignored, and RC*_REV saved as -1.000000 load as 0 into the now integer
parameters. The script applies the same conversions to the file.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* fix(tools): keep the v1.18 heater sensor default in converted files

A v1.17 vehicle does not store SENS_TEMP_ID at its default of 0, so the
upgrade never converts it and HEATER1_SENS_ID keeps its v1.18 default,
the board's sensor or auto-select. The script wrote -1 instead, which
disables the heater on boards that v1.18 heats by default.

Also list EKF2_REQ_PDOP, which v1.18 raises to 4 on fixed-wing, log
integer values without an exponent, end a copied line that has no
newline before the parameters follow it, and say what the translation
test catches.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* docs(releases): link the v1.17 parameter file script in 1.18 notes

Item 13 tells users to check a parameter file saved on v1.17 by hand.
Point them to Tools/migrate_param_file.py, which converts such a file.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* fix(tools): convert the v1.17 auxiliary global position parameters

param_translation.cpp moves EKF2_AGP_CTRL, _MODE, _DELAY, _NOISE and
_GATE to the first source set, EKF2_AGP0_*, and sets EKF2_AGP0_ID to 1
when EKF2_AGP_CTRL is set. The script listed them as removed, so a
converted file came out with aux global position fusion disabled.

Convert them the same way. QGroundControl lists EKF2_AGP0_* only once
EKF2_AGP0_ID is set and the vehicle reboots, so the script and item 13
of the 1.18 notes say to load the file again after a reboot.
EKF2_AGP_NOISE at 0.9 is listed as a v1.17 default (1.0 in v1.18).

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* fix(tools): replace the v1.17 RoboClaw output defaults

The RoboClaw outputs moved from 0 to 256 with stop at 128 to 0 to 254
with stop at 127. A saved file holds the v1.17 defaults, and the script
kept them: RBCLW_DIS 128 drives the motors forward at speed 1 while
disarmed, and RBCLW_MAX 256 is above the v1.18 maximum of 254.

At their v1.17 defaults RBCLW_DIS, _MIN and _MAX now get the v1.18
default, as after an upgrade of the parameters stored on the vehicle,
since the firmware does not store defaults. Other RBCLW_DIS, _MIN, _MAX
and _FAIL values are kept and listed for a check.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* fix(tools): drop the reload after a reboot for EKF2_AGP0_*

QGroundControl sends the rows of a .params file that the vehicle does not
list as new parameters, since the file holds their types, and PX4
accepts PARAM_SET for any parameter in its table. So EKF2_AGP0_* are set
on the first load, and the note to load the file again after a reboot
is wrong. Only a Mission Planner file, which has no types, cannot send
them.

Remove the note from the script and from item 13 of the 1.18 notes.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* fix(tools): list the X25-EVO core heater and other components

- CORE_IMU_TEMP, _FF, _I, _P and CORE_TEMP_ID of the CUAV X25-EVO core
  heater are gone in v1.18 without a translation, the board now uses
  HEATER2_*. They passed through unlisted; list them as removed with
  the HEATER2_* parameter to set.
- rc.boat_defaults still sets NAV_ACC_RAD 2, so the note that v1.18 uses
  10 applies to multicopters only.
- A vehicle with MAV_COMP_ID other than 1 saves its parameters under
  that component, so the script converted nothing and said nothing.
  Warn when the file has no parameters of component 1.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

* fix(tools): list board defaults changed on Skynode and i.MX RT

A saved v1.17 file holds the v1.17 board defaults, and v1.18 changed
some of them:
- On Skynode the fmu-v5x defaults set EKF2_MULTI_IMU 0 and
  SENS_IMU_MODE 1, since it is too loaded for the three EKF instances of
  the STM32F7 defaults (3 and 0).
- The i.MX RT defaults match fmu-v6x: EKF2_MULTI_IMU 3, SENS_IMU_MODE 0,
  IMU_GYRO_FFT_EN 1 and UAVCAN_ENABLE 2, where v1.17 used 0, 1, 0 and 0.

List these values as v1.17 defaults with the boards they apply to. One
parameter can change differently on each set of boards.

Airframes 4016, 4020 and 24001 still set NAV_ACC_RAD 2 in v1.18, so name
them in the multicopter note.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>

---------

Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com>
(cherry picked from commit 06036f2163)
This commit is contained in:
Ahmet Burak Tektas authored and Ramon Roche committed 2026-11-18 07:15:56 -08:00
1 parent ac8af487d2
commit 3312ad50df
4 files changed
+657

No files matched your search

+5
View File
@@ -37,3 +37,8 @@ jobs:
- name: Check MAVSDK test scripts with flake8
run: flake8 test/mavsdk_tests/*.py
- name: Check parameter file migration
run: |
flake8 Tools/migrate_param_file.py Tools/test_migrate_param_file.py
python3 -m unittest discover -s Tools -p 'test_migrate_param_file.py' -v
+386
View File
@@ -0,0 +1,386 @@
#!/usr/bin/env python3
############################################################################
#
# Copyright (c) 2026 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
"""Convert a parameter file saved on PX4 v1.17 for loading on v1.18.
param_translation.cpp converts renamed parameters only when PX4 upgrades
the parameters stored on the vehicle. Loading a .params file in
QGroundControl sets each parameter by name, so values saved under old
names are ignored. This script applies the same conversions to a
QGroundControl .params file, writes RC*_REV as integers (QGroundControl
loads a saved -1.000000 into the now integer parameter as 0), and drops
the parameters v1.18 no longer has, listing each one on stderr.
A saved file also holds the v1.17 defaults. Values still at a v1.17
default that v1.18 changed are kept and listed, so they can be reviewed.
The RoboClaw output defaults, whose scale changed, get the v1.18 default,
as after an upgrade of the parameters stored on the vehicle.
Check the converted file before loading it.
Examples:
Tools/migrate_param_file.py saved.params converted.params
"""
import argparse
import struct
import sys
AUTOPILOT_COMPONENT = 1
MAV_PARAM_TYPE_INT32 = 6
MAV_PARAM_TYPE_REAL32 = 9
# Conversions of param_translation.cpp from v1.17 to v1.18.
# old name: (kind, new name(s), argument)
CONVERSIONS = {
'EKF2_GPS_POS_X': ('rename', 'SENS_GPS0_OFFX', None),
'EKF2_GPS_POS_Y': ('rename', 'SENS_GPS0_OFFY', None),
'EKF2_GPS_POS_Z': ('rename', 'SENS_GPS0_OFFZ', None),
'EKF2_GPS_DELAY': ('copy_int',
('SENS_GPS0_DELAY', 'SENS_GPS1_DELAY'), None),
'MNT_RANGE_PITCH': ('half_range',
('MNT_MAX_PITCH', 'MNT_MIN_PITCH'), None),
'MOT_POLE_COUNT': ('copy_int',
tuple(f'DSHOT_MOT_POL{i}' for i in range(1, 13)),
None),
# only "disabled" is converted
'COM_RC_OVERRIDE': ('if_zero_set', 'MAN_OVERRIDE_SPD', -1.0),
'SENS_IMU_TEMP': ('rename', 'HEATER1_TEMP', None),
'SENS_IMU_TEMP_FF': ('rename', 'HEATER1_TEMP_FF', None),
'SENS_IMU_TEMP_I': ('rename', 'HEATER1_TEMP_I', None),
'SENS_IMU_TEMP_P': ('rename', 'HEATER1_TEMP_P', None),
# SENS_TEMP_ID 0 is the v1.17 default, which the vehicle does not store,
# so the upgrade leaves HEATER1_SENS_ID at its v1.18 default (the file
# cannot show a 0 stored over a board default, which becomes -1)
'SENS_TEMP_ID': ('if_nonzero_rename_int', 'HEATER1_SENS_ID', None),
# landing nudging is bit 1 of MPC_AUTO_NUDGING (v1.18 default 0)
'MPC_LAND_RC_HELP': ('if_nonzero_set_bit', 'MPC_AUTO_NUDGING', 1),
# the first source slot only fuses messages with id EKF2_AGP0_ID, which
# is set to 1 (the id v1.17 sources arrive with) when fusion was enabled
'EKF2_AGP_CTRL': ('rename_if_nonzero_set',
('EKF2_AGP0_CTRL', 'EKF2_AGP0_ID'), 1),
'EKF2_AGP_MODE': ('rename', 'EKF2_AGP0_MODE', None),
'EKF2_AGP_DELAY': ('rename', 'EKF2_AGP0_DELAY', None),
'EKF2_AGP_NOISE': ('rename', 'EKF2_AGP0_NOISE', None),
'EKF2_AGP_GATE': ('rename', 'EKF2_AGP0_GATE', None),
}
# Types of the parameters the conversions write
NEW_TYPES = {
'SENS_GPS0_OFFX': MAV_PARAM_TYPE_REAL32,
'SENS_GPS0_OFFY': MAV_PARAM_TYPE_REAL32,
'SENS_GPS0_OFFZ': MAV_PARAM_TYPE_REAL32,
'SENS_GPS0_DELAY': MAV_PARAM_TYPE_INT32,
'SENS_GPS1_DELAY': MAV_PARAM_TYPE_INT32,
'MNT_MAX_PITCH': MAV_PARAM_TYPE_REAL32,
'MNT_MIN_PITCH': MAV_PARAM_TYPE_REAL32,
**{f'DSHOT_MOT_POL{i}': MAV_PARAM_TYPE_INT32 for i in range(1, 13)},
'MAN_OVERRIDE_SPD': MAV_PARAM_TYPE_REAL32,
'HEATER1_TEMP': MAV_PARAM_TYPE_REAL32,
'HEATER1_TEMP_FF': MAV_PARAM_TYPE_REAL32,
'HEATER1_TEMP_I': MAV_PARAM_TYPE_REAL32,
'HEATER1_TEMP_P': MAV_PARAM_TYPE_REAL32,
'HEATER1_SENS_ID': MAV_PARAM_TYPE_INT32,
'MPC_AUTO_NUDGING': MAV_PARAM_TYPE_INT32,
'EKF2_AGP0_CTRL': MAV_PARAM_TYPE_INT32,
'EKF2_AGP0_ID': MAV_PARAM_TYPE_INT32,
'EKF2_AGP0_MODE': MAV_PARAM_TYPE_INT32,
'EKF2_AGP0_DELAY': MAV_PARAM_TYPE_REAL32,
'EKF2_AGP0_NOISE': MAV_PARAM_TYPE_REAL32,
'EKF2_AGP0_GATE': MAV_PARAM_TYPE_REAL32,
}
# RC*_REV changed from float to int32
REVERSE_PARAMS = {f'RC{i}_REV' for i in range(1, 19)}
_SEE_LIGHTS = 'see UAVCAN_LGT_MODE, UAVCAN_LGT_NUM, UAVCAN_LGT_IDn/FNn'
# Parameters removed in v1.18 without a conversion: name: hint
REMOVED = {
'ASPD_BETA_GATE': '', 'ASPD_BETA_NOISE': '', 'ASPD_SCALE_NSD': '',
'ASPD_TAS_GATE': '',
'BAT1_I_CHANNEL': '', 'BAT2_I_CHANNEL': '', 'BAT_ADC_CHANNEL': '',
'COM_ARM_SDCARD': '', 'COM_DISARM_MAN': '', 'COM_FLT_PROFILE': '',
'COM_HLDL_REG_T': '', 'COM_IMB_PROP_ACT': 'see FD_IMB_PROP_THR',
'COM_KILL_DISARM': '', 'COM_LKDOWN_TKO': '', 'COM_MOT_TEST_EN': '',
'COM_OBC_LOSS_T': '', 'COM_RC_ARM_HYST': '',
'COM_RC_STICK_OV': 'see MAN_OVERRIDE_SPD (stick speed in 1/s)',
'COM_TAKEOFF_ACT': '',
# CUAV X25-EVO core heater, now the second heater instance
'CORE_IMU_TEMP': 'see HEATER2_TEMP',
'CORE_IMU_TEMP_FF': 'see HEATER2_TEMP_FF',
'CORE_IMU_TEMP_I': 'see HEATER2_TEMP_I',
'CORE_IMU_TEMP_P': 'see HEATER2_TEMP_P',
'CORE_TEMP_ID': 'see HEATER2_SENS_ID',
'DSHOT_BIDIR_EN': 'choose BDShot in PWM_MAIN_TIMn / PWM_AUX_TIMn',
'FD_ACT_MOT_C2T': 'see MOTFAIL_C2T and MOTFAIL_OFF',
'FD_ACT_MOT_THR': '',
'FD_ACT_MOT_TOUT': 'see MOTFAIL_TIME (in s)',
'FD_ESCS_EN': 'see FD_ACT_EN',
'FW_AT_START': '', 'FW_T_SPD_DEV_STD': '', 'FW_T_SPD_PRC_STD': '',
'FW_T_SPD_STD': '', 'GF_PREDICT': '', 'INA226_CONFIG': '',
'LNDMC_TRIG_TIME': '', 'MC_AT_START': '',
'MNT_OFF_PITCH': 'use the output trim',
'MNT_OFF_ROLL': 'use the output trim',
'MNT_OFF_YAW': 'use the output trim',
'MPC_USE_HTE': '', 'SIM_ARSPD_FAIL': '',
'SIM_BAT_ENABLE': 'see SIM_BAT_DRAIN',
'UAVCAN_LGT_ANTCL': _SEE_LIGHTS, 'UAVCAN_LGT_LAND': _SEE_LIGHTS,
'UAVCAN_LGT_NAV': _SEE_LIGHTS, 'UAVCAN_LGT_STROB': _SEE_LIGHTS,
}
# Defaults changed in v1.18: name: (v1.17 default, v1.18 default)
# A converted parameter is listed under its v1.17 name.
DEFAULT_CHANGES = {
'EKF2_AGP_NOISE': (0.9, 1.0),
'FD_ACT_EN': (1, 0),
'FW_T_HRATE_FF': (0.3, 0.5),
'MPC_LAND_RADIUS': (1000.0, -1.0),
'SENS_MAG_AUTOCAL': (1, 0),
'VT_LND_PITCH_MIN': (-5.0, 0.0),
'VT_PITCH_MIN': (-5.0, 0.0),
# set by the v1.18 fixed-wing defaults, still 2.5 for other vehicles
'EKF2_REQ_PDOP': (2.5, 4.0),
# set by the v1.17 multicopter defaults, no longer in v1.18 (boats and
# airframes 4016, 4020 and 24001 keep 2)
'NAV_ACC_RAD': (2.0, 10.0),
}
# Defaults that v1.18 changed for some vehicles only
DEFAULT_CHANGE_SCOPES = {
'EKF2_REQ_PDOP': 'on fixed-wing',
'NAV_ACC_RAD': ('on multicopter, except airframes 4016, 4020 and 24001,'
' which keep 2'),
}
_SKYNODE = 'on Skynode'
_IMXRT = 'on i.MX RT boards (fmu-v6xrt, mr-tropic, tropic-community)'
# Defaults that the v1.18 board or chip defaults changed on some boards:
# name: [(v1.17 default, v1.18 default, scope)]
BOARD_DEFAULT_CHANGES = {
# Skynode (fmu-v5x) runs a single EKF in v1.18 instead of the three of
# the STM32F7 defaults. The i.MX RT defaults now match fmu-v6x.
'EKF2_MULTI_IMU': [(3, 0, _SKYNODE), (0, 3, _IMXRT)],
'SENS_IMU_MODE': [(0, 1, _SKYNODE), (1, 0, _IMXRT)],
'IMU_GYRO_FFT_EN': [(0, 1, _IMXRT)],
'UAVCAN_ENABLE': [(0, 2, _IMXRT)],
}
# RoboClaw outputs: 0 to 256 with stop at 128 in v1.17, 0 to 254 with stop
# at 127 in v1.18. In v1.18 the v1.17 defaults are out of range or one
# step off (DIS 128 drives forward while disarmed), so they are replaced:
# name: (v1.17 default, v1.18 default)
REPLACED_DEFAULTS = {
'RBCLW_DIS1': (128, 127), 'RBCLW_DIS2': (128, 127),
'RBCLW_MAX1': (256, 254), 'RBCLW_MAX2': (256, 254),
'RBCLW_MIN1': (1, 0), 'RBCLW_MIN2': (1, 0),
}
_RBCLW_SCALE = ('RoboClaw outputs use 0 to 254 with stop at 127 in v1.18'
' (v1.17: 0 to 256, stop at 128)')
# Parameters whose other values need a check: name: (value to skip, note)
SCALE_CHECKS = {
**{name: (None, _RBCLW_SCALE) for name in REPLACED_DEFAULTS},
'RBCLW_FAIL1': (-1, _RBCLW_SCALE), 'RBCLW_FAIL2': (-1, _RBCLW_SCALE),
}
def float32(value):
return struct.unpack('<f', struct.pack('<f', value))[0]
def show(value):
"""Format a value for the log, integers without an exponent."""
if float(value).is_integer():
return str(int(value))
return f'{value:g}'
def format_value(value, mav_type):
"""Format a value the way QGroundControl saves it."""
if mav_type == MAV_PARAM_TYPE_REAL32:
return f'{float32(value):.18f}'
return str(int(value))
def convert(name, value, current):
"""Return [(name, value)] for an old parameter, as PX4 converts it.
current: values already in the file, for MPC_AUTO_NUDGING.
"""
kind, new, arg = CONVERSIONS[name]
if kind == 'rename':
return [(new, value)]
if kind == 'copy_int':
return [(n, int(value)) for n in new]
if kind == 'half_range':
if value <= 0:
return []
half = float32(value) * 0.5
return [(new[0], half), (new[1], -half)]
if kind == 'if_zero_set':
return [(new, arg)] if value == 0 else []
if kind == 'if_nonzero_rename_int':
return [(new, int(value))] if value != 0 else []
if kind == 'rename_if_nonzero_set':
return [(new[0], value)] + ([(new[1], arg)] if value != 0 else [])
if kind == 'if_nonzero_set_bit':
if value == 0:
return []
return [(new, int(current.get(new, 0)) | (1 << arg))]
raise ValueError(kind)
def log_old_default(name, value, log):
"""List a value still at a v1.17 default that v1.18 changed."""
if name in DEFAULT_CHANGES:
old, new = DEFAULT_CHANGES[name]
if value == float32(old):
scope = DEFAULT_CHANGE_SCOPES.get(name)
log(f'default: {name} {show(value)} is a v1.17 default,'
f' v1.18 uses {show(new)}'
+ (f' {scope}' if scope else ''))
for old, new, scope in BOARD_DEFAULT_CHANGES.get(name, []):
if value == float32(old):
log(f'default: {name} {show(value)} is a v1.17 default,'
f' v1.18 uses {show(new)} {scope}')
def migrate(lines, log):
"""Convert the lines of a .params file and return the new lines."""
rows = []
for line in lines:
fields = line.rstrip('\r\n').split('\t')
try:
int(fields[1])
float(fields[3])
assert len(fields) == 5
except (AssertionError, IndexError, ValueError):
if line.strip() and not line.startswith('#'):
log(f'copied unchanged, not in the QGroundControl format:'
f' {line.strip()}')
# parameters follow these lines in the output
rows.append(line if line.endswith('\n') else line + '\n')
continue
rows.append(fields)
params = [r for r in rows if isinstance(r, list)
and r[1] == str(AUTOPILOT_COMPONENT)]
if not params and any(isinstance(r, list) for r in rows):
log(f'warning: no parameters of component {AUTOPILOT_COMPONENT},'
f' nothing converted: only an autopilot with MAV_COMP_ID'
f' {AUTOPILOT_COMPONENT} is supported')
current = {r[2]: float(r[3]) for r in params}
vehicle = params[0][0] if params else '1'
new_values = {}
out = []
for row in rows:
if not isinstance(row, list) or row[1] != str(AUTOPILOT_COMPONENT):
out.append(row)
continue
name = row[2]
value = float32(float(row[3]))
if name in CONVERSIONS:
writes = convert(name, value, {**current, **new_values})
for new_name, new_value in writes:
new_values[new_name] = new_value
done = ', '.join(f'{n} {show(v)}' for n, v in writes)
log(f'converted: {name} {show(value)} ->'
f' {done or "nothing to set"}')
log_old_default(name, value, log)
elif name in REMOVED:
hint = f': {REMOVED[name]}' if REMOVED[name] else ''
log(f'removed: {name} {show(value)}{hint}')
elif (name in REPLACED_DEFAULTS
and value == REPLACED_DEFAULTS[name][0]):
old, new = REPLACED_DEFAULTS[name]
log(f'replaced: {name} {show(old)} -> {show(new)},'
f' the v1.17 default by the v1.18 default')
out.append([row[0], row[1], name,
format_value(new, int(row[4])), row[4]])
elif name in REVERSE_PARAMS and row[4] != str(MAV_PARAM_TYPE_INT32):
reverse = -1 if value < 0 else 1
if reverse < 0:
log(f'reversed: {name} written as the integer -1')
out.append([row[0], row[1], name, str(reverse),
str(MAV_PARAM_TYPE_INT32)])
else:
log_old_default(name, value, log)
if name in SCALE_CHECKS and value != SCALE_CHECKS[name][0]:
log(f'check: {name} {show(value)}: {SCALE_CHECKS[name][1]}')
out.append(row)
# A converted value replaces the file's own value of that parameter
out = [r for r in out if not (isinstance(r, list)
and r[1] == str(AUTOPILOT_COMPONENT)
and r[2] in new_values)]
for name, value in new_values.items():
out.append([vehicle, str(AUTOPILOT_COMPONENT), name,
format_value(value, NEW_TYPES[name]),
str(NEW_TYPES[name])])
header = [r for r in out if not isinstance(r, list)]
body = sorted((r for r in out if isinstance(r, list)),
key=lambda r: (int(r[1]), r[2]))
return header + ['\t'.join(r) + '\n' for r in body]
def main():
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('input', help='.params file saved on PX4 v1.17')
parser.add_argument('output', help='converted .params file to write')
args = parser.parse_args()
with open(args.input, encoding='utf-8') as f:
lines = f.readlines()
version = next((line.split(':', 1)[1].strip() for line in lines
if line.startswith('# Version:')), None)
if version is not None and not version.startswith('1.17'):
print(f'warning: the file was saved on PX4 {version}, not v1.17',
file=sys.stderr)
converted = migrate(lines, lambda message: print(message, file=sys.stderr))
with open(args.output, 'w', encoding='utf-8') as f:
f.writelines(converted)
if __name__ == '__main__':
main()
+257
View File
@@ -0,0 +1,257 @@
#!/usr/bin/env python3
"""Tests for migrate_param_file.py."""
import os
import unittest
import migrate_param_file as m
TRANSLATION = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
'src', 'lib', 'parameters', 'param_translation.cpp')
HEADER = ['# Onboard parameters for Vehicle 1\n', '#\n',
'# Version: 1.17.0 \n', '#\n',
'# Vehicle-Id Component-Id Name Value Type\n']
def params_file(*rows):
return HEADER + [f'1\t{c}\t{n}\t{v}\t{t}\n' for c, n, v, t in rows]
def migrate(*rows):
log = []
lines = m.migrate(params_file(*rows), log.append)
values = {}
for line in lines:
f = line.rstrip('\n').split('\t')
if not line.startswith('#'):
values[(int(f[1]), f[2])] = (f[3], int(f[4]))
return lines, values, log
class MigrateParamFileTest(unittest.TestCase):
def test_conversions(self):
lines, values, _ = migrate(
(1, 'EKF2_GPS_DELAY', '150.000000000000000000', 9),
(1, 'EKF2_GPS_POS_X', '0.119999997317790985', 9),
(1, 'MNT_RANGE_PITCH', '90.000000000000000000', 9),
(1, 'MOT_POLE_COUNT', '12', 6),
(1, 'COM_RC_OVERRIDE', '0', 6),
(1, 'MPC_LAND_RC_HELP', '1', 6),
(1, 'SENS_IMU_TEMP', '45.000000000000000000', 9),
(1, 'SENS_TEMP_ID', '0', 6),
(1, 'MPC_XY_VEL_MAX', '8.000000000000000000', 9))
self.assertEqual(lines[:len(HEADER)], HEADER)
self.assertEqual(values, {
(1, 'SENS_GPS0_DELAY'): ('150', 6),
(1, 'SENS_GPS1_DELAY'): ('150', 6),
(1, 'SENS_GPS0_OFFX'): ('0.119999997317790985', 9),
(1, 'MNT_MAX_PITCH'): ('45.000000000000000000', 9),
(1, 'MNT_MIN_PITCH'): ('-45.000000000000000000', 9),
**{(1, f'DSHOT_MOT_POL{i}'): ('12', 6) for i in range(1, 13)},
(1, 'MAN_OVERRIDE_SPD'): ('-1.000000000000000000', 9),
(1, 'MPC_AUTO_NUDGING'): ('2', 6),
(1, 'HEATER1_TEMP'): ('45.000000000000000000', 9),
(1, 'MPC_XY_VEL_MAX'): ('8.000000000000000000', 9),
})
def test_values_firmware_does_not_convert(self):
_, values, log = migrate(
(1, 'COM_RC_OVERRIDE', '1', 6),
(1, 'MNT_RANGE_PITCH', '0.000000000000000000', 9),
(1, 'MPC_LAND_RC_HELP', '0', 6),
(1, 'SENS_TEMP_ID', '0', 6))
self.assertEqual(values, {})
self.assertIn('converted: COM_RC_OVERRIDE 1 -> nothing to set', log)
self.assertIn('converted: SENS_TEMP_ID 0 -> nothing to set', log)
def test_heater_sensor_id_kept(self):
_, values, log = migrate((1, 'SENS_TEMP_ID', '2621474', 6))
self.assertEqual(values, {(1, 'HEATER1_SENS_ID'): ('2621474', 6)})
self.assertEqual(log, ['converted: SENS_TEMP_ID 2621474 ->'
' HEATER1_SENS_ID 2621474'])
def test_aux_global_position_moved_to_first_source(self):
_, values, log = migrate(
(1, 'EKF2_AGP_CTRL', '1', 6),
(1, 'EKF2_AGP_MODE', '1', 6),
(1, 'EKF2_AGP_DELAY', '50.000000000000000000', 9),
(1, 'EKF2_AGP_NOISE', '0.899999976158142090', 9),
(1, 'EKF2_AGP_GATE', '3.000000000000000000', 9))
self.assertEqual(values, {
(1, 'EKF2_AGP0_CTRL'): ('1', 6),
(1, 'EKF2_AGP0_ID'): ('1', 6),
(1, 'EKF2_AGP0_MODE'): ('1', 6),
(1, 'EKF2_AGP0_DELAY'): ('50.000000000000000000', 9),
(1, 'EKF2_AGP0_NOISE'): ('0.899999976158142090', 9),
(1, 'EKF2_AGP0_GATE'): ('3.000000000000000000', 9),
})
self.assertIn('converted: EKF2_AGP_CTRL 1 ->'
' EKF2_AGP0_CTRL 1, EKF2_AGP0_ID 1', log)
self.assertIn('default: EKF2_AGP_NOISE 0.9 is a v1.17 default,'
' v1.18 uses 1', log)
def test_aux_global_position_id_kept_when_disabled(self):
_, values, log = migrate((1, 'EKF2_AGP_CTRL', '0', 6))
self.assertEqual(values, {(1, 'EKF2_AGP0_CTRL'): ('0', 6)})
self.assertEqual(log, ['converted: EKF2_AGP_CTRL 0 ->'
' EKF2_AGP0_CTRL 0'])
def test_landing_nudging_merged_into_existing_bits(self):
_, values, _ = migrate((1, 'MPC_AUTO_NUDGING', '1', 6),
(1, 'MPC_LAND_RC_HELP', '1', 6))
self.assertEqual(values, {(1, 'MPC_AUTO_NUDGING'): ('3', 6)})
def test_rc_reverse_written_as_integer(self):
_, values, log = migrate((1, 'RC1_REV', '-1.000000000000000000', 9),
(1, 'RC2_REV', '1.000000000000000000', 9),
(1, 'RC3_REV', '-1', 6))
self.assertEqual(values, {(1, 'RC1_REV'): ('-1', 6),
(1, 'RC2_REV'): ('1', 6),
(1, 'RC3_REV'): ('-1', 6)})
self.assertEqual(log, ['reversed: RC1_REV written as the integer -1'])
def test_removed_dropped_and_listed(self):
_, values, log = migrate((1, 'COM_RC_STICK_OV', '30.0', 9),
(1, 'FW_AT_START', '0', 6))
self.assertEqual(values, {})
self.assertEqual(log, [
'removed: COM_RC_STICK_OV 30: see MAN_OVERRIDE_SPD'
' (stick speed in 1/s)',
'removed: FW_AT_START 0'])
def test_old_default_kept_and_listed(self):
_, values, log = migrate((1, 'FD_ACT_EN', '1', 6),
(1, 'SENS_MAG_AUTOCAL', '0', 6))
self.assertEqual(values, {(1, 'FD_ACT_EN'): ('1', 6),
(1, 'SENS_MAG_AUTOCAL'): ('0', 6)})
self.assertEqual(
log, ['default: FD_ACT_EN 1 is a v1.17 default, v1.18 uses 0'])
def test_roboclaw_defaults_replaced(self):
_, values, log = migrate((1, 'RBCLW_DIS1', '128', 6),
(1, 'RBCLW_MAX1', '256', 6),
(1, 'RBCLW_MIN1', '1', 6),
(1, 'RBCLW_FAIL1', '-1', 6))
self.assertEqual(values, {(1, 'RBCLW_DIS1'): ('127', 6),
(1, 'RBCLW_MAX1'): ('254', 6),
(1, 'RBCLW_MIN1'): ('0', 6),
(1, 'RBCLW_FAIL1'): ('-1', 6)})
self.assertEqual(log, [
'replaced: RBCLW_DIS1 128 -> 127, the v1.17 default by the'
' v1.18 default',
'replaced: RBCLW_MAX1 256 -> 254, the v1.17 default by the'
' v1.18 default',
'replaced: RBCLW_MIN1 1 -> 0, the v1.17 default by the'
' v1.18 default'])
def test_roboclaw_set_values_kept_and_listed(self):
_, values, log = migrate((1, 'RBCLW_MAX2', '200', 6),
(1, 'RBCLW_FAIL2', '128', 6))
self.assertEqual(values, {(1, 'RBCLW_MAX2'): ('200', 6),
(1, 'RBCLW_FAIL2'): ('128', 6)})
note = ('RoboClaw outputs use 0 to 254 with stop at 127 in v1.18'
' (v1.17: 0 to 256, stop at 128)')
self.assertEqual(log, [f'check: RBCLW_MAX2 200: {note}',
f'check: RBCLW_FAIL2 128: {note}'])
def test_vehicle_type_default_listed_with_its_scope(self):
_, values, log = migrate(
(1, 'EKF2_REQ_PDOP', '2.500000000000000000', 9))
self.assertEqual(values,
{(1, 'EKF2_REQ_PDOP'): ('2.500000000000000000', 9)})
self.assertEqual(log, ['default: EKF2_REQ_PDOP 2.5 is a v1.17 default,'
' v1.18 uses 4 on fixed-wing'])
def test_other_components_untouched(self):
_, values, log = migrate((1, 'MPC_XY_VEL_MAX', '8.0', 9),
(154, 'EKF2_GPS_DELAY', '150.0', 9))
self.assertEqual(values, {(1, 'MPC_XY_VEL_MAX'): ('8.0', 9),
(154, 'EKF2_GPS_DELAY'): ('150.0', 9)})
self.assertEqual(log, [])
def test_no_autopilot_component_listed(self):
_, values, log = migrate((2, 'EKF2_GPS_DELAY', '150.0', 9))
self.assertEqual(values, {(2, 'EKF2_GPS_DELAY'): ('150.0', 9)})
self.assertEqual(log, ['warning: no parameters of component 1,'
' nothing converted: only an autopilot with'
' MAV_COMP_ID 1 is supported'])
def test_core_heater_removed_with_hint(self):
_, values, log = migrate((1, 'CORE_TEMP_ID', '3014698', 6))
self.assertEqual(values, {})
self.assertEqual(log, ['removed: CORE_TEMP_ID 3014698:'
' see HEATER2_SENS_ID'])
def test_nav_acceptance_radius_listed_for_multicopter(self):
_, _, log = migrate((1, 'NAV_ACC_RAD', '2.000000000000000000', 9))
self.assertEqual(log, ['default: NAV_ACC_RAD 2 is a v1.17 default,'
' v1.18 uses 10 on multicopter, except'
' airframes 4016, 4020 and 24001, which keep'
' 2'])
def test_multi_ekf_defaults_listed_for_skynode(self):
_, values, log = migrate((1, 'EKF2_MULTI_IMU', '3', 6),
(1, 'SENS_IMU_MODE', '0', 6))
self.assertEqual(values, {(1, 'EKF2_MULTI_IMU'): ('3', 6),
(1, 'SENS_IMU_MODE'): ('0', 6)})
self.assertEqual(log, ['default: EKF2_MULTI_IMU 3 is a v1.17 default,'
' v1.18 uses 0 on Skynode',
'default: SENS_IMU_MODE 0 is a v1.17 default,'
' v1.18 uses 1 on Skynode'])
def test_imxrt_defaults_listed(self):
boards = 'on i.MX RT boards (fmu-v6xrt, mr-tropic, tropic-community)'
_, values, log = migrate((1, 'EKF2_MULTI_IMU', '0', 6),
(1, 'SENS_IMU_MODE', '1', 6),
(1, 'IMU_GYRO_FFT_EN', '0', 6),
(1, 'UAVCAN_ENABLE', '0', 6))
self.assertEqual(values, {(1, 'EKF2_MULTI_IMU'): ('0', 6),
(1, 'SENS_IMU_MODE'): ('1', 6),
(1, 'IMU_GYRO_FFT_EN'): ('0', 6),
(1, 'UAVCAN_ENABLE'): ('0', 6)})
self.assertEqual(log, [
f'default: EKF2_MULTI_IMU 0 is a v1.17 default, v1.18 uses 3'
f' {boards}',
f'default: SENS_IMU_MODE 1 is a v1.17 default, v1.18 uses 0'
f' {boards}',
f'default: IMU_GYRO_FFT_EN 0 is a v1.17 default, v1.18 uses 1'
f' {boards}',
f'default: UAVCAN_ENABLE 0 is a v1.17 default, v1.18 uses 2'
f' {boards}'])
def test_board_default_set_by_hand_not_listed(self):
_, _, log = migrate((1, 'EKF2_MULTI_IMU', '2', 6),
(1, 'UAVCAN_ENABLE', '3', 6))
self.assertEqual(log, [])
def test_other_lines_copied_and_listed(self):
log = []
lines = m.migrate(HEADER + ['EKF2_GPS_DELAY,150\n'], log.append)
self.assertEqual(lines, HEADER + ['EKF2_GPS_DELAY,150\n'])
self.assertEqual(log, ['copied unchanged, not in the QGroundControl'
' format: EKF2_GPS_DELAY,150'])
def test_line_without_newline_kept_apart(self):
lines = m.migrate(['# saved by hand'] + params_file(
(1, 'MPC_XY_VEL_MAX', '8.0', 9))[len(HEADER):], lambda _: None)
self.assertEqual(lines, ['# saved by hand\n',
'1\t1\tMPC_XY_VEL_MAX\t8.0\t9\n'])
def test_every_written_parameter_has_a_type(self):
for kind, new, _ in m.CONVERSIONS.values():
for name in (new,) if isinstance(new, str) else new:
self.assertIn(name, m.NEW_TYPES)
def test_firmware_translates_every_converted_parameter(self):
# Catches a translation removed from the firmware, not a changed
# target: main already writes SENS_GNSS*, the script the v1.18 names
with open(TRANSLATION, encoding='utf-8') as f:
source = f.read()
for old in m.CONVERSIONS:
self.assertIn(f'"{old}"', source)
if __name__ == '__main__':
unittest.main()
+9
View File
@@ -158,6 +158,15 @@ For users upgrading from v1.17, please take a moment to review the following bef
PX4 now rejects a `COMMAND_LONG`, `COMMAND_INT` or mission item that sets a value other than `0` or `NaN` in a parameter (1 to 4) that the command does not use: commands are denied with `MAV_RESULT_DENIED` and mission uploads fail with `MAV_MISSION_INVALID_PARAMn`.
([PX4-Autopilot#27541](https://github.com/PX4/PX4-Autopilot/pull/27541))
14. **Check parameter files saved on v1.17 before loading them.**
PX4 migrates renamed parameters only when it upgrades the parameters stored on the vehicle.
Loading a parameter file saved on v1.17 in _QGroundControl_ sets each parameter by name, so values saved under old names such as `EKF2_GPS_DELAY`, `EKF2_GPS_POS_X/Y/Z`, `COM_RC_OVERRIDE` and `MPC_LAND_RC_HELP` are not applied: the parameters that replace them keep their current values (the defaults on a new or reset vehicle).
`RC1_REV` to `RC18_REV` are now integers: _QGroundControl_ v5.1.5 and earlier load a saved `-1.000000` as `0`, so a reversed channel is no longer reversed ([QGC#15357](https://github.com/mavlink/qgroundcontrol/issues/15357)).
_QGroundControl_ saves every parameter, so such a file also restores v1.17 values whose defaults changed, including `FD_ACT_EN` and `SENS_MAG_AUTOCAL`.
[Tools/migrate_param_file.py](https://github.com/PX4/PX4-Autopilot/blob/release/1.18/Tools/migrate_param_file.py) converts such a file for v1.18: it applies the renames, writes `RC*_REV` as integers, drops the removed parameters, replaces the v1.17 RoboClaw output defaults, whose scale changed, and lists the other v1.17 defaults it keeps.
After loading such a file, check the replacement parameters and the direction of every RC channel.
([PX4-Autopilot#26833](https://github.com/PX4/PX4-Autopilot/pull/26833))
## Hardware Support
### New Flight Controllers