mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-10-06 09:02:52 +08:00
parameters: support for an optional remote parameter database (#22836)
The voxl2 has a split architecture. PX4 runs on a posix platform and a Qurt platform. The two communicate uorb topics back and forth with the muorb module. But each has it's own parameters database and they need to stay in sync with each other. This PR adds support to keep the 2 parameter databases in sync. The main parameters database running on Linux has file system support while the Qurt one does not. The Linux side is considered the primary and the Qurt side is considered the remote.
This commit is contained in:
@@ -30,3 +30,4 @@ CONFIG_MODULES_SIMULATION_PWM_OUT_SIM=y
|
||||
CONFIG_SYSTEMCMDS_UORB=y
|
||||
CONFIG_SYSTEMCMDS_PARAM=y
|
||||
CONFIG_ORB_COMMUNICATOR=y
|
||||
CONFIG_PARAM_REMOTE=y
|
||||
|
||||
@@ -26,3 +26,4 @@ CONFIG_SYSTEMCMDS_TOPIC_LISTENER=y
|
||||
CONFIG_SYSTEMCMDS_UORB=y
|
||||
CONFIG_SYSTEMCMDS_VER=y
|
||||
CONFIG_ORB_COMMUNICATOR=y
|
||||
CONFIG_PARAM_PRIMARY=y
|
||||
|
||||
@@ -154,6 +154,10 @@ set(msg_files
|
||||
OrbTest.msg
|
||||
OrbTestLarge.msg
|
||||
OrbTestMedium.msg
|
||||
ParameterResetRequest.msg
|
||||
ParameterSetUsedRequest.msg
|
||||
ParameterSetValueRequest.msg
|
||||
ParameterSetValueResponse.msg
|
||||
ParameterUpdate.msg
|
||||
Ping.msg
|
||||
PositionControllerLandingStatus.msg
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# ParameterResetRequest : Used by the primary to reset one or all parameter value(s) on the remote
|
||||
|
||||
uint64 timestamp
|
||||
uint16 parameter_index
|
||||
|
||||
bool reset_all # If this is true then ignore parameter_index
|
||||
|
||||
uint8 ORB_QUEUE_LENGTH = 4
|
||||
@@ -0,0 +1,6 @@
|
||||
# ParameterSetUsedRequest : Used by a remote to update the used flag for a parameter on the primary
|
||||
|
||||
uint64 timestamp
|
||||
uint16 parameter_index
|
||||
|
||||
uint8 ORB_QUEUE_LENGTH = 64
|
||||
@@ -0,0 +1,11 @@
|
||||
# ParameterSetValueRequest : Used by a remote or primary to update the value for a parameter at the other end
|
||||
|
||||
uint64 timestamp
|
||||
uint16 parameter_index
|
||||
|
||||
int32 int_value # Optional value for an integer parameter
|
||||
float32 float_value # Optional value for a float parameter
|
||||
|
||||
uint8 ORB_QUEUE_LENGTH = 32
|
||||
|
||||
# TOPICS parameter_set_value_request parameter_remote_set_value_request parameter_primary_set_value_request
|
||||
@@ -0,0 +1,9 @@
|
||||
# ParameterSetValueResponse : Response to a set value request by either primary or secondary
|
||||
|
||||
uint64 timestamp
|
||||
uint64 request_timestamp
|
||||
uint16 parameter_index
|
||||
|
||||
uint8 ORB_QUEUE_LENGTH = 4
|
||||
|
||||
# TOPICS parameter_set_value_response parameter_remote_set_value_response parameter_primary_set_value_response
|
||||
@@ -630,7 +630,7 @@ int16_t uORB::Manager::process_remote_topic(const char *topic_name)
|
||||
// We didn't find a node so we need to create it via an advertisement
|
||||
PX4_DEBUG("Advertising remote topic %s", topic_name);
|
||||
_remote_topics.insert(topic_name);
|
||||
orb_advertise(topic_ptr, nullptr, topic_ptr->o_queue);
|
||||
orb_advertise(topic_ptr, nullptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
rsource "*/Kconfig"
|
||||
@@ -156,7 +156,23 @@ add_custom_target(parameters_header DEPENDS px4_parameters.hpp)
|
||||
|
||||
set(SRCS)
|
||||
|
||||
list(APPEND SRCS parameters.cpp atomic_transaction.cpp autosave.cpp)
|
||||
list(APPEND SRCS
|
||||
parameters.cpp
|
||||
atomic_transaction.cpp
|
||||
autosave.cpp
|
||||
)
|
||||
|
||||
if(CONFIG_PARAM_PRIMARY)
|
||||
list(APPEND SRCS
|
||||
parameters_primary.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CONFIG_PARAM_REMOTE)
|
||||
list(APPEND SRCS
|
||||
parameters_remote.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
list(APPEND SRCS param_translation_unit_tests.cpp)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
menuconfig PARAM_PRIMARY
|
||||
bool "parameter primary"
|
||||
default n
|
||||
---help---
|
||||
Enable support for the parameter primary in distributed board architectures
|
||||
|
||||
menuconfig PARAM_REMOTE
|
||||
bool "parameter remote"
|
||||
default n
|
||||
---help---
|
||||
Enable support for the parameter remote in distributed board architectures
|
||||
@@ -267,6 +267,18 @@ __EXPORT void param_set_used(param_t param);
|
||||
*/
|
||||
__EXPORT int param_set_no_notification(param_t param, const void *val);
|
||||
|
||||
/**
|
||||
* Set the value of a parameter, but do not update the remote system. This avoids
|
||||
* a set loop between primary and remote.
|
||||
*
|
||||
* @param param A handle returned by param_find or passed by param_foreach.
|
||||
* @param val The value to set; assumed to point to a variable of the parameter type.
|
||||
* For structures, the pointer is assumed to point to a structure to be copied.
|
||||
* @param notify Set this to true for the primary (to send out a param update) and false on client
|
||||
* @return Zero if the parameter's value could be set from a scalar, nonzero otherwise.
|
||||
*/
|
||||
__EXPORT int param_set_no_remote_update(param_t param, const void *val, bool notify);
|
||||
|
||||
/**
|
||||
* Notify the system about parameter changes. Can be used for example after several calls to
|
||||
* param_set_no_notification() to avoid unnecessary system notifications.
|
||||
|
||||
@@ -105,8 +105,10 @@ static DynamicSparseLayer runtime_defaults{&firmware_defaults};
|
||||
DynamicSparseLayer user_config{&runtime_defaults};
|
||||
|
||||
/** parameter update topic handle */
|
||||
#if not defined(CONFIG_PARAM_REMOTE)
|
||||
static orb_advert_t param_topic = nullptr;
|
||||
static unsigned int param_instance = 0;
|
||||
#endif
|
||||
|
||||
static perf_counter_t param_export_perf;
|
||||
static perf_counter_t param_find_perf;
|
||||
@@ -116,6 +118,14 @@ static perf_counter_t param_set_perf;
|
||||
static pthread_mutex_t file_mutex =
|
||||
PTHREAD_MUTEX_INITIALIZER; ///< this protects against concurrent param saves (file or flash access).
|
||||
|
||||
// Support for remote parameter node
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
# include "parameters_primary.h"
|
||||
#endif // CONFIG_PARAM_PRIMARY
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
# include "parameters_remote.h"
|
||||
#endif // CONFIG_PARAM_REMOTE
|
||||
|
||||
void
|
||||
param_init()
|
||||
{
|
||||
@@ -128,14 +138,27 @@ param_init()
|
||||
px4_register_boardct_ioctl(_PARAMIOCBASE, param_ioctl);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
param_primary_init();
|
||||
#endif // CONFIG_PARAM_PRIMARY
|
||||
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
param_remote_init();
|
||||
#endif // CONFIG_PARAM_REMOTE
|
||||
|
||||
#if not defined(CONFIG_PARAM_REMOTE)
|
||||
autosave_instance = new ParamAutosave();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
param_notify_changes()
|
||||
{
|
||||
parameter_update_s pup{};
|
||||
// Don't send if this is a remote node. Only the primary
|
||||
// sends out update notices
|
||||
#if not defined(CONFIG_PARAM_REMOTE)
|
||||
parameter_update_s pup {};
|
||||
pup.instance = param_instance++;
|
||||
pup.get_count = perf_event_count(param_get_perf);
|
||||
pup.set_count = perf_event_count(param_set_perf);
|
||||
@@ -152,6 +175,8 @@ param_notify_changes()
|
||||
} else {
|
||||
orb_publish(ORB_ID(parameter_update), param_topic, &pup);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static param_t param_find_internal(const char *name, bool notification)
|
||||
@@ -372,7 +397,7 @@ param_control_autosave(bool enable)
|
||||
}
|
||||
|
||||
static int
|
||||
param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_changes)
|
||||
param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_changes, bool update_remote = true)
|
||||
{
|
||||
if (!handle_in_range(param)) {
|
||||
PX4_ERR("set invalid param %d", param);
|
||||
@@ -421,6 +446,24 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_
|
||||
param_autosave();
|
||||
}
|
||||
|
||||
// If this is the parameter server, make sure that the remote is updated
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
|
||||
if (param_changed && update_remote) {
|
||||
param_primary_set_value(param, val);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// If this is the parameter remote, make sure that the primary is updated
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
|
||||
if (param_changed && update_remote) {
|
||||
param_remote_set_value(param, val);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
perf_end(param_set_perf);
|
||||
|
||||
/*
|
||||
@@ -456,6 +499,11 @@ int param_set_no_notification(param_t param, const void *val)
|
||||
return param_set_internal(param, val, false, false);
|
||||
}
|
||||
|
||||
int param_set_no_remote_update(param_t param, const void *val, bool notify)
|
||||
{
|
||||
return param_set_internal(param, val, false, notify, false);
|
||||
}
|
||||
|
||||
bool param_used(param_t param)
|
||||
{
|
||||
if (handle_in_range(param)) {
|
||||
@@ -468,6 +516,14 @@ bool param_used(param_t param)
|
||||
void param_set_used(param_t param)
|
||||
{
|
||||
if (handle_in_range(param)) {
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
|
||||
if (!param_used(param)) {
|
||||
param_remote_set_used(param);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
params_active.set(param, true);
|
||||
}
|
||||
}
|
||||
@@ -544,6 +600,11 @@ int param_set_default_value(param_t param, const void *val)
|
||||
|
||||
static int param_reset_internal(param_t param, bool notify = true, bool autosave = true)
|
||||
{
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
// Remote doesn't support reset
|
||||
return false;
|
||||
#endif
|
||||
|
||||
bool param_found = user_config.contains(param);
|
||||
|
||||
if (handle_in_range(param)) {
|
||||
@@ -558,6 +619,10 @@ static int param_reset_internal(param_t param, bool notify = true, bool autosave
|
||||
param_notify_changes();
|
||||
}
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
param_primary_reset(param);
|
||||
#endif
|
||||
|
||||
return param_found;
|
||||
}
|
||||
|
||||
@@ -567,6 +632,11 @@ int param_reset_no_notification(param_t param) { return param_reset_internal(par
|
||||
static void
|
||||
param_reset_all_internal(bool auto_save)
|
||||
{
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
// Remote doesn't support reset
|
||||
return;
|
||||
#endif
|
||||
|
||||
for (param_t param = 0; handle_in_range(param); param++) {
|
||||
param_reset_internal(param, false, false);
|
||||
}
|
||||
@@ -575,6 +645,10 @@ param_reset_all_internal(bool auto_save)
|
||||
param_autosave();
|
||||
}
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
param_primary_reset_all();
|
||||
#endif
|
||||
|
||||
param_notify_changes();
|
||||
}
|
||||
|
||||
@@ -1280,4 +1354,27 @@ void param_print_status()
|
||||
perf_print_counter(param_find_perf);
|
||||
perf_print_counter(param_get_perf);
|
||||
perf_print_counter(param_set_perf);
|
||||
|
||||
#if defined(CONFIG_PARAM_PRIMARY)
|
||||
struct param_primary_counters counts;
|
||||
param_primary_get_counters(&counts);
|
||||
PX4_INFO("set value requests received: %" PRIu32 ", set value responses sent: %" PRIu32,
|
||||
counts.set_value_request_received, counts.set_value_response_sent);
|
||||
PX4_INFO("set value requests sent: %" PRIu32 ", set value responses received: %" PRIu32,
|
||||
counts.set_value_request_sent, counts.set_value_response_received);
|
||||
PX4_INFO("resets sent: %" PRIu32 ", set used requests received: %" PRIu32,
|
||||
counts.reset_sent, counts.set_used_received);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_PARAM_REMOTE)
|
||||
struct param_remote_counters counts;
|
||||
param_remote_get_counters(&counts);
|
||||
PX4_INFO("set value requests received: %" PRIu32 ", set value responses sent: %" PRIu32,
|
||||
counts.set_value_request_received, counts.set_value_response_sent);
|
||||
PX4_INFO("set value requests sent: %" PRIu32 ", set value responses received: %" PRIu32,
|
||||
counts.set_value_request_sent, counts.set_value_response_received);
|
||||
PX4_INFO("resets received: %" PRIu32 ", set used requests sent: %" PRIu32,
|
||||
counts.reset_received, counts.set_used_sent);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "param.h"
|
||||
|
||||
struct param_primary_counters {
|
||||
uint32_t set_value_request_received;
|
||||
uint32_t set_value_response_sent;
|
||||
uint32_t reset_sent;
|
||||
uint32_t set_value_request_sent;
|
||||
uint32_t set_value_response_received;
|
||||
uint32_t set_used_received;
|
||||
};
|
||||
|
||||
void param_primary_init();
|
||||
void param_primary_set_value(param_t param, const void *val);
|
||||
void param_primary_reset(param_t param);
|
||||
void param_primary_reset_all();
|
||||
void param_primary_get_counters(struct param_primary_counters *cnt);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "param.h"
|
||||
|
||||
struct param_remote_counters {
|
||||
uint32_t set_value_request_received;
|
||||
uint32_t set_value_response_sent;
|
||||
uint32_t reset_received;
|
||||
uint32_t set_value_request_sent;
|
||||
uint32_t set_value_response_received;
|
||||
uint32_t set_used_sent;
|
||||
};
|
||||
|
||||
void param_remote_init();
|
||||
void param_remote_set_used(param_t param);
|
||||
void param_remote_set_value(param_t param, const void *val);
|
||||
void param_remote_get_counters(struct param_remote_counters *cnt);
|
||||
Reference in New Issue
Block a user