mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-22 14:19:57 +08:00
feat(mavlink): let boards set the number of MAVLink instances (#29573)
* feat(mavlink): make the MAV_x instance count a per-board Kconfig option MAV_x_* params and rc.serial were fixed at 3, though up to 6 MAVLink instances can run. CONFIG_MAVLINK_NUM_CONFIG_INSTANCES (default 3) sets it; extra instances take instance 2's defaults. Signed-off-by: abhijithcv <abhijithcv1212@gmail.com> * feat(boards/agam): enable 5 MAVLink instances on the v6X-RT Signed-off-by: abhijithcv <abhijithcv1212@gmail.com> * docs(releases): add per-board MAVLink instance count to main release notes Signed-off-by: abhijithcv <abhijithcv1212@gmail.com> * fix(mavlink): share main's --board-config in the instance count generators main already passes the boardconfig as --board-config to generate_params.py, so the duplicate option failed every build after a rebase. Both generators now read it through the shared load_board_config. Kconfig caps the count at 5, or 3 on constrained-memory boards, leaving a channel for USB, and list defaults keep their length check unless the count comes from Kconfig. Signed-off-by: abhijithcv <abhijithcv1212@gmail.com> --------- Signed-off-by: abhijithcv <abhijithcv1212@gmail.com>
This commit is contained in:
1 parent
36572dfd1c
commit
5d9263851e
12 files changed
+91
-22
No files matched your search
@@ -125,6 +125,7 @@ add_custom_command(
|
||||
${romfs_copy_files}
|
||||
${jinja_templates}
|
||||
${module_config_files}
|
||||
${PX4_BINARY_DIR}/px4_boardconfig.h
|
||||
${romfs_cmake_files}
|
||||
${PX4_SOURCE_DIR}/Tools/px_process_airframes.py
|
||||
${PX4_SOURCE_DIR}/Tools/px4airframes/markdownout.py
|
||||
@@ -133,6 +134,7 @@ add_custom_command(
|
||||
${PX4_SOURCE_DIR}/Tools/px4airframes/srcscanner.py
|
||||
${PX4_SOURCE_DIR}/Tools/px4airframes/xmlout.py
|
||||
${PX4_SOURCE_DIR}/Tools/serial/generate_config.py
|
||||
${PX4_SOURCE_DIR}/Tools/module_config/output_groups_from_timer_config.py
|
||||
)
|
||||
|
||||
|
||||
@@ -153,7 +155,8 @@ add_custom_command(
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/serial/generate_config.py
|
||||
--rc-dir ${romfs_gen_root_dir}/init.d
|
||||
--serial-ports ${board_serial_ports} ${added_arguments}
|
||||
--config-files ${module_config_files} #--verbose
|
||||
--config-files ${module_config_files}
|
||||
--board-config ${BOARD_CONFIG} #--verbose
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/filepaths/generate_config.py
|
||||
--rc-dir ${romfs_gen_root_dir}/init.d
|
||||
--params-file ${CONFIG_BOARD_PARAM_FILE}
|
||||
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
|
||||
from output_groups_from_timer_config import get_timer_groups, get_output_groups
|
||||
from output_groups_from_timer_config import get_timer_groups, get_output_groups, load_board_config
|
||||
|
||||
try:
|
||||
import yaml
|
||||
@@ -29,7 +29,7 @@ parser.add_argument('--params-file', type=str, action='store',
|
||||
parser.add_argument('--timer-config', type=str, action='store',
|
||||
help='board-specific timer_config.cpp file')
|
||||
parser.add_argument('--board-config', type=str, action='store',
|
||||
help='board Kconfig boardconfig file, evaluates the timer_config.cpp preprocessor conditionals')
|
||||
help='board Kconfig boardconfig file, evaluates the timer_config.cpp preprocessor conditionals and Kconfig instance counts')
|
||||
parser.add_argument('--ethernet', action='store_true',
|
||||
help='Ethernet support')
|
||||
parser.add_argument('--board', type=str, action='store',
|
||||
@@ -52,6 +52,15 @@ board = args.board
|
||||
root_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../..")
|
||||
output_functions_file = os.path.join(root_dir,"src/lib/mixer_module/output_functions.yaml")
|
||||
|
||||
board_config = load_board_config(args.board_config)
|
||||
|
||||
def get_num_instances(num_instances):
|
||||
""" num_instances is an integer or {kconfig: SYMBOL, default: N} """
|
||||
if isinstance(num_instances, dict):
|
||||
return int(board_config.get('CONFIG_' + num_instances['kconfig'],
|
||||
num_instances['default']))
|
||||
return num_instances
|
||||
|
||||
def process_module_name(module_name):
|
||||
if module_name == '${PWM_MAIN_OR_AUX}':
|
||||
if board_with_io: return 'PWM AUX'
|
||||
@@ -102,7 +111,8 @@ def parse_yaml_parameters_config(yaml_config, ethernet_supported):
|
||||
for param in param_list:
|
||||
if param.get('requires_ethernet', False) and not ethernet_supported:
|
||||
continue
|
||||
num_instances = param.get('num_instances', 1)
|
||||
num_instances_config = param.get('num_instances', 1)
|
||||
num_instances = get_num_instances(num_instances_config)
|
||||
instance_start = param.get('instance_start', 0) # offset
|
||||
instance_start_label = param.get('instance_start_label', instance_start)
|
||||
|
||||
@@ -146,10 +156,13 @@ def parse_yaml_parameters_config(yaml_config, ethernet_supported):
|
||||
# default value
|
||||
default_value = 0
|
||||
if 'default' in param:
|
||||
# default can be a list of num_instances or a single value
|
||||
# default can be a list of num_instances or a single value.
|
||||
# With a Kconfig count, instances past the end of the list
|
||||
# take its last entry.
|
||||
if type(param['default']) == list:
|
||||
assert len(param['default']) == num_instances
|
||||
default_value = param['default'][i]
|
||||
if not isinstance(num_instances_config, dict):
|
||||
assert len(param['default']) == num_instances
|
||||
default_value = param['default'][min(i, len(param['default']) - 1)]
|
||||
else:
|
||||
default_value = param['default']
|
||||
|
||||
|
||||
@@ -78,12 +78,13 @@ def imxrt_is_dshot(line):
|
||||
return False
|
||||
|
||||
def load_board_config(board_config):
|
||||
""" return the set of symbols assigned in a Kconfig .config style file
|
||||
(e.g. the boardconfig the build generates); None gives an empty set """
|
||||
""" return the symbols assigned in a Kconfig .config style file (e.g. the
|
||||
boardconfig the build generates) as a dict of symbol to value, with string
|
||||
quotes stripped; None gives an empty dict """
|
||||
if board_config is None:
|
||||
return set()
|
||||
return {}
|
||||
with open(board_config, 'r') as f:
|
||||
return {m.group(1) for m in (re.match(r'(\w+)=', l) for l in f) if m}
|
||||
return {m.group(1): m.group(2).strip('"') for m in (re.match(r'(\w+)=(.*)', l.strip()) for l in f) if m}
|
||||
|
||||
def preprocess(text, defined):
|
||||
""" return the lines of text the C preprocessor keeps, given the set of defined symbols.
|
||||
|
||||
@@ -5,6 +5,9 @@ import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../module_config'))
|
||||
from output_groups_from_timer_config import load_board_config
|
||||
|
||||
try:
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
except ImportError as e:
|
||||
@@ -162,6 +165,8 @@ parser.add_argument('--params-file', type=str, action='store',
|
||||
help='Parameter output file', default=None)
|
||||
parser.add_argument('--ethernet', action='store_true',
|
||||
help='Ethernet support')
|
||||
parser.add_argument('--board-config', type=str, action='store', default=None,
|
||||
help='board Kconfig boardconfig file, for Kconfig instance counts')
|
||||
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
|
||||
help='Verbose Output')
|
||||
|
||||
@@ -201,6 +206,15 @@ if ethernet_supported:
|
||||
'index': 1000
|
||||
})
|
||||
|
||||
board_config = load_board_config(args.board_config)
|
||||
|
||||
def get_num_instances(num_instances):
|
||||
""" num_instances is an integer or {kconfig: SYMBOL, default: N} """
|
||||
if isinstance(num_instances, dict):
|
||||
return int(board_config.get('CONFIG_' + num_instances['kconfig'],
|
||||
num_instances['default']))
|
||||
return num_instances
|
||||
|
||||
def parse_yaml_serial_config(yaml_config):
|
||||
""" parse the serial_config section from the yaml config file """
|
||||
if 'serial_config' not in yaml_config:
|
||||
@@ -247,7 +261,10 @@ for tag, device in board_ports:
|
||||
# construct commands based on selected board
|
||||
commands = []
|
||||
for serial_command in serial_commands:
|
||||
num_instances = serial_command.get('num_instances', 1)
|
||||
num_instances_config = serial_command.get('num_instances', 1)
|
||||
num_instances = get_num_instances(num_instances_config)
|
||||
# a Kconfig count of 1 still needs ${i} set in the script
|
||||
multi_instance = num_instances > 1 or isinstance(num_instances_config, dict)
|
||||
# TODO: use a loop in the script instead of explicitly enumerating all instances
|
||||
for i in range(num_instances):
|
||||
port_config = serial_command['port_config_param']
|
||||
@@ -264,8 +281,10 @@ for serial_command in serial_commands:
|
||||
default_port = 0 # disabled
|
||||
if 'default' in port_config:
|
||||
if type(port_config['default']) == list:
|
||||
assert len(port_config['default']) == num_instances
|
||||
default_port_str = port_config['default'][i]
|
||||
# with a Kconfig count, instances past the end of the list take its last entry
|
||||
if not isinstance(num_instances_config, dict):
|
||||
assert len(port_config['default']) == num_instances
|
||||
default_port_str = port_config['default'][min(i, len(port_config['default']) - 1)]
|
||||
else:
|
||||
default_port_str = port_config['default']
|
||||
|
||||
@@ -281,7 +300,7 @@ for serial_command in serial_commands:
|
||||
'command': serial_command['command'],
|
||||
'label': serial_command['label'],
|
||||
'instance': i,
|
||||
'multi_instance': num_instances > 1,
|
||||
'multi_instance': multi_instance,
|
||||
'port_param_name': port_param_name,
|
||||
'default_port': default_port,
|
||||
'param_group': port_config['group'],
|
||||
|
||||
@@ -77,6 +77,7 @@ CONFIG_MODULES_LOGGER=y
|
||||
CONFIG_MODULES_MAG_BIAS_ESTIMATOR=y
|
||||
CONFIG_MODULES_MANUAL_CONTROL=y
|
||||
CONFIG_MODULES_MAVLINK=y
|
||||
CONFIG_MAVLINK_NUM_CONFIG_INSTANCES=5
|
||||
CONFIG_MODULES_MC_ATT_CONTROL=y
|
||||
CONFIG_MODULES_MC_AUTOTUNE_ATTITUDE_CONTROL=y
|
||||
CONFIG_MODULES_MC_HOVER_THRUST_ESTIMATOR=y
|
||||
|
||||
@@ -135,6 +135,8 @@ Notes:
|
||||
| LPUART10 | /dev/ttyS6 | TELEM3 |
|
||||
| LPUART11 | /dev/ttyS7 | EXT2 |
|
||||
|
||||
The board has five [MAVLink instances](../peripherals/mavlink_peripherals.md#mavlink-instances) (`MAV_0_CONFIG` to `MAV_4_CONFIG`) rather than the usual three.
|
||||
|
||||
## Radio Control {#radio_control}
|
||||
|
||||
A remote control (RC) radio system is required if you want to _manually_ control your vehicle (PX4 does not require a radio system for autonomous flight modes).
|
||||
|
||||
@@ -12,7 +12,8 @@ The most relevant parameters are described below (the full set are listed in the
|
||||
In order to assign a particular peripheral to a serial port we use the concept of a _MAVLink instance_.
|
||||
|
||||
Each MAVLink instance represents a particular MAVLink configuration that you can apply to a particular port.
|
||||
At time of writing three MAVLink _instances_ are defined, each represented by a parameter [MAV_X_CONFIG](#MAV_X_CONFIG), where X is 0, 1, 2.
|
||||
Most boards define three MAVLink _instances_, each represented by a parameter [MAV_X_CONFIG](#MAV_X_CONFIG), where X is 0, 1, 2.
|
||||
Some boards define more, such as [Agam Autopilot v6X-RT](../flight_controller/agam_v6xrt.md), which has five (X is 0 to 4).
|
||||
|
||||
Each instance has associated parameters that you can use to define the properties of the instance on that port, such as the set of streamed messages (see [MAV_X_MODE](#MAV_X_MODE) below), data rate ([MAV_X_RATE](#MAV_X_RATE)), whether incoming traffic is forwarded to other MAVLink instances ([MAV_X_FORWARD](#MAV_X_FORWARD)), and so on.
|
||||
|
||||
@@ -23,7 +24,7 @@ The number in the name means nothing; you can assign any instance to any port.
|
||||
|
||||
The parameters for each instance are:
|
||||
|
||||
- <a id="MAV_X_CONFIG"></a>[MAV_X_CONFIG](../advanced_config/parameter_reference.md#MAV_0_CONFIG) - Set the serial port (UART) for this instance "X", where X is 0, 1, 2.
|
||||
- <a id="MAV_X_CONFIG"></a>[MAV_X_CONFIG](../advanced_config/parameter_reference.md#MAV_0_CONFIG) - Set the serial port (UART) for this instance "X".
|
||||
It can be any unused port, e.g.: `TELEM2`, `TELEM3`, `GPS2` etc.
|
||||
For more information see [Serial Port Configuration](../peripherals/serial_configuration.md).
|
||||
- <a id="MAV_X_MODE"></a>[MAV_X_MODE](../advanced_config/parameter_reference.md#MAV_0_MODE) - Specify the [MAVLink profile](../mavlink/mavlink_profiles.md) for the instance, such as _Normal_ or _OSD_.
|
||||
|
||||
@@ -192,6 +192,7 @@ Please continue reading for [upgrade instructions](#upgrade-guide).
|
||||
- [SYS_STATUS](https://mavlink.io/en/messages/common.html#SYS_STATUS) now sets the [MAV_SYS_STATUS_EXTENSION_USED](https://mavlink.io/en/messages/common.html#MAV_SYS_STATUS_EXTENSION_USED) flag in `onboard_control_sensors_present` when extended sensor fields are used.
|
||||
- [TIME_ESTIMATE_TO_TARGET](https://mavlink.io/en/messages/common.html#TIME_ESTIMATE_TO_TARGET) reports `safe_return` as `-1` (landed or no estimate) when Return has no time estimate: before Home is set, on the ground unless Return would follow a mission landing, and with [RTL_TYPE](../advanced_config/parameter_reference.md#RTL_TYPE) = 2 or 4 and a valid mission.
|
||||
It used to send `0`, or an undefined value with `RTL_TYPE` 2 and 4.
|
||||
- The number of [MAVLink instances](../peripherals/mavlink_peripherals.md#mavlink-instances) can now be set per board, and the [Agam Autopilot v6X-RT](../flight_controller/agam_v6xrt.md) has five (`MAV_0_CONFIG` to `MAV_4_CONFIG`). ([PX4-Autopilot#29573](https://github.com/PX4/PX4-Autopilot/pull/29573))
|
||||
|
||||
### RC
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ add_custom_command(OUTPUT ${generated_serial_params_file} ${generated_module_par
|
||||
--params-file ${generated_serial_params_file}
|
||||
--serial-ports ${board_serial_ports} ${added_arguments} ${constrained_flash_arg}
|
||||
--config-files ${module_config_files}
|
||||
--board-config ${BOARD_CONFIG}
|
||||
#--verbose
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/module_config/generate_params.py
|
||||
--params-file ${generated_module_params_file}
|
||||
|
||||
@@ -11,6 +11,16 @@ depends on MODULES_MAVLINK
|
||||
---help---
|
||||
Select the Mavlink dialect to generate and use.
|
||||
|
||||
menuconfig MAVLINK_NUM_CONFIG_INSTANCES
|
||||
depends on MODULES_MAVLINK
|
||||
int "Number of MAVLink instance configurations"
|
||||
default 3
|
||||
range 1 3 if BOARD_CONSTRAINED_MEMORY
|
||||
range 1 5
|
||||
---help---
|
||||
Number of MAV_x_* parameter sets. At most 6 MAVLink instances can
|
||||
run at once (4 on constrained-memory boards), and USB takes one.
|
||||
|
||||
menuconfig MAVLINK_UAVCAN_PARAMETERS
|
||||
depends on MODULES_MAVLINK && DRIVERS_UAVCAN
|
||||
bool "Mavlink UAVCAN parameter support"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
__max_num_config_instances: &max_num_config_instances 3
|
||||
__max_num_config_instances: &max_num_config_instances
|
||||
kconfig: MAVLINK_NUM_CONFIG_INSTANCES
|
||||
default: 3
|
||||
|
||||
module_name: MAVLink
|
||||
serial_config:
|
||||
@@ -48,6 +50,7 @@ serial_config:
|
||||
# 0: Telem1 Port (Telemetry Link)
|
||||
# 1: Telem2 Port (Companion Link). Disabled by default to reduce RAM usage
|
||||
# 2: Board-specific / no fixed function or port
|
||||
# 3+: Optional (CONFIG_MAVLINK_NUM_CONFIG_INSTANCES), defaults as instance 2
|
||||
default: [TEL1, "", ""]
|
||||
num_instances: *max_num_config_instances
|
||||
supports_networking: true
|
||||
|
||||
@@ -72,9 +72,23 @@ serial_config:
|
||||
# For multiple instances, '${i}' can be used to refer to
|
||||
# an instance, for example in the parameter name or script
|
||||
# command.
|
||||
# Either an integer, or a Kconfig int symbol (without the
|
||||
# CONFIG_ prefix) that sets the count per board, plus the
|
||||
# count used when the symbol is not set.
|
||||
# A list default shorter than the count repeats its last entry.
|
||||
# Default: 1
|
||||
type: integer
|
||||
min: 1
|
||||
anyof: &num_instances
|
||||
- type: integer
|
||||
min: 1
|
||||
- type: dict
|
||||
schema:
|
||||
kconfig:
|
||||
type: string
|
||||
required: true
|
||||
default:
|
||||
type: integer
|
||||
min: 1
|
||||
required: true
|
||||
supports_networking:
|
||||
# set to true if the module supports networking (UDP)
|
||||
type: boolean
|
||||
@@ -207,9 +221,9 @@ parameters:
|
||||
# For multiple instances, '${i}' can be used to
|
||||
# refer to an instance, for example in the parameter
|
||||
# name or description.
|
||||
# Same format as serial_config num_instances.
|
||||
# Default: 1
|
||||
type: integer
|
||||
min: 1
|
||||
anyof: *num_instances
|
||||
instance_start:
|
||||
# The value of the first instance for multiple
|
||||
# instances, used in '${i}'. If 0, ${i} expands to
|
||||
|
||||
Reference in new issue
Block a user