feat(logger): append topics defined in logger_topics.txt instead of replacing all (#27462)

* feat(logger): append topics defined in logger_topics.txt instead of replacing logging profile

* docs(logger): Explain how logger_topics.txt topics are being used

* refactor(logger): squash initialize functions into a single one

* docs(docs): Subedit

---------

Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
This commit is contained in:
János Arenhövel
2026-05-29 04:53:31 +02:00
committed by GitHub
parent 1c79648e8d
commit 9ae1e0f04f
4 changed files with 31 additions and 34 deletions

View File

@@ -52,21 +52,27 @@ This allows, for example, logging of your own uORB topics.
### SD Card Configuration ### SD Card Configuration
Separately, the list of logged topics can also be customized with a file on the SD card. The list of logged topics can also be customized with a file on the SD card: `etc/logging/logger_topics.txt` (for SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`).
Create a file `etc/logging/logger_topics.txt` on the card with a list of topics (For SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`):
Each topic to be logged is listed on a separate line, with the following format:
```plain ```plain
<topic_name> <interval> <instance> <topic_name> <interval> <instance>
``` ```
The `<interval>` is optional, and if specified, defines the minimum interval in ms between two logged messages of this topic. Where:
If not specified, the topic is logged at full rate. - `<interval>` (optional).
Defines the minimum interval in ms between two logged messages of this topic.
If not specified or `0`, the topic is logged at full rate.
- `<instance>` (optional).
Defines the instance to log.
NOte that `<interval>` must be specified in order to set `instance`
If not specified, all instances of the topic are logged.
The `<instance>` is optional, and if specified, defines the instance to log. The topics in this file will be added on top of the already selected topics.
If not specified, all instances of the topic are logged. To just log the topics defined in this file, set [SDLOG_PROFILE=0](../advanced_config/parameter_reference.md#SDLOG_PROFILE).
To specify `<instance>`, `<interval>` must be specified. It can be set to 0 to log at full rate If a topic is already included, it will update it's rate.
The topics in this file replace all of the default logged topics.
Example : Example :
@@ -77,7 +83,7 @@ sensor_gyro 200
sensor_mag 200 1 sensor_mag 200 1
``` ```
This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz, all sensor_gyro instances at 5Hz and sensor_mag 1 at 5Hz. This configuration will log sensor_accel 0 at full rate, sensor_accel 1 at 10Hz, all `sensor_gyro` instances at 5Hz and `sensor_mag` 1 at 5Hz.
## Scripts ## Scripts

View File

@@ -558,20 +558,6 @@ bool LoggedTopics::add_topic_multi(const char *name, uint16_t interval_ms, uint8
} }
bool LoggedTopics::initialize_logged_topics(SDLogProfileMask profile) bool LoggedTopics::initialize_logged_topics(SDLogProfileMask profile)
{
int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt");
if (ntopics > 0) {
PX4_INFO("logging %d topics from logger_topics.txt", ntopics);
} else {
initialize_configured_topics(profile);
}
return _subscriptions.count > 0;
}
void LoggedTopics::initialize_configured_topics(SDLogProfileMask profile)
{ {
// load appropriate topics for profile // load appropriate topics for profile
// the order matters: if several profiles add the same topic, the logging rate of the last one will be used // the order matters: if several profiles add the same topic, the logging rate of the last one will be used
@@ -622,4 +608,16 @@ void LoggedTopics::initialize_configured_topics(SDLogProfileMask profile)
if (profile & SDLogProfileMask::HIGH_RATE_SENSORS) { if (profile & SDLogProfileMask::HIGH_RATE_SENSORS) {
add_high_rate_sensors_topics(); add_high_rate_sensors_topics();
} }
int ntopics = add_topics_from_file(PX4_STORAGEDIR "/etc/logging/logger_topics.txt");
if (ntopics > 0) {
PX4_INFO("logging %d topics from logger_topics.txt", ntopics);
} else if ((int32_t)profile == 0) {
PX4_WARN("No logging topics added. Using default set");
add_default_topics();
}
return _subscriptions.count > 0;
} }

View File

@@ -102,6 +102,9 @@ public:
*/ */
void initialize_mission_topics(MissionLogType mission_log_type); void initialize_mission_topics(MissionLogType mission_log_type);
/**
* Add topic subscriptions based on the profile configuration and additional topics from SD card
*/
bool initialize_logged_topics(SDLogProfileMask profile); bool initialize_logged_topics(SDLogProfileMask profile);
const RequestedSubscriptionArray &subscriptions() const { return _subscriptions; } const RequestedSubscriptionArray &subscriptions() const { return _subscriptions; }
@@ -160,11 +163,6 @@ private:
*/ */
void add_mission_topic(const char *name, uint16_t interval_ms = 0); void add_mission_topic(const char *name, uint16_t interval_ms = 0);
/**
* Add topic subscriptions based on the profile configuration
*/
void initialize_configured_topics(SDLogProfileMask profile);
void add_default_topics(); void add_default_topics();
void add_estimator_replay_topics(); void add_estimator_replay_topics();
void add_thermal_calibration_topics(); void add_thermal_calibration_topics();

View File

@@ -507,11 +507,6 @@ bool Logger::initialize_topics()
// get the logging profile // get the logging profile
SDLogProfileMask sdlog_profile = (SDLogProfileMask)_param_sdlog_profile.get(); SDLogProfileMask sdlog_profile = (SDLogProfileMask)_param_sdlog_profile.get();
if ((int32_t)sdlog_profile == 0) {
PX4_WARN("No logging profile selected. Using default set");
sdlog_profile = SDLogProfileMask::DEFAULT;
}
LoggedTopics logged_topics; LoggedTopics logged_topics;
logged_topics.set_rate_factor(_rate_factor); logged_topics.set_rate_factor(_rate_factor);